continue with reply handler unittesting
All checks were successful
Rust/sat-rs/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2024-03-11 12:35:56 +01:00
parent d0f10c7d1d
commit e7cec1d333
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 137 additions and 48 deletions

View File

@ -591,13 +591,10 @@ mod tests {
assert_eq!(reply.message, mode_reply); assert_eq!(reply.message, mode_reply);
} }
#[test]
fn test_simple_mode_request_handler() {}
#[test] #[test]
fn test_mode_requestor_and_request_handler_request_sending() { fn test_mode_requestor_and_request_handler_request_sending() {
let (reply_sender_to_connector, reply_receiver_of_connector) = mpsc::channel(); let (_reply_sender_to_connector, reply_receiver_of_connector) = mpsc::channel();
let (request_sender_to_connector, request_receiver_of_connector) = mpsc::channel(); let (_request_sender_to_connector, request_receiver_of_connector) = mpsc::channel();
let (request_sender_to_channel_1, request_receiver_channel_1) = mpsc::channel(); let (request_sender_to_channel_1, request_receiver_channel_1) = mpsc::channel();
//let (reply_sender_to_channel_2, reply_receiver_channel_2) = mpsc::channel(); //let (reply_sender_to_channel_2, reply_receiver_channel_2) = mpsc::channel();
@ -634,8 +631,8 @@ mod tests {
#[test] #[test]
fn test_mode_requestor_and_request_handler_reply_sending() { fn test_mode_requestor_and_request_handler_reply_sending() {
let (reply_sender_to_connector, reply_receiver_of_connector) = mpsc::channel(); let (_reply_sender_to_connector, reply_receiver_of_connector) = mpsc::channel();
let (request_sender_to_connector, request_receiver_of_connector) = mpsc::channel(); let (_request_sender_to_connector, request_receiver_of_connector) = mpsc::channel();
let (reply_sender_to_channel_2, reply_receiver_channel_2) = mpsc::channel(); let (reply_sender_to_channel_2, reply_receiver_channel_2) = mpsc::channel();
let mut mode_connector = ModeRequestorAndHandlerMpsc::new( let mut mode_connector = ModeRequestorAndHandlerMpsc::new(

View File

@ -37,7 +37,7 @@ pub struct ActionReplyPusWithIds {
pub enum ActionReplyPus { pub enum ActionReplyPus {
Completed, Completed,
StepSuccess { StepSuccess {
step: EcssEnumU16, step: u16,
}, },
CompletionFailed { CompletionFailed {
error_code: ResultU16, error_code: ResultU16,
@ -45,7 +45,7 @@ pub enum ActionReplyPus {
}, },
StepFailed { StepFailed {
error_code: ResultU16, error_code: ResultU16,
step: EcssEnumU16, step: u16,
params: Params, params: Params,
}, },
} }
@ -348,7 +348,7 @@ pub mod std_mod {
active_req.token, active_req.token,
FailParamsWithStep::new( FailParamsWithStep::new(
time_stamp, time_stamp,
&step, &EcssEnumU16::new(step),
&error_code, &error_code,
&self.fail_data_buf, &self.fail_data_buf,
), ),
@ -365,8 +365,11 @@ pub mod std_mod {
.remove(&action_reply_with_ids.request_id); .remove(&action_reply_with_ids.request_id);
} }
ActionReplyPus::StepSuccess { step } => { ActionReplyPus::StepSuccess { step } => {
self.verification_reporter self.verification_reporter.step_success(
.step_success(&active_req.token, time_stamp, step)?; &active_req.token,
time_stamp,
EcssEnumU16::new(step),
)?;
} }
} }
Ok(()) Ok(())
@ -400,10 +403,10 @@ mod tests {
verification::{ verification::{
self, self,
tests::{SharedVerificationMap, TestVerificationReporter}, tests::{SharedVerificationMap, TestVerificationReporter},
FailParams, RequestId, VerificationReportingProvider, FailParams, TcStateNone, TcStateStarted, VerificationReportingProvider,
}, },
EcssTcInVecConverter, GenericRoutingError, MpscTcReceiver, PusPacketHandlerResult, EcssTcInVecConverter, EcssTmtcError, GenericRoutingError, MpscTcReceiver,
PusPacketHandlingError, TmAsVecSenderWithMpsc, PusPacketHandlerResult, PusPacketHandlingError, TmAsVecSenderWithMpsc,
}, },
}; };
@ -471,7 +474,7 @@ mod tests {
} }
} }
struct Pus8HandlerWithVecTester { struct Pus8RequestTestbenchWithVec {
common: PusServiceHandlerWithVecCommon<TestVerificationReporter>, common: PusServiceHandlerWithVecCommon<TestVerificationReporter>,
handler: PusService8ActionHandler< handler: PusService8ActionHandler<
MpscTcReceiver, MpscTcReceiver,
@ -484,7 +487,7 @@ mod tests {
>, >,
} }
impl Pus8HandlerWithVecTester { impl Pus8RequestTestbenchWithVec {
pub fn new() -> Self { pub fn new() -> Self {
let (common, srv_handler) = let (common, srv_handler) =
PusServiceHandlerWithVecCommon::new_with_test_verif_sender(); PusServiceHandlerWithVecCommon::new_with_test_verif_sender();
@ -516,7 +519,7 @@ mod tests {
} }
} }
impl PusTestHarness for Pus8HandlerWithVecTester { impl PusTestHarness for Pus8RequestTestbenchWithVec {
delegate! { delegate! {
to self.common { to self.common {
fn send_tc(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted>; fn send_tc(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted>;
@ -525,12 +528,12 @@ mod tests {
fn check_next_verification_tm( fn check_next_verification_tm(
&self, &self,
subservice: u8, subservice: u8,
expected_request_id: RequestId, expected_request_id: verification::RequestId,
); );
} }
} }
} }
impl SimplePusPacketHandler for Pus8HandlerWithVecTester { impl SimplePusPacketHandler for Pus8RequestTestbenchWithVec {
delegate! { delegate! {
to self.handler { to self.handler {
fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError>; fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError>;
@ -560,9 +563,86 @@ mod tests {
} }
} }
pub struct Pus8ReplyTestbench {
verif_reporter: TestVerificationReporter,
handler: PusService8ReplyHandler<TestVerificationReporter, TestReplyHandlerHook>,
}
impl Pus8ReplyTestbench {
pub fn new() -> Self {
let reply_handler_hook = TestReplyHandlerHook::default();
let shared_verif_map = SharedVerificationMap::default();
let test_verif_reporter = TestVerificationReporter::new(shared_verif_map.clone());
let reply_handler =
PusService8ReplyHandler::new(test_verif_reporter.clone(), 128, reply_handler_hook);
Self {
verif_reporter: test_verif_reporter,
handler: reply_handler,
}
}
pub fn init_handling_for_request(
&mut self,
request_id: RequestId,
_action_id: ActionId,
) -> VerificationToken<TcStateStarted> {
// let action_req = ActionRequest::new(action_id, ActionRequestVariant::NoData);
let token = self.add_tc_with_req_id(request_id.into());
let token = self
.verif_reporter
.acceptance_success(token, &[])
.expect("acceptance success failure");
let token = self
.verif_reporter
.start_success(token, &[])
.expect("start success failure");
let verif_info = self
.verif_reporter
.verification_info(&verification::RequestId::from(request_id))
.expect("no verification info found");
assert!(verif_info.started.expect("request was not started"));
assert!(verif_info.accepted.expect("request was not accepted"));
token
}
pub fn assert_request_completion(&self, step: Option<u16>, request_id: RequestId) {
let verif_info = self
.verif_reporter
.verification_info(&verification::RequestId::from(request_id))
.expect("no verification info found");
if let Some(step) = step {
assert!(verif_info.step_status.is_some());
assert!(verif_info.step_status.unwrap());
assert_eq!(step, verif_info.step);
}
assert!(verif_info.completed.expect("request is not completed"));
}
delegate! {
to self.handler {
pub fn handle_action_reply(
&mut self,
action_reply_with_ids: ActionReplyPusWithIds,
time_stamp: &[u8],
) -> Result<(), EcssTmtcError>;
pub fn add_routed_request(
&mut self,
request_id: verification::RequestId,
action_id: ActionId,
token: VerificationToken<TcStateStarted>,
timeout: Duration,
);
}
to self.verif_reporter {
fn add_tc_with_req_id(&mut self, req_id: verification::RequestId) -> VerificationToken<TcStateNone>;
}
}
}
#[test] #[test]
fn basic_test() { fn basic_test() {
let mut action_handler = Pus8HandlerWithVecTester::new(); let mut action_handler = Pus8RequestTestbenchWithVec::new();
let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap(); let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(8, 1); let sec_header = PusTcSecondaryHeader::new_simple(8, 1);
let action_id: u32 = 1; let action_id: u32 = 1;
@ -582,7 +662,7 @@ mod tests {
#[test] #[test]
fn test_routing_error() { fn test_routing_error() {
let mut action_handler = Pus8HandlerWithVecTester::new(); let mut action_handler = Pus8RequestTestbenchWithVec::new();
let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap(); let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(8, 1); let sec_header = PusTcSecondaryHeader::new_simple(8, 1);
let action_id: u32 = 1; let action_id: u32 = 1;
@ -624,27 +704,11 @@ mod tests {
#[test] #[test]
fn test_reply_handler() { fn test_reply_handler() {
let reply_handler_hook = TestReplyHandlerHook::default(); let mut reply_testbench = Pus8ReplyTestbench::new();
let shared_verif_map = SharedVerificationMap::default();
let mut test_verif_reporter = TestVerificationReporter::new(shared_verif_map.clone());
let mut reply_handler =
PusService8ReplyHandler::new(test_verif_reporter.clone(), 128, reply_handler_hook);
let request_id = 0x02; let request_id = 0x02;
let action_id = 0x03; let action_id = 0x03;
// let action_req = ActionRequest::new(action_id, ActionRequestVariant::NoData); let token = reply_testbench.init_handling_for_request(request_id, action_id);
let token = test_verif_reporter.add_tc_with_req_id(request_id.into()); reply_testbench.add_routed_request(
let token = test_verif_reporter
.acceptance_success(token, &[])
.expect("acceptance success failure");
let token = test_verif_reporter
.start_success(token, &[])
.expect("start success failure");
let verif_info = test_verif_reporter
.verification_info(&verification::RequestId::from(request_id))
.expect("no verification info found");
assert!(verif_info.started.expect("not started"));
assert!(verif_info.accepted.expect("not accepted"));
reply_handler.add_routed_request(
request_id.into(), request_id.into(),
action_id, action_id,
token, token,
@ -655,12 +719,40 @@ mod tests {
action_id, action_id,
reply: ActionReplyPus::Completed, reply: ActionReplyPus::Completed,
}; };
reply_handler reply_testbench
.handle_action_reply(action_reply, &[]) .handle_action_reply(action_reply, &[])
.expect("reply handling failure"); .expect("reply handling failure");
let verif_info = test_verif_reporter reply_testbench.assert_request_completion(None, request_id);
.verification_info(&verification::RequestId::from(request_id)) }
.expect("no verification info found");
assert!(verif_info.completed.expect("not started")); #[test]
fn test_reply_handler_step_success() {
let mut reply_testbench = Pus8ReplyTestbench::new();
let request_id = 0x02;
let action_id = 0x03;
let token = reply_testbench.init_handling_for_request(request_id, action_id);
reply_testbench.add_routed_request(
request_id.into(),
action_id,
token,
Duration::from_millis(1),
);
let action_reply = ActionReplyPusWithIds {
request_id,
action_id,
reply: ActionReplyPus::StepSuccess { step: 1 },
};
reply_testbench
.handle_action_reply(action_reply, &[])
.expect("reply handling failure");
let action_reply = ActionReplyPusWithIds {
request_id,
action_id,
reply: ActionReplyPus::Completed,
};
reply_testbench
.handle_action_reply(action_reply, &[])
.expect("reply handling failure");
reply_testbench.assert_request_completion(Some(1), request_id);
} }
} }

View File

@ -1462,7 +1462,7 @@ pub mod tests {
pub struct VerificationStatus { pub struct VerificationStatus {
pub accepted: Option<bool>, pub accepted: Option<bool>,
pub started: Option<bool>, pub started: Option<bool>,
pub step: u64, pub step: u16,
pub step_status: Option<bool>, pub step_status: Option<bool>,
pub completed: Option<bool>, pub completed: Option<bool>,
pub failure_data: Option<Vec<u8>>, pub failure_data: Option<Vec<u8>>,
@ -1590,7 +1590,7 @@ pub mod tests {
let verif_map = self.verification_map.lock().unwrap(); let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) { match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => { Some(entry) => {
entry.step = step.value(); entry.step = step.value().try_into().unwrap();
entry.step_status = Some(true); entry.step_status = Some(true);
} }
None => panic!("unexpected start success for request ID {}", token.req_id()), None => panic!("unexpected start success for request ID {}", token.req_id()),