diff --git a/tests/cfail/borrow.rs b/tests/cfail/borrow.rs index 14762dc7dc..6f9e1a863a 100644 --- a/tests/cfail/borrow.rs +++ b/tests/cfail/borrow.rs @@ -12,22 +12,26 @@ static R6: Resource = Resource::new(0); fn j1(prio: P2) { let ceil = prio.as_ceiling(); - ceil.raise(&R1, |ceil| { - // CAN borrow a resource with ceiling C when the current ceiling SC > C - let r2 = R2.borrow(&prio, ceil); + ceil.raise( + &R1, |ceil| { + // NOTE CC = Current Ceiling, P = task Priority - // CAN borrow a resource with ceiling C when the current ceiling SC == C - let r3 = R3.borrow(&prio, ceil); + // CAN borrow a resource with ceiling RC when CC > RC + let r2 = R2.borrow(&prio, ceil); - // CAN'T borrow a resource with ceiling C when the current ceiling SC < C - let r4 = R4.borrow(&prio, ceil); - //~^ error + // CAN borrow a resource with ceiling RC when CC == RC + let r3 = R3.borrow(&prio, ceil); - // CAN'T borrow a resource with ceiling C < P (task priority) - let r5 = R5.borrow(&prio, ceil); - //~^ error + // CAN'T borrow a resource with ceiling RC when CC < RC + let r4 = R4.borrow(&prio, ceil); + //~^ error - // CAN borrow a resource with ceiling C == P (task priority) - let r6 = R6.borrow(&prio, ceil); - }); + // CAN'T borrow a resource with ceiling RC when RC < P + let r5 = R5.borrow(&prio, ceil); + //~^ error + + // CAN borrow a resource with ceiling RC when RC == P + let r6 = R6.borrow(&prio, ceil); + } + ); } diff --git a/tests/cfail/ceiling.rs b/tests/cfail/ceiling.rs index 8bbd1f7b40..b13be80239 100644 --- a/tests/cfail/ceiling.rs +++ b/tests/cfail/ceiling.rs @@ -7,20 +7,24 @@ static R1: Resource<(), C3> = Resource::new(()); fn j1(prio: P2) { let ceil = prio.as_ceiling(); - let c3 = ceil.raise(&R1, |ceil| { - // forbidden: ceiling token can't outlive critical section - ceil //~ error - }); + let c3 = ceil.raise( + &R1, |ceil| { + // forbidden: ceiling token can't outlive the critical section + ceil //~ error + } + ); // Would be bad: lockless access to a resource with ceiling = 3 let r2 = R1.borrow(&prio, c3); } fn j2(prio: P0) { - let c16 = rtfm::critical(|c16| { - // forbidden: ceiling token can't outlive critical section - c16 //~ error - }); + let c16 = rtfm::critical( + |c16| { + // forbidden: ceiling token can't outlive the critical section + c16 //~ error + }, + ); // Would be bad: lockless access to a resource with ceiling = 16 let r1 = R1.borrow(&prio, c16); diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs index 36541f2542..ca4ea73c4d 100644 --- a/tests/cfail/lock.rs +++ b/tests/cfail/lock.rs @@ -4,17 +4,16 @@ use rtfm::{C16, C2, P1, P16, P2, P3, Resource}; static R1: Resource = Resource::new(0); -// You CAN'T lock a resource with ceiling C from a task with priority P if P > C +// You CAN'T use `raise` to lower the system ceiling fn j1(prio: P3) { let ceil = prio.as_ceiling(); - ceil.raise(&R1, |ceil| { - //~^ error - }); + ceil.raise(&R1, |ceil| {}); + //~^ error } -// DON'T lock a resource with ceiling equal to the task priority. -// Instead use `borrow` +// You don't need to raise the ceiling to access a resource with ceiling equal +// to the task priority. fn j2(prio: P2) { let ceil = prio.as_ceiling(); @@ -25,28 +24,26 @@ fn j2(prio: P2) { let r1 = R1.borrow(&prio, ceil); } -// You CAN lock a resource with ceiling C from a task with priority P if C > P +// 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) { let ceil = prio.as_ceiling(); // OK - ceil.raise(&R1, |ceil| { - let r1 = R1.borrow(&prio, ceil); - }) + ceil.raise(&R1, |ceil| { let r1 = R1.borrow(&prio, ceil); }) } static R2: Resource = Resource::new(0); -// Tasks with priority less than P16 can't lock a resource with ceiling C16 +// Tasks with priority less than P16 can't access a resource with ceiling C16 fn j4(prio: P1) { let ceil = prio.as_ceiling(); - ceil.raise(&R2, |ceil| { - //~^ error - }); + ceil.raise(&R2, |ceil| {}); + //~^ error } -// Only tasks with priority P16 can claim a resource with ceiling C16 +// Only tasks with priority P16 can access a resource with ceiling C16 fn j5(prio: P16) { // OK let r2 = R2.borrow(&prio, prio.as_ceiling()); diff --git a/tests/cfail/race-1.rs b/tests/cfail/race-1.rs index e9d030d484..9037ed44f9 100644 --- a/tests/cfail/race-1.rs +++ b/tests/cfail/race-1.rs @@ -7,17 +7,38 @@ static R1: Resource = Resource::new(0); fn j1(prio: P1) { let ceil = prio.as_ceiling(); - ceil.raise(&R1, |ceil| { - let r1 = R1.borrow(&prio, ceil); + ceil.raise( + &R1, |ceil| { + let r1 = R1.borrow(&prio, ceil); - // Would preempt this critical section - // rtfm::request(j2); - }); + // `j2` preempts this critical section + rtfm::request(j2); + } + ); } -fn j2(prio: P3) { - rtfm::critical(|ceil| { - let r1 = R1.borrow(&prio, &ceil); - //~^ error - }); +fn j2(_task: Task, prio: P3) { + rtfm::critical( + |ceil| { + // OK C2 (R1's ceiling) <= C16 (system ceiling) + // BAD C2 (R1's ceiling) < P3 (j2's priority) + let r1 = R1.borrow(&prio, &ceil); + //~^ error + }, + ); +} + +// glue +extern crate cortex_m; + +use cortex_m::ctxt::Context; +use cortex_m::interrupt::Nr; + +struct Task; + +unsafe impl Context for Task {} +unsafe impl Nr for Task { + fn nr(&self) -> u8 { + 0 + } } diff --git a/tests/cfail/race-2.rs b/tests/cfail/race-2.rs index 55dedb6ee5..6bd957e5dc 100644 --- a/tests/cfail/race-2.rs +++ b/tests/cfail/race-2.rs @@ -8,21 +8,40 @@ static R2: Resource = Resource::new(0); fn j1(prio: P1) { let ceil = prio.as_ceiling(); - ceil.raise(&R1, |ceil| { - let r1 = R1.borrow(&prio, ceil); + ceil.raise( + &R1, |ceil| { + let r1 = R1.borrow(&prio, ceil); - // Would preempt this critical section - // rtfm::request(j2); - }); + // `j2` preempts this critical section + rtfm::request(j2); + } + ); } -fn j2(prio: P3) { +fn j2(_task: Task, prio: P3) { let ceil = prio.as_ceiling(); - ceil.raise(&R2, |ceil| { - // OK C2 (R1's ceiling) <= C4 (system ceiling) - // BAD C2 (R1's ceiling) < P3 (j2's priority) - let r1 = R1.borrow(&prio, ceil); - //~^ error - }); + ceil.raise( + &R2, |ceil| { + // OK C2 (R1's ceiling) <= C4 (system ceiling) + // BAD C2 (R1's ceiling) < P3 (j2's priority) + let r1 = R1.borrow(&prio, ceil); + //~^ error + } + ); +} + +// glue +extern crate cortex_m; + +use cortex_m::ctxt::Context; +use cortex_m::interrupt::Nr; + +struct Task; + +unsafe impl Context for Task {} +unsafe impl Nr for Task { + fn nr(&self) -> u8 { + 0 + } } diff --git a/tests/cfail/tasks-p0.rs b/tests/cfail/tasks-p0.rs index f1e83a378d..4db3d3895e 100644 --- a/tests/cfail/tasks-p0.rs +++ b/tests/cfail/tasks-p0.rs @@ -2,15 +2,14 @@ #![feature(used)] -extern crate core; -extern crate cortex_m; #[macro_use] extern crate cortex_m_rtfm as rtfm; use rtfm::{C16, P0, P1}; use device::interrupt::Exti0; -/// Tasks can't have priority 0. Only idle has priority 0 +// WRONG: Tasks can't have a priority of 0. +// Only idle and init can have a priority of 0. tasks!(device, { j1: (Exti0, P0), }); @@ -23,6 +22,10 @@ fn idle(_: P0) -> ! { fn j1(_task: Exti0, _prio: P1) {} +// fake device crate +extern crate core; +extern crate cortex_m; + mod device { pub mod interrupt { use cortex_m::interrupt::Nr; diff --git a/tests/cfail/tasks-same-handler.rs b/tests/cfail/tasks-same-handler.rs index 662a67db4a..89e20121bf 100644 --- a/tests/cfail/tasks-same-handler.rs +++ b/tests/cfail/tasks-same-handler.rs @@ -2,8 +2,6 @@ #![feature(used)] -extern crate core; -extern crate cortex_m; #[macro_use] extern crate cortex_m_rtfm as rtfm; @@ -26,6 +24,9 @@ fn j1(_task: Exti0, _prio: P1) {} fn j2(_task: Exti0, _prio: P1) {} +// fake device crate +extern crate core; +extern crate cortex_m; mod device { pub mod interrupt { diff --git a/tests/cfail/tasks-wrong-idle.rs b/tests/cfail/tasks-wrong-idle.rs index 77afef6b3f..4ee910ee84 100644 --- a/tests/cfail/tasks-wrong-idle.rs +++ b/tests/cfail/tasks-wrong-idle.rs @@ -2,15 +2,12 @@ #![feature(used)] -extern crate core; -extern crate cortex_m; #[macro_use] extern crate cortex_m_rtfm as rtfm; use device::interrupt::Exti0; use rtfm::{C16, P0, P1}; -/// Tasks can't have priority 0. Only idle has priority 0 tasks!(device, { j1: (Exti0, P1), }); @@ -24,6 +21,10 @@ fn idle(_: P1) -> ! { fn j1(_task: Exti0, _prio: P1) {} +// fake device crate +extern crate core; +extern crate cortex_m; + mod device { pub mod interrupt { use cortex_m::interrupt::Nr; diff --git a/tests/cfail/tasks-wrong-init.rs b/tests/cfail/tasks-wrong-init.rs index 8b8359c40a..0f6e1c1e1c 100644 --- a/tests/cfail/tasks-wrong-init.rs +++ b/tests/cfail/tasks-wrong-init.rs @@ -2,8 +2,6 @@ #![feature(used)] -extern crate core; -extern crate cortex_m; #[macro_use] extern crate cortex_m_rtfm as rtfm; @@ -23,6 +21,10 @@ fn idle(_: P0) -> ! { fn j1(_task: Exti0, _prio: P1) {} +// fake device crate +extern crate core; +extern crate cortex_m; + mod device { pub mod interrupt { use cortex_m::interrupt::Nr; diff --git a/tests/cfail/tasks-wrong-priority.rs b/tests/cfail/tasks-wrong-priority.rs index 08deef32e9..75cbc0cc40 100644 --- a/tests/cfail/tasks-wrong-priority.rs +++ b/tests/cfail/tasks-wrong-priority.rs @@ -2,8 +2,6 @@ #![feature(used)] -extern crate core; -extern crate cortex_m; #[macro_use] extern crate cortex_m_rtfm as rtfm; @@ -23,6 +21,10 @@ fn idle(_: P0) -> ! { // Wrong priority token. Declared P1, got P2 fn j1(_task: Exti1, _prio: P1) {} +// fake device crate +extern crate core; +extern crate cortex_m; + mod device { pub mod interrupt { use cortex_m::interrupt::Nr; diff --git a/tests/cfail/tasks-wrong-task.rs b/tests/cfail/tasks-wrong-task.rs index 15bd7764cd..0200da2d18 100644 --- a/tests/cfail/tasks-wrong-task.rs +++ b/tests/cfail/tasks-wrong-task.rs @@ -2,8 +2,6 @@ #![feature(used)] -extern crate core; -extern crate cortex_m; #[macro_use] extern crate cortex_m_rtfm as rtfm; @@ -23,6 +21,10 @@ fn idle(_: P0) -> ! { // Wrong task token. Declared Exti0, got Exti1 fn j1(_task: Exti1, _prio: P1) {} +// fake device crate +extern crate core; +extern crate cortex_m; + mod device { pub mod interrupt { use cortex_m::interrupt::Nr;