From e7b2c89364e87024ca3e87961c90d8dd4109ff9c Mon Sep 17 00:00:00 2001 From: Filip Demski Date: Mon, 30 Oct 2023 16:30:25 +0100 Subject: [PATCH] Tests: Added `test-execution-time-exceeded` --- .../.cargo/config.toml | 5 ++ .../test-execution-time-exceeded/Cargo.toml | 8 ++ .../test-execution-time-exceeded/src/main.rs | 78 +++++++++++++++++++ tests/requirements/test/mod.rs | 1 + .../test/test_execution_time_exceeded.rs | 21 +++++ 5 files changed, 113 insertions(+) create mode 100644 testbins/test-execution-time-exceeded/.cargo/config.toml create mode 100644 testbins/test-execution-time-exceeded/Cargo.toml create mode 100644 testbins/test-execution-time-exceeded/src/main.rs create mode 100644 tests/requirements/test/test_execution_time_exceeded.rs diff --git a/testbins/test-execution-time-exceeded/.cargo/config.toml b/testbins/test-execution-time-exceeded/.cargo/config.toml new file mode 100644 index 00000000..c34c88bf --- /dev/null +++ b/testbins/test-execution-time-exceeded/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +target = "x86_64-unknown-linux-gnu" + +[env] +AERUGO_TASKLET_COUNT = { value = "3" } diff --git a/testbins/test-execution-time-exceeded/Cargo.toml b/testbins/test-execution-time-exceeded/Cargo.toml new file mode 100644 index 00000000..4be6416f --- /dev/null +++ b/testbins/test-execution-time-exceeded/Cargo.toml @@ -0,0 +1,8 @@ +[package] +authors = ["Filip Demski "] +edition = "2021" +name = "test-execution-time-exceeded" +version = "1.0.0" + +[dependencies] +aerugo = { version = "0.1.0", path = "../..", features = ["use-aerugo-x86"] } diff --git a/testbins/test-execution-time-exceeded/src/main.rs b/testbins/test-execution-time-exceeded/src/main.rs new file mode 100644 index 00000000..10c528ab --- /dev/null +++ b/testbins/test-execution-time-exceeded/src/main.rs @@ -0,0 +1,78 @@ +use aerugo::{ + logln, Aerugo, Duration, EventId, EventStorage, InitApi, RuntimeApi, SystemHardwareConfig, + TaskletConfig, TaskletStorage, +}; + +enum MyEvents { + TimeExceeded, +} + +impl From for EventId { + fn from(value: MyEvents) -> Self { + match value { + MyEvents::TimeExceeded => 1, + } + } +} + +#[derive(Default)] +struct TaskAContext { + cnt: u8, +} + +fn task_a(_: (), context: &mut TaskAContext, _: &'static dyn RuntimeApi) { + context.cnt = context.cnt.wrapping_add(1); + + let sleep_time = if context.cnt == 1 { + logln!("Running 20ms"); + std::time::Duration::from_millis(20) + } else { + logln!("Running 150ms"); + std::time::Duration::from_millis(150) + }; + + std::thread::sleep(sleep_time); +} + +#[derive(Default)] +struct TaskBContext {} + +fn task_b(_: EventId, _: &mut TaskBContext, _: &'static dyn RuntimeApi) { + logln!("Time exceeded"); + std::process::exit(0); +} + +static TASK_A_STORAGE: TaskletStorage<(), TaskAContext, 0> = TaskletStorage::new(); +static TASK_B_STORAGE: TaskletStorage = TaskletStorage::new(); +static TIME_EXCEEDED_EVENT_STORAGE: EventStorage = EventStorage::new(); + +fn main() -> ! { + let (aerugo, _) = Aerugo::initialize(SystemHardwareConfig::default()); + + aerugo.create_event(MyEvents::TimeExceeded.into(), &TIME_EXCEEDED_EVENT_STORAGE); + + let task_a_config = TaskletConfig { + name: "TaskA", + priority: 1, + }; + let task_a_context = TaskAContext { cnt: 0 }; + + let task_b_config = TaskletConfig { + name: "TaskB", + priority: 1, + }; + + aerugo.create_tasklet_with_context(task_a_config, task_a, task_a_context, &TASK_A_STORAGE); + aerugo.create_tasklet(task_b_config, task_b, &TASK_B_STORAGE); + + let task_a_handle = TASK_A_STORAGE.create_handle().unwrap(); + aerugo.subscribe_tasklet_to_cyclic(&task_a_handle, Some(Duration::secs(1)), None); + + let task_b_handle = TASK_B_STORAGE.create_handle().unwrap(); + aerugo.subscribe_tasklet_to_events(&task_b_handle, [MyEvents::TimeExceeded.into()]); + + let time_exceeded_handle = TIME_EXCEEDED_EVENT_STORAGE.create_handle().unwrap(); + aerugo.set_execution_time_exceeded_maximum_event(&time_exceeded_handle, Duration::millis(100)); + + aerugo.start(); +} diff --git a/tests/requirements/test/mod.rs b/tests/requirements/test/mod.rs index 7710940a..781accbb 100644 --- a/tests/requirements/test/mod.rs +++ b/tests/requirements/test/mod.rs @@ -8,6 +8,7 @@ mod test_event_clear_queue; mod test_event_interrupt; mod test_event_scheduled; mod test_execution_monitoring; +mod test_execution_time_exceeded; mod test_hal_nvic; mod test_hal_pio; mod test_hal_pmc; diff --git a/tests/requirements/test/test_execution_time_exceeded.rs b/tests/requirements/test/test_execution_time_exceeded.rs new file mode 100644 index 00000000..52a3748c --- /dev/null +++ b/tests/requirements/test/test_execution_time_exceeded.rs @@ -0,0 +1,21 @@ +use assert_cmd::Command; +use test_binary::build_test_binary; + +/// @SRS{ROS-FUN-RTOS-5040} +#[cfg_attr(not(doc), test)] +fn req_test_execution_time_exceeded() { + let test_bin_path = build_test_binary("test-execution-time-exceeded", "testbins") + .expect("error building test binary"); + + Command::new(test_bin_path) + .timeout(std::time::Duration::from_secs(5)) + .assert() + .success() + .code(0) + .stdout( + r"Running 20ms +Running 150ms +Time exceeded +", + ); +}