Skip to content

Commit a284732

Browse files
committed
test(test_suite): test Kernel::{is_task_context, is_interrupt_context, is_boot_complete}
1 parent 1b4c8bb commit a284732

File tree

5 files changed

+78
-7
lines changed

5 files changed

+78
-7
lines changed

src/r3_test_suite/src/kernel_tests/interrupt_misc.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//! Validates error codes returned by interrupt line manipulation methods. Also,
22
//! checks miscellaneous properties of interrupt lines.
3-
use r3::kernel::{
4-
self, prelude::*, traits, Cfg, InterruptLine, StartupHook, StaticInterruptHandler, StaticTask,
3+
use core::sync::atomic::{AtomicBool, Ordering};
4+
use r3::{
5+
hunk::Hunk,
6+
kernel::{
7+
self, prelude::*, traits, Cfg, InterruptLine, StartupHook, StaticInterruptHandler,
8+
StaticTask,
9+
},
510
};
611

712
use super::Driver;
@@ -17,6 +22,7 @@ impl<T: traits::KernelBase + traits::KernelInterruptLine + traits::KernelStatic>
1722

1823
pub struct App<System: SupportedSystem> {
1924
int: Option<InterruptLine<System>>,
25+
interrupt_expected: Hunk<System, AtomicBool>,
2026
}
2127

2228
impl<System: SupportedSystem> App<System> {
@@ -36,6 +42,8 @@ impl<System: SupportedSystem> App<System> {
3642
.start(startup_hook::<System, D>)
3743
.finish(b);
3844

45+
let interrupt_expected = Hunk::<System, AtomicBool>::define().finish(b);
46+
3947
let int = if let [int_line, ..] = *D::INTERRUPT_LINES {
4048
unsafe {
4149
StaticInterruptHandler::define()
@@ -50,7 +58,10 @@ impl<System: SupportedSystem> App<System> {
5058
None
5159
};
5260

53-
App { int }
61+
App {
62+
int,
63+
interrupt_expected,
64+
}
5465
}
5566
}
5667

@@ -167,9 +178,25 @@ fn task_body<System: SupportedSystem, D: Driver<App<System>>>() {
167178
value => panic!("{:?}", value),
168179
}
169180

170-
D::success();
181+
if let &[pri, ..] = D::INTERRUPT_PRIORITIES {
182+
D::app().interrupt_expected.store(true, Ordering::Relaxed);
183+
log::debug!("Pending the interrupt line");
184+
int.set_priority(pri).unwrap();
185+
int.pend().unwrap();
186+
} else {
187+
log::warn!("No interrupt priorities defined, skipping the rest of the test");
188+
D::success();
189+
}
171190
}
172191

173192
fn isr<System: SupportedSystem, D: Driver<App<System>>>() {
174-
unreachable!();
193+
log::debug!("The interrupt handler is running");
194+
assert!(D::app().interrupt_expected.load(Ordering::Relaxed));
195+
196+
// Context query
197+
assert!(!System::is_task_context());
198+
assert!(System::is_interrupt_context());
199+
assert!(System::is_boot_complete());
200+
201+
D::success();
175202
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! Checks miscellaneous properties of `StartupHook`.
2+
use core::marker::PhantomData;
3+
use r3::kernel::{prelude::*, traits, Cfg, StartupHook};
4+
5+
use super::Driver;
6+
7+
pub trait SupportedSystem: traits::KernelBase + traits::KernelStatic {}
8+
impl<T: traits::KernelBase + traits::KernelStatic> SupportedSystem for T {}
9+
10+
pub struct App<System: SupportedSystem> {
11+
_phantom: PhantomData<System>,
12+
}
13+
14+
impl<System: SupportedSystem> App<System> {
15+
pub const fn new<C, D: Driver<Self>>(b: &mut Cfg<C>) -> Self
16+
where
17+
C: ~const traits::CfgBase<System = System> + ~const traits::CfgTask,
18+
{
19+
StartupHook::define().start(hook::<System, D>).finish(b);
20+
21+
App {
22+
_phantom: PhantomData,
23+
}
24+
}
25+
}
26+
27+
fn hook<System: SupportedSystem, D: Driver<App<System>>>() {
28+
log::trace!("The startup hook is running");
29+
30+
// Context query
31+
assert!(!System::is_task_context());
32+
assert!(!System::is_interrupt_context());
33+
assert!(!System::is_boot_complete());
34+
35+
D::success();
36+
}

src/r3_test_suite/src/kernel_tests/task_misc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ fn task1_body<System: SupportedSystem, D: Driver<App<System>, System = System>>(
129129
// task.
130130
assert_eq!(LocalTask::current().unwrap(), app.task1);
131131

132+
// Context query
133+
assert!(System::is_task_context());
134+
assert!(!System::is_interrupt_context());
135+
assert!(System::is_boot_complete());
136+
132137
// CPU Lock active
133138
System::acquire_cpu_lock().unwrap();
134139
assert_eq!(

src/r3_test_suite/src/kernel_tests/timer_misc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ fn timer1_body<System: SupportedSystem, D: Driver<App<System>, System = System>>
146146

147147
assert_eq!(param, 42);
148148

149-
// FIXME: Re-add this assertion
150-
// assert!(!System::is_task_context());
149+
// Context query
150+
assert!(!System::is_task_context());
151+
assert!(System::is_interrupt_context());
152+
assert!(System::is_boot_complete());
151153

152154
// Check `timer1`'s expiration time in `task`
153155
// (`System::time` is disallowed in a non-task context)

src/r3_test_suite/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ pub mod kernel_tests {
270270
(mod semaphore_signal_and_dispatch {}, "semaphore_signal_and_dispatch"),
271271
(mod semaphore_timeout {}, "semaphore_timeout"),
272272
(mod startup_hook_disallowed_services {}, "startup_hook_disallowed_services"),
273+
(mod startup_hook_misc {}, "startup_hook_misc"),
273274
(mod startup_hook_pend_interrupt {}, "startup_hook_pend_interrupt"),
274275
(mod startup_hook_priority {}, "startup_hook_priority"),
275276
(mod sync_mutex_lock_and_dispatch {}, "sync_mutex_lock_and_dispatch"),

0 commit comments

Comments
 (0)