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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use satrs::{
|
use satrs::{
|
||||||
pus::{
|
hk::HkRequest,
|
||||||
test_util::TEST_APID,
|
pus::{test_util::TEST_APID, ActiveRequestProvider},
|
||||||
verification::{
|
request::TargetAndApidId,
|
||||||
test_util::{SharedVerificationMap, TestVerificationReporter},
|
|
||||||
VerificationReportingProvider,
|
|
||||||
},
|
|
||||||
PusTcToRequestConverter,
|
|
||||||
},
|
|
||||||
spacepackets::{
|
spacepackets::{
|
||||||
ecss::{
|
ecss::{
|
||||||
|
hk::Subservice,
|
||||||
tc::{PusTcCreator, PusTcReader},
|
tc::{PusTcCreator, PusTcReader},
|
||||||
WritablePusPacket,
|
WritablePusPacket,
|
||||||
},
|
},
|
||||||
@ -386,21 +382,42 @@ mod tests {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::pus::tests::ConverterTestbench;
|
||||||
|
|
||||||
use super::ExampleHkRequestConverter;
|
use super::ExampleHkRequestConverter;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hk_converter() {
|
fn test_hk_converter_one_shot_req() {
|
||||||
let shared_verif_map = SharedVerificationMap::default();
|
let mut hk_bench = ConverterTestbench::new(ExampleHkRequestConverter::default());
|
||||||
let mut test_verif_reporter = TestVerificationReporter::new(shared_verif_map.clone());
|
|
||||||
let mut converter = ExampleHkRequestConverter::default();
|
|
||||||
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
|
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 target_id = 2_u32;
|
||||||
let accepted_token = test_verif_reporter
|
let unique_id = 5_u32;
|
||||||
.acceptance_success(token, &[])
|
let mut app_data: [u8; 8] = [0; 8];
|
||||||
.expect("acceptance failed");
|
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
|
||||||
let pus_tc_raw = ping.to_vec().unwrap();
|
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");
|
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::{
|
use satrs::{
|
||||||
pus::{
|
pus::{
|
||||||
verification::VerificationReporterWithVecMpscSender, ActiveRequestMapProvider,
|
verification::{
|
||||||
EcssTcInVecConverter, MpscTcReceiver, TmAsVecSenderWithMpsc,
|
test_util::{SharedVerificationMap, TestVerificationReporter},
|
||||||
|
VerificationReporterWithVecMpscSender,
|
||||||
|
},
|
||||||
|
ActiveRequestMapProvider, EcssTcInVecConverter, MpscTcReceiver, TmAsVecSenderWithMpsc,
|
||||||
},
|
},
|
||||||
request::TargetAndApidId,
|
request::TargetAndApidId,
|
||||||
|
spacepackets::ecss::tc::PusTcCreator,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::requests::CompositeRequest;
|
use crate::requests::CompositeRequest;
|
||||||
@ -482,6 +486,52 @@ pub(crate) mod tests {
|
|||||||
pub const TEST_APID_TARGET_ID: u32 = 5;
|
pub const TEST_APID_TARGET_ID: u32 = 5;
|
||||||
pub const TARGET_ID: TargetAndApidId = TargetAndApidId::new(TEST_APID, TEST_APID_TARGET_ID);
|
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<
|
pub struct TargetedPusRequestTestbench<
|
||||||
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = GenericConversionError>,
|
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = GenericConversionError>,
|
||||||
ReplyHandler: PusReplyHandler<ActiveRequestInfo, ReplyType, Error = EcssTmtcError>,
|
ReplyHandler: PusReplyHandler<ActiveRequestInfo, ReplyType, Error = EcssTmtcError>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user