From 4b6bf0a4adc034c0cfcfd55e3645f73d61d76d33 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Mon, 26 Dec 2022 21:34:09 -0500 Subject: [PATCH] improved test --- zssp/src/counter.rs | 3 ++- zssp/src/tests.rs | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/zssp/src/counter.rs b/zssp/src/counter.rs index af0b8f2eb..66b215ed0 100644 --- a/zssp/src/counter.rs +++ b/zssp/src/counter.rs @@ -142,6 +142,7 @@ impl CounterWindow { //atomic instructions are only ever atomic within themselves; //sequentially consistent atomics do not guarantee that the thread is not preempted between individual atomic instructions if let Some(history) = self.0.lock().unwrap().as_mut() { + const NONCE_MAX_DELTA: i64 = (2*COUNTER_MAX_ALLOWED_OOO as i64).wrapping_shl(32); let mut is_in = false; let mut idx = 0; let mut smallest = fragment_nonce; @@ -154,7 +155,7 @@ impl CounterWindow { idx = i; } } - if !is_in & (smallest != fragment_nonce) { + if !is_in & (smallest != fragment_nonce) & ((fragment_nonce as i64).wrapping_sub(smallest as i64) < NONCE_MAX_DELTA) { history[idx] = fragment_nonce; return true } diff --git a/zssp/src/tests.rs b/zssp/src/tests.rs index a58d23498..07a1375e1 100644 --- a/zssp/src/tests.rs +++ b/zssp/src/tests.rs @@ -229,7 +229,7 @@ mod tests { #[test] fn counter_window() { let sqrt_out_of_order_max = (COUNTER_MAX_ALLOWED_OOO as f32).sqrt() as u32; - let mut rng = 8234; + let mut rng = 1027;//8234 let mut counter = u32::MAX - 16; let mut fragment_no: u8 = 0; let mut history = Vec::<(u32, u8)>::new(); @@ -239,26 +239,33 @@ mod tests { let p = xorshift64(&mut rng)%1000; let c; let f; - if p < 250 { + if p < 200 { let r = xorshift64(&mut rng); c = counter.wrapping_add(r%sqrt_out_of_order_max); f = fragment_no + 1 + ((r/sqrt_out_of_order_max)%sqrt_out_of_order_max) as u8; - } else if p < 500 { + } else if p < 400 { if history.len() > 0 { let idx = xorshift64(&mut rng) as usize%history.len(); let (c, f) = history[idx]; assert!(!w.message_received(c, f)); } continue; - } else if p < 750 { + } else if p < 650 { fragment_no = u8::min(fragment_no + 1, 63); c = counter; f = fragment_no; - } else if p < 999 { + } else if p < 900 { counter = counter.wrapping_add(1); fragment_no = 0; c = counter; f = fragment_no; + } else if p < 999 { + c = xorshift64(&mut rng); + f = (xorshift64(&mut rng)%64) as u8; + if w.message_received(c, f) { + history.push((c, f)); + } + continue; } else { //simulate rekeying counter = xorshift64(&mut rng);