Skip to content

Commit

Permalink
Tests: Added test-execution-time-exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
Glamhoth committed Oct 31, 2023
1 parent c04b380 commit e7b2c89
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
5 changes: 5 additions & 0 deletions testbins/test-execution-time-exceeded/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
target = "x86_64-unknown-linux-gnu"

[env]
AERUGO_TASKLET_COUNT = { value = "3" }
8 changes: 8 additions & 0 deletions testbins/test-execution-time-exceeded/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
authors = ["Filip Demski <glamhoth@protonmail.com>"]
edition = "2021"
name = "test-execution-time-exceeded"
version = "1.0.0"

[dependencies]
aerugo = { version = "0.1.0", path = "../..", features = ["use-aerugo-x86"] }
78 changes: 78 additions & 0 deletions testbins/test-execution-time-exceeded/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use aerugo::{
logln, Aerugo, Duration, EventId, EventStorage, InitApi, RuntimeApi, SystemHardwareConfig,
TaskletConfig, TaskletStorage,
};

enum MyEvents {
TimeExceeded,
}

impl From<MyEvents> 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<EventId, TaskBContext, 0> = 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();
}
1 change: 1 addition & 0 deletions tests/requirements/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions tests/requirements/test/test_execution_time_exceeded.rs
Original file line number Diff line number Diff line change
@@ -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
",
);
}

0 comments on commit e7b2c89

Please sign in to comment.