diff options
| author | Jorge Aparicio <jorge@japaric.io> | 2017-05-08 12:05:42 -0500 |
|---|---|---|
| committer | Jorge Aparicio <jorge@japaric.io> | 2017-05-08 12:05:42 -0500 |
| commit | fc4cb7d472dad1ea0fa137bb116bd907efc19601 (patch) | |
| tree | dd3e462f3fa683ed26c2f6dcd4a2d8be504231c7 /tests | |
| parent | 2063697c626a7547f5d9fb140fbc7eb9773a5120 (diff) | |
replace the ceiling token with a preemption threshold token
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cfail/access.rs | 30 | ||||
| -rw-r--r-- | tests/cfail/ceiling.rs | 12 | ||||
| -rw-r--r-- | tests/cfail/lock.rs | 34 | ||||
| -rw-r--r-- | tests/cfail/peripherals-alias-1.rs | 6 | ||||
| -rw-r--r-- | tests/cfail/peripherals-alias-2.rs | 6 | ||||
| -rw-r--r-- | tests/cfail/race-1.rs | 18 | ||||
| -rw-r--r-- | tests/cfail/race-2.rs | 20 | ||||
| -rw-r--r-- | tests/cfail/raise.rs | 24 | ||||
| -rw-r--r-- | tests/cfail/tasks-p0.rs | 8 | ||||
| -rw-r--r-- | tests/cfail/tasks-same-handler.rs | 10 | ||||
| -rw-r--r-- | tests/cfail/tasks-wrong-idle.rs | 8 | ||||
| -rw-r--r-- | tests/cfail/tasks-wrong-init.rs | 10 | ||||
| -rw-r--r-- | tests/cfail/tasks-wrong-priority.rs | 8 | ||||
| -rw-r--r-- | tests/cfail/tasks-wrong-task.rs | 8 | ||||
| -rw-r--r-- | tests/cfail/tasks-wrong-threshold.rs (renamed from tests/cfail/tasks-wrong-ceiling.rs) | 10 |
15 files changed, 115 insertions, 97 deletions
diff --git a/tests/cfail/access.rs b/tests/cfail/access.rs index 7524b06..b35fb37 100644 --- a/tests/cfail/access.rs +++ b/tests/cfail/access.rs @@ -1,6 +1,6 @@ extern crate cortex_m_rtfm as rtfm; -use rtfm::{C1, C2, C3, C4, C5, P2, Resource}; +use rtfm::{C1, C2, C3, C4, C5, P2, Resource, T2}; static R1: Resource<i32, C4> = Resource::new(0); static R2: Resource<i32, C3> = Resource::new(0); @@ -9,27 +9,27 @@ static R4: Resource<i32, C5> = Resource::new(0); static R5: Resource<i32, C1> = Resource::new(0); static R6: Resource<i32, C2> = Resource::new(0); -fn j1(prio: P2, ceil: C2) { - ceil.raise( - &R1, |ceil| { - // NOTE SC = System Ceiling, P = task Priority +fn j1(prio: P2, thr: T2) { + thr.raise( + &R1, |thr| { + // NOTE PT = Preemption Threshold, TP = Task Priority - // CAN access a resource with ceiling RC when SC > RC - let r2 = R2.access(&prio, ceil); + // CAN access a resource with ceiling RC when PT > RC + let r2 = R2.access(&prio, thr); - // CAN access a resource with ceiling RC when SC == RC - let r3 = R3.access(&prio, ceil); + // CAN access a resource with ceiling RC when PT == RC + let r3 = R3.access(&prio, thr); - // CAN'T access a resource with ceiling RC when SC < RC - let r4 = R4.access(&prio, ceil); + // CAN'T access a resource with ceiling RC when PT < RC + let r4 = R4.access(&prio, thr); //~^ error - // CAN'T access a resource with ceiling RC when RC < P - let r5 = R5.access(&prio, ceil); + // CAN'T access a resource with ceiling RC when RC < TP + let r5 = R5.access(&prio, thr); //~^ error - // CAN access a resource with ceiling RC when RC == P - let r6 = R6.access(&prio, ceil); + // CAN access a resource with ceiling RC when RC == tP + let r6 = R6.access(&prio, thr); } ); } diff --git a/tests/cfail/ceiling.rs b/tests/cfail/ceiling.rs index d1961c9..118dbcf 100644 --- a/tests/cfail/ceiling.rs +++ b/tests/cfail/ceiling.rs @@ -1,19 +1,19 @@ extern crate cortex_m_rtfm as rtfm; -use rtfm::{C2, C3, P0, P2, Resource}; +use rtfm::{C2, C3, P0, P2, Resource, T2}; static R1: Resource<(), C3> = Resource::new(()); -fn j1(prio: P2, ceil: C2) { - let c3 = ceil.raise( - &R1, |ceil| { +fn j1(prio: P2, thr: T2) { + let t3 = thr.raise( + &R1, |thr| { // forbidden: ceiling token can't outlive the critical section - ceil //~ error + thr //~ error } ); // Would be bad: lockless access to a resource with ceiling = 3 - let r2 = R1.access(&prio, c3); + let r2 = R1.access(&prio, t3); } fn j2(prio: P0) { diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs index 62d3c6e..64753ac 100644 --- a/tests/cfail/lock.rs +++ b/tests/cfail/lock.rs @@ -1,42 +1,36 @@ extern crate cortex_m_rtfm as rtfm; -use rtfm::{C16, C1, C2, C3, P1, P16, P2, P3, Resource}; +use rtfm::{CMax, C2, P1, P2, P3, PMax, Resource, T1, T2, T3, TMax}; static R1: Resource<i32, C2> = Resource::new(0); -// You CAN'T use `raise` to lower the system ceiling -fn j1(prio: P3, ceil: C3) { - ceil.raise(&R1, |ceil| {}); - //~^ error -} - // You don't need to raise the ceiling to access a resource with ceiling equal // to the task priority. -fn j2(prio: P2, ceil: C2) { - ceil.raise(&R1, |_| {}); +fn j1(prio: P2, thr: T2) { + thr.raise(&R1, |_| {}); //~^ error // OK - let r1 = R1.access(&prio, &ceil); + let r1 = R1.access(&prio, &thr); } // You CAN access a resource with ceiling C from a task with priority P if C > P -// and you raise the ceiling first -fn j3(prio: P1, ceil: C1) { +// if you raise the preemption threshold first +fn j2(prio: P1, thr: T1) { // OK - ceil.raise(&R1, |ceil| { let r1 = R1.access(&prio, ceil); }) + thr.raise(&R1, |thr| { let r1 = R1.access(&prio, thr); }) } -static R2: Resource<i32, C16> = Resource::new(0); +static R2: Resource<i32, CMax> = Resource::new(0); -// Tasks with priority less than P16 can't access a resource with ceiling C16 -fn j4(prio: P1, ceil: C1) { - ceil.raise(&R2, |ceil| {}); +// Tasks with priority less than P16 can't access a resource with ceiling CMax +fn j4(prio: P1, thr: T1) { + thr.raise(&R2, |thr| {}); //~^ error } -// Only tasks with priority P16 can access a resource with ceiling C16 -fn j5(prio: P16, ceil: C16) { +// Only tasks with priority P16 can directly access a resource with ceiling CMax +fn j5(prio: PMax, thr: TMax) { // OK - let r2 = R2.access(&prio, &ceil); + let r2 = R2.access(&prio, &thr); } diff --git a/tests/cfail/peripherals-alias-1.rs b/tests/cfail/peripherals-alias-1.rs index 0dfe8d1..124f351 100644 --- a/tests/cfail/peripherals-alias-1.rs +++ b/tests/cfail/peripherals-alias-1.rs @@ -5,7 +5,7 @@ #[macro_use] extern crate cortex_m_rtfm as rtfm; -use rtfm::{C16, P0, P1}; +use rtfm::{P0, P1, T0, TMax}; use device::interrupt::Exti0; peripherals!(device, { @@ -22,9 +22,9 @@ peripherals!(device, { tasks!(device, {}); -fn init(_: P0, _: &C16) {} +fn init(_: P0, _: &TMax) {} -fn idle(_: P0) -> ! { +fn idle(_: P0, _: T0) -> ! { loop {} } diff --git a/tests/cfail/peripherals-alias-2.rs b/tests/cfail/peripherals-alias-2.rs index 555cd74..b50931e 100644 --- a/tests/cfail/peripherals-alias-2.rs +++ b/tests/cfail/peripherals-alias-2.rs @@ -6,7 +6,7 @@ #[macro_use] extern crate cortex_m_rtfm as rtfm; -use rtfm::{C0, C16, P0, P1}; +use rtfm::{P0, P1, T0, TMax}; use device::interrupt::Exti0; peripherals!(device, { @@ -28,9 +28,9 @@ mod foo { tasks!(device, {}); -fn init(_: P0, _: &C16) {} +fn init(_: P0, _: &TMax) {} -fn idle(_: P0, _: C0) -> ! { +fn idle(_: P0, _: T0) -> ! { loop {} } diff --git a/tests/cfail/race-1.rs b/tests/cfail/race-1.rs index 167802d..8d32c42 100644 --- a/tests/cfail/race-1.rs +++ b/tests/cfail/race-1.rs @@ -1,13 +1,13 @@ extern crate cortex_m_rtfm as rtfm; -use rtfm::{C1, C2, C3, C4, P1, P3, Resource}; +use rtfm::{C2, P1, P3, Resource, T1, T3}; static R1: Resource<i32, C2> = Resource::new(0); -fn j1(prio: P1, ceil: C1) { - ceil.raise( - &R1, |ceil| { - let r1 = R1.access(&prio, ceil); +fn j1(prio: P1, thr: T1) { + thr.raise( + &R1, |thr| { + let r1 = R1.access(&prio, thr); // `j2` preempts this critical section rtfm::request(j2); @@ -15,12 +15,12 @@ fn j1(prio: P1, ceil: C1) { ); } -fn j2(_task: Task, prio: P3, ceil: C3) { +fn j2(_task: Task, prio: P3, thr: T3) { rtfm::atomic( - |ceil| { - // OK C2 (R1's ceiling) <= C16 (system ceiling) + |thr| { + // OK C2 (R1's ceiling) <= T16 (preemption threshold) // BAD C2 (R1's ceiling) < P3 (j2's priority) - let r1 = R1.access(&prio, &ceil); + let r1 = R1.access(&prio, &thr); //~^ error }, ); diff --git a/tests/cfail/race-2.rs b/tests/cfail/race-2.rs index 402a483..f44856e 100644 --- a/tests/cfail/race-2.rs +++ b/tests/cfail/race-2.rs @@ -1,14 +1,14 @@ extern crate cortex_m_rtfm as rtfm; -use rtfm::{C1, C2, C3, C4, P1, P3, Resource}; +use rtfm::{C2, C4, P1, P3, Resource, T1, T3}; static R1: Resource<i32, C2> = Resource::new(0); static R2: Resource<i32, C4> = Resource::new(0); -fn j1(prio: P1, ceil: C1) { - ceil.raise( - &R1, |ceil| { - let r1 = R1.access(&prio, ceil); +fn j1(prio: P1, thr: T1) { + thr.raise( + &R1, |thr| { + let r1 = R1.access(&prio, thr); // `j2` preempts this critical section rtfm::request(j2); @@ -16,12 +16,12 @@ fn j1(prio: P1, ceil: C1) { ); } -fn j2(_task: Task, prio: P3, ceil: C3) { - ceil.raise( - &R2, |ceil| { - // OK C2 (R1's ceiling) <= C4 (system ceiling) +fn j2(_task: Task, prio: P3, thr: T3) { + thr.raise( + &R2, |thr| { + // OK C2 (R1's ceiling) <= T4 (preemption threshold) // BAD C2 (R1's ceiling) < P3 (j2's priority) - let r1 = R1.access(&prio, ceil); + let r1 = R1.access(&prio, thr); //~^ error } ); diff --git a/tests/cfail/raise.rs b/tests/cfail/raise.rs new file mode 100644 index 0000000..3d7e564 --- /dev/null +++ b/tests/cfail/raise.rs @@ -0,0 +1,24 @@ +extern crate cortex_m_rtfm as rtfm; + +use rtfm::{C2, CMax, P1, P3, Resource, T1, T3}; + +static R1: Resource<i32, C2> = Resource::new(0); + +// You CAN'T use `raise` to lower the preemption level +fn j1(prio: P3, thr: T3) { + thr.raise(&R1, |thr| {}); + //~^ error +} + +static R2: Resource<i32, CMax> = Resource::new(0); + +// You CAN'T `raise` the preemption level to the maximum +fn j2(prio: P1, thr: T1) { + thr.raise(&R2, |thr| {}); + //~^ error + + // Instead use `rtfm::atomic` to access a resource with ceiling C16 + rtfm::atomic(|thr| { + let r2 = R2.access(&prio, thr); + }); +} diff --git a/tests/cfail/tasks-p0.rs b/tests/cfail/tasks-p0.rs index 4034f62..588ac5d 100644 --- a/tests/cfail/tasks-p0.rs +++ b/tests/cfail/tasks-p0.rs @@ -5,7 +5,7 @@ #[macro_use] extern crate cortex_m_rtfm as rtfm; -use rtfm::{C0, C1, C16, P0, P1}; +use rtfm::{P0, P1, T0, T1, TMax}; use device::interrupt::Exti0; // WRONG: Tasks can't have a priority of 0. @@ -18,13 +18,13 @@ tasks!(device, { }, }); -fn init(_: P0, _: &C16) {} +fn init(_: P0, _: &TMax) {} -fn idle(_: P0, _: C0) -> ! { +fn idle(_: P0, _: T0) -> ! { loop {} } -fn j1(_task: Exti0, _prio: P1, _ceil: C1) {} +fn j1(_task: Exti0, _prio: P1, _thr: T1) {} // fake device crate extern crate core; diff --git a/tests/cfail/tasks-same-handler.rs b/tests/cfail/tasks-same-handler.rs index 1d32d58..fdd8b06 100644 --- a/tests/cfail/tasks-same-handler.rs +++ b/tests/cfail/tasks-same-handler.rs @@ -5,7 +5,7 @@ #[macro_use] extern crate cortex_m_rtfm as rtfm; -use rtfm::{C0, C1, C16, C2, P0, P1, P2}; +use rtfm::{P0, P1, P2, T0, T1, T2, TMax}; use device::interrupt::{Exti0, Exti1}; // WRONG: Two tasks mapped to the same interrupt handler @@ -22,15 +22,15 @@ tasks!(device, { }, }); -fn init(_: P0, _: &C16) {} +fn init(_: P0, _: &TMax) {} -fn idle(_: P0, _: C0) -> ! { +fn idle(_: P0, _: T0) -> ! { loop {} } -fn j1(_task: Exti0, _prio: P1, _ceil: C1) {} +fn j1(_task: Exti0, _prio: P1, _thr: T1) {} -fn j2(_task: Exti0, _prio: P2, _ceil: C2) {} +fn j2(_task: Exti0, _prio: P2, _thr: T2) {} // fake device crate extern crate core; diff --git a/tests/cfail/tasks-wrong-idle.rs b/tests/cfail/tasks-wrong-idle.rs index 954fd22..e6ff779 100644 --- a/tests/cfail/tasks-wrong-idle.rs +++ b/tests/cfail/tasks-wrong-idle.rs @@ -6,7 +6,7 @@ extern crate cortex_m_rtfm as rtfm; use device::interrupt::Exti0; -use rtfm::{C0, C1, C16, P0, P1}; +use rtfm::{P0, P1, T0, T1, TMax}; tasks!(device, { j1: Task { @@ -16,12 +16,12 @@ tasks!(device, { }, }); -fn init(_: P0, _: &C16) {} +fn init(_: P0, _: &TMax) {} // WRONG. `idle` must have signature `fn(P0, C0) -> !` -fn idle(_: P0, _: C0) {} +fn idle(_: P0, _: T0) {} -fn j1(_task: Exti0, _prio: P1, _ceil: C1) {} +fn j1(_task: Exti0, _prio: P1, _thr: T1) {} // fake device crate extern crate core; diff --git a/tests/cfail/tasks-wrong-init.rs b/tests/cfail/tasks-wrong-init.rs index e9ebc61..d12b427 100644 --- a/tests/cfail/tasks-wrong-init.rs +++ b/tests/cfail/tasks-wrong-init.rs @@ -5,7 +5,7 @@ #[macro_use] extern crate cortex_m_rtfm as rtfm; -use rtfm::{C0, C1, C16, P0, P1}; +use rtfm::{P0, P1, T0, T1, TMax}; use device::interrupt::Exti0; tasks!(device, { @@ -16,14 +16,14 @@ tasks!(device, { }, }); -// WRONG. `init` must have signature `fn(P0, &C16)` -fn init(_: P0, _: &C1) {} +// WRONG. `init` must have signature `fn(P0, &TMax)` +fn init(_: P0, _: &T1) {} -fn idle(_: P0, _: C0) -> ! { +fn idle(_: P0, _: T0) -> ! { loop {} } -fn j1(_task: Exti0, _prio: P1, _ceil: C1) {} +fn j1(_task: Exti0, _prio: P1, _thr: T1) {} // fake device crate extern crate core; diff --git a/tests/cfail/tasks-wrong-priority.rs b/tests/cfail/tasks-wrong-priority.rs index 01ff7df..4d05d6b 100644 --- a/tests/cfail/tasks-wrong-priority.rs +++ b/tests/cfail/tasks-wrong-priority.rs @@ -6,7 +6,7 @@ extern crate cortex_m_rtfm as rtfm; use device::interrupt::Exti0; -use rtfm::{C0, C1, C16, C2, P0, P1, P2}; +use rtfm::{P0, P1, P2, T0, T1, T2, TMax}; tasks!(device, { j1: Task { @@ -16,14 +16,14 @@ tasks!(device, { }, }); -fn init(_: P0, _: &C16) {} +fn init(_: P0, _: &TMax) {} -fn idle(_: P0, _: C0) -> ! { +fn idle(_: P0, _: T0) -> ! { loop {} } // Wrong priority token. Declared P1, got P2 -fn j1(_task: Exti0, _prio: P2, _ceil: C2) {} +fn j1(_task: Exti0, _prio: P2, _thr: T2) {} // fake device crate extern crate core; diff --git a/tests/cfail/tasks-wrong-task.rs b/tests/cfail/tasks-wrong-task.rs index 5fae160..026290a 100644 --- a/tests/cfail/tasks-wrong-task.rs +++ b/tests/cfail/tasks-wrong-task.rs @@ -6,7 +6,7 @@ extern crate cortex_m_rtfm as rtfm; use device::interrupt::{Exti0, Exti1}; -use rtfm::{C0, C1, C16, P0, P1}; +use rtfm::{P0, P1, T0, T1, TMax}; tasks!(device, { j1: Task { @@ -16,14 +16,14 @@ tasks!(device, { }, }); -fn init(_: P0, _: &C16) {} +fn init(_: P0, _: &TMax) {} -fn idle(_: P0, _: C0) -> ! { +fn idle(_: P0, _: T0) -> ! { loop {} } // Wrong task token. Declared Exti0, got Exti1 -fn j1(_task: Exti1, _prio: P1, _ceil: C1) {} +fn j1(_task: Exti1, _prio: P1, _thr: T1) {} // fake device crate extern crate core; diff --git a/tests/cfail/tasks-wrong-ceiling.rs b/tests/cfail/tasks-wrong-threshold.rs index 84dd133..4fca734 100644 --- a/tests/cfail/tasks-wrong-ceiling.rs +++ b/tests/cfail/tasks-wrong-threshold.rs @@ -5,7 +5,7 @@ #[macro_use] extern crate cortex_m_rtfm as rtfm; -use rtfm::{C0, C1, C16, C2, P0, P1}; +use rtfm::{C2, P0, P1, T0, T2, TMax}; use device::interrupt::Exti0; tasks!(device, { @@ -16,14 +16,14 @@ tasks!(device, { }, }); -fn init(_: P0, _: &C16) {} +fn init(_: P0, _: &TMax) {} -fn idle(_: P0, _: C0) -> ! { +fn idle(_: P0, _: T0) -> ! { loop {} } -// Wrong ceiling token. `prio` and `ceil` must match in levels -fn j1(_task: Exti0, _prio: P1, _ceil: C2) {} +// Wrong ceiling token. `prio` and `thr` must match in levels +fn j1(_task: Exti0, _prio: P1, _thr: T2) {} // fake device crate extern crate core; |
