PUS Event Generation #17
@ -257,6 +257,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::events::{Event, Severity};
|
use crate::events::{Event, Severity};
|
||||||
use crate::pus::tests::CommonTmInfo;
|
use crate::pus::tests::CommonTmInfo;
|
||||||
|
use std::vec::Vec;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
const EXAMPLE_APID: u16 = 0xee;
|
const EXAMPLE_APID: u16 = 0xee;
|
||||||
@ -269,6 +270,7 @@ mod tests {
|
|||||||
struct TmInfo {
|
struct TmInfo {
|
||||||
pub common: CommonTmInfo,
|
pub common: CommonTmInfo,
|
||||||
pub event: Event,
|
pub event: Event,
|
||||||
|
pub aux_data: Vec<u8>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -284,9 +286,14 @@ mod tests {
|
|||||||
let event = Event::try_from(u32::from_be_bytes(src_data[0..4].try_into().unwrap()));
|
let event = Event::try_from(u32::from_be_bytes(src_data[0..4].try_into().unwrap()));
|
||||||
assert!(event.is_ok());
|
assert!(event.is_ok());
|
||||||
let event = event.unwrap();
|
let event = event.unwrap();
|
||||||
|
let mut aux_data = Vec::new();
|
||||||
|
if src_data.len() > 4 {
|
||||||
|
aux_data.extend_from_slice(&src_data[4..]);
|
||||||
|
}
|
||||||
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,
|
event,
|
||||||
|
aux_data
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -307,37 +314,42 @@ mod tests {
|
|||||||
time_stamp: &[u8],
|
time_stamp: &[u8],
|
||||||
event: Event,
|
event: Event,
|
||||||
severity: Severity,
|
severity: Severity,
|
||||||
|
aux_data: Option<&[u8]>
|
||||||
) {
|
) {
|
||||||
match severity {
|
match severity {
|
||||||
Severity::INFO => {
|
Severity::INFO => {
|
||||||
reporter
|
reporter
|
||||||
.event_info(sender, time_stamp, event, None)
|
.event_info(sender, time_stamp, event, aux_data)
|
||||||
.expect("Error reporting info event");
|
.expect("Error reporting info event");
|
||||||
}
|
}
|
||||||
Severity::LOW => {
|
Severity::LOW => {
|
||||||
reporter
|
reporter
|
||||||
.event_low_severity(sender, time_stamp, event, None)
|
.event_low_severity(sender, time_stamp, event, aux_data)
|
||||||
.expect("Error reporting low event");
|
.expect("Error reporting low event");
|
||||||
}
|
}
|
||||||
Severity::MEDIUM => {
|
Severity::MEDIUM => {
|
||||||
reporter
|
reporter
|
||||||
.event_medium_severity(sender, time_stamp, event, None)
|
.event_medium_severity(sender, time_stamp, event, aux_data)
|
||||||
.expect("Error reporting medium event");
|
.expect("Error reporting medium event");
|
||||||
}
|
}
|
||||||
Severity::HIGH => {
|
Severity::HIGH => {
|
||||||
reporter
|
reporter
|
||||||
.event_high_severity(sender, time_stamp, event, None)
|
.event_high_severity(sender, time_stamp, event, aux_data)
|
||||||
.expect("Error reporting high event");
|
.expect("Error reporting high event");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn basic_event_test(severity: Severity) {
|
fn basic_event_test(max_event_aux_data_buf: usize, severity: Severity, error_data: Option<&[u8]>) {
|
||||||
let mut sender = TestSender::default();
|
let mut sender = TestSender::default();
|
||||||
let reporter = EventReporter::new(EXAMPLE_APID, 16);
|
let reporter = EventReporter::new(EXAMPLE_APID, max_event_aux_data_buf);
|
||||||
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 mut error_copy = Vec::new();
|
||||||
|
if let Some(err_data) = error_data {
|
||||||
|
error_copy.extend_from_slice(err_data);
|
||||||
|
}
|
||||||
let event = Event::new(severity, EXAMPLE_GROUP_ID, EXAMPLE_EVENT_ID_0)
|
let event = Event::new(severity, EXAMPLE_GROUP_ID, EXAMPLE_EVENT_ID_0)
|
||||||
.expect("Error creating example event");
|
.expect("Error creating example event");
|
||||||
report_basic_event(
|
report_basic_event(
|
||||||
@ -346,6 +358,7 @@ mod tests {
|
|||||||
&time_stamp_empty,
|
&time_stamp_empty,
|
||||||
event,
|
event,
|
||||||
severity,
|
severity,
|
||||||
|
error_data
|
||||||
);
|
);
|
||||||
assert_eq!(sender.service_queue.len(), 1);
|
assert_eq!(sender.service_queue.len(), 1);
|
||||||
let tm_info = sender.service_queue.pop_front().unwrap();
|
let tm_info = sender.service_queue.pop_front().unwrap();
|
||||||
@ -358,25 +371,32 @@ mod tests {
|
|||||||
assert_eq!(tm_info.common.msg_counter, 0);
|
assert_eq!(tm_info.common.msg_counter, 0);
|
||||||
assert_eq!(tm_info.common.apid, EXAMPLE_APID);
|
assert_eq!(tm_info.common.apid, EXAMPLE_APID);
|
||||||
assert_eq!(tm_info.event, event);
|
assert_eq!(tm_info.event, event);
|
||||||
|
assert_eq!(tm_info.aux_data, error_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_info_event_generation() {
|
fn basic_info_event_generation() {
|
||||||
basic_event_test(Severity::INFO);
|
basic_event_test(4, Severity::INFO, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_low_severity_event() {
|
fn basic_low_severity_event() {
|
||||||
basic_event_test(Severity::LOW);
|
basic_event_test(4, Severity::LOW, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_medium_severity_event() {
|
fn basic_medium_severity_event() {
|
||||||
basic_event_test(Severity::MEDIUM);
|
basic_event_test(4, Severity::MEDIUM, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_high_severity_event() {
|
fn basic_high_severity_event() {
|
||||||
basic_event_test(Severity::HIGH);
|
basic_event_test(4, Severity::HIGH, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn event_with_info_string() {
|
||||||
|
let info_string = "Test Information";
|
||||||
|
basic_event_test(32, Severity::INFO, Some(info_string.as_bytes()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user