Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more integration tests #147

Merged
merged 24 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions src/backends/metal/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use {
utils::{
asyncevent::AsyncEvent, bitflags::BitflagsExt, clonecell::CloneCell,
copyhashmap::CopyHashMap, debug_fn::debug_fn, errorfmt::ErrorFmt, numcell::NumCell,
opaque_cell::OpaqueCell, oserror::OsError, syncqueue::SyncQueue,
on_change::OnChange, opaque_cell::OpaqueCell, oserror::OsError,
transform_ext::TransformExt,
},
video::{
Expand Down Expand Up @@ -320,38 +320,6 @@ impl Debug for ConnectorFutures {
}
}

pub struct OnChange<T> {
pub on_change: CloneCell<Option<Rc<dyn Fn()>>>,
pub events: SyncQueue<T>,
}

impl<T> OnChange<T> {
pub fn send_event(&self, event: T) {
self.events.push(event);
if let Some(cb) = self.on_change.get() {
cb();
}
}
}

impl<T> Default for OnChange<T> {
fn default() -> Self {
Self {
on_change: Default::default(),
events: Default::default(),
}
}
}

impl<T> Debug for OnChange<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self.on_change.get() {
None => f.write_str("None"),
Some(_) => f.write_str("Some"),
}
}
}

#[derive(Debug)]
pub struct DirectScanoutCache {
tex: Weak<dyn GfxTexture>,
Expand Down
20 changes: 17 additions & 3 deletions src/ifs/jay_compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {
clonecell::CloneCell,
errorfmt::ErrorFmt,
},
wire::{jay_compositor::*, JayCompositorId},
wire::{jay_compositor::*, JayCompositorId, JayScreenshotId},
},
bstr::ByteSlice,
log::Level,
Expand Down Expand Up @@ -125,14 +125,27 @@ impl JayCompositor {

fn take_screenshot(&self, parser: MsgParser<'_, '_>) -> Result<(), JayCompositorError> {
let req: TakeScreenshot = self.client.parse(self, parser)?;
self.take_screenshot_impl(req.id, false)
}

fn take_screenshot2(&self, parser: MsgParser<'_, '_>) -> Result<(), JayCompositorError> {
let req: TakeScreenshot2 = self.client.parse(self, parser)?;
self.take_screenshot_impl(req.id, req.include_cursor != 0)
}

fn take_screenshot_impl(
&self,
id: JayScreenshotId,
include_cursor: bool,
) -> Result<(), JayCompositorError> {
let ss = Rc::new(JayScreenshot {
id: req.id,
id,
client: self.client.clone(),
tracker: Default::default(),
});
track!(self.client, ss);
self.client.add_client_obj(&ss)?;
match take_screenshot(&self.client.state) {
match take_screenshot(&self.client.state, include_cursor) {
Ok(s) => {
let dmabuf = s.bo.dmabuf();
let plane = &dmabuf.planes[0];
Expand Down Expand Up @@ -347,6 +360,7 @@ object_base! {
CREATE_SCREENCAST => create_screencast,
GET_RANDR => get_randr,
GET_INPUT => get_input,
TAKE_SCREENSHOT2 => take_screenshot2,
}

impl Object for JayCompositor {}
Expand Down
5 changes: 5 additions & 0 deletions src/ifs/wl_seat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,11 @@ impl WlSeatGlobal {
}
}

#[cfg_attr(not(feature = "it"), allow(dead_code))]
pub fn get_desired_known_cursor(&self) -> Option<KnownCursor> {
self.desired_known_cursor.get()
}

pub fn set_known_cursor(&self, cursor: KnownCursor) {
self.desired_known_cursor.set(Some(cursor));
let cursors = match self.state.cursors.get() {
Expand Down
24 changes: 15 additions & 9 deletions src/ifs/wl_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ pub struct WlSurface {
tearing: Cell<bool>,
version: u32,
pub has_content_type_manager: Cell<bool>,
content_type: Cell<Option<ContentType>>,
pub content_type: Cell<Option<ContentType>>,
pub drm_feedback: CopyHashMap<ZwpLinuxDmabufFeedbackV1Id, Rc<ZwpLinuxDmabufFeedbackV1>>,
sync_obj_surface: CloneCell<Option<Rc<WpLinuxDrmSyncobjSurfaceV1>>>,
destroyed: Cell<bool>,
Expand Down Expand Up @@ -553,6 +553,11 @@ impl WlSurface {
Ok(ext.into_xsurface().unwrap())
}

#[cfg_attr(not(feature = "it"), allow(dead_code))]
pub fn get_output(&self) -> Rc<OutputNode> {
self.output.get()
}

pub fn set_output(&self, output: &Rc<OutputNode>) {
let old = self.output.set(output.clone());
if old.id == output.id {
Expand Down Expand Up @@ -910,14 +915,6 @@ impl WlSurface {
release,
};
self.buffer.set(Some(Rc::new(surface_buffer)));
self.buf_x.fetch_add(dx);
self.buf_y.fetch_add(dy);
if (dx, dy) != (0, 0) {
self.need_extents_update.set(true);
for (_, cursor) in &self.cursors {
cursor.dec_hotspot(dx, dy);
}
}
} else {
self.buf_x.set(0);
self.buf_y.set(0);
Expand All @@ -926,6 +923,14 @@ impl WlSurface {
}
}
}
if self.buffer.is_some() && (dx, dy) != (0, 0) {
self.buf_x.fetch_add(dx);
self.buf_y.fetch_add(dy);
self.need_extents_update.set(true);
for (_, cursor) in &self.cursors {
cursor.dec_hotspot(dx, dy);
}
}
let transform_changed = viewport_changed || scale_changed || buffer_transform_changed;
if buffer_changed || transform_changed {
let mut buffer_points = self.buffer_points.borrow_mut();
Expand Down Expand Up @@ -1019,6 +1024,7 @@ impl WlSurface {
{
if let Some(region) = pending.input_region.take() {
self.input_region.set(region);
self.client.state.tree_changed();
}
if let Some(region) = pending.opaque_region.take() {
self.opaque_region.set(region);
Expand Down
2 changes: 1 addition & 1 deletion src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const STATE_TILED_LEFT: u32 = 5;
const STATE_TILED_RIGHT: u32 = 6;
const STATE_TILED_TOP: u32 = 7;
const STATE_TILED_BOTTOM: u32 = 8;
const STATE_SUSPENDED: u32 = 9;
pub const STATE_SUSPENDED: u32 = 9;

#[allow(dead_code)]
const CAP_WINDOW_MENU: u32 = 1;
Expand Down
10 changes: 7 additions & 3 deletions src/it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ mod tests;
const SINGLE_THREAD: bool = false;

pub fn run_tests() {
run_tests_(tests::tests());
}

fn run_tests_(tests: Vec<&'static dyn TestCase>) {
leaks::init();
test_logger::install();
test_logger::set_level(Level::Trace);
Expand All @@ -54,13 +58,13 @@ pub fn run_tests() {
failed: Default::default(),
});
if SINGLE_THREAD {
for test in tests::tests() {
for test in tests {
with_test_config(|cfg| {
run_test(&it_run, test, cfg);
})
}
} else {
let queue = Arc::new(Mutex::new(VecDeque::from_iter(tests::tests())));
let queue = Arc::new(Mutex::new(VecDeque::from_iter(tests)));
let mut threads = vec![];
let num_cpus = match num_cpus() {
Ok(n) => n,
Expand Down Expand Up @@ -139,7 +143,7 @@ fn run_test(it_run: &ItRun, test: &'static dyn TestCase, cfg: Rc<TestConfig>) {
Box::new(async move {
let future: Pin<_> = test.run(testrun.clone()).into();
let future = state.eng.spawn2(Phase::Present, future);
let timeout = state.wheel.timeout(5000);
let timeout = state.wheel.timeout(500000);
match future::select(future, timeout).await {
Either::Left((Ok(..), _)) => {}
Either::Left((Err(e), _)) => {
Expand Down
63 changes: 40 additions & 23 deletions src/it/test_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use {
ScrollAxis, TransformMatrix,
},
compositor::TestFuture,
drm_feedback::DrmFeedback,
fixed::Fixed,
gfx_api::GfxError,
it::test_error::TestResult,
it::{test_error::TestResult, test_utils::test_expected_event::TEEH},
state::State,
time::now_usec,
utils::{
clonecell::CloneCell, copyhashmap::CopyHashMap, oserror::OsError, syncqueue::SyncQueue,
clonecell::CloneCell, copyhashmap::CopyHashMap, on_change::OnChange, oserror::OsError,
syncqueue::SyncQueue,
},
video::drm::{ConnectorType, Drm},
},
Expand All @@ -39,10 +41,12 @@ pub enum TestBackendError {
pub struct TestBackend {
pub state: Rc<State>,
pub test_future: TestFuture,
pub default_monitor_info: MonitorInfo,
pub default_connector: Rc<TestConnector>,
pub default_mouse: Rc<TestBackendMouse>,
pub default_kb: Rc<TestBackendKb>,
pub render_context_installed: Cell<bool>,
pub idle: TEEH<bool>,
}

impl TestBackend {
Expand All @@ -55,7 +59,7 @@ impl TestBackend {
idx: 1,
},
events: Default::default(),
on_change: Default::default(),
feedback: Default::default(),
});
let default_mouse = Rc::new(TestBackendMouse {
common: TestInputDeviceCommon {
Expand Down Expand Up @@ -89,13 +93,29 @@ impl TestBackend {
name: Rc::new("default-keyboard".to_string()),
},
});
let mode = Mode {
width: 800,
height: 600,
refresh_rate_millihz: 60_000,
};
let default_monitor_info = MonitorInfo {
modes: vec![mode],
manufacturer: "jay".to_string(),
product: "TestConnector".to_string(),
serial_number: default_connector.id.to_string(),
initial_mode: mode,
width_mm: 80,
height_mm: 60,
};
Self {
state: state.clone(),
test_future: future,
default_monitor_info,
default_connector,
default_mouse,
default_kb,
render_context_installed: Cell::new(false),
idle: Rc::new(Default::default()),
}
}

Expand All @@ -113,22 +133,9 @@ impl TestBackend {
self.state
.backend_events
.push(BackendEvent::NewConnector(self.default_connector.clone()));
let mode = Mode {
width: 800,
height: 600,
refresh_rate_millihz: 60_000,
};
self.default_connector
.events
.push(ConnectorEvent::Connected(MonitorInfo {
modes: vec![mode],
manufacturer: "jay".to_string(),
product: "TestConnector".to_string(),
serial_number: self.default_connector.id.to_string(),
initial_mode: mode,
width_mm: 80,
height_mm: 60,
}));
.send_event(ConnectorEvent::Connected(self.default_monitor_info.clone()));
self.state
.backend_events
.push(BackendEvent::NewInputDevice(self.default_kb.clone()));
Expand Down Expand Up @@ -205,7 +212,9 @@ impl Backend for TestBackend {
let _ = vtnr;
}

fn set_idle(&self, _idle: bool) {}
fn set_idle(&self, idle: bool) {
self.idle.push(idle);
}

fn supports_presentation_feedback(&self) -> bool {
true
Expand All @@ -215,8 +224,8 @@ impl Backend for TestBackend {
pub struct TestConnector {
pub id: ConnectorId,
pub kernel_id: ConnectorKernelId,
pub events: SyncQueue<ConnectorEvent>,
pub on_change: CloneCell<Option<Rc<dyn Fn()>>>,
pub events: OnChange<ConnectorEvent>,
pub feedback: CloneCell<Option<Rc<DrmFeedback>>>,
}

impl Connector for TestConnector {
Expand All @@ -229,11 +238,11 @@ impl Connector for TestConnector {
}

fn event(&self) -> Option<ConnectorEvent> {
self.events.pop()
self.events.events.pop()
}

fn on_change(&self, cb: Rc<dyn Fn()>) {
self.on_change.set(Some(cb));
self.events.on_change.set(Some(cb));
}

fn damage(&self) {
Expand All @@ -247,6 +256,10 @@ impl Connector for TestConnector {
fn set_mode(&self, _mode: Mode) {
// todo
}

fn drm_feedback(&self) -> Option<Rc<DrmFeedback>> {
self.feedback.get()
}
}

pub struct TestMouseClick {
Expand Down Expand Up @@ -319,13 +332,17 @@ impl TestBackendMouse {
}

pub fn scroll_px(&self, dy: i32) {
self.scroll_px2(dy, false);
}

pub fn scroll_px2(&self, dy: i32, inverted: bool) {
self.common.event(InputEvent::AxisSource {
source: AxisSource::Finger,
});
self.common.event(InputEvent::AxisPx {
dist: Fixed::from_int(dy),
axis: ScrollAxis::Vertical,
inverted: false,
inverted,
});
self.common.event(InputEvent::AxisFrame {
time_usec: now_usec(),
Expand Down
Loading
Loading