add cfail tests

This commit is contained in:
Jorge Aparicio 2017-07-18 15:14:39 -05:00
parent e9788ff9b6
commit 1f1cf84ab4
14 changed files with 438 additions and 2 deletions

View file

@ -14,5 +14,11 @@ version = "0.2.0"
[dependencies]
cortex-m = "0.3.0"
cortex-m-rtfm-macros = { path = "macros" }
static-ref = "0.2.0"
static-ref = "0.2.0"
[dependencies.cortex-m-rtfm-macros]
path = "macros"
[dev-dependencies]
compiletest_rs = "0.2.8"
stm32f103xx = "0.7.1"

16
tests/cfail.rs Normal file
View file

@ -0,0 +1,16 @@
extern crate compiletest_rs as compiletest;
use std::path::PathBuf;
use compiletest::common::Mode;
#[test]
fn cfail() {
let mut config = compiletest::default_config();
config.mode = Mode::CompileFail;
config.src_base = PathBuf::from(format!("tests/cfail"));
config.target_rustcflags =
Some("-L target/debug -L target/debug/deps ".to_string());
compiletest::run_tests(&config);
}

View file

@ -0,0 +1,35 @@
// error-pattern: the name `EXTI0` is defined multiple times
#![deny(warnings)]
#![feature(proc_macro)]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! {
device: stm32f103xx,
tasks: {
EXTI0: {
enabled: true,
priority: 1,
},
},
}
fn init(_p: init::Peripherals) {}
fn idle() -> ! {
loop {}
}
task!(EXTI0, exti0);
fn exti0(_t: Threshold, _r: EXTI0::Resources) {}
task!(EXTI0, exti1);
fn exti1(_t: Threshold, _r: EXTI0::Resources) {}

View file

@ -0,0 +1,27 @@
#![deny(warnings)]
#![feature(proc_macro)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::app;
app! {
//~^ error proc macro panicked
//~| help parsing
device: stm32f103xx,
tasks: {
SYS_TICK: {
priority: 1,
},
SYS_TICK: {
priority: 2,
},
},
}
fn init(_p: init::Peripherals) {}
fn idle() -> ! {}

16
tests/cfail/idle.rs Normal file
View file

@ -0,0 +1,16 @@
#![deny(warnings)]
#![feature(proc_macro)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::app;
app! { //~ error mismatched types
device: stm32f103xx,
}
fn init(_p: init::Peripherals) {}
// ERROR `idle` must be a diverging function
fn idle() {}

18
tests/cfail/init.rs Normal file
View file

@ -0,0 +1,18 @@
#![deny(warnings)]
#![feature(proc_macro)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::app;
app! { //~ error mismatched types
device: stm32f103xx,
}
// ERROR `init` must have signature `fn (init::Peripherals)`
fn init() {}
fn idle() -> ! {
loop {}
}

67
tests/cfail/lock.rs Normal file
View file

@ -0,0 +1,67 @@
#![deny(warnings)]
#![feature(const_fn)]
#![feature(proc_macro)]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! {
device: stm32f103xx,
resources: {
STATE: bool = false;
MAX: u8 = 0;
},
tasks: {
EXTI0: {
enabled: true,
priority: 1,
resources: [MAX, STATE],
},
EXTI1: {
enabled: true,
priority: 2,
resources: [STATE],
},
EXTI2: {
enabled: true,
priority: 16,
resources: [MAX],
},
},
}
fn init(_p: init::Peripherals, _r: init::Resources) {}
fn idle() -> ! {
loop {}
}
task!(EXTI0, exti0);
fn exti0(mut t: Threshold, r: EXTI0::Resources) {
// OK need to lock to access the resource
if r.STATE.claim(&mut t, |state, _| **state) {}
// OK can claim a resource with maximum ceiling
r.MAX.claim_mut(&mut t, |max, _| **max += 1);
}
task!(EXTI1, exti1);
fn exti1(mut t: Threshold, r: EXTI1::Resources) {
// ERROR no need to lock. Has direct access because priority == ceiling
if r.STATE.claim(&mut t, |state, _| **state) {
//~^ error no method named `claim` found for type
}
if **r.STATE {
// OK
}
}

View file

@ -0,0 +1,26 @@
#![deny(warnings)]
#![feature(proc_macro)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::app;
app! { //~ error proc macro panicked
device: stm32f103xx,
tasks: {
EXTI0: {
enabled: true,
priority: 1,
// ERROR peripheral appears twice in this list
resources: [GPIOA, GPIOA],
},
},
}
fn init(_p: init::Peripherals) {}
fn idle() -> ! {
loop {}
}

