Skip to content

Commit 27de459

Browse files
committed
test(time_misc): add some tests for adjust_time
- `adjust_time(0)` should be no-op - `adjust_time` is disallowed when CPU Lock is active Achieves 100% line coverage in `timeout.rs` (excluding `Debug::fmt` and inlined functions, the latter of which can't be reliably measured by `cargo-cov`).
1 parent 412501f commit 27de459

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/constance_test_suite/src/kernel_tests/time_misc.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ fn task_body<System: Kernel, D: Driver<App<System>>>(_: usize) {
5151
System::set_time(now),
5252
Err(constance::kernel::TimeError::BadContext)
5353
);
54+
assert_eq!(
55+
System::adjust_time(Duration::ZERO),
56+
Err(constance::kernel::AdjustTimeError::BadContext)
57+
);
5458
unsafe { System::release_cpu_lock().unwrap() };
5559

5660
// System time should wrap around
@@ -68,6 +72,15 @@ fn task_body<System: Kernel, D: Driver<App<System>>>(_: usize) {
6872
log::trace!("time = {:?} (expected >= {:?})", now4_got, now4);
6973
assert!(now4_got.as_micros() >= now4.as_micros());
7074

75+
// `adjust_time(0)` is no-op
76+
System::adjust_time(Duration::ZERO).unwrap();
77+
78+
let now5 = now4_got;
79+
let now5_got = System::time().unwrap();
80+
log::trace!("time = {:?} (expected {:?})", now5_got, now5);
81+
assert!(now5_got.as_micros() >= now5.as_micros());
82+
assert!(now5_got.as_micros() <= now5.as_micros() + 100_000);
83+
7184
// Out-of-range duration
7285
assert_eq!(
7386
System::sleep(Duration::from_micros(-1)),

0 commit comments

Comments
 (0)