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) {
let ceil = prio.as_ceiling();
ceil.raise(&R1, |ceil| {
// CAN borrow a resource with ceiling C when the current ceiling SC > C
ceil.raise(
&R1, |ceil| {
// NOTE CC = Current Ceiling, P = task Priority
// CAN borrow a resource with ceiling RC when CC > RC
let r2 = R2.borrow(&prio, ceil);
// 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);
// CAN'T borrow a resource with ceiling C when the current ceiling SC < C
// CAN'T borrow a resource with ceiling RC when CC < RC
let r4 = R4.borrow(&prio, ceil);
//~^ error
// CAN'T borrow a resource with ceiling C < P (task priority)
// CAN'T borrow a resource with ceiling RC when RC < P
let r5 = R5.borrow(&prio, ceil);
//~^ error
// CAN borrow a resource with ceiling C == P (task priority)
// 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) {
let ceil = prio.as_ceiling();
let c3 = ceil.raise(&R1, |ceil| {
// forbidden: ceiling token can't outlive critical section
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
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);

View file

@ -4,17 +4,16 @@ use rtfm::{C16, C2, P1, P16, P2, P3, Resource};
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) {
let ceil = prio.as_ceiling();
ceil.raise(&R1, |ceil| {
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<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) {
let ceil = prio.as_ceiling();
ceil.raise(&R2, |ceil| {
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());

View file

@ -7,17 +7,38 @@ static R1: Resource<i32, C2> = Resource::new(0);
fn j1(prio: P1) {
let ceil = prio.as_ceiling();
ceil.raise(&R1, |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| {
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
}
}

View file

@ -8,21 +8,40 @@ static R2: Resource<i32, C4> = Resource::new(0);
fn j1(prio: P1) {
let ceil = prio.as_ceiling();
ceil.raise(&R1, |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| {
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
}
}

View file

@ -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;

View file

@ -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 {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;