basic event tests

This commit is contained in:
Robin Müller 2022-10-21 20:07:30 +02:00
parent 183aa01b7f
commit ac850533e1
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C

View File

@ -261,11 +261,14 @@ mod tests {
const EXAMPLE_APID: u16 = 0xee; const EXAMPLE_APID: u16 = 0xee;
const EXAMPLE_GROUP_ID: u16 = 2; const EXAMPLE_GROUP_ID: u16 = 2;
const EXAMPLE_EVENT_ID: u16 = 1; const EXAMPLE_EVENT_ID_0: u16 = 1;
#[allow(dead_code)]
const EXAMPLE_EVENT_ID_1: u16 = 2;
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
struct TmInfo { struct TmInfo {
pub common: CommonTmInfo, pub common: CommonTmInfo,
pub event: Event,
} }
#[derive(Default)] #[derive(Default)]
@ -275,24 +278,104 @@ mod tests {
impl EcssTmSender<()> for TestSender { impl EcssTmSender<()> for TestSender {
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> { fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> {
assert!(tm.source_data().is_some());
let src_data = tm.source_data().unwrap();
assert!(src_data.len() >= 4);
let event = Event::try_from(u32::from_be_bytes(src_data[0..4].try_into().unwrap()));
assert!(event.is_ok());
let event = event.unwrap();
self.service_queue.push_back(TmInfo { self.service_queue.push_back(TmInfo {
common: CommonTmInfo::new_from_tm(&tm), common: CommonTmInfo::new_from_tm(&tm),
event,
}); });
Ok(()) Ok(())
} }
} }
#[test] fn severity_to_subservice(severity: Severity) -> Subservices {
fn basic_event_generation() { match severity {
Severity::INFO => Subservices::TmInfoReport,
Severity::LOW => Subservices::TmLowSeverityReport,
Severity::MEDIUM => Subservices::TmMediumSeverityReport,
Severity::HIGH => Subservices::TmHighSeverityReport,
}
}
fn report_basic_event(
reporter: &mut EventReporter,
sender: &mut TestSender,
time_stamp: &[u8],
event: Event,
severity: Severity,
) {
match severity {
Severity::INFO => {
reporter
.event_info(sender, time_stamp, event, None)
.expect("Error reporting info event");
}
Severity::LOW => {
reporter
.event_low_severity(sender, time_stamp, event, None)
.expect("Error reporting low event");
}
Severity::MEDIUM => {
reporter
.event_medium_severity(sender, time_stamp, event, None)
.expect("Error reporting medium event");
}
Severity::HIGH => {
reporter
.event_high_severity(sender, time_stamp, event, None)
.expect("Error reporting high event");
}
}
}
fn basic_event_test(severity: Severity) {
let mut sender = TestSender::default(); let mut sender = TestSender::default();
let reporter = EventReporter::new(EXAMPLE_APID, 16); let reporter = EventReporter::new(EXAMPLE_APID, 16);
assert!(reporter.is_some()); assert!(reporter.is_some());
let mut reporter = reporter.unwrap(); let mut reporter = reporter.unwrap();
let time_stamp_empty: [u8; 7] = [0; 7]; let time_stamp_empty: [u8; 7] = [0; 7];
let event = Event::new(Severity::INFO, EXAMPLE_GROUP_ID, EXAMPLE_EVENT_ID) let event = Event::new(severity, EXAMPLE_GROUP_ID, EXAMPLE_EVENT_ID_0)
.expect("Error creating example event"); .expect("Error creating example event");
reporter report_basic_event(
.event_info(&mut sender, &time_stamp_empty, event, None) &mut reporter,
.expect("Error reporting info event"); &mut sender,
&time_stamp_empty,
event,
severity,
);
assert_eq!(sender.service_queue.len(), 1);
let tm_info = sender.service_queue.pop_front().unwrap();
assert_eq!(
tm_info.common.subservice,
severity_to_subservice(severity) as u8
);
assert_eq!(tm_info.common.dest_id, 0);
assert_eq!(tm_info.common.time_stamp, time_stamp_empty);
assert_eq!(tm_info.common.msg_counter, 0);
assert_eq!(tm_info.common.apid, EXAMPLE_APID);
assert_eq!(tm_info.event, event);
}
#[test]
fn basic_info_event_generation() {
basic_event_test(Severity::INFO);
}
#[test]
fn basic_low_severity_event() {
basic_event_test(Severity::LOW);
}
#[test]
fn basic_medium_severity_event() {
basic_event_test(Severity::MEDIUM);
}
#[test]
fn basic_high_severity_event() {
basic_event_test(Severity::HIGH);
} }
} }