aboutsummaryrefslogtreecommitdiff
path: root/rtic-time/tests/timer_queue.rs
diff options
context:
space:
mode:
authorGravatar Finomnis <Finomnis@users.noreply.github.com> 2023-12-01 08:59:22 +0100
committerGravatar GitHub <noreply@github.com> 2023-12-01 07:59:22 +0000
commit612a47ef4d09da3553145d77bf1750314bbb7b16 (patch)
tree7f6f6beca7e0c81397994b4f835c6a7f0bbee331 /rtic-time/tests/timer_queue.rs
parent9f5820da1d36a8c84455b1bc0458d34eb7dd9a70 (diff)
downloadrtic-612a47ef4d09da3553145d77bf1750314bbb7b16.tar.gz
rtic-612a47ef4d09da3553145d77bf1750314bbb7b16.tar.zst
rtic-612a47ef4d09da3553145d77bf1750314bbb7b16.zip
Fix mono delay (#843)
* rtic-time: Compenstate for timer uncertainty * Update changelog and incorrect cargo.lock in an example * Fix Monotonic impls * Fix tests * Fix other monotonics, again * Update changelog * Fix example * Fix DelayUs and DelayMs impls * Minor coding style fix in u64 conversions * Fix all changelogs * Fix changelog * Fix blocking DelayUs * Minor monotonic rework * Add delay precision test * Add more tests * Add rust-version tags to Cargo.toml * Fix imxrt, rp2040 and systick timer * Fix more monotonics * Fix systick monotonic * Some reverts * Fix imxrt * Fix nrf * Fix rp2040 * Fix stm32 * Fix systick * Fix rtic-time tests * Bump to e-h.rc2 * Apply e-h.rc2 fixes to rtic-time * Apply fixes from arbiter * Fix clippy warning * Minor beautification * Revert previous changes * Fix variable name * Add blocking tests, but disable them by default
Diffstat (limited to 'rtic-time/tests/timer_queue.rs')
-rw-r--r--rtic-time/tests/timer_queue.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/rtic-time/tests/timer_queue.rs b/rtic-time/tests/timer_queue.rs
index 9ad71757..8bae3853 100644
--- a/rtic-time/tests/timer_queue.rs
+++ b/rtic-time/tests/timer_queue.rs
@@ -17,7 +17,7 @@ static NOW: Mutex<Option<Instant>> = Mutex::new(None);
pub struct Duration(u64);
impl Duration {
- pub fn from_ticks(millis: u64) -> Self {
+ pub const fn from_ticks(millis: u64) -> Self {
Self(millis)
}
@@ -161,6 +161,7 @@ impl TestMono {
impl Monotonic for TestMono {
const ZERO: Self::Instant = Instant::ZERO;
+ const TICK_PERIOD: Self::Duration = Duration::from_ticks(1);
type Instant = Instant;
@@ -210,7 +211,8 @@ fn timer_queue() {
let elapsed = start.elapsed().as_ticks();
println!("{total_millis} ticks delay reached after {elapsed} ticks");
- if elapsed != total_millis {
+ // Expect a delay of one longer, to compensate for timer uncertainty
+ if elapsed != total_millis + 1 {
panic!(
"{total_millis} ticks delay was not on time ({elapsed} ticks passed instead)"
);
@@ -263,25 +265,25 @@ fn timer_queue() {
if Instant::now() == 0.into() {
// First, we want to be waiting for our 300 tick delay
- assert_eq!(TestMono::compare(), Some(300.into()));
+ assert_eq!(TestMono::compare(), Some(301.into()));
}
if Instant::now() == 100.into() {
// After 100 ticks, we enqueue a new delay that is supposed to last
// until the 200-tick-mark
- assert_eq!(TestMono::compare(), Some(200.into()));
+ assert_eq!(TestMono::compare(), Some(201.into()));
}
- if Instant::now() == 200.into() {
+ if Instant::now() == 201.into() {
// After 200 ticks, we dequeue the 200-tick-mark delay and
// requeue the 300 tick delay
- assert_eq!(TestMono::compare(), Some(300.into()));
+ assert_eq!(TestMono::compare(), Some(301.into()));
}
- if Instant::now() == 300.into() {
+ if Instant::now() == 301.into() {
// After 300 ticks, we dequeue the 300-tick-mark delay and
// go to the 400 tick delay that is already enqueued
- assert_eq!(TestMono::compare(), Some(400.into()));
+ assert_eq!(TestMono::compare(), Some(401.into()));
}
}