From 1f1cf84ab41ec26ac58c31260667f97507def0d0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 18 Jul 2017 15:14:39 -0500 Subject: add cfail tests --- 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 +++++++++++++++++++++++++++++++ 13 files changed, 430 insertions(+) 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 (limited to 'tests') diff --git a/tests/cfail.rs b/tests/cfail.rs new file mode 100644 index 0000000..44c982c --- /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 0000000..cae5d8a --- /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 0000000..ab80519 --- /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 0000000..e517170 --- /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 0000000..19bc13c --- /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 0000000..f93b79a --- /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 0000000..840f0dc --- /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 0000000..ac3a704 --- /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 0000000..8bb0801 --- /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 0000000..159b526 --- /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 0000000..9bcd288 --- /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 0000000..e517a6b --- /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 0000000..af8bb05 --- /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) {} -- cgit v1.2.3