diff --git a/satrs-example/src/pus/action.rs b/satrs-example/src/pus/action.rs index 35c7491..2857e9a 100644 --- a/satrs-example/src/pus/action.rs +++ b/satrs-example/src/pus/action.rs @@ -648,4 +648,14 @@ mod tests { fn reply_handling_step_failure() { // TODO: Implement } + + #[test] + fn reply_handling_unrequested_reply() { + // TODO: Implement + } + + #[test] + fn reply_handling_reply_timeout() { + // TODO: Implement + } } diff --git a/satrs-example/src/pus/hk.rs b/satrs-example/src/pus/hk.rs index c2951f0..dc5f927 100644 --- a/satrs-example/src/pus/hk.rs +++ b/satrs-example/src/pus/hk.rs @@ -450,12 +450,82 @@ mod tests { #[test] fn hk_conversion_disable_periodic_generation() { - // TODO: Implement + let mut hk_bench = PusConverterTestbench::new(HkRequestConverter::default()); + let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); + let target_id = TEST_APID_TARGET_ID; + 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 mut generic_check = |tc: &PusTcCreator| { + let accepted_token = hk_bench.add_tc(tc); + let (_active_req, req) = hk_bench + .convert(accepted_token, &[], TEST_APID, TEST_APID_TARGET_ID) + .expect("conversion failed"); + if let HkRequest::Disable(id) = req { + assert_eq!(id, unique_id); + } else { + panic!("unexpected HK request") + } + }; + let tc0 = PusTcCreator::new_simple( + &mut sp_header, + 3, + Subservice::TcDisableHkGeneration as u8, + Some(&app_data), + true, + ); + generic_check(&tc0); + let tc1 = PusTcCreator::new_simple( + &mut sp_header, + 3, + Subservice::TcDisableDiagGeneration as u8, + Some(&app_data), + true, + ); + generic_check(&tc1); } #[test] fn hk_conversion_modify_interval() { - // TODO: Implement + let mut hk_bench = PusConverterTestbench::new(HkRequestConverter::default()); + let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); + let target_id = TEST_APID_TARGET_ID; + let unique_id = 5_u32; + let mut app_data: [u8; 12] = [0; 12]; + let collection_interval_factor = 5_u32; + app_data[0..4].copy_from_slice(&target_id.to_be_bytes()); + app_data[4..8].copy_from_slice(&unique_id.to_be_bytes()); + app_data[8..12].copy_from_slice(&collection_interval_factor.to_be_bytes()); + + let mut generic_check = |tc: &PusTcCreator| { + let accepted_token = hk_bench.add_tc(tc); + let (_active_req, req) = hk_bench + .convert(accepted_token, &[], TEST_APID, TEST_APID_TARGET_ID) + .expect("conversion failed"); + if let HkRequest::ModifyCollectionInterval(id, interval_factor) = req { + assert_eq!(id, unique_id); + assert_eq!(interval_factor, collection_interval_factor); + } else { + panic!("unexpected HK request") + } + }; + let tc0 = PusTcCreator::new_simple( + &mut sp_header, + 3, + Subservice::TcModifyHkCollectionInterval as u8, + Some(&app_data), + true, + ); + generic_check(&tc0); + let tc1 = PusTcCreator::new_simple( + &mut sp_header, + 3, + Subservice::TcModifyDiagCollectionInterval as u8, + Some(&app_data), + true, + ); + generic_check(&tc1); } #[test] @@ -471,5 +541,5 @@ mod tests { reply_testbench.verif_reporter.check_completed(&req_id); } - // TODO: Add more tests for reply handler. + // TODO: Add more tests for reply handler: Request timeout and unrequested reply. } diff --git a/satrs-example/src/pus/mode.rs b/satrs-example/src/pus/mode.rs index a17edb5..e1b23fc 100644 --- a/satrs-example/src/pus/mode.rs +++ b/satrs-example/src/pus/mode.rs @@ -199,7 +199,7 @@ impl PusTcToRequestConverter for ModeRequestCo #[cfg(test)] mod tests { use satrs::{ - mode::ModeRequest, + mode::{ModeAndSubmode, ModeRequest}, pus::mode::Subservice, spacepackets::{ ecss::tc::{PusTcCreator, PusTcSecondaryHeader}, @@ -212,12 +212,11 @@ mod tests { use super::ModeRequestConverter; #[test] - fn mode_converter_set_mode_request() { + fn mode_converter_read_mode_request() { let mut testbench = PusConverterTestbench::new(ModeRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcReadMode as u8); let mut app_data: [u8; 4] = [0; 4]; - // Invalid ID, routing should fail. app_data[0..4].copy_from_slice(&TEST_APID_TARGET_ID.to_be_bytes()); let tc = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true); let token = testbench.add_tc(&tc); @@ -226,4 +225,54 @@ mod tests { .expect("conversion has failed"); assert_eq!(req, ModeRequest::ReadMode); } + + #[test] + fn mode_converter_set_mode_request() { + let mut testbench = PusConverterTestbench::new(ModeRequestConverter::default()); + let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); + let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcSetMode as u8); + let mut app_data: [u8; 4 + ModeAndSubmode::RAW_LEN] = [0; 4 + ModeAndSubmode::RAW_LEN]; + let mode_and_submode = ModeAndSubmode::new(2, 1); + app_data[0..4].copy_from_slice(&TEST_APID_TARGET_ID.to_be_bytes()); + mode_and_submode.write_to_be_bytes(&mut app_data[4..]).unwrap(); + let tc = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true); + let token = testbench.add_tc(&tc); + let (_active_req, req) = testbench + .convert(token, &[], TEST_APID, TEST_APID_TARGET_ID) + .expect("conversion has failed"); + assert_eq!(req, ModeRequest::SetMode(mode_and_submode)); + + } + + #[test] + fn mode_converter_announce_mode() { + let mut testbench = PusConverterTestbench::new(ModeRequestConverter::default()); + let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); + let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcAnnounceMode as u8); + let mut app_data: [u8; 4] = [0; 4]; + app_data[0..4].copy_from_slice(&TEST_APID_TARGET_ID.to_be_bytes()); + let tc = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true); + let token = testbench.add_tc(&tc); + let (_active_req, req) = testbench + .convert(token, &[], TEST_APID, TEST_APID_TARGET_ID) + .expect("conversion has failed"); + assert_eq!(req, ModeRequest::AnnounceMode); + } + + #[test] + fn mode_converter_announce_mode_recursively() { + let mut testbench = PusConverterTestbench::new(ModeRequestConverter::default()); + let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); + let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcAnnounceModeRecursive as u8); + let mut app_data: [u8; 4] = [0; 4]; + app_data[0..4].copy_from_slice(&TEST_APID_TARGET_ID.to_be_bytes()); + let tc = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true); + let token = testbench.add_tc(&tc); + let (_active_req, req) = testbench + .convert(token, &[], TEST_APID, TEST_APID_TARGET_ID) + .expect("conversion has failed"); + assert_eq!(req, ModeRequest::AnnounceModeRecursive); + } + + // TODO: Add reply handler tests. }