From 1f1cf84ab41ec26ac58c31260667f97507def0d0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 18 Jul 2017 15:14:39 -0500 Subject: [PATCH] add cfail tests --- Cargo.toml | 10 ++++- tests/cfail.rs | 16 ++++++++ tests/cfail/duplicated-handler.rs | 35 ++++++++++++++++ tests/cfail/duplicated-task.rs | 27 +++++++++++++ tests/cfail/idle.rs | 16 ++++++++ tests/cfail/init.rs | 18 +++++++++ tests/cfail/lock.rs | 67 +++++++++++++++++++++++++++++++ tests/cfail/peripheral-alias.rs | 26 ++++++++++++ tests/cfail/priority-too-high.rs | 29 +++++++++++++ tests/cfail/priority-too-low.rs | 29 +++++++++++++ tests/cfail/resource-alias.rs | 30 ++++++++++++++ tests/cfail/token-outlive.rs | 49 ++++++++++++++++++++++ tests/cfail/token-transfer.rs | 35 ++++++++++++++++ tests/cfail/wrong-threshold.rs | 53 ++++++++++++++++++++++++ 14 files changed, 438 insertions(+), 2 deletions(-) create mode 100644 tests/cfail.rs create mode 100644 tests/cfail/duplicated-handler.rs create mode 100644 tests/cfail/duplicated-task.rs create mode 100644 tests/cfail/idle.rs create mode 100644 tests/cfail/init.rs create mode 100644 tests/cfail/lock.rs create mode 100644 tests/cfail/peripheral-alias.rs create mode 100644 tests/cfail/priority-too-high.rs create mode 100644 tests/cfail/priority-too-low.rs create mode 100644 tests/cfail/resource-alias.rs create mode 100644 tests/cfail/token-outlive.rs create mode 100644 tests/cfail/token-transfer.rs create mode 100644 tests/cfail/wrong-threshold.rs diff --git a/Cargo.toml b/Cargo.toml index 09acc71f86..443ba4271b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" \ No newline at end of file +static-ref = "0.2.0" + +[dependencies.cortex-m-rtfm-macros] +path = "macros" + +[dev-dependencies] +compiletest_rs = "0.2.8" +stm32f103xx = "0.7.1" diff --git a/tests/cfail.rs b/tests/cfail.rs new file mode 100644 index 0000000000..44c982ce5a --- /dev/null +++ b/tests/cfail.rs @@ -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); +} diff --git a/tests/cfail/duplicated-handler.rs b/tests/cfail/duplicated-handler.rs new file mode 100644 index 0000000000..cae5d8a5e8 --- /dev/null +++ b/tests/cfail/duplicated-handler.rs @@ -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) {} diff --git a/tests/cfail/duplicated-task.rs b/tests/cfail/duplicated-task.rs new file mode 100644 index 0000000000..ab80519c0c --- /dev/null +++ b/tests/cfail/duplicated-task.rs @@ -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() -> ! {} diff --git a/tests/cfail/idle.rs b/tests/cfail/idle.rs new file mode 100644 index 0000000000..e517170517 --- /dev/null +++ b/tests/cfail/idle.rs @@ -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() {} diff --git a/tests/cfail/init.rs b/tests/cfail/init.rs new file mode 100644 index 0000000000..19bc13c1e2 --- /dev/null +++ b/tests/cfail/init.rs @@ -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 {} +} diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs new file mode 100644 index 0000000000..f93b79aa11 --- /dev/null +++ b/tests/cfail/lock.rs @@ -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 + } +} diff --git a/tests/cfail/peripheral-alias.rs b/tests/cfail/peripheral-alias.rs new file mode 100644 index 0000000000..840f0dc04d --- /dev/null +++ b/tests/cfail/peripheral-alias.rs @@ -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 {} +} diff --git a/tests/cfail/priority-too-high.rs b/tests/cfail/priority-too-high.rs new file mode 100644 index 0000000000..ac3a7043a6 --- /dev/null +++ b/tests/cfail/priority-too-high.rs @@ -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) {} diff --git a/tests/cfail/priority-too-low.rs b/tests/cfail/priority-too-low.rs new file mode 100644 index 0000000000..8bb080171b --- /dev/null +++ b/tests/cfail/priority-too-low.rs @@ -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) {} diff --git a/tests/cfail/resource-alias.rs b/tests/cfail/resource-alias.rs new file mode 100644 index 0000000000..159b526304 --- /dev/null +++ b/tests/cfail/resource-alias.rs @@ -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 {} +} diff --git a/tests/cfail/token-outlive.rs b/tests/cfail/token-outlive.rs new file mode 100644 index 0000000000..9bcd288260 --- /dev/null +++ b/tests/cfail/token-outlive.rs @@ -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) {} diff --git a/tests/cfail/token-transfer.rs b/tests/cfail/token-transfer.rs new file mode 100644 index 0000000000..e517a6bf49 --- /dev/null +++ b/tests/cfail/token-transfer.rs @@ -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 = 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) {} diff --git a/tests/cfail/wrong-threshold.rs b/tests/cfail/wrong-threshold.rs new file mode 100644 index 0000000000..af8bb05d73 --- /dev/null +++ b/tests/cfail/wrong-threshold.rs @@ -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) {}