View file

@ -0,0 +1,29 @@
#![deny(warnings)]
#![feature(proc_macro)]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! { //~ error attempt to subtract with overflow
device: stm32f103xx,
tasks: {
SYS_TICK: {
// ERROR priority must be in the range [1, 16]
priority: 17,
},
},
}
fn init(_p: init::Peripherals) {}
fn idle() -> ! {
loop {}
}
task!(SYS_TICK, sys_tick);
fn sys_tick(_: Threshold, _: SYS_TICK::Resources) {}

View file

@ -0,0 +1,29 @@
#![deny(warnings)]
#![feature(proc_macro)]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! { //~ error attempt to subtract with overflow
device: stm32f103xx,
tasks: {
SYS_TICK: {
// ERROR priority must be in the range [1, 16]
priority: 0,
},
},
}
fn init(_p: init::Peripherals) {}
fn idle() -> ! {
loop {}
}
task!(SYS_TICK, sys_tick);
fn sys_tick(_: Threshold, _: SYS_TICK::Resources) {}

View file

@ -0,0 +1,30 @@
#![deny(warnings)]
#![feature(proc_macro)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::app;
app! { //~ error proc macro panicked
device: stm32f103xx,
resources: {
// resource `MAX` listed twice
MAX: u8 = 0;
MAX: u16 = 0;
},
tasks: {
EXTI0: {
enabled: true,
priority: 1,
},
},
}
fn init(_p: init::Peripherals) {}
fn idle() -> ! {
loop {}
}

View file

@ -0,0 +1,49 @@
#![deny(warnings)]
#![feature(const_fn)]
#![feature(proc_macro)]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! {
device: stm32f103xx,
resources: {
STATE: bool = false;
},
tasks: {
EXTI0: {
enabled: true,
priority: 1,
resources: [STATE],
},
EXTI1: {
enabled: true,
priority: 2,
resources: [STATE],
},
},
}
fn init(_p: init::Peripherals, _r: init::Resources) {}
fn idle() -> ! {
loop {}
}
task!(EXTI0, exti0);
fn exti0(mut t: Threshold, r: EXTI0::Resources) {
// ERROR token should not outlive the critical section
let t = r.STATE.claim(&mut t, |_state, t| t);
//~^ error cannot infer an appropriate lifetime
}
task!(EXTI1, exti1);
fn exti1(_t: Threshold, _r: EXTI1::Resources) {}

View file

@ -0,0 +1,35 @@
#![deny(warnings)]
#![feature(const_fn)]
#![feature(proc_macro)]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! { //~ error bound `rtfm::Threshold: std::marker::Send` is not satisfied
device: stm32f103xx,
resources: {
TOKEN: Option<Threshold> = None;
},
tasks: {
EXTI0: {
enabled: true,
priority: 1,
resources: [TOKEN],
},
}
}
fn init(_p: init::Peripherals, _r: init::Resources) {}
fn idle() -> ! {
loop {}
}
task!(EXTI0, exti0);
fn exti0(_t: Threshold, _r: EXTI0::Resources) {}

View file

@ -0,0 +1,53 @@
#![deny(warnings)]
#![feature(const_fn)]
#![feature(proc_macro)]
#[macro_use(task)]
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use rtfm::{app, Threshold};
app! {
device: stm32f103xx,
resources: {
A: u8 = 0;
B: u8 = 0;
},
tasks: {
EXTI0: {
enabled: true,
priority: 1,
resources: [A, B],
},
EXTI1: {
enabled: true,
priority: 2,
resources: [A, B],
},
},
}
fn init(_p: init::Peripherals, _r: init::Resources) {}
fn idle() -> ! {
loop {}
}
task!(EXTI0, exti0);
fn exti0(mut ot: Threshold, r: EXTI0::Resources) {
r.A.claim(&mut ot, |_a, mut _it| {
//~^ error cannot borrow `ot` as mutable more than once at a time
//~| error cannot borrow `ot` as mutable more than once at a time
// ERROR must use inner token `it` instead of the outer one (`ot`)
r.B.claim(&mut ot, |_b, _| {})
});
}
task!(EXTI1, exti1);
fn exti1(_t: Threshold, r: EXTI1::Resources) {}