1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Host-test support: serialized, reset-able kernel state.
//!
//! Host tests exercise kernel logic that lives in *global* statics (`TASKS`,
//! waker bitmaps, `TIMER_SLOTS`, `CURRENT`/`RR_COUNTER`), and `cargo test`
//! runs test functions on parallel threads. Without serialization, tests
//! racing on those statics are flaky (observed: 1/8 consecutive runs of
//! `cargo test -p rivet` failed in `schedule_round_robins_same_priority`).
//!
//! Every kernel test must run inside [`macro@crate::kernel_test`], which
//! acquires a global [`std::sync::Mutex`] and resets all kernel state to
//! boot values before running the body. This is deliberately *not*
//! `--test-threads=1`: that would hide the problem, and silently stops
//! applying if anyone runs a subset of the suite.
//!
//! Only compiled with `feature = "test-support"` (enabled exclusively from
//! this crate's `[dev-dependencies]`), so it never affects embedded builds.
use Mutex;
/// Serializes all kernel tests: exactly one test mutates kernel globals at
/// a time, so no two tests can interleave their state.
static KERNEL_TEST_LOCK: = new;
/// Acquire the global kernel-test lock. Held for the duration of the
/// [`macro@crate::kernel_test`] body.
/// Reset every kernel global to its boot-time state. Called by
/// [`macro@crate::kernel_test`] before each test body runs.