From 4588d002914104e8790e74c7256bdffbdc96558c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 17 Feb 2024 14:43:46 +0100 Subject: [PATCH] created baseline for tests --- satrs/src/pus/action.rs | 62 +++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/satrs/src/pus/action.rs b/satrs/src/pus/action.rs index 4b7c018..936a694 100644 --- a/satrs/src/pus/action.rs +++ b/satrs/src/pus/action.rs @@ -168,18 +168,23 @@ pub mod std_mod { #[cfg(test)] mod tests { use core::cell::RefCell; + use delegate::delegate; use alloc::{collections::VecDeque, vec::Vec}; use spacepackets::{ - ecss::{tc::PusTcReader, PusPacket}, + ecss::{ + tc::{PusTcCreator, PusTcReader}, + tm::PusTmReader, + PusPacket, + }, CcsdsPacket, }; use crate::pus::{ - tests::PusServiceHandlerWithVecCommon, - verification::{tests::TestVerificationReporter, VerificationReportingProvider}, - EcssTcInVecConverter, GenericRoutingError, PusPacketHandlingError, PusRoutingErrorHandler, - PusServiceHelper, + tests::{PusServiceHandlerWithVecCommon, PusTestHarness, SimplePusPacketHandler}, + verification::{tests::TestVerificationReporter, RequestId, VerificationReportingProvider}, + EcssTcInVecConverter, GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError, + PusRoutingErrorHandler, PusServiceHelper, }; use super::*; @@ -187,6 +192,7 @@ mod tests { #[derive(Default)] pub struct TestRouter { pub routing_requests: RefCell>, + pub routing_error: RefCell>, } impl PusActionRequestRouter for TestRouter { @@ -211,13 +217,15 @@ mod tests { fn handle_error( &self, target_id: TargetId, - token: VerificationToken, - tc: &PusTcReader, + _token: VerificationToken, + _tc: &PusTcReader, error: Self::Error, - time_stamp: &[u8], - verif_reporter: &impl VerificationReportingProvider, + _time_stamp: &[u8], + _verif_reporter: &impl VerificationReportingProvider, ) { - todo!() + self.routing_error + .borrow_mut() + .push_back((target_id, error)); } } @@ -230,14 +238,17 @@ mod tests { type Error = PusPacketHandlingError; fn convert( &mut self, - _token: VerificationToken, + token: VerificationToken, tc: &PusTcReader, - _time_stamp: &[u8], - _verif_reporter: &impl VerificationReportingProvider, + time_stamp: &[u8], + verif_reporter: &impl VerificationReportingProvider, ) -> Result<(TargetId, ActionRequest), Self::Error> { self.conversion_request.push_back(tc.raw_data().to_vec()); let target_id = tc.apid(); if tc.subservice() == 1 { + verif_reporter + .start_success(token, Some(time_stamp)) + .expect("start success failure"); return Ok(( target_id.into(), ActionRequest::UnsignedIdAndVecData { @@ -279,9 +290,30 @@ mod tests { } } + impl PusTestHarness for Pus8HandlerWithVecTester { + delegate! { + to self.common { + fn send_tc(&mut self, tc: &PusTcCreator) -> VerificationToken; + fn read_next_tm(&mut self) -> PusTmReader<'_>; + fn check_no_tm_available(&self) -> bool; + fn check_next_verification_tm( + &self, + subservice: u8, + expected_request_id: RequestId, + ); + } + } + } + impl SimplePusPacketHandler for Pus8HandlerWithVecTester { + delegate! { + to self.handler { + fn handle_one_tc(&mut self) -> Result; + } + } + } + #[test] fn basic_test() { - //let service_helper = PusServiceHelper::new(); - let action_handler = Pus8HandlerWithVecTester::new(); + let _action_handler = Pus8HandlerWithVecTester::new(); } }