-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: Added
test-execution-time-exceeded
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
", | ||
); | ||
} |