From 38abb2260679aea55c618162b951582e9a8a6d96 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 3 Apr 2024 16:06:35 +0200 Subject: [PATCH] it: test idle timeout --- src/it/test_backend.rs | 8 ++++++-- src/it/test_config.rs | 6 +++++- src/it/tests.rs | 2 ++ src/it/tests/t0036_idle.rs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/it/tests/t0036_idle.rs diff --git a/src/it/test_backend.rs b/src/it/test_backend.rs index 0c75066b..b1be7de0 100644 --- a/src/it/test_backend.rs +++ b/src/it/test_backend.rs @@ -11,7 +11,7 @@ use { 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::{ @@ -46,6 +46,7 @@ pub struct TestBackend { pub default_mouse: Rc, pub default_kb: Rc, pub render_context_installed: Cell, + pub idle: TEEH, } impl TestBackend { @@ -114,6 +115,7 @@ impl TestBackend { default_mouse, default_kb, render_context_installed: Cell::new(false), + idle: Rc::new(Default::default()), } } @@ -210,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 diff --git a/src/it/test_config.rs b/src/it/test_config.rs index 5e2a9ae0..377387d3 100644 --- a/src/it/test_config.rs +++ b/src/it/test_config.rs @@ -19,7 +19,7 @@ use { video::{Connector, Transform}, Axis, Direction, }, - std::{cell::Cell, ops::Deref, ptr, rc::Rc}, + std::{cell::Cell, ops::Deref, ptr, rc::Rc, time::Duration}, }; pub static TEST_CONFIG_ENTRY: ConfigEntry = ConfigEntry { @@ -246,6 +246,10 @@ impl TestConfig { }) } + pub fn set_idle(&self, timeout: Duration) -> TestResult { + self.send(ClientMessage::SetIdle { timeout }) + } + pub fn set_floating(&self, seat: SeatId, floating: bool) -> TestResult { self.send(ClientMessage::SetFloating { seat: Seat(seat.raw() as _), diff --git a/src/it/tests.rs b/src/it/tests.rs index 1ceadc89..882a0e10 100644 --- a/src/it/tests.rs +++ b/src/it/tests.rs @@ -67,6 +67,7 @@ mod t0032_data_control; mod t0033_float_size_memoization; mod t0034_workspace_restoration; mod t0035_scanout_feedback; +mod t0036_idle; pub trait TestCase: Sync { fn name(&self) -> &'static str; @@ -121,5 +122,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> { t0033_float_size_memoization, t0034_workspace_restoration, t0035_scanout_feedback, + t0036_idle, } } diff --git a/src/it/tests/t0036_idle.rs b/src/it/tests/t0036_idle.rs new file mode 100644 index 00000000..0d87dd50 --- /dev/null +++ b/src/it/tests/t0036_idle.rs @@ -0,0 +1,30 @@ +use { + crate::it::{ + test_error::{TestErrorExt, TestResult}, + testrun::TestRun, + }, + std::{rc::Rc, time::Duration}, +}; + +testcase!(); + +async fn test(run: Rc) -> TestResult { + let ds = run.create_default_setup().await?; + + run.cfg.set_idle(Duration::from_micros(100))?; + + let idle = run.backend.idle.expect()?; + tassert!(idle.next().is_err()); + + run.state.wheel.timeout(3).await?; + + tassert_eq!(idle.next().with_context(|| "idle")?, true); + tassert!(idle.next().is_err()); + + ds.mouse.rel(1.0, 1.0); + run.state.eng.yield_now().await; + + tassert_eq!(idle.next().with_context(|| "wake")?, false); + + Ok(()) +}