Skip to content

Commit

Permalink
it: test idle timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Apr 3, 2024
1 parent 017775e commit 38abb22
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/it/test_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -46,6 +46,7 @@ pub struct TestBackend {
pub default_mouse: Rc<TestBackendMouse>,
pub default_kb: Rc<TestBackendKb>,
pub render_context_installed: Cell<bool>,
pub idle: TEEH<bool>,
}

impl TestBackend {
Expand Down Expand Up @@ -114,6 +115,7 @@ impl TestBackend {
default_mouse,
default_kb,
render_context_installed: Cell::new(false),
idle: Rc::new(Default::default()),
}
}

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/it/test_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 _),
Expand Down
2 changes: 2 additions & 0 deletions src/it/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,5 +122,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> {
t0033_float_size_memoization,
t0034_workspace_restoration,
t0035_scanout_feedback,
t0036_idle,
}
}
30 changes: 30 additions & 0 deletions src/it/tests/t0036_idle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use {
crate::it::{
test_error::{TestErrorExt, TestResult},
testrun::TestRun,
},
std::{rc::Rc, time::Duration},
};

testcase!();

async fn test(run: Rc<TestRun>) -> 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(())
}

0 comments on commit 38abb22

Please sign in to comment.