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 started: Option<bool>,
pub step: u32,
pub step_status: Option<bool>,
pub completed: Option<bool>,
pub failure_data: Option<Vec<u8>>,
pub fail_enum: Option<Vec<u8>>,
}
pub struct TestVerificationReporter {
verification_map: HashMap<RequestId, VerificationStatus>,
pub verification_map: RefCell<HashMap<RequestId, VerificationStatus>>,
}
impl VerificationReportingProvider for TestVerificationReporter {
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,
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<TcStateNone>,
time_stamp: Option<&[u8]>,
_time_stamp: Option<&[u8]>,
) -> Result<
VerificationToken<super::TcStateAccepted>,
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(
@ -1469,18 +1486,37 @@ pub mod tests {
token: VerificationToken<TcStateNone>,
params: FailParams,
) -> 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(
&self,
token: VerificationToken<super::TcStateAccepted>,
time_stamp: Option<&[u8]>,
_time_stamp: Option<&[u8]>,
) -> Result<
VerificationToken<super::TcStateStarted>,
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(
@ -1488,32 +1524,64 @@ pub mod tests {
token: VerificationToken<super::TcStateAccepted>,
params: FailParams,
) -> 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(
&self,
token: &VerificationToken<super::TcStateStarted>,
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<super::TcStateStarted>,
params: FailParamsWithStep,
_params: FailParamsWithStep,
) -> 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>(
&self,
token: VerificationToken<TcState>,
time_stamp: Option<&[u8]>,
_time_stamp: Option<&[u8]>,
) -> 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>(
@ -1521,7 +1589,19 @@ pub mod tests {
token: VerificationToken<TcState>,
params: FailParams,
) -> 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(())
}
}