thats one hell of a test suite..

This commit is contained in:
Robin Müller 2024-02-17 01:07:01 +01:00
parent 51bccf32af
commit d7be5224f1
Signed by: muellerr
GPG Key ID: A649FB78196E3849
4 changed files with 160 additions and 30 deletions

View File

@ -167,12 +167,27 @@ pub mod std_mod {
#[cfg(test)]
mod tests {
use spacepackets::ecss::tc::PusTcReader;
use core::cell::RefCell;
use crate::pus::{verification::VerificationReportingProvider, GenericRoutingError};
use alloc::{collections::VecDeque, vec::Vec};
use spacepackets::{
ecss::{tc::PusTcReader, PusPacket},
CcsdsPacket,
};
use crate::pus::{
tests::PusServiceHandlerWithVecCommon,
verification::{tests::TestVerificationReporter, VerificationReportingProvider},
EcssTcInVecConverter, GenericRoutingError, PusPacketHandlingError, PusRoutingErrorHandler,
PusServiceHelper,
};
use super::*;
pub struct TestRouter {}
#[derive(Default)]
pub struct TestRouter {
pub routing_requests: RefCell<VecDeque<(TargetId, ActionRequest)>>,
}
impl PusActionRequestRouter for TestRouter {
type Error = GenericRoutingError;
@ -181,23 +196,92 @@ mod tests {
&self,
target_id: TargetId,
hk_request: ActionRequest,
token: VerificationToken<TcStateAccepted>,
_token: VerificationToken<TcStateAccepted>,
) -> Result<(), Self::Error> {
self.routing_requests
.borrow_mut()
.push_back((target_id, hk_request));
Ok(())
}
}
impl PusRoutingErrorHandler for TestRouter {
type Error = GenericRoutingError;
fn handle_error(
&self,
target_id: TargetId,
token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader,
error: Self::Error,
time_stamp: &[u8],
verif_reporter: &impl VerificationReportingProvider,
) {
todo!()
}
}
pub struct TestConverter {}
#[derive(Default)]
pub struct TestConverter {
pub conversion_request: VecDeque<Vec<u8>>,
}
impl PusActionToRequestConverter for TestConverter {
type Error = GenericRoutingError;
type Error = PusPacketHandlingError;
fn convert(
&mut self,
token: VerificationToken<TcStateAccepted>,
_token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader,
time_stamp: &[u8],
verif_reporter: &impl VerificationReportingProvider,
_time_stamp: &[u8],
_verif_reporter: &impl VerificationReportingProvider,
) -> Result<(TargetId, ActionRequest), Self::Error> {
todo!()
self.conversion_request.push_back(tc.raw_data().to_vec());
let target_id = tc.apid();
if tc.subservice() == 1 {
return Ok((
target_id.into(),
ActionRequest::UnsignedIdAndVecData {
action_id: u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap()),
data: tc.user_data()[4..].to_vec(),
},
));
}
Err(PusPacketHandlingError::InvalidAppData(
"unexpected app data".into(),
))
}
}
struct Pus8HandlerWithVecTester {
common: PusServiceHandlerWithVecCommon<TestVerificationReporter>,
handler: PusService8ActionHandler<
EcssTcInVecConverter,
TestVerificationReporter,
TestConverter,
TestRouter,
TestRouter,
>,
}
impl Pus8HandlerWithVecTester {
pub fn new() -> Self {
let (common, srv_handler) =
PusServiceHandlerWithVecCommon::new_with_test_verif_sender();
Self {
common,
handler: PusService8ActionHandler::new(
srv_handler,
TestConverter::default(),
TestRouter::default(),
TestRouter::default(),
),
}
}
}
#[test]
fn basic_test() {
//let service_helper = PusServiceHelper::new();
let action_handler = Pus8HandlerWithVecTester::new();
}
}

View File

