reword the comments in compile-fail tests

This commit is contained in:
Jorge Aparicio 2017-04-21 21:24:28 -05:00
parent 1c82f1b119
commit eea8030083
11 changed files with 129 additions and 73 deletions

View file

@ -12,22 +12,26 @@ static R6: Resource<i32, C2> = Resource::new(0);
fn j1(prio: P2) { fn j1(prio: P2) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
ceil.raise(&R1, |ceil| { ceil.raise(
// CAN borrow a resource with ceiling C when the current ceiling SC > C &R1, |ceil| {
let r2 = R2.borrow(&prio, ceil); // NOTE CC = Current Ceiling, P = task Priority
// CAN borrow a resource with ceiling C when the current ceiling SC == C // CAN borrow a resource with ceiling RC when CC > RC
let r3 = R3.borrow(&prio, ceil); let r2 = R2.borrow(&prio, ceil);
// CAN'T borrow a resource with ceiling C when the current ceiling SC < C // CAN borrow a resource with ceiling RC when CC == RC
let r4 = R4.borrow(&prio, ceil); let r3 = R3.borrow(&prio, ceil);
//~^ error
// CAN'T borrow a resource with ceiling C < P (task priority) // CAN'T borrow a resource with ceiling RC when CC < RC
let r5 = R5.borrow(&prio, ceil); let r4 = R4.borrow(&prio, ceil);
//~^ error //~^ error
// CAN borrow a resource with ceiling C == P (task priority) // CAN'T borrow a resource with ceiling RC when RC < P
let r6 = R6.borrow(&prio, ceil); let r5 = R5.borrow(&prio, ceil);
}); //~^ error
// CAN borrow a resource with ceiling RC when RC == P
let r6 = R6.borrow(&prio, ceil);
}
);
} }

View file

