aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml10
-rw-r--r--tests/cfail.rs16
-rw-r--r--tests/cfail/duplicated-handler.rs35
-rw-r--r--tests/cfail/duplicated-task.rs27
-rw-r--r--tests/cfail/idle.rs16
-rw-r--r--tests/cfail/init.rs18
-rw-r--r--tests/cfail/lock.rs67
-rw-r--r--tests/cfail/peripheral-alias.rs26
-rw-r--r--tests/cfail/priority-too-high.rs29
-rw-r--r--tests/cfail/priority-too-low.rs29
-rw-r--r--tests/cfail/resource-alias.rs30
-rw-r--r--tests/cfail/token-outlive.rs49
-rw-r--r--tests/cfail/token-transfer.rs35
-rw-r--r--tests/cfail/wrong-threshold.rs53
14 files changed, 438 insertions, 2 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 09acc71f..443ba427 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 00000000..44c982ce
--- /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 00000000..cae5d8a5
--- /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 00000000..ab80519c
--- /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 00000000..e5171705
--- /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 00000000..19bc13c1
--- /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 00000000..f93b79aa
--- /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 00000000..840f0dc0
--- /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 00000000..ac3a7043
--- /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 00000000..8bb08017
--- /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 00000000..159b5263
--- /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 00000000..9bcd2882
--- /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 00000000..e517a6bf
--- /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<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) {}
diff --git a/tests/cfail/wrong-threshold.rs b/tests/cfail/wrong-threshold.rs
new file mode 100644
index 00000000..af8bb05d
--- /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) {}