added last set of unittests
All checks were successful
Rust/sat-rs/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2024-02-20 14:32:14 +01:00
parent c691e29070
commit b85a34c1bb
3 changed files with 78 additions and 28 deletions

View File

@ -176,7 +176,7 @@ mod tests {
ecss::{ ecss::{
tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader}, tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader},
tm::PusTmReader, tm::PusTmReader,
PusPacket, WritablePusPacket, PusPacket,
}, },
CcsdsPacket, SequenceFlags, SpHeader, CcsdsPacket, SequenceFlags, SpHeader,
}; };
@ -206,10 +206,7 @@ mod tests {
self.routing_requests self.routing_requests
.borrow_mut() .borrow_mut()
.push_back((target_id, hk_request)); .push_back((target_id, hk_request));
if self.injected_routing_failure.borrow().is_some() { self.check_for_injected_error()
return Err(self.injected_routing_failure.borrow_mut().take().unwrap());
}
Ok(())
} }
} }
@ -295,6 +292,11 @@ mod tests {
pub fn retrieve_next_request(&mut self) -> (TargetId, ActionRequest); pub fn retrieve_next_request(&mut self) -> (TargetId, ActionRequest);
} }
} }
delegate! {
to self.handler.routing_error_handler {
pub fn retrieve_next_error(&mut self) -> (TargetId, GenericRoutingError);
}
}
} }
impl PusTestHarness for Pus8HandlerWithVecTester { impl PusTestHarness for Pus8HandlerWithVecTester {
@ -376,22 +378,7 @@ mod tests {
assert_eq!(data, &[]); assert_eq!(data, &[]);
} }
assert_eq!( let (target_id, found_error) = action_handler.retrieve_next_error();
action_handler
.handler
.routing_error_handler
.routing_errors
.borrow()
.len(),
1
);
let (target_id, found_error) = action_handler
.handler
.routing_error_handler
.routing_errors
.borrow_mut()
.pop_front()
.unwrap();
assert_eq!(target_id, TEST_APID.into()); assert_eq!(target_id, TEST_APID.into());
check_error(found_error); check_error(found_error);
} }

View File

@ -104,7 +104,7 @@ pub mod std_mod {
RequestConverter: PusHkToRequestConverter<Error = PusPacketHandlingError>, RequestConverter: PusHkToRequestConverter<Error = PusPacketHandlingError>,
RequestRouter: PusHkRequestRouter<Error = RoutingError>, RequestRouter: PusHkRequestRouter<Error = RoutingError>,
RoutingErrorHandler: PusRoutingErrorHandler<Error = RoutingError>, RoutingErrorHandler: PusRoutingErrorHandler<Error = RoutingError>,
RoutingError, RoutingError: Clone,
> >
PusService3HkHandler< PusService3HkHandler<
TcInMemConverter, TcInMemConverter,
@ -114,6 +114,8 @@ pub mod std_mod {
RoutingErrorHandler, RoutingErrorHandler,
RoutingError, RoutingError,
> >
where
PusPacketHandlingError: From<RoutingError>,
{ {
pub fn new( pub fn new(
service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>, service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
@ -158,10 +160,11 @@ pub mod std_mod {
target_id, target_id,
ecss_tc_and_token.token, ecss_tc_and_token.token,
&tc, &tc,
e, e.clone(),
&time_stamp, &time_stamp,
&self.service_helper.common.verification_handler, &self.service_helper.common.verification_handler,
); );
return Err(e.into());
} }
Ok(PusPacketHandlerResult::RequestHandled) Ok(PusPacketHandlerResult::RequestHandled)
} }
@ -213,10 +216,7 @@ mod tests {
self.routing_requests self.routing_requests
.borrow_mut() .borrow_mut()
.push_back((target_id, hk_request)); .push_back((target_id, hk_request));
if self.injected_routing_failure.borrow().is_some() { self.check_for_injected_error()
return Err(self.injected_routing_failure.borrow_mut().take().unwrap());
}
Ok(())
} }
} }
@ -301,6 +301,11 @@ mod tests {
pub fn retrieve_next_request(&mut self) -> (TargetId, HkRequest); pub fn retrieve_next_request(&mut self) -> (TargetId, HkRequest);
} }
} }
delegate! {
to self.handler.routing_error_handler {
pub fn retrieve_next_error(&mut self) -> (TargetId, GenericRoutingError);
}
}
} }
impl PusTestHarness for Pus3HandlerWithVecTester { impl PusTestHarness for Pus3HandlerWithVecTester {
@ -347,5 +352,43 @@ mod tests {
} }
#[test] #[test]
fn test_routing_error() {} fn test_routing_error() {
let mut hk_handler = Pus3HandlerWithVecTester::new();
let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(3, Subservice::TcGenerateOneShotHk as u8);
let unique_id: u32 = 1;
let unique_id_raw = unique_id.to_be_bytes();
let tc = PusTcCreator::new(&mut sp_header, sec_header, unique_id_raw.as_ref(), true);
let error = GenericRoutingError::UnknownTargetId(25);
hk_handler
.handler
.request_router
.inject_routing_error(error);
hk_handler.send_tc(&tc);
let result = hk_handler.handle_one_tc();
assert!(result.is_err());
let check_error = |routing_error: GenericRoutingError| {
if let GenericRoutingError::UnknownTargetId(id) = routing_error {
assert_eq!(id, 25);
} else {
panic!("unexpected error type");
}
};
if let PusPacketHandlingError::RequestRoutingError(routing_error) = result.unwrap_err() {
check_error(routing_error);
} else {
panic!("unexpected error type");
}
hk_handler.check_next_conversion(&tc);
let (target_id, hk_req) = hk_handler.retrieve_next_request();
assert_eq!(target_id, TEST_APID.into());
if let HkRequest::OneShot(unique_id) = hk_req {
assert_eq!(unique_id, 1);
}
let (target_id, found_error) = hk_handler.retrieve_next_error();
assert_eq!(target_id, TEST_APID.into());
check_error(found_error);
}
} }

View File

@ -1283,6 +1283,19 @@ pub mod tests {
} }
} }
impl TestRoutingErrorHandler {
pub fn is_empty(&self) -> bool {
self.routing_errors.borrow().is_empty()
}
pub fn retrieve_next_error(&mut self) -> (TargetId, GenericRoutingError) {
if self.routing_errors.borrow().is_empty() {
panic!("no routing request available");
}
self.routing_errors.borrow_mut().pop_front().unwrap()
}
}
pub struct TestRouter<REQUEST> { pub struct TestRouter<REQUEST> {
pub routing_requests: RefCell<VecDeque<(TargetId, REQUEST)>>, pub routing_requests: RefCell<VecDeque<(TargetId, REQUEST)>>,
pub injected_routing_failure: RefCell<Option<GenericRoutingError>>, pub injected_routing_failure: RefCell<Option<GenericRoutingError>>,
@ -1298,6 +1311,13 @@ pub mod tests {
} }
impl<REQUEST> TestRouter<REQUEST> { impl<REQUEST> TestRouter<REQUEST> {
pub fn check_for_injected_error(&self) -> Result<(), GenericRoutingError> {
if self.injected_routing_failure.borrow().is_some() {
return Err(self.injected_routing_failure.borrow_mut().take().unwrap());
}
Ok(())
}
pub fn inject_routing_error(&mut self, error: GenericRoutingError) { pub fn inject_routing_error(&mut self, error: GenericRoutingError) {
*self.injected_routing_failure.borrow_mut() = Some(error); *self.injected_routing_failure.borrow_mut() = Some(error);
} }