fix: Disable asserts that rely on timing characteristics during coverage testing

This commit is contained in:
Karolin Varner
2024-12-18 13:16:47 +01:00
committed by David Niehues
parent 00696321ff
commit d398ad369e
4 changed files with 41 additions and 26 deletions

View File

@@ -20,3 +20,6 @@ memsec = { workspace = true }
[dev-dependencies] [dev-dependencies]
rand = "0.8.5" rand = "0.8.5"
[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(coverage)'] }

View File

@@ -113,9 +113,10 @@ mod tests {
// Pearson correlation // Pearson correlation
let correlation = cv / (sd_x * sd_y); let correlation = cv / (sd_x * sd_y);
println!("correlation: {:.6?}", correlation); println!("correlation: {:.6?}", correlation);
#[cfg(not(coverage))]
assert!( assert!(
correlation.abs() < 0.01, correlation.abs() < 0.01,
"execution time correlates with result" "execution time correlates with result"
) );
} }
} }

View File

@@ -91,3 +91,6 @@ experiment_api = [
internal_signal_handling_for_coverage_reports = ["signal-hook"] internal_signal_handling_for_coverage_reports = ["signal-hook"]
internal_testing = [] internal_testing = []
internal_bin_gen_ipc_msg_types = ["hex", "heck"] internal_bin_gen_ipc_msg_types = ["hex", "heck"]
[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(coverage)'] }

View File

@@ -2,11 +2,9 @@
use std::{ use std::{
borrow::{Borrow, BorrowMut}, borrow::{Borrow, BorrowMut},
collections::VecDeque, collections::VecDeque,
fmt::{Debug, Write}, ops::DerefMut,
ops::{DerefMut, RangeBounds},
}; };
use rand::distributions::uniform::SampleBorrow;
use rosenpass_cipher_traits::Kem; use rosenpass_cipher_traits::Kem;
use rosenpass_ciphers::kem::StaticKem; use rosenpass_ciphers::kem::StaticKem;
use rosenpass_util::result::OkExt; use rosenpass_util::result::OkExt;
@@ -28,48 +26,53 @@ fn test_successful_exchange_with_poll() -> anyhow::Result<()> {
sim.poll_loop(150)?; // Poll 75 times sim.poll_loop(150)?; // Poll 75 times
let transcript = sim.transcript; let transcript = sim.transcript;
let completions: Vec<_> = transcript let _completions: Vec<_> = transcript
.iter() .iter()
.filter(|elm| matches!(elm, (_, TranscriptEvent::CompletedExchange(_)))) .filter(|elm| matches!(elm, (_, TranscriptEvent::CompletedExchange(_))))
.collect(); .collect();
#[cfg(not(coverage))]
assert!( assert!(
!completions.is_empty(), !_completions.is_empty(),
"\ "\
Should have performed a successful key exchanged!\n\ Should have performed a successful key exchanged!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
" "
); );
#[cfg(not(coverage))]
assert!( assert!(
completions[0].0 < 20.0, _completions[0].0 < 20.0,
"\ "\
First key exchange should happen in under twenty seconds!\n\ First key exchange should happen in under twenty seconds!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
" "
); );
#[cfg(not(coverage))]
assert!( assert!(
completions.len() >= 3, _completions.len() >= 3,
"\ "\
Should have at least two renegotiations!\n\ Should have at least two renegotiations!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
" "
); );
#[cfg(not(coverage))]
assert!( assert!(
(110.0..175.0).contains(&completions[1].0), (110.0..175.0).contains(&_completions[1].0),
"\ "\
First renegotiation should happen in between two and three minutes!\n\ First renegotiation should happen in between two and three minutes!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
" "
); );
assert!((110.0..175.0).contains(&(completions[2].0 - completions[1].0)), "\ #[cfg(not(coverage))]
assert!((110.0..175.0).contains(&(_completions[2].0 - _completions[1].0)), "\
First renegotiation should happen in between two and three minutes after the first renegotiation!\n\ First renegotiation should happen in between two and three minutes after the first renegotiation!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
"); ");
Ok(()) Ok(())
@@ -106,48 +109,53 @@ fn test_successful_exchange_under_packet_loss() -> anyhow::Result<()> {
} }
let transcript = sim.transcript; let transcript = sim.transcript;
let completions: Vec<_> = transcript let _completions: Vec<_> = transcript
.iter() .iter()
.filter(|elm| matches!(elm, (_, TranscriptEvent::CompletedExchange(_)))) .filter(|elm| matches!(elm, (_, TranscriptEvent::CompletedExchange(_))))
.collect(); .collect();
#[cfg(not(coverage))]
assert!( assert!(
!completions.is_empty(), !_completions.is_empty(),
"\ "\
Should have performed a successful key exchanged!\n\ Should have performed a successful key exchanged!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
" "
); );
#[cfg(not(coverage))]
assert!( assert!(
completions[0].0 < 10.0, _completions[0].0 < 10.0,
"\ "\
First key exchange should happen in under twenty seconds!\n\ First key exchange should happen in under twenty seconds!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
" "
); );
#[cfg(not(coverage))]
assert!( assert!(
completions.len() >= 3, _completions.len() >= 3,
"\ "\
Should have at least two renegotiations!\n\ Should have at least two renegotiations!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
" "
); );
#[cfg(not(coverage))]
assert!( assert!(
(110.0..175.0).contains(&completions[1].0), (110.0..175.0).contains(&_completions[1].0),
"\ "\
First renegotiation should happen in between two and three minutes!\n\ First renegotiation should happen in between two and three minutes!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
" "
); );
assert!((110.0..175.0).contains(&(completions[2].0 - completions[1].0)), "\ #[cfg(not(coverage))]
assert!((110.0..175.0).contains(&(_completions[2].0 - _completions[1].0)), "\
First renegotiation should happen in between two and three minutes after the first renegotiation!\n\ First renegotiation should happen in between two and three minutes after the first renegotiation!\n\
Transcript: {transcript:?}\n\ Transcript: {transcript:?}\n\
Completions: {completions:?}\ Completions: {_completions:?}\
"); ");
Ok(()) Ok(())