@ -947,6 +947,7 @@ pub mod tests {
use crate::pus::verification::RequestId;
use crate::tmtc::tm_helper::SharedTmPool;
use super::verification::tests::TestVerificationReporter;
use super::verification::{
TcStateAccepted, VerificationReporterCfg, VerificationReporterWithSender,
VerificationReportingProvider, VerificationToken,
@ -1105,15 +1106,15 @@ pub mod tests {
}
}
pub struct PusServiceHandlerWithVecCommon {
pub struct PusServiceHandlerWithVecCommon<VerificationReporter: VerificationReportingProvider> {
current_tm: Option<alloc::vec::Vec<u8>>,
tc_sender: mpsc::Sender<EcssTcAndToken>,
tm_receiver: mpsc::Receiver<alloc::vec::Vec<u8>>,
verification_handler: VerificationReporterWithSender,
verification_handler: VerificationReporter,
}
impl PusServiceHandlerWithVecCommon {
pub fn new() -> (
impl PusServiceHandlerWithVecCommon<VerificationReporterWithSender> {
pub fn new_with_standard_verif_reporter() -> (
Self,
PusServiceHelper<EcssTcInVecConverter, VerificationReporterWithSender>,
) {
@ -1124,6 +1125,7 @@ pub mod tests {
let verif_cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
let verification_handler =
VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
let test_srv_tm_sender = MpscTmAsVecSender::new(0, "test-sender", tm_tx);
let test_srv_tc_receiver = MpscTcReceiver::new(0, "test-receiver", test_srv_tc_rx);
let in_store_converter = EcssTcInVecConverter::default();
@ -1143,7 +1145,41 @@ pub mod tests {
),
)
}
}
impl PusServiceHandlerWithVecCommon<TestVerificationReporter> {
pub fn new_with_test_verif_sender() -> (
Self,
PusServiceHelper<EcssTcInVecConverter, TestVerificationReporter>,
) {
let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel();
let (tm_tx, tm_rx) = mpsc::channel();
let test_srv_tm_sender = MpscTmAsVecSender::new(0, "test-sender", tm_tx);
let test_srv_tc_receiver = MpscTcReceiver::new(0, "test-receiver", test_srv_tc_rx);
let in_store_converter = EcssTcInVecConverter::default();
let verification_handler = TestVerificationReporter::default();
(
Self {
current_tm: None,
tc_sender: test_srv_tc_tx,
tm_receiver: tm_rx,
verification_handler: verification_handler.clone(),
},
PusServiceHelper::new(
Box::new(test_srv_tc_receiver),
Box::new(test_srv_tm_sender),
TEST_APID,
verification_handler,
in_store_converter,
),
)
}
}
impl<VerificationReporter: VerificationReportingProvider>
PusServiceHandlerWithVecCommon<VerificationReporter>
{
pub fn send_tc(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> {
let token = self.verification_handler.add_tc(tc);
let token = self

View File

@ -104,9 +104,7 @@ mod tests {
PusServiceHandlerWithSharedStoreCommon, PusServiceHandlerWithVecCommon, PusTestHarness,
SimplePusPacketHandler, TEST_APID,
};
use crate::pus::verification::{
RequestId, VerificationReporterWithSender, VerificationReportingProvider,
};
use crate::pus::verification::{RequestId, VerificationReporterWithSender};
use crate::pus::verification::{TcStateAccepted, VerificationToken};
use crate::pus::{
EcssTcInSharedStoreConverter, EcssTcInVecConverter, PusPacketHandlerResult,
@ -160,13 +158,14 @@ mod tests {
}
struct Pus17HandlerWithVecTester {
common: PusServiceHandlerWithVecCommon,
common: PusServiceHandlerWithVecCommon<VerificationReporterWithSender>,
handler: PusService17TestHandler<EcssTcInVecConverter, VerificationReporterWithSender>,
}
impl Pus17HandlerWithVecTester {
pub fn new() -> Self {
let (common, srv_handler) = PusServiceHandlerWithVecCommon::new();
let (common, srv_handler) =
PusServiceHandlerWithVecCommon::new_with_standard_verif_reporter();
Self {
common,
handler: PusService17TestHandler::new(srv_handler),

View File

@ -1407,6 +1407,7 @@ pub mod tests {
use crate::ChannelId;
use alloc::boxed::Box;
use alloc::format;
use alloc::sync::Arc;
use hashbrown::HashMap;
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
use spacepackets::ecss::tm::PusTmReader;
@ -1415,7 +1416,7 @@ pub mod tests {
use spacepackets::{ByteConversionError, CcsdsPacket, SpHeader};
use std::cell::RefCell;
use std::collections::VecDeque;
use std::sync::mpsc;
use std::sync::{mpsc, Mutex};
use std::time::Duration;
use std::vec;
use std::vec::Vec;
@ -1436,13 +1437,15 @@ pub mod tests {
pub fail_enum: Option<Vec<u8>>,
}
#[derive(Default, Clone)]
pub struct TestVerificationReporter {
pub verification_map: RefCell<HashMap<RequestId, VerificationStatus>>,
pub verification_map: Arc<Mutex<RefCell<HashMap<RequestId, VerificationStatus>>>>,
}
impl VerificationReportingProvider for TestVerificationReporter {
fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone> {
self.verification_map.borrow_mut().insert(
let verif_map = self.verification_map.lock().unwrap();
verif_map.borrow_mut().insert(
req_id,
VerificationStatus {
accepted: None,
@ -1468,7 +1471,8 @@ pub mod tests {
VerificationToken<super::TcStateAccepted>,
super::VerificationOrSendErrorWithToken<TcStateNone>,
> {
match self.verification_map.borrow_mut().get_mut(&token.req_id) {
let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => entry.accepted = Some(true),
None => panic!(
"unexpected acceptance success for request ID {}",
@ -1486,7 +1490,8 @@ pub mod tests {
token: VerificationToken<TcStateNone>,
params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<TcStateNone>> {
match self.verification_map.borrow_mut().get_mut(&token.req_id) {
let verif_map = self.verification_map.lock().unwrap();
match verif_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());
@ -1509,7 +1514,8 @@ pub mod tests {
VerificationToken<super::TcStateStarted>,
super::VerificationOrSendErrorWithToken<super::TcStateAccepted>,
> {
match self.verification_map.borrow_mut().get_mut(&token.req_id) {
let verif_map = self.verification_map.lock().unwrap();
match verif_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()),
};
@ -1524,7 +1530,8 @@ pub mod tests {
token: VerificationToken<super::TcStateAccepted>,
params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<super::TcStateAccepted>> {
match self.verification_map.borrow_mut().get_mut(&token.req_id) {
let verif_map = self.verification_map.lock().unwrap();
match verif_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());
@ -1542,7 +1549,8 @@ pub mod tests {
_time_stamp: Option<&[u8]>,
_step: impl spacepackets::ecss::EcssEnumeration,
) -> Result<(), EcssTmtcError> {
match self.verification_map.borrow_mut().get_mut(&token.req_id) {
let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => {
// TODO: Enable this after the spacepackets update.
// entry.step = Some(step.value()),
@ -1558,7 +1566,8 @@ pub mod tests {
token: VerificationToken<super::TcStateStarted>,
_params: FailParamsWithStep,
) -> Result<(), super::VerificationOrSendErrorWithToken<super::TcStateStarted>> {
match self.verification_map.borrow_mut().get_mut(&token.req_id) {
let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => {
// TODO: Enable this after the spacepackets update.
// entry.step = Some(step.value()),
@ -1574,7 +1583,8 @@ pub mod tests {
token: VerificationToken<TcState>,
_time_stamp: Option<&[u8]>,
) -> Result<(), super::VerificationOrSendErrorWithToken<TcState>> {
match self.verification_map.borrow_mut().get_mut(&token.req_id) {
let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => entry.completed = Some(true),
None => panic!(
"unexpected acceptance success for request ID {}",
@ -1589,7 +1599,8 @@ pub mod tests {
token: VerificationToken<TcState>,
params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<TcState>> {
match self.verification_map.borrow_mut().get_mut(&token.req_id) {
let verif_map = self.verification_map.lock().unwrap();
match verif_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());