From 51bccf32af8d20742704a16f98316f775fa41d2a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 17 Feb 2024 00:21:30 +0100 Subject: [PATCH] fnished test verification helper --- satrs/src/pus/verification.rs | 112 +++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 16 deletions(-) diff --git a/satrs/src/pus/verification.rs b/satrs/src/pus/verification.rs index 98ba223..ae61c64 100644 --- a/satrs/src/pus/verification.rs +++ b/satrs/src/pus/verification.rs @@ -1430,21 +1430,28 @@ pub mod tests { pub accepted: Option, pub started: Option, pub step: u32, + pub step_status: Option, pub completed: Option, + pub failure_data: Option>, + pub fail_enum: Option>, } + pub struct TestVerificationReporter { - verification_map: HashMap, + pub verification_map: RefCell>, } impl VerificationReportingProvider for TestVerificationReporter { fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken { - self.verification_map.insert( + self.verification_map.borrow_mut().insert( req_id, VerificationStatus { accepted: None, started: None, step: 0, + step_status: None, completed: None, + failure_data: None, + fail_enum: None, }, ); VerificationToken { @@ -1456,12 +1463,22 @@ pub mod tests { fn acceptance_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + _time_stamp: Option<&[u8]>, ) -> Result< VerificationToken, super::VerificationOrSendErrorWithToken, > { - todo!() + match self.verification_map.borrow_mut().get_mut(&token.req_id) { + Some(entry) => entry.accepted = Some(true), + None => panic!( + "unexpected acceptance success for request ID {}", + token.req_id() + ), + }; + Ok(VerificationToken { + state: core::marker::PhantomData, + req_id: token.req_id, + }) } fn acceptance_failure( @@ -1469,18 +1486,37 @@ pub mod tests { token: VerificationToken, params: FailParams, ) -> Result<(), super::VerificationOrSendErrorWithToken> { - todo!() + match self.verification_map.borrow_mut().get_mut(&token.req_id) { + Some(entry) => { + entry.accepted = Some(false); + entry.failure_data = params.failure_data.map(|v| v.to_vec()); + // TODO: Enable this after the spacepackets update. + // entry.fail_enum= params.failure_code.to_vec(); + } + None => panic!( + "unexpected acceptance failure for request ID {}", + token.req_id() + ), + }; + Ok(()) } fn start_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + _time_stamp: Option<&[u8]>, ) -> Result< VerificationToken, super::VerificationOrSendErrorWithToken, > { - todo!() + match self.verification_map.borrow_mut().get_mut(&token.req_id) { + Some(entry) => entry.started = Some(true), + None => panic!("unexpected start success for request ID {}", token.req_id()), + }; + Ok(VerificationToken { + state: core::marker::PhantomData, + req_id: token.req_id, + }) } fn start_failure( @@ -1488,32 +1524,64 @@ pub mod tests { token: VerificationToken, params: FailParams, ) -> Result<(), super::VerificationOrSendErrorWithToken> { - todo!() + match self.verification_map.borrow_mut().get_mut(&token.req_id) { + Some(entry) => { + entry.started = Some(false); + entry.failure_data = params.failure_data.map(|v| v.to_vec()); + // TODO: Enable this after the spacepackets update. + // entry.fail_enum= params.failure_code.to_vec(); + } + None => panic!("unexpected start failure for request ID {}", token.req_id()), + }; + Ok(()) } fn step_success( &self, token: &VerificationToken, - time_stamp: Option<&[u8]>, - step: impl spacepackets::ecss::EcssEnumeration, + _time_stamp: Option<&[u8]>, + _step: impl spacepackets::ecss::EcssEnumeration, ) -> Result<(), EcssTmtcError> { - todo!() + match self.verification_map.borrow_mut().get_mut(&token.req_id) { + Some(entry) => { + // TODO: Enable this after the spacepackets update. + // entry.step = Some(step.value()), + entry.step_status = Some(true); + } + None => panic!("unexpected start success for request ID {}", token.req_id()), + }; + Ok(()) } fn step_failure( &self, token: VerificationToken, - params: FailParamsWithStep, + _params: FailParamsWithStep, ) -> Result<(), super::VerificationOrSendErrorWithToken> { - todo!() + match self.verification_map.borrow_mut().get_mut(&token.req_id) { + Some(entry) => { + // TODO: Enable this after the spacepackets update. + // entry.step = Some(step.value()), + entry.step_status = Some(false); + } + None => panic!("unexpected start success for request ID {}", token.req_id()), + }; + Ok(()) } fn completion_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + _time_stamp: Option<&[u8]>, ) -> Result<(), super::VerificationOrSendErrorWithToken> { - todo!() + match self.verification_map.borrow_mut().get_mut(&token.req_id) { + Some(entry) => entry.completed = Some(true), + None => panic!( + "unexpected acceptance success for request ID {}", + token.req_id() + ), + }; + Ok(()) } fn completion_failure( @@ -1521,7 +1589,19 @@ pub mod tests { token: VerificationToken, params: FailParams, ) -> Result<(), super::VerificationOrSendErrorWithToken> { - todo!() + match self.verification_map.borrow_mut().get_mut(&token.req_id) { + Some(entry) => { + entry.completed = Some(false); + entry.failure_data = params.failure_data.map(|v| v.to_vec()); + // TODO: Enable this after the spacepackets update. + // entry.fail_enum= params.failure_code.to_vec(); + } + None => panic!( + "unexpected acceptance success for request ID {}", + token.req_id() + ), + }; + Ok(()) } }