yet another testbench
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
This commit is contained in:
parent
ce5d333962
commit
6a95a7f087
@ -369,16 +369,12 @@ impl<
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use satrs::{
|
||||
pus::{
|
||||
test_util::TEST_APID,
|
||||
verification::{
|
||||
test_util::{SharedVerificationMap, TestVerificationReporter},
|
||||
VerificationReportingProvider,
|
||||
},
|
||||
PusTcToRequestConverter,
|
||||
},
|
||||
hk::HkRequest,
|
||||
pus::{test_util::TEST_APID, ActiveRequestProvider},
|
||||
request::TargetAndApidId,
|
||||
spacepackets::{
|
||||
ecss::{
|
||||
hk::Subservice,
|
||||
tc::{PusTcCreator, PusTcReader},
|
||||
WritablePusPacket,
|
||||
},
|
||||
@ -386,21 +382,42 @@ mod tests {
|
||||
},
|
||||
};
|
||||
|
||||
use crate::pus::tests::ConverterTestbench;
|
||||
|
||||
use super::ExampleHkRequestConverter;
|
||||
|
||||
#[test]
|
||||
fn test_hk_converter() {
|
||||
let shared_verif_map = SharedVerificationMap::default();
|
||||
let mut test_verif_reporter = TestVerificationReporter::new(shared_verif_map.clone());
|
||||
let mut converter = ExampleHkRequestConverter::default();
|
||||
fn test_hk_converter_one_shot_req() {
|
||||
let mut hk_bench = ConverterTestbench::new(ExampleHkRequestConverter::default());
|
||||
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
|
||||
let ping = PusTcCreator::new_simple(&mut sp_header, 3, 25, Some(&[1, 2, 3, 4]), true);
|
||||
let token = test_verif_reporter.add_tc(&ping);
|
||||
let accepted_token = test_verif_reporter
|
||||
.acceptance_success(token, &[])
|
||||
.expect("acceptance failed");
|
||||
let pus_tc_raw = ping.to_vec().unwrap();
|
||||
|
||||
let target_id = 2_u32;
|
||||
let unique_id = 5_u32;
|
||||
let mut app_data: [u8; 8] = [0; 8];
|
||||
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
|
||||
app_data[4..8].copy_from_slice(&unique_id.to_be_bytes());
|
||||
|
||||
let hk_req = PusTcCreator::new_simple(
|
||||
&mut sp_header,
|
||||
3,
|
||||
Subservice::TcGenerateOneShotHk as u8,
|
||||
Some(&app_data),
|
||||
true,
|
||||
);
|
||||
let accepted_token = hk_bench.add_tc(&hk_req);
|
||||
let pus_tc_raw = hk_req.to_vec().unwrap();
|
||||
let pus_tc_reader = PusTcReader::new(&pus_tc_raw).expect("invalid pus tc");
|
||||
converter.convert(accepted_token, &pus_tc_reader.0, &[], &test_verif_reporter);
|
||||
let (active_req, req) = hk_bench
|
||||
.convert(accepted_token, &pus_tc_reader.0, &[])
|
||||
.expect("conversion failed");
|
||||
assert_eq!(
|
||||
active_req.target_id(),
|
||||
TargetAndApidId::new(TEST_APID, target_id).into()
|
||||
);
|
||||
if let HkRequest::OneShot(id) = req {
|
||||
assert_eq!(id, unique_id);
|
||||
} else {
|
||||
panic!("unexpected HK request")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -468,10 +468,14 @@ pub(crate) mod tests {
|
||||
|
||||
use satrs::{
|
||||
pus::{
|
||||
verification::VerificationReporterWithVecMpscSender, ActiveRequestMapProvider,
|
||||
EcssTcInVecConverter, MpscTcReceiver, TmAsVecSenderWithMpsc,
|
||||
verification::{
|
||||
test_util::{SharedVerificationMap, TestVerificationReporter},
|
||||
VerificationReporterWithVecMpscSender,
|
||||
},
|
||||
ActiveRequestMapProvider, EcssTcInVecConverter, MpscTcReceiver, TmAsVecSenderWithMpsc,
|
||||
},
|
||||
request::TargetAndApidId,
|
||||
spacepackets::ecss::tc::PusTcCreator,
|
||||
};
|
||||
|
||||
use crate::requests::CompositeRequest;
|
||||
@ -482,6 +486,52 @@ pub(crate) mod tests {
|
||||
pub const TEST_APID_TARGET_ID: u32 = 5;
|
||||
pub const TARGET_ID: TargetAndApidId = TargetAndApidId::new(TEST_APID, TEST_APID_TARGET_ID);
|
||||
|
||||
pub struct ConverterTestbench<
|
||||
Converter: PusTcToRequestConverter<ActiveRequestInfo, Request, Error = GenericConversionError>,
|
||||
ActiveRequestInfo: ActiveRequestProvider,
|
||||
Request,
|
||||
> {
|
||||
pub shared_verif_map: SharedVerificationMap,
|
||||
pub verif_reporter: TestVerificationReporter,
|
||||
pub converter: Converter,
|
||||
phantom: std::marker::PhantomData<(ActiveRequestInfo, Request)>,
|
||||
}
|
||||
|
||||
impl<
|
||||
Converter: PusTcToRequestConverter<ActiveRequestInfo, Request, Error = GenericConversionError>,
|
||||
ActiveRequestInfo: ActiveRequestProvider,
|
||||
Request,
|
||||
> ConverterTestbench<Converter, ActiveRequestInfo, Request>
|
||||
{
|
||||
pub fn new(converter: Converter) -> Self {
|
||||
let shared_verif_map = SharedVerificationMap::default();
|
||||
let test_verif_reporter = TestVerificationReporter::new(shared_verif_map.clone());
|
||||
Self {
|
||||
shared_verif_map,
|
||||
verif_reporter: test_verif_reporter,
|
||||
converter,
|
||||
phantom: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_tc(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> {
|
||||
let token = self.verif_reporter.add_tc(tc);
|
||||
self.verif_reporter
|
||||
.acceptance_success(token, &[])
|
||||
.expect("acceptance failed")
|
||||
}
|
||||
|
||||
pub fn convert(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
tc_reader: &PusTcReader,
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(ActiveRequestInfo, Request), Converter::Error> {
|
||||
self.converter
|
||||
.convert(token, tc_reader, time_stamp, &self.verif_reporter)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TargetedPusRequestTestbench<
|
||||
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = GenericConversionError>,
|
||||
ReplyHandler: PusReplyHandler<ActiveRequestInfo, ReplyType, Error = EcssTmtcError>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user