@ -7,20 +7,24 @@ static R1: Resource<(), C3> = Resource::new(());
fn j1(prio: P2) { fn j1(prio: P2) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
let c3 = ceil.raise(&R1, |ceil| { let c3 = ceil.raise(
// forbidden: ceiling token can't outlive critical section &R1, |ceil| {
ceil //~ error // forbidden: ceiling token can't outlive the critical section
}); ceil //~ error
}
);
// Would be bad: lockless access to a resource with ceiling = 3 // Would be bad: lockless access to a resource with ceiling = 3
let r2 = R1.borrow(&prio, c3); let r2 = R1.borrow(&prio, c3);
} }
fn j2(prio: P0) { fn j2(prio: P0) {
let c16 = rtfm::critical(|c16| { let c16 = rtfm::critical(
// forbidden: ceiling token can't outlive critical section |c16| {
c16 //~ error // forbidden: ceiling token can't outlive the critical section
}); c16 //~ error
},
);
// Would be bad: lockless access to a resource with ceiling = 16 // Would be bad: lockless access to a resource with ceiling = 16
let r1 = R1.borrow(&prio, c16); let r1 = R1.borrow(&prio, c16);

View file

@ -4,17 +4,16 @@ use rtfm::{C16, C2, P1, P16, P2, P3, Resource};
static R1: Resource<i32, C2> = Resource::new(0); static R1: Resource<i32, C2> = 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) { fn j1(prio: P3) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
ceil.raise(&R1, |ceil| { ceil.raise(&R1, |ceil| {});
//~^ error //~^ error
});
} }
// DON'T lock a resource with ceiling equal to the task priority. // You don't need to raise the ceiling to access a resource with ceiling equal
// Instead use `borrow` // to the task priority.
fn j2(prio: P2) { fn j2(prio: P2) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
@ -25,28 +24,26 @@ fn j2(prio: P2) {
let r1 = R1.borrow(&prio, ceil); 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) { fn j3(prio: P1) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
// OK // OK
ceil.raise(&R1, |ceil| { ceil.raise(&R1, |ceil| { let r1 = R1.borrow(&prio, ceil); })
let r1 = R1.borrow(&prio, ceil);
})
} }
static R2: Resource<i32, C16> = Resource::new(0); static R2: Resource<i32, C16> = 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) { fn j4(prio: P1) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
ceil.raise(&R2, |ceil| { ceil.raise(&R2, |ceil| {});
//~^ error //~^ 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) { fn j5(prio: P16) {
// OK // OK
let r2 = R2.borrow(&prio, prio.as_ceiling()); let r2 = R2.borrow(&prio, prio.as_ceiling());

View file

@ -7,17 +7,38 @@ static R1: Resource<i32, C2> = Resource::new(0);
fn j1(prio: P1) { fn j1(prio: P1) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
ceil.raise(&R1, |ceil| { ceil.raise(
let r1 = R1.borrow(&prio, ceil); &R1, |ceil| {
let r1 = R1.borrow(&prio, ceil);
// Would preempt this critical section // `j2` preempts this critical section
// rtfm::request(j2); rtfm::request(j2);
}); }
);
} }
fn j2(prio: P3) { fn j2(_task: Task, prio: P3) {
rtfm::critical(|ceil| { rtfm::critical(
let r1 = R1.borrow(&prio, &ceil); |ceil| {
//~^ error // 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
}
} }

View file

@ -8,21 +8,40 @@ static R2: Resource<i32, C4> = Resource::new(0);
fn j1(prio: P1) { fn j1(prio: P1) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
ceil.raise(&R1, |ceil| { ceil.raise(
let r1 = R1.borrow(&prio, ceil); &R1, |ceil| {
let r1 = R1.borrow(&prio, ceil);
// Would preempt this critical section // `j2` preempts this critical section
// rtfm::request(j2); rtfm::request(j2);
}); }
);
} }
fn j2(prio: P3) { fn j2(_task: Task, prio: P3) {
let ceil = prio.as_ceiling(); let ceil = prio.as_ceiling();
ceil.raise(&R2, |ceil| { ceil.raise(
// OK C2 (R1's ceiling) <= C4 (system ceiling) &R2, |ceil| {
// BAD C2 (R1's ceiling) < P3 (j2's priority) // OK C2 (R1's ceiling) <= C4 (system ceiling)
let r1 = R1.borrow(&prio, ceil); // BAD C2 (R1's ceiling) < P3 (j2's priority)
//~^ error 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
}
} }

View file

@ -2,15 +2,14 @@
#![feature(used)] #![feature(used)]
extern crate core;
extern crate cortex_m;
#[macro_use] #[macro_use]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
use rtfm::{C16, P0, P1}; use rtfm::{C16, P0, P1};
use device::interrupt::Exti0; 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, { tasks!(device, {
j1: (Exti0, P0), j1: (Exti0, P0),
}); });
@ -23,6 +22,10 @@ fn idle(_: P0) -> ! {
fn j1(_task: Exti0, _prio: P1) {} fn j1(_task: Exti0, _prio: P1) {}
// fake device crate
extern crate core;
extern crate cortex_m;
mod device { mod device {
pub mod interrupt { pub mod interrupt {
use cortex_m::interrupt::Nr; use cortex_m::interrupt::Nr;

View file

@ -2,8 +2,6 @@
#![feature(used)] #![feature(used)]
extern crate core;
extern crate cortex_m;
#[macro_use] #[macro_use]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
@ -26,6 +24,9 @@ fn j1(_task: Exti0, _prio: P1) {}
fn j2(_task: Exti0, _prio: P1) {} fn j2(_task: Exti0, _prio: P1) {}
// fake device crate
extern crate core;
extern crate cortex_m;
mod device { mod device {
pub mod interrupt { pub mod interrupt {

View file

@ -2,15 +2,12 @@
#![feature(used)] #![feature(used)]
extern crate core;
extern crate cortex_m;
#[macro_use] #[macro_use]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
use device::interrupt::Exti0; use device::interrupt::Exti0;
use rtfm::{C16, P0, P1}; use rtfm::{C16, P0, P1};
/// Tasks can't have priority 0. Only idle has priority 0
tasks!(device, { tasks!(device, {
j1: (Exti0, P1), j1: (Exti0, P1),
}); });
@ -24,6 +21,10 @@ fn idle(_: P1) -> ! {
fn j1(_task: Exti0, _prio: P1) {} fn j1(_task: Exti0, _prio: P1) {}
// fake device crate
extern crate core;
extern crate cortex_m;
mod device { mod device {
pub mod interrupt { pub mod interrupt {
use cortex_m::interrupt::Nr; use cortex_m::interrupt::Nr;

View file

@ -2,8 +2,6 @@
#![feature(used)] #![feature(used)]
extern crate core;
extern crate cortex_m;
#[macro_use] #[macro_use]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
@ -23,6 +21,10 @@ fn idle(_: P0) -> ! {
fn j1(_task: Exti0, _prio: P1) {} fn j1(_task: Exti0, _prio: P1) {}
// fake device crate
extern crate core;
extern crate cortex_m;
mod device { mod device {
pub mod interrupt { pub mod interrupt {
use cortex_m::interrupt::Nr; use cortex_m::interrupt::Nr;

View file

@ -2,8 +2,6 @@
#![feature(used)] #![feature(used)]
extern crate core;
extern crate cortex_m;
#[macro_use] #[macro_use]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
@ -23,6 +21,10 @@ fn idle(_: P0) -> ! {
// Wrong priority token. Declared P1, got P2 // Wrong priority token. Declared P1, got P2
fn j1(_task: Exti1, _prio: P1) {} fn j1(_task: Exti1, _prio: P1) {}
// fake device crate
extern crate core;
extern crate cortex_m;
mod device { mod device {
pub mod interrupt { pub mod interrupt {
use cortex_m::interrupt::Nr; use cortex_m::interrupt::Nr;

View file

@ -2,8 +2,6 @@
#![feature(used)] #![feature(used)]
extern crate core;
extern crate cortex_m;
#[macro_use] #[macro_use]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
@ -23,6 +21,10 @@ fn idle(_: P0) -> ! {
// Wrong task token. Declared Exti0, got Exti1 // Wrong task token. Declared Exti0, got Exti1
fn j1(_task: Exti1, _prio: P1) {} fn j1(_task: Exti1, _prio: P1) {}
// fake device crate
extern crate core;
extern crate cortex_m;
mod device { mod device {
pub mod interrupt { pub mod interrupt {
use cortex_m::interrupt::Nr; use cortex_m::interrupt::Nr;