fnished test verification helper

This commit is contained in:
Robin Müller 2024-02-17 00:21:30 +01:00
parent 931c37be7a
commit 51bccf32af
Signed by: muellerr
GPG Key ID: A649FB78196E3849

View File

@ -1430,21 +1430,28 @@ pub mod tests {
pub accepted: Option<bool>, pub accepted: Option<bool>,
pub started: Option<bool>, pub started: Option<bool>,
pub step: u32, pub step: u32,
pub step_status: Option<bool>,
pub completed: Option<bool>, pub completed: Option<bool>,
pub failure_data: Option<Vec<u8>>,
pub fail_enum: Option<Vec<u8>>,
} }
pub struct TestVerificationReporter { pub struct TestVerificationReporter {
verification_map: HashMap<RequestId, VerificationStatus>, pub verification_map: RefCell<HashMap<RequestId, VerificationStatus>>,
} }
impl VerificationReportingProvider for TestVerificationReporter { impl VerificationReportingProvider for TestVerificationReporter {
fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone> { fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone> {
self.verification_map.insert( self.verification_map.borrow_mut().insert(
req_id, req_id,
VerificationStatus { VerificationStatus {
accepted: None, accepted: None,
started: None, started: None,
step: 0, step: 0,
step_status: None,
completed: None, completed: None,
failure_data: None,
fail_enum: None,
}, },
); );
VerificationToken { VerificationToken {
@ -1456,12 +1463,22 @@ pub mod tests {
fn acceptance_success( fn acceptance_success(
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
time_stamp: Option<&[u8]>, _time_stamp: Option<&[u8]>,
) -> Result< ) -> Result<
VerificationToken<super::TcStateAccepted>, VerificationToken<super::TcStateAccepted>,
super::VerificationOrSendErrorWithToken<TcStateNone>, super::VerificationOrSendErrorWithToken<TcStateNone>,
> { > {
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( fn acceptance_failure(
@ -1469,18 +1486,37 @@ pub mod tests {
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
params: FailParams, params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<TcStateNone>> { ) -> Result<(), super::VerificationOrSendErrorWithToken<TcStateNone>> {
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( fn start_success(
&self, &self,
token: VerificationToken<super::TcStateAccepted>, token: VerificationToken<super::TcStateAccepted>,
time_stamp: Option<&[u8]>, _time_stamp: Option<&[u8]>,
) -> Result< ) -> Result<
VerificationToken<super::TcStateStarted>, VerificationToken<super::TcStateStarted>,
super::VerificationOrSendErrorWithToken<super::TcStateAccepted>, super::VerificationOrSendErrorWithToken<super::TcStateAccepted>,
> { > {
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( fn start_failure(
@ -1488,32 +1524,64 @@ pub mod tests {
token: VerificationToken<super::TcStateAccepted>, token: VerificationToken<super::TcStateAccepted>,
params: FailParams, params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<super::TcStateAccepted>> { ) -> Result<(), super::VerificationOrSendErrorWithToken<super::TcStateAccepted>> {
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( fn step_success(
&self, &self,
token: &VerificationToken<super::TcStateStarted>, token: &VerificationToken<super::TcStateStarted>,
time_stamp: Option<&[u8]>, _time_stamp: Option<&[u8]>,
step: impl spacepackets::ecss::EcssEnumeration, _step: impl spacepackets::ecss::EcssEnumeration,
) -> Result<(), EcssTmtcError> { ) -> 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( fn step_failure(
&self, &self,
token: VerificationToken<super::TcStateStarted>, token: VerificationToken<super::TcStateStarted>,
params: FailParamsWithStep, _params: FailParamsWithStep,
) -> Result<(), super::VerificationOrSendErrorWithToken<super::TcStateStarted>> { ) -> Result<(), super::VerificationOrSendErrorWithToken<super::TcStateStarted>> {
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<TcState: super::WasAtLeastAccepted + Copy>( fn completion_success<TcState: super::WasAtLeastAccepted + Copy>(
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
time_stamp: Option<&[u8]>, _time_stamp: Option<&[u8]>,
) -> Result<(), super::VerificationOrSendErrorWithToken<TcState>> { ) -> Result<(), super::VerificationOrSendErrorWithToken<TcState>> {
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<TcState: super::WasAtLeastAccepted + Copy>( fn completion_failure<TcState: super::WasAtLeastAccepted + Copy>(
@ -1521,7 +1589,19 @@ pub mod tests {
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
params: FailParams, params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<TcState>> { ) -> Result<(), super::VerificationOrSendErrorWithToken<TcState>> {
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(())
} }
} }