added complete testset
This commit is contained in:
parent
982b1afcb9
commit
0f639900e2
@ -110,22 +110,35 @@ mod tests {
|
|||||||
use crate::pool::{LocalPool, PoolCfg, SharedPool};
|
use crate::pool::{LocalPool, PoolCfg, SharedPool};
|
||||||
use crate::pus::test::PusService17TestHandler;
|
use crate::pus::test::PusService17TestHandler;
|
||||||
use crate::pus::verification::{
|
use crate::pus::verification::{
|
||||||
RequestId, VerificationReporterCfg, VerificationReporterWithSender,
|
RequestId, VerificationReporterCfg, VerificationReporterWithSender, VerificationToken,
|
||||||
};
|
};
|
||||||
use crate::pus::{
|
use crate::pus::{
|
||||||
EcssTcAndToken, EcssTcInStoreConverter, MpscTcReceiver, MpscTmInStoreSender, MpscTmAsVecSender, EcssTcInVecConverter, TcInMemory,
|
EcssTcAndToken, EcssTcInStoreConverter, EcssTcInVecConverter, MpscTcReceiver,
|
||||||
|
MpscTmAsVecSender, MpscTmInStoreSender, TcInMemory,
|
||||||
};
|
};
|
||||||
use crate::tmtc::tm_helper::SharedTmStore;
|
use crate::tmtc::tm_helper::SharedTmStore;
|
||||||
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
|
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
|
||||||
use spacepackets::ecss::tm::PusTmReader;
|
use spacepackets::ecss::tm::PusTmReader;
|
||||||
use spacepackets::ecss::{PusPacket, WritablePusPacket};
|
use spacepackets::ecss::{PusPacket, WritablePusPacket};
|
||||||
use spacepackets::{SequenceFlags, SpHeader};
|
use spacepackets::{CcsdsPacket, SequenceFlags, SpHeader};
|
||||||
use std::boxed::Box;
|
use std::boxed::Box;
|
||||||
use std::sync::{mpsc, RwLock};
|
use std::sync::{mpsc, RwLock};
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
const TEST_APID: u16 = 0x101;
|
const TEST_APID: u16 = 0x101;
|
||||||
|
|
||||||
|
fn verify_verification_tm<STATE>(
|
||||||
|
subservice: u8,
|
||||||
|
tm: &PusTmReader<'_>,
|
||||||
|
token: VerificationToken<STATE>,
|
||||||
|
) {
|
||||||
|
assert_eq!(tm.service(), 1);
|
||||||
|
assert_eq!(tm.subservice(), subservice);
|
||||||
|
assert_eq!(tm.apid(), TEST_APID);
|
||||||
|
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
|
||||||
|
assert_eq!(req_id, token.req_id());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic_ping_processing_using_store() {
|
fn test_basic_ping_processing_using_store() {
|
||||||
let mut pus_buf: [u8; 64] = [0; 64];
|
let mut pus_buf: [u8; 64] = [0; 64];
|
||||||
@ -177,11 +190,7 @@ mod tests {
|
|||||||
let mut tm_addr = next_msg.unwrap();
|
let mut tm_addr = next_msg.unwrap();
|
||||||
let tm_pool = tm_pool_shared.read().unwrap();
|
let tm_pool = tm_pool_shared.read().unwrap();
|
||||||
let tm_raw = tm_pool.read(&tm_addr).unwrap();
|
let tm_raw = tm_pool.read(&tm_addr).unwrap();
|
||||||
let (tm, _) = PusTmReader::new(tm_raw, 0).unwrap();
|
verify_verification_tm(1, &PusTmReader::new(tm_raw, 0).unwrap().0, token);
|
||||||
assert_eq!(tm.service(), 1);
|
|
||||||
assert_eq!(tm.subservice(), 1);
|
|
||||||
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
|
|
||||||
assert_eq!(req_id, token.req_id());
|
|
||||||
|
|
||||||
// Acceptance TM
|
// Acceptance TM
|
||||||
next_msg = tm_rx.try_recv();
|
next_msg = tm_rx.try_recv();
|
||||||
@ -189,11 +198,7 @@ mod tests {
|
|||||||
tm_addr = next_msg.unwrap();
|
tm_addr = next_msg.unwrap();
|
||||||
let tm_raw = tm_pool.read(&tm_addr).unwrap();
|
let tm_raw = tm_pool.read(&tm_addr).unwrap();
|
||||||
// Is generated with CDS short timestamp.
|
// Is generated with CDS short timestamp.
|
||||||
let (tm, _) = PusTmReader::new(tm_raw, 7).unwrap();
|
verify_verification_tm(3, &PusTmReader::new(tm_raw, 7).unwrap().0, token);
|
||||||
assert_eq!(tm.service(), 1);
|
|
||||||
assert_eq!(tm.subservice(), 3);
|
|
||||||
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
|
|
||||||
assert_eq!(req_id, token.req_id());
|
|
||||||
|
|
||||||
// Ping reply
|
// Ping reply
|
||||||
next_msg = tm_rx.try_recv();
|
next_msg = tm_rx.try_recv();
|
||||||
@ -211,12 +216,7 @@ mod tests {
|
|||||||
assert!(next_msg.is_ok());
|
assert!(next_msg.is_ok());
|
||||||
tm_addr = next_msg.unwrap();
|
tm_addr = next_msg.unwrap();
|
||||||
let tm_raw = tm_pool.read(&tm_addr).unwrap();
|
let tm_raw = tm_pool.read(&tm_addr).unwrap();
|
||||||
// Is generated with CDS short timestamp.
|
verify_verification_tm(7, &PusTmReader::new(tm_raw, 7).unwrap().0, token);
|
||||||
let (tm, _) = PusTmReader::new(tm_raw, 7).unwrap();
|
|
||||||
assert_eq!(tm.service(), 1);
|
|
||||||
assert_eq!(tm.subservice(), 7);
|
|
||||||
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
|
|
||||||
assert_eq!(req_id, token.req_id());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -224,8 +224,7 @@ mod tests {
|
|||||||
let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel();
|
let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel();
|
||||||
let (tm_tx, tm_rx) = mpsc::channel();
|
let (tm_tx, tm_rx) = mpsc::channel();
|
||||||
|
|
||||||
let verif_sender =
|
let verif_sender = MpscTmAsVecSender::new(0, "verif_sender", tm_tx.clone());
|
||||||
MpscTmAsVecSender::new(0, "verif_sender", tm_tx.clone());
|
|
||||||
let verif_cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
|
let verif_cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
|
||||||
let mut verification_handler =
|
let mut verification_handler =
|
||||||
VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
|
VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
|
||||||
@ -244,11 +243,15 @@ mod tests {
|
|||||||
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(17, 1);
|
let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||||
let ping_tc = PusTcCreator::new_no_app_data(&mut sp_header, sec_header, true);
|
let ping_tc = PusTcCreator::new_no_app_data(&mut sp_header, sec_header, true);
|
||||||
let token = verification_handler.add_tc(&ping_tc);
|
let init_token = verification_handler.add_tc(&ping_tc);
|
||||||
verification_handler.acceptance_success(token, None);
|
let token = verification_handler
|
||||||
|
.acceptance_success(init_token, None)
|
||||||
|
.expect("acceptance failed");
|
||||||
let ping_tc_as_vec = ping_tc.to_vec().unwrap();
|
let ping_tc_as_vec = ping_tc.to_vec().unwrap();
|
||||||
let tc_in_memory = TcInMemory::from(ping_tc_as_vec);
|
let tc_in_memory = TcInMemory::from(ping_tc_as_vec);
|
||||||
test_srv_tc_tx.send(EcssTcAndToken::new(tc_in_memory, token)).unwrap();
|
test_srv_tc_tx
|
||||||
|
.send(EcssTcAndToken::new(tc_in_memory, token))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let result = pus_17_handler.handle_one_tc();
|
let result = pus_17_handler.handle_one_tc();
|
||||||
if let Err(e) = result.as_ref() {
|
if let Err(e) = result.as_ref() {
|
||||||
@ -259,10 +262,25 @@ mod tests {
|
|||||||
let mut next_msg = tm_rx.try_recv();
|
let mut next_msg = tm_rx.try_recv();
|
||||||
assert!(next_msg.is_ok());
|
assert!(next_msg.is_ok());
|
||||||
let mut tm_raw = next_msg.unwrap();
|
let mut tm_raw = next_msg.unwrap();
|
||||||
let (tm, _) = PusTmReader::new(&tm_raw, 0).unwrap();
|
verify_verification_tm(1, &PusTmReader::new(&tm_raw, 0).unwrap().0, token);
|
||||||
assert_eq!(tm.service(), 1);
|
|
||||||
assert_eq!(tm.subservice(), 1);
|
next_msg = tm_rx.try_recv();
|
||||||
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
|
assert!(next_msg.is_ok());
|
||||||
assert_eq!(req_id, token.req_id());
|
tm_raw = next_msg.unwrap();
|
||||||
|
verify_verification_tm(3, &PusTmReader::new(&tm_raw, 7).unwrap().0, token);
|
||||||
|
|
||||||
|
next_msg = tm_rx.try_recv();
|
||||||
|
assert!(next_msg.is_ok());
|
||||||
|
tm_raw = next_msg.unwrap();
|
||||||
|
// Is generated with CDS short timestamp.
|
||||||
|
let (tm, _) = PusTmReader::new(&tm_raw, 7).unwrap();
|
||||||
|
assert_eq!(tm.service(), 17);
|
||||||
|
assert_eq!(tm.subservice(), 2);
|
||||||
|
assert!(tm.user_data().is_empty());
|
||||||
|
|
||||||
|
next_msg = tm_rx.try_recv();
|
||||||
|
assert!(next_msg.is_ok());
|
||||||
|
tm_raw = next_msg.unwrap();
|
||||||
|
verify_verification_tm(7, &PusTmReader::new(&tm_raw, 7).unwrap().0, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user