From 4d415cc0ade3d1621b3b9d21771a14f18e933eaa Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 15 Oct 2022 19:56:53 +0200 Subject: [PATCH] create shared test module for PUS tests --- fsrc-core/src/pus/event.rs | 17 ++++++++- fsrc-core/src/pus/mod.rs | 55 ++++++++++++++++++++++++++++ fsrc-core/src/pus/verification.rs | 61 ++++--------------------------- spacepackets | 2 +- 4 files changed, 79 insertions(+), 56 deletions(-) diff --git a/fsrc-core/src/pus/event.rs b/fsrc-core/src/pus/event.rs index 04a11b5..9472f6a 100644 --- a/fsrc-core/src/pus/event.rs +++ b/fsrc-core/src/pus/event.rs @@ -179,10 +179,10 @@ mod allocvec { } impl EventReporter { - pub fn new(apid: u16, max_event_id_and_aux_data: usize) -> Option { + pub fn new(apid: u16, max_event_id_and_aux_data_size: usize) -> Option { let reporter = EventReporterBase::new(apid)?; Some(Self { - source_data_buf: vec![0; max_event_id_and_aux_data], + source_data_buf: vec![0; max_event_id_and_aux_data_size], reporter, }) } @@ -251,3 +251,16 @@ mod allocvec { } } } + +#[cfg(test)] +mod tests { + use super::*; + + const EXAMPLE_APID: u16 = 0xee; + + #[test] + fn basic_event_generation() { + let _reporter = EventReporter::new(EXAMPLE_APID, 16); + //reporter. + } +} diff --git a/fsrc-core/src/pus/mod.rs b/fsrc-core/src/pus/mod.rs index 074402f..7e016a8 100644 --- a/fsrc-core/src/pus/mod.rs +++ b/fsrc-core/src/pus/mod.rs @@ -52,3 +52,58 @@ pub(crate) fn source_buffer_large_enough(cap: usize, len: usize) -> Result<() } Ok(()) } + +#[cfg(test)] +pub(crate) mod tests { + use crate::pus::verification::RequestId; + use crate::pus::{EcssTmError, EcssTmSender}; + use alloc::vec::Vec; + use spacepackets::ecss::PusPacket; + use spacepackets::tm::{PusTm, PusTmSecondaryHeaderT}; + use spacepackets::CcsdsPacket; + use std::collections::VecDeque; + + #[derive(Debug, Eq, PartialEq)] + pub(crate) struct TmInfo { + pub subservice: u8, + pub apid: u16, + pub msg_counter: u16, + pub dest_id: u16, + pub time_stamp: [u8; 7], + pub req_id: RequestId, + pub additional_data: Option>, + } + + #[derive(Default)] + pub(crate) struct TestSender { + pub service_queue: VecDeque, + } + + impl EcssTmSender<()> for TestSender { + fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> { + assert_eq!(PusPacket::service(&tm), 1); + assert!(tm.source_data().is_some()); + let mut time_stamp = [0; 7]; + time_stamp.clone_from_slice(&tm.time_stamp()[0..7]); + let src_data = tm.source_data().unwrap(); + assert!(src_data.len() >= 4); + let req_id = RequestId::from_bytes(&src_data[0..RequestId::SIZE_AS_BYTES]).unwrap(); + let mut vec = None; + if src_data.len() > 4 { + let mut new_vec = Vec::new(); + new_vec.extend_from_slice(&src_data[RequestId::SIZE_AS_BYTES..]); + vec = Some(new_vec); + } + self.service_queue.push_back(TmInfo { + subservice: PusPacket::subservice(&tm), + apid: tm.apid(), + msg_counter: tm.msg_counter(), + dest_id: tm.dest_id(), + time_stamp, + req_id, + additional_data: vec, + }); + Ok(()) + } + } +} diff --git a/fsrc-core/src/pus/verification.rs b/fsrc-core/src/pus/verification.rs index b242594..fd8076f 100644 --- a/fsrc-core/src/pus/verification.rs +++ b/fsrc-core/src/pus/verification.rs @@ -191,16 +191,16 @@ pub struct VerificationToken { } #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum StateNone {} +pub struct StateNone; #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum StateAccepted {} +pub struct StateAccepted; #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum StateStarted {} +pub struct StateStarted; pub enum StateToken { None(StateNone), Accepted(StateAccepted), - Started(StateStarted) + Started(StateStarted), } impl VerificationToken { @@ -1066,6 +1066,7 @@ mod stdmod { #[cfg(test)] mod tests { + use crate::pus::tests::{TestSender, TmInfo}; use crate::pus::verification::{ EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, RequestId, StateNone, VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender, @@ -1073,60 +1074,14 @@ mod tests { }; use alloc::boxed::Box; use alloc::format; - use alloc::vec::Vec; - use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration, PusPacket}; + use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration}; use spacepackets::tc::{PusTc, PusTcSecondaryHeader}; - use spacepackets::tm::{PusTm, PusTmSecondaryHeaderT}; - use spacepackets::{ByteConversionError, CcsdsPacket, SpHeader}; - use std::collections::VecDeque; + use spacepackets::tm::PusTm; + use spacepackets::{ByteConversionError, SpHeader}; const TEST_APID: u16 = 0x02; const EMPTY_STAMP: [u8; 7] = [0; 7]; - #[derive(Debug, Eq, PartialEq)] - struct TmInfo { - pub subservice: u8, - pub apid: u16, - pub msg_counter: u16, - pub dest_id: u16, - pub time_stamp: [u8; 7], - pub req_id: RequestId, - pub additional_data: Option>, - } - - #[derive(Default)] - struct TestSender { - pub service_queue: VecDeque, - } - - impl EcssTmSender<()> for TestSender { - fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> { - assert_eq!(PusPacket::service(&tm), 1); - assert!(tm.source_data().is_some()); - let mut time_stamp = [0; 7]; - time_stamp.clone_from_slice(&tm.time_stamp()[0..7]); - let src_data = tm.source_data().unwrap(); - assert!(src_data.len() >= 4); - let req_id = RequestId::from_bytes(&src_data[0..RequestId::SIZE_AS_BYTES]).unwrap(); - let mut vec = None; - if src_data.len() > 4 { - let mut new_vec = Vec::new(); - new_vec.extend_from_slice(&src_data[RequestId::SIZE_AS_BYTES..]); - vec = Some(new_vec); - } - self.service_queue.push_back(TmInfo { - subservice: PusPacket::subservice(&tm), - apid: tm.apid(), - msg_counter: tm.msg_counter(), - dest_id: tm.dest_id(), - time_stamp, - req_id, - additional_data: vec, - }); - Ok(()) - } - } - #[derive(Debug, Copy, Clone, Eq, PartialEq)] struct DummyError {} #[derive(Default)] diff --git a/spacepackets b/spacepackets index 638e4cd..603f688 160000 --- a/spacepackets +++ b/spacepackets @@ -1 +1 @@ -Subproject commit 638e4cda620fbb0ef6aed9faa0e9375d3762a339 +Subproject commit 603f688ac3e914de13037fd22ac544e125b6305b