Skip to content

Commit

Permalink
Add test for task concurrent restart.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyma98 committed Aug 18, 2024
1 parent fb3a655 commit e5020e0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/actions/build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ runs:
sub-category: unwind
test-name: deferred_nested_drop

- name: Build test test-task-unwind-concurrent_restart
uses: ./.github/workflows/actions/build-test
with:
category: task
sub-category: unwind
test-name: concurrent_restart

# *** Tests for task - segmented stack ***

- name: Build test test-task-segmented_stack-function_arguments
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/task-unwind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,17 @@ jobs:
category: task
sub-category: unwind
test-name: deferred_nested_drop

concurrent_restart:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run test concurrent_restart
uses: ./.github/workflows/actions/run-test
with:
cookie: ${{ secrets.cookie }}
category: task
sub-category: unwind
test-name: concurrent_restart
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ path = "examples/tests/task/unwind/deferred_indirect_drop.rs"
name = "test-task-unwind-deferred_nested_drop"
path = "examples/tests/task/unwind/deferred_nested_drop.rs"

[[example]]
name = "test-task-unwind-concurrent_restart"
path = "examples/tests/task/unwind/concurrent_restart.rs"

# *** Tests for task - segmented stack ***

[[example]]
Expand Down
46 changes: 46 additions & 0 deletions examples/tests/task/unwind/concurrent_restart.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Tests that a panicked task will be restarted by a new instance running in
//! concurrent with the unwinding process of the panicked instance. The old
//! panicked instance should be reduced to a low priority (`UNWIND_PRIORITY`)
//! and thus the restarted instance should finish before the unwinding completes.
#![no_std]
#![no_main]

extern crate alloc;
use core::sync::atomic::{AtomicBool, Ordering};
use hopter::{boot::main, config, debug::semihosting, hprintln, task};

#[main]
fn main(_: cortex_m::Peripherals) {
task::build()
.set_entry(will_panic)
.spawn_restartable()
.unwrap();

// Let the test task and its unwinding complete first.
task::change_current_priority(config::UNWIND_PRIORITY + 1).unwrap();

semihosting::terminate(true);
}

fn will_panic() {
static FIRST_TIME: AtomicBool = AtomicBool::new(true);
let first_time = FIRST_TIME.fetch_and(false, Ordering::SeqCst);

// Deliberate panic when the task is executed for the first time.
// Unwinding should happen after the second run is completed.
if first_time {
let _print_on_drop = PrintOnDrop("First run dropped on panic");
panic!()
}

hprintln!("Second run completed");
}

struct PrintOnDrop(&'static str);

impl Drop for PrintOnDrop {
fn drop(&mut self) {
hprintln!("{}", self.0)
}
}
2 changes: 2 additions & 0 deletions examples/tests/task/unwind/concurrent_restart.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Second run completed
First run dropped on panic

0 comments on commit e5020e0

Please sign in to comment.