From c631049efcadca8b07940c794cce2be58fa48444 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 3 Nov 2018 17:02:41 +0100 Subject: v0.4.0 closes #32 closes #33 --- tests/cfail.rs | 17 ------ tests/cfail/critical-section.rs | 47 ----------------- tests/cfail/duplicated-task.rs | 27 ---------- tests/cfail/exception-divergent.rs | 20 ++++++++ tests/cfail/exception-input.rs | 19 +++++++ tests/cfail/exception-invalid.rs | 19 +++++++ tests/cfail/exception-output.rs | 20 ++++++++ tests/cfail/exception-sys-tick.rs | 19 +++++++ tests/cfail/exception.rs | 26 ---------- tests/cfail/idle-input.rs | 19 +++++++ tests/cfail/idle-not-divergent.rs | 19 +++++++ tests/cfail/idle.rs | 17 ------ tests/cfail/init-divergent.rs | 17 ++++++ tests/cfail/init-input.rs | 16 ++++++ tests/cfail/init-not-send.rs | 30 +++++++++++ tests/cfail/init-output.rs | 17 ++++++ tests/cfail/init-resource-share-idle.rs | 30 ----------- tests/cfail/init-resource-share-task.rs | 35 ------------- tests/cfail/init.rs | 19 ------- tests/cfail/insufficient-free-interrupts.rs | 17 ++++++ tests/cfail/interrupt-divergent.rs | 20 ++++++++ tests/cfail/interrupt-input.rs | 19 +++++++ tests/cfail/interrupt-output.rs | 20 ++++++++ tests/cfail/interrupt.rs | 26 ---------- tests/cfail/late-assigned-to-init.rs | 16 ++++++ tests/cfail/late-not-send.rs | 31 +++++++++++ tests/cfail/late-resource-init.rs | 49 ------------------ tests/cfail/late-uninit.rs | 16 ++++++ tests/cfail/lock.rs | 67 ------------------------ tests/cfail/needs-send.rs | 30 +++++++++++ tests/cfail/needs-sync.rs | 36 +++++++++++++ tests/cfail/peripheral-alias.rs | 27 ---------- tests/cfail/priority-too-high.rs | 30 ----------- tests/cfail/priority-too-low.rs | 30 ----------- tests/cfail/resource-alias.rs | 31 ----------- tests/cfail/resource-not-declared.rs | 14 +++++ tests/cfail/resource-not-send-sync.rs | 53 ------------------- tests/cfail/resource-pub.rs | 17 ++++++ tests/cfail/task-divergent.rs | 24 +++++++++ tests/cfail/task-idle.rs | 23 +++++++++ tests/cfail/task-not-declared.rs | 14 +++++ tests/cfail/token-outlive.rs | 45 ---------------- tests/cfail/token-transfer.rs | 36 ------------- tests/cfail/used-free-interrupt.rs | 21 ++++++++ tests/cfail/wrong-threshold.rs | 47 ----------------- tests/compiletest.rs | 59 +++++++++++++++++++++ tests/cpass/late-not-send.rs | 33 ++++++++++++ tests/cpass/late-resource.rs | 22 ++++++++ tests/cpass/peripheral.rs | 19 +++++++ tests/cpass/resource.rs | 80 +++++++++++++++++++++++++++++ tests/cpass/schedule.rs | 59 +++++++++++++++++++++ tests/cpass/singleton.rs | 67 ++++++++++++++++++++++++ tests/cpass/spawn.rs | 60 ++++++++++++++++++++++ tests/cpass/unsafe.rs | 46 +++++++++++++++++ 54 files changed, 978 insertions(+), 659 deletions(-) delete mode 100644 tests/cfail.rs delete mode 100644 tests/cfail/critical-section.rs delete mode 100644 tests/cfail/duplicated-task.rs create mode 100644 tests/cfail/exception-divergent.rs create mode 100644 tests/cfail/exception-input.rs create mode 100644 tests/cfail/exception-invalid.rs create mode 100644 tests/cfail/exception-output.rs create mode 100644 tests/cfail/exception-sys-tick.rs delete mode 100644 tests/cfail/exception.rs create mode 100644 tests/cfail/idle-input.rs create mode 100644 tests/cfail/idle-not-divergent.rs delete mode 100644 tests/cfail/idle.rs create mode 100644 tests/cfail/init-divergent.rs create mode 100644 tests/cfail/init-input.rs create mode 100644 tests/cfail/init-not-send.rs create mode 100644 tests/cfail/init-output.rs delete mode 100644 tests/cfail/init-resource-share-idle.rs delete mode 100644 tests/cfail/init-resource-share-task.rs delete mode 100644 tests/cfail/init.rs create mode 100644 tests/cfail/insufficient-free-interrupts.rs create mode 100644 tests/cfail/interrupt-divergent.rs create mode 100644 tests/cfail/interrupt-input.rs create mode 100644 tests/cfail/interrupt-output.rs delete mode 100644 tests/cfail/interrupt.rs create mode 100644 tests/cfail/late-assigned-to-init.rs create mode 100644 tests/cfail/late-not-send.rs delete mode 100644 tests/cfail/late-resource-init.rs create mode 100644 tests/cfail/late-uninit.rs delete mode 100644 tests/cfail/lock.rs create mode 100644 tests/cfail/needs-send.rs create mode 100644 tests/cfail/needs-sync.rs delete mode 100644 tests/cfail/peripheral-alias.rs delete mode 100644 tests/cfail/priority-too-high.rs delete mode 100644 tests/cfail/priority-too-low.rs delete mode 100644 tests/cfail/resource-alias.rs create mode 100644 tests/cfail/resource-not-declared.rs delete mode 100644 tests/cfail/resource-not-send-sync.rs create mode 100644 tests/cfail/resource-pub.rs create mode 100644 tests/cfail/task-divergent.rs create mode 100644 tests/cfail/task-idle.rs create mode 100644 tests/cfail/task-not-declared.rs delete mode 100644 tests/cfail/token-outlive.rs delete mode 100644 tests/cfail/token-transfer.rs create mode 100644 tests/cfail/used-free-interrupt.rs delete mode 100644 tests/cfail/wrong-threshold.rs create mode 100644 tests/compiletest.rs create mode 100644 tests/cpass/late-not-send.rs create mode 100644 tests/cpass/late-resource.rs create mode 100644 tests/cpass/peripheral.rs create mode 100644 tests/cpass/resource.rs create mode 100644 tests/cpass/schedule.rs create mode 100644 tests/cpass/singleton.rs create mode 100644 tests/cpass/spawn.rs create mode 100644 tests/cpass/unsafe.rs (limited to 'tests') diff --git a/tests/cfail.rs b/tests/cfail.rs deleted file mode 100644 index 6572d65..0000000 --- a/tests/cfail.rs +++ /dev/null @@ -1,17 +0,0 @@ -extern crate compiletest_rs as compiletest; - -use std::path::PathBuf; - -use compiletest::common::Mode; -use compiletest::Config; - -#[test] -fn cfail() { - let mut config = Config::default(); - config.mode = Mode::CompileFail; - config.src_base = PathBuf::from(format!("tests/cfail")); - config.target_rustcflags = - Some("-C panic=abort -L target/debug -L target/debug/deps ".to_string()); - - compiletest::run_tests(&config); -} diff --git a/tests/cfail/critical-section.rs b/tests/cfail/critical-section.rs deleted file mode 100644 index c0f475c..0000000 --- a/tests/cfail/critical-section.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![feature(const_fn)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Resource, Threshold}; - -app! { - device: stm32f103xx, - - resources: { - static ON: bool = false; - }, - - idle: { - resources: [ON], - }, - - tasks: { - EXTI0: { - path: exti0, - priority: 1, - resources: [ON], - }, - }, -} - -fn init(_p: init::Peripherals, _r: init::Resources) {} - -fn idle(t: &mut Threshold, r: idle::Resources) -> ! { - let state = rtfm::atomic(t, |t| { - // ERROR borrow can't escape this *global* critical section - r.ON.borrow(t) //~ error cannot infer an appropriate lifetime - }); - - let state = r.ON.claim(t, |state, _t| { - // ERROR borrow can't escape this critical section - state //~ error cannot infer an appropriate lifetime - }); - - loop {} -} - -fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} diff --git a/tests/cfail/duplicated-task.rs b/tests/cfail/duplicated-task.rs deleted file mode 100644 index 885c961..0000000 --- a/tests/cfail/duplicated-task.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::app; - -app! { - //~^ error proc macro panicked - device: stm32f103xx, - - tasks: { - SYS_TICK: { - priority: 1, - }, - - SYS_TICK: { - priority: 2, - }, - }, -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! {} diff --git a/tests/cfail/exception-divergent.rs b/tests/cfail/exception-divergent.rs new file mode 100644 index 0000000..692a57c --- /dev/null +++ b/tests/cfail/exception-divergent.rs @@ -0,0 +1,20 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[exception] + fn SVCall() -> ! { + //~^ ERROR `exception` handlers must have type signature `[unsafe] fn()` + loop {} + } +}; diff --git a/tests/cfail/exception-input.rs b/tests/cfail/exception-input.rs new file mode 100644 index 0000000..cb0711c --- /dev/null +++ b/tests/cfail/exception-input.rs @@ -0,0 +1,19 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[exception] + fn SVCall(undef: u32) { + //~^ ERROR `exception` handlers must have type signature `[unsafe] fn()` + } +}; diff --git a/tests/cfail/exception-invalid.rs b/tests/cfail/exception-invalid.rs new file mode 100644 index 0000000..0a7fb52 --- /dev/null +++ b/tests/cfail/exception-invalid.rs @@ -0,0 +1,19 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[exception] + fn NonMaskableInt() { + //~^ ERROR only exceptions with configurable priority can be used as hardware tasks + } +}; diff --git a/tests/cfail/exception-output.rs b/tests/cfail/exception-output.rs new file mode 100644 index 0000000..758dbdd --- /dev/null +++ b/tests/cfail/exception-output.rs @@ -0,0 +1,20 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[exception] + fn SVCall() -> u32 { + //~^ ERROR `exception` handlers must have type signature `[unsafe] fn()` + 0 + } +}; diff --git a/tests/cfail/exception-sys-tick.rs b/tests/cfail/exception-sys-tick.rs new file mode 100644 index 0000000..69d73db --- /dev/null +++ b/tests/cfail/exception-sys-tick.rs @@ -0,0 +1,19 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[exception] + fn SysTick() { + //~^ ERROR the `SysTick` exception can't be used because it's used by the runtime + } +}; diff --git a/tests/cfail/exception.rs b/tests/cfail/exception.rs deleted file mode 100644 index b4e025f..0000000 --- a/tests/cfail/exception.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::app; - -app! { //~ error proc macro panicked - device: stm32f103xx, - - tasks: { - // ERROR exceptions can't be enabled / disabled here - SYS_TICK: { - enabled: true, - priority: 1, - }, - }, -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! { - loop {} -} diff --git a/tests/cfail/idle-input.rs b/tests/cfail/idle-input.rs new file mode 100644 index 0000000..5095977 --- /dev/null +++ b/tests/cfail/idle-input.rs @@ -0,0 +1,19 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[idle] + fn idle(undef: u32) { + //~^ ERROR `idle` must have type signature `[unsafe] fn() -> !` + } +}; diff --git a/tests/cfail/idle-not-divergent.rs b/tests/cfail/idle-not-divergent.rs new file mode 100644 index 0000000..e90eff0 --- /dev/null +++ b/tests/cfail/idle-not-divergent.rs @@ -0,0 +1,19 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[idle] + fn idle() { + //~^ ERROR `idle` must have type signature `[unsafe] fn() -> !` + } +}; diff --git a/tests/cfail/idle.rs b/tests/cfail/idle.rs deleted file mode 100644 index ef20e1a..0000000 --- a/tests/cfail/idle.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -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-divergent.rs b/tests/cfail/init-divergent.rs new file mode 100644 index 0000000..400c805 --- /dev/null +++ b/tests/cfail/init-divergent.rs @@ -0,0 +1,17 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() -> ! { + //~^ ERROR `init` must have type signature `[unsafe] fn()` + loop {} + } +}; diff --git a/tests/cfail/init-input.rs b/tests/cfail/init-input.rs new file mode 100644 index 0000000..fa79099 --- /dev/null +++ b/tests/cfail/init-input.rs @@ -0,0 +1,16 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init(undef: u32) { + //~^ ERROR `init` must have type signature `[unsafe] fn()` + } +}; diff --git a/tests/cfail/init-not-send.rs b/tests/cfail/init-not-send.rs new file mode 100644 index 0000000..3ac495f --- /dev/null +++ b/tests/cfail/init-not-send.rs @@ -0,0 +1,30 @@ +//! This is equivalent to the `late-not-send` cfail test + +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use core::marker::PhantomData; + +use rtfm::app; + +pub struct NotSend { + _0: PhantomData<*const ()>, +} + +#[app(device = lm3s6965)] //~ ERROR `*const ()` cannot be sent between threads safely +const APP: () = { + static mut X: Option = None; + + #[init(resources = [X])] + fn init() { + *resources.X = Some(NotSend { _0: PhantomData }) + } + + #[interrupt(resources = [X])] + fn UART0() {} +}; diff --git a/tests/cfail/init-output.rs b/tests/cfail/init-output.rs new file mode 100644 index 0000000..1200aca --- /dev/null +++ b/tests/cfail/init-output.rs @@ -0,0 +1,17 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() -> u32 { + //~^ ERROR `init` must have type signature `[unsafe] fn()` + 0 + } +}; diff --git a/tests/cfail/init-resource-share-idle.rs b/tests/cfail/init-resource-share-idle.rs deleted file mode 100644 index 5b29f30..0000000 --- a/tests/cfail/init-resource-share-idle.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::app; - -app! { //~ proc macro panicked - device: stm32f103xx, - - resources: { - static BUFFER: [u8; 16] = [0; 16]; - }, - - init: { - resources: [BUFFER], - }, - - idle: { - resources: [BUFFER], - //~^ error: this resource is owned by `init` and can't be shared - }, -} - -fn init(_p: init::Peripherals, _r: init::Resources) {} - -fn idle(_r: init::Resources) -> ! { - loop {} -} diff --git a/tests/cfail/init-resource-share-task.rs b/tests/cfail/init-resource-share-task.rs deleted file mode 100644 index a93e840..0000000 --- a/tests/cfail/init-resource-share-task.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::app; - -app! { //~ proc macro panicked - device: stm32f103xx, - - resources: { - static BUFFER: [u8; 16] = [0; 16]; - }, - - init: { - resources: [BUFFER], - }, - - tasks: { - SYS_TICK: { - path: sys_tick, - resources: [BUFFER], - //~^ error: this resource is owned by `init` and can't be shared - }, - }, -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! { - loop {} -} - -fn sys_tick() {} diff --git a/tests/cfail/init.rs b/tests/cfail/init.rs deleted file mode 100644 index 057a2ee..0000000 --- a/tests/cfail/init.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -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/insufficient-free-interrupts.rs b/tests/cfail/insufficient-free-interrupts.rs new file mode 100644 index 0000000..baa2582 --- /dev/null +++ b/tests/cfail/insufficient-free-interrupts.rs @@ -0,0 +1,17 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] //~ ERROR 1 free interrupt (`extern { .. }`) is required +const APP: () = { + #[init] + fn init() {} + + #[task] + fn foo() {} +}; diff --git a/tests/cfail/interrupt-divergent.rs b/tests/cfail/interrupt-divergent.rs new file mode 100644 index 0000000..4a01533 --- /dev/null +++ b/tests/cfail/interrupt-divergent.rs @@ -0,0 +1,20 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[interrupt] + fn UART0() -> ! { + //~^ ERROR `interrupt` handlers must have type signature `[unsafe] fn()` + loop {} + } +}; diff --git a/tests/cfail/interrupt-input.rs b/tests/cfail/interrupt-input.rs new file mode 100644 index 0000000..d0240f4 --- /dev/null +++ b/tests/cfail/interrupt-input.rs @@ -0,0 +1,19 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[interrupt] + fn UART0(undef: u32) { + //~^ ERROR `interrupt` handlers must have type signature `[unsafe] fn()` + } +}; diff --git a/tests/cfail/interrupt-output.rs b/tests/cfail/interrupt-output.rs new file mode 100644 index 0000000..37cd7c2 --- /dev/null +++ b/tests/cfail/interrupt-output.rs @@ -0,0 +1,20 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[interrupt] + fn UART0() -> u32 { + //~^ ERROR `interrupt` handlers must have type signature `[unsafe] fn()` + 0 + } +}; diff --git a/tests/cfail/interrupt.rs b/tests/cfail/interrupt.rs deleted file mode 100644 index 522763a..0000000 --- a/tests/cfail/interrupt.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::app; - -app! { //~ error no variant named `EXTI33` found for type - device: stm32f103xx, - - tasks: { - EXTI33: { - path: exti33, - }, - }, -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! { - loop {} -} - -fn exti33() {} diff --git a/tests/cfail/late-assigned-to-init.rs b/tests/cfail/late-assigned-to-init.rs new file mode 100644 index 0000000..70a361c --- /dev/null +++ b/tests/cfail/late-assigned-to-init.rs @@ -0,0 +1,16 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + static mut X: u32 = (); + + #[init(resources = [X])] //~ ERROR late resources can NOT be assigned to `init` + fn init() {} +}; diff --git a/tests/cfail/late-not-send.rs b/tests/cfail/late-not-send.rs new file mode 100644 index 0000000..b9180fe --- /dev/null +++ b/tests/cfail/late-not-send.rs @@ -0,0 +1,31 @@ +//! `init` has a static priority of `0`. Initializing resources from it is equivalent to sending a +//! message to the task that will own the resource + +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use core::marker::PhantomData; + +use rtfm::app; + +struct NotSend { + _0: PhantomData<*const ()>, +} + +#[app(device = lm3s6965)] //~ ERROR `*const ()` cannot be sent between threads safely +const APP: () = { + static mut X: NotSend = (); + + #[init] + fn init() { + X = NotSend { _0: PhantomData }; + } + + #[interrupt(resources = [X])] + fn UART0() {} +}; diff --git a/tests/cfail/late-resource-init.rs b/tests/cfail/late-resource-init.rs deleted file mode 100644 index 5235d93..0000000 --- a/tests/cfail/late-resource-init.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Threshold}; - -app! { - device: stm32f103xx, - - resources: { - static A: u8 = 0; - static LATE: u8; - }, - - tasks: { - EXTI0: { - path: exti0, - priority: 1, - resources: [A, LATE], - }, - - EXTI1: { - path: exti1, - priority: 2, - resources: [A, LATE], - }, - }, -} - -fn init(_p: init::Peripherals, r: init::Resources) -> init::LateResources { - // Try to use a resource that's not yet initialized: - r.LATE; - //~^ error: no field `LATE` - - init::LateResources { - LATE: 0, - } -} - -fn idle() -> ! { - loop {} -} - -fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} - -fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} diff --git a/tests/cfail/late-uninit.rs b/tests/cfail/late-uninit.rs new file mode 100644 index 0000000..eeb9bd4 --- /dev/null +++ b/tests/cfail/late-uninit.rs @@ -0,0 +1,16 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + static mut X: u32 = (); //~ ERROR late resources MUST be initialized at the end of `init` + + #[init] + fn init() {} +}; diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs deleted file mode 100644 index 9cb0f3e..0000000 --- a/tests/cfail/lock.rs +++ /dev/null @@ -1,67 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![feature(const_fn)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Resource, Threshold}; - -app! { - device: stm32f103xx, - - resources: { - static ON: bool = false; - static MAX: u8 = 0; - }, - - tasks: { - EXTI0: { - path: exti0, - priority: 1, - resources: [MAX, ON], - }, - - EXTI1: { - path: exti1, - priority: 2, - resources: [ON], - }, - - EXTI2: { - path: exti2, - priority: 16, - resources: [MAX], - }, - }, -} - -fn init(_p: init::Peripherals, _r: init::Resources) {} - -fn idle() -> ! { - loop {} -} - -fn exti0(mut t: &mut Threshold, mut r: EXTI0::Resources) { - // ERROR need to lock to access the resource because priority < ceiling - if *r.ON { - //~^ error type `EXTI0::ON` cannot be dereferenced - } - - // OK need to lock to access the resource - if r.ON.claim(&mut t, |on, _| *on) {} - - // OK can claim a resource with maximum ceiling - r.MAX.claim_mut(&mut t, |max, _| *max += 1); -} - -fn exti1(mut t: &mut Threshold, r: EXTI1::Resources) { - // OK to directly access the resource because priority == ceiling - if *r.ON {} - - // though the resource can still be claimed -- the claim is a no-op - if r.ON.claim(&mut t, |on, _| *on) {} -} - -fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) {} diff --git a/tests/cfail/needs-send.rs b/tests/cfail/needs-send.rs new file mode 100644 index 0000000..7e3ca30 --- /dev/null +++ b/tests/cfail/needs-send.rs @@ -0,0 +1,30 @@ +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use core::marker::PhantomData; + +use rtfm::app; + +pub struct NotSend { + _0: PhantomData<*const ()>, +} + +unsafe impl Sync for NotSend {} + +#[app(device = lm3s6965)] //~ ERROR cannot be sent between threads safely +const APP: () = { + #[init(spawn = [foo])] + fn init() {} + + #[task] + fn foo(_x: NotSend) {} + + extern "C" { + fn UART0(); + } +}; diff --git a/tests/cfail/needs-sync.rs b/tests/cfail/needs-sync.rs new file mode 100644 index 0000000..f25f91a --- /dev/null +++ b/tests/cfail/needs-sync.rs @@ -0,0 +1,36 @@ +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use core::marker::PhantomData; + +use rtfm::app; + +pub struct NotSync { + _0: PhantomData<*const ()>, +} + +unsafe impl Send for NotSync {} + +#[app(device = lm3s6965)] //~ ERROR cannot be shared between threads safely +const APP: () = { + static X: NotSync = NotSync { _0: PhantomData }; + + #[init(spawn = [foo])] + fn init() {} + + #[task(priority = 1, resources = [X])] + fn foo() {} + + #[task(priority = 2, resources = [X])] + fn bar() {} + + extern "C" { + fn UART0(); + fn UART1(); + } +}; diff --git a/tests/cfail/peripheral-alias.rs b/tests/cfail/peripheral-alias.rs deleted file mode 100644 index 7f3790a..0000000 --- a/tests/cfail/peripheral-alias.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -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 deleted file mode 100644 index d63b9d0..0000000 --- a/tests/cfail/priority-too-high.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::app; - -app! { //~ error referenced constant has errors - //~^ error could not evaluate constant - //~| error constant evaluation error - device: stm32f103xx, - - tasks: { - SYS_TICK: { - path: sys_tick, - // ERROR priority must be in the range [1, 16] - priority: 17, - }, - }, -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! { - loop {} -} - -fn sys_tick() {} diff --git a/tests/cfail/priority-too-low.rs b/tests/cfail/priority-too-low.rs deleted file mode 100644 index 476b7a0..0000000 --- a/tests/cfail/priority-too-low.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::app; - -app! { //~ error referenced constant has errors - //~^ error could not evaluate constant - //~| error constant evaluation error - device: stm32f103xx, - - tasks: { - SYS_TICK: { - path: sys_tick, - // ERROR priority must be in the range [1, 16] - priority: 0, - }, - }, -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! { - loop {} -} - -fn sys_tick() {} diff --git a/tests/cfail/resource-alias.rs b/tests/cfail/resource-alias.rs deleted file mode 100644 index 81eeea0..0000000 --- a/tests/cfail/resource-alias.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -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/resource-not-declared.rs b/tests/cfail/resource-not-declared.rs new file mode 100644 index 0000000..f6d08a6 --- /dev/null +++ b/tests/cfail/resource-not-declared.rs @@ -0,0 +1,14 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init(resources = [X])] //~ ERROR this resource has NOT been declared + fn init() {} +}; diff --git a/tests/cfail/resource-not-send-sync.rs b/tests/cfail/resource-not-send-sync.rs deleted file mode 100644 index 27e5cb0..0000000 --- a/tests/cfail/resource-not-send-sync.rs +++ /dev/null @@ -1,53 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![feature(const_fn)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Threshold}; - -app! { - device: stm32f103xx, - - resources: { - static SHARED: bool = false; - }, - - tasks: { - EXTI0: { - path: exti0, - priority: 1, - resources: [SHARED], - }, - - EXTI1: { - path: exti1, - priority: 2, - resources: [SHARED], - }, - }, -} - -fn init(_p: init::Peripherals, _r: init::Resources) {} - -fn idle() -> ! { - loop {} -} - -fn is_send(_: &T) where T: Send {} -fn is_sync(_: &T) where T: Sync {} - -fn exti0(_t: &mut Threshold, r: EXTI0::Resources) { - // ERROR resource proxies can't be shared between tasks - is_sync(&r.SHARED); - //~^ error `*const ()` cannot be shared between threads safely - - // ERROR resource proxies are not `Send`able across tasks - is_send(&r.SHARED); - //~^ error `*const ()` cannot be sent between threads safely -} - -fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) { -} diff --git a/tests/cfail/resource-pub.rs b/tests/cfail/resource-pub.rs new file mode 100644 index 0000000..970fc6c --- /dev/null +++ b/tests/cfail/resource-pub.rs @@ -0,0 +1,17 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + pub static mut X: u32 = 0; + //~^ ERROR resources must have inherited / private visibility + + #[init] + fn init() {} +}; diff --git a/tests/cfail/task-divergent.rs b/tests/cfail/task-divergent.rs new file mode 100644 index 0000000..3822d75 --- /dev/null +++ b/tests/cfail/task-divergent.rs @@ -0,0 +1,24 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[task] + fn foo() -> ! { + //~^ ERROR `task` handlers must have type signature `[unsafe] fn(..)` + loop {} + } + + extern "C" { + fn UART0(); + } +}; diff --git a/tests/cfail/task-idle.rs b/tests/cfail/task-idle.rs new file mode 100644 index 0000000..62d927b --- /dev/null +++ b/tests/cfail/task-idle.rs @@ -0,0 +1,23 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[task] + fn idle() { + //~^ ERROR `task` handlers can NOT be named `idle`, `init` or `resources` + } + + extern "C" { + fn UART0(); + } +}; diff --git a/tests/cfail/task-not-declared.rs b/tests/cfail/task-not-declared.rs new file mode 100644 index 0000000..3e6d87c --- /dev/null +++ b/tests/cfail/task-not-declared.rs @@ -0,0 +1,14 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init(spawn = [X])] //~ ERROR this task has NOT been declared + fn init() {} +}; diff --git a/tests/cfail/token-outlive.rs b/tests/cfail/token-outlive.rs deleted file mode 100644 index 41ee827..0000000 --- a/tests/cfail/token-outlive.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![feature(const_fn)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Resource, Threshold}; - -app! { - device: stm32f103xx, - - resources: { - static STATE: bool = false; - }, - - tasks: { - EXTI0: { - path: exti0, - priority: 1, - resources: [STATE], - }, - - EXTI1: { - path: exti1, - priority: 2, - resources: [STATE], - }, - }, -} - -fn init(_p: init::Peripherals, _r: init::Resources) {} - -fn idle() -> ! { - loop {} -} - -fn exti0(mut t: &mut 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 -} - -fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} diff --git a/tests/cfail/token-transfer.rs b/tests/cfail/token-transfer.rs deleted file mode 100644 index 5c6a22b..0000000 --- a/tests/cfail/token-transfer.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![feature(const_fn)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Threshold}; - -app! { //~ error `*const ()` cannot be sent between threads safely - device: stm32f103xx, - - resources: { - static TOKEN: Option = None; - }, - - idle: { - resources: [TOKEN], - }, - - tasks: { - EXTI0: { - path: exti0, - resources: [TOKEN], - }, - } -} - -fn init(_p: init::Peripherals, _r: init::Resources) {} - -fn idle(_t: &mut Threshold, _r: idle::Resources) -> ! { - loop {} -} - -fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} diff --git a/tests/cfail/used-free-interrupt.rs b/tests/cfail/used-free-interrupt.rs new file mode 100644 index 0000000..78ae540 --- /dev/null +++ b/tests/cfail/used-free-interrupt.rs @@ -0,0 +1,21 @@ +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() {} + + #[interrupt] + fn UART0() {} //~ ERROR free interrupts (`extern { .. }`) can't be used as interrupt handlers + + extern "C" { + fn UART0(); + } +}; diff --git a/tests/cfail/wrong-threshold.rs b/tests/cfail/wrong-threshold.rs deleted file mode 100644 index 86d8e26..0000000 --- a/tests/cfail/wrong-threshold.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Resource, Threshold}; - -app! { - device: stm32f103xx, - - resources: { - static A: u8 = 0; - static B: u8 = 0; - }, - - tasks: { - EXTI0: { - path: exti0, - priority: 1, - resources: [A, B], - }, - - EXTI1: { - path: exti1, - priority: 2, - resources: [A, B], - }, - }, -} - -fn init(_p: init::Peripherals, _r: init::Resources) {} - -fn idle() -> ! { - loop {} -} - -fn exti0(mut ot: &mut 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 must use inner token `it` instead of the outer one (`ot`) - r.B.claim(&mut ot, |_b, _| {}) - }); -} - -fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} diff --git a/tests/compiletest.rs b/tests/compiletest.rs new file mode 100644 index 0000000..acc8954 --- /dev/null +++ b/tests/compiletest.rs @@ -0,0 +1,59 @@ +use std::{fs, path::PathBuf, process::Command}; + +use compiletest_rs::{common::Mode, Config}; +use tempdir::TempDir; + +#[test] +fn cfail() { + let mut config = Config::default(); + + config.mode = Mode::CompileFail; + config.src_base = PathBuf::from("tests/cfail"); + config.link_deps(); + + // remove duplicate and trailing `-L` flags + let mut s = String::new(); + if let Some(flags) = config.target_rustcflags.as_mut() { + let mut iter = flags.split_whitespace().peekable(); + + while let Some(flag) = iter.next() { + if flag == "-L" && (iter.peek() == Some(&"-L") || iter.peek() == None) { + iter.next(); + continue; + } + + s += flag; + s += " "; + } + + // path to proc-macro crate + s += "-L target/debug/deps "; + + // avoid "error: language item required, but not found: `eh_personality`" + s += "-C panic=abort "; + } + + let td = TempDir::new("rtfm").unwrap(); + for f in fs::read_dir("tests/cpass").unwrap() { + let f = f.unwrap().path(); + let name = f.file_stem().unwrap().to_str().unwrap(); + + assert!( + Command::new("rustc") + .args(s.split_whitespace()) + .arg(f.display().to_string()) + .arg("-o") + .arg(td.path().join(name).display().to_string()) + .arg("-C") + .arg("linker=true") + .status() + .unwrap() + .success() + ); + } + + config.target_rustcflags = Some(s); + config.clean_rmeta(); + + compiletest_rs::run_tests(&config); +} diff --git a/tests/cpass/late-not-send.rs b/tests/cpass/late-not-send.rs new file mode 100644 index 0000000..b7d2d60 --- /dev/null +++ b/tests/cpass/late-not-send.rs @@ -0,0 +1,33 @@ +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use core::marker::PhantomData; + +use rtfm::app; + +pub struct NotSend { + _0: PhantomData<*const ()>, +} + +#[app(device = lm3s6965)] +const APP: () = { + static mut X: NotSend = (); + static mut Y: Option = None; + + #[init(resources = [Y])] + fn init() { + *resources.Y = Some(NotSend { _0: PhantomData }); + + X = NotSend { _0: PhantomData }; + } + + #[idle(resources = [X, Y])] + fn idle() -> ! { + loop {} + } +}; diff --git a/tests/cpass/late-resource.rs b/tests/cpass/late-resource.rs new file mode 100644 index 0000000..43f5170 --- /dev/null +++ b/tests/cpass/late-resource.rs @@ -0,0 +1,22 @@ +//! Runtime initialized resources +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + static mut X: u32 = (); + static Y: u32 = (); + + #[init] + fn init() { + X = 0; + Y = 1; + } +}; diff --git a/tests/cpass/peripheral.rs b/tests/cpass/peripheral.rs new file mode 100644 index 0000000..0ca720c --- /dev/null +++ b/tests/cpass/peripheral.rs @@ -0,0 +1,19 @@ +//! Core and device peripherals +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() { + let _: rtfm::Peripherals = core; + let _: lm3s6965::Peripherals = device; + } +}; diff --git a/tests/cpass/resource.rs b/tests/cpass/resource.rs new file mode 100644 index 0000000..6a7a873 --- /dev/null +++ b/tests/cpass/resource.rs @@ -0,0 +1,80 @@ +//! Check code generation of resources + +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + static mut O1: u32 = 0; // init + static mut O2: u32 = 0; // idle + static mut O3: u32 = 0; // EXTI0 + static O4: u32 = 0; // idle + static O5: u32 = 0; // EXTI1 + static O6: u32 = 0; // init + + static mut S1: u32 = 0; // idle & EXTI0 + static mut S2: u32 = 0; // EXTI0 & EXTI1 + static S3: u32 = 0; + + #[init(resources = [O1, O4, O5, O6, S3])] + fn init() { + // owned by `init` == `&'static mut` + let _: &'static mut u32 = resources.O1; + + // owned by `init` == `&'static` if read-only + let _: &'static u32 = resources.O6; + + // `init` has exclusive access to all resources + let _: &mut u32 = resources.O4; + let _: &mut u32 = resources.O5; + let _: &mut u32 = resources.S3; + } + + #[idle(resources = [O2, O4, S1, S3])] + fn idle() -> ! { + // owned by `idle` == `&'static mut` + let _: &'static mut u32 = resources.O2; + + // owned by `idle` == `&'static` if read-only + let _: &'static u32 = resources.O4; + + // shared with `idle` == `Mutex` + resources.S1.lock(|_| {}); + + // `&` if read-only + let _: &u32 = resources.S3; + + loop {} + } + + #[interrupt(resources = [O3, S1, S2, S3])] + fn UART0() { + // owned by interrupt == `&mut` + let _: &mut u32 = resources.O3; + + // no `Mutex` when access from highest priority task + let _: &mut u32 = resources.S1; + + // no `Mutex` when co-owned by cooperative (same priority) tasks + let _: &mut u32 = resources.S2; + + // `&` if read-only + let _: &u32 = resources.S3; + } + + #[interrupt(resources = [S2, O5])] + fn UART1() { + // owned by interrupt == `&` if read-only + let _: &u32 = resources.O5; + + // no `Mutex` when co-owned by cooperative (same priority) tasks + let _: &mut u32 = resources.S2; + } +}; diff --git a/tests/cpass/schedule.rs b/tests/cpass/schedule.rs new file mode 100644 index 0000000..bc7fe34 --- /dev/null +++ b/tests/cpass/schedule.rs @@ -0,0 +1,59 @@ +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::{app, Instant}; + +#[app(device = lm3s6965)] +const APP: () = { + #[init(schedule = [foo, bar, baz])] + fn init() { + let _: Result<(), ()> = schedule.foo(start + 10.cycles()); + let _: Result<(), u32> = schedule.bar(start + 20.cycles(), 0); + let _: Result<(), (u32, u32)> = schedule.baz(start + 30.cycles(), 0, 1); + } + + #[idle(schedule = [foo, bar, baz])] + fn idle() -> ! { + let _: Result<(), ()> = schedule.foo(Instant::now() + 40.cycles()); + let _: Result<(), u32> = schedule.bar(Instant::now() + 50.cycles(), 0); + let _: Result<(), (u32, u32)> = schedule.baz(Instant::now() + 60.cycles(), 0, 1); + + loop {} + } + + #[exception(schedule = [foo, bar, baz])] + fn SVCall() { + let _: Result<(), ()> = schedule.foo(start + 70.cycles()); + let _: Result<(), u32> = schedule.bar(start + 80.cycles(), 0); + let _: Result<(), (u32, u32)> = schedule.baz(start + 90.cycles(), 0, 1); + } + + #[interrupt(schedule = [foo, bar, baz])] + fn UART0() { + let _: Result<(), ()> = schedule.foo(start + 100.cycles()); + let _: Result<(), u32> = schedule.bar(start + 110.cycles(), 0); + let _: Result<(), (u32, u32)> = schedule.baz(start + 120.cycles(), 0, 1); + } + + #[task(schedule = [foo, bar, baz])] + fn foo() { + let _: Result<(), ()> = schedule.foo(scheduled + 130.cycles()); + let _: Result<(), u32> = schedule.bar(scheduled + 140.cycles(), 0); + let _: Result<(), (u32, u32)> = schedule.baz(scheduled + 150.cycles(), 0, 1); + } + + #[task] + fn bar(_x: u32) {} + + #[task] + fn baz(_x: u32, _y: u32) {} + + extern "C" { + fn UART1(); + } +}; diff --git a/tests/cpass/singleton.rs b/tests/cpass/singleton.rs new file mode 100644 index 0000000..77159f3 --- /dev/null +++ b/tests/cpass/singleton.rs @@ -0,0 +1,67 @@ +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate owned_singleton; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[Singleton] + static mut O1: u32 = 0; + #[Singleton] + static mut O2: u32 = 0; + #[Singleton] + static mut O3: u32 = 0; + #[Singleton] + static O4: u32 = 0; + #[Singleton] + static O5: u32 = 0; + #[Singleton] + static O6: u32 = 0; + + #[Singleton] + static mut S1: u32 = 0; + #[Singleton] + static mut S2: u32 = 0; + + #[init(resources = [O1, O2, O3, O4, O5, O6, S1, S2])] + fn init() { + let _: O1 = resources.O1; + let _: &mut O2 = resources.O2; + let _: &mut O3 = resources.O3; + let _: O4 = resources.O4; + let _: &mut O5 = resources.O5; + let _: &mut O6 = resources.O6; + + let _: &mut S1 = resources.S1; + let _: &mut S2 = resources.S2; + } + + #[idle(resources = [O2, O5])] + fn idle() -> ! { + let _: O2 = resources.O2; + let _: O5 = resources.O5; + + loop {} + } + + #[interrupt(resources = [O3, O6, S1, S2])] + fn UART0() { + let _: &mut O3 = resources.O3; + let _: &O6 = resources.O6; + + let _: &mut S1 = resources.S1; + let _: &S2 = resources.S2; + } + + #[interrupt(resources = [S1, S2])] + fn UART1() { + let _: &mut S1 = resources.S1; + let _: &S2 = resources.S2; + } +}; diff --git a/tests/cpass/spawn.rs b/tests/cpass/spawn.rs new file mode 100644 index 0000000..ba5a855 --- /dev/null +++ b/tests/cpass/spawn.rs @@ -0,0 +1,60 @@ +//! Check code generation of `spawn` +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[init(spawn = [foo, bar, baz])] + fn init() { + let _: Result<(), ()> = spawn.foo(); + let _: Result<(), u32> = spawn.bar(0); + let _: Result<(), (u32, u32)> = spawn.baz(0, 1); + } + + #[idle(spawn = [foo, bar, baz])] + fn idle() -> ! { + let _: Result<(), ()> = spawn.foo(); + let _: Result<(), u32> = spawn.bar(0); + let _: Result<(), (u32, u32)> = spawn.baz(0, 1); + + loop {} + } + + #[exception(spawn = [foo, bar, baz])] + fn SVCall() { + let _: Result<(), ()> = spawn.foo(); + let _: Result<(), u32> = spawn.bar(0); + let _: Result<(), (u32, u32)> = spawn.baz(0, 1); + } + + #[interrupt(spawn = [foo, bar, baz])] + fn UART0() { + let _: Result<(), ()> = spawn.foo(); + let _: Result<(), u32> = spawn.bar(0); + let _: Result<(), (u32, u32)> = spawn.baz(0, 1); + } + + #[task(spawn = [foo, bar, baz])] + fn foo() { + let _: Result<(), ()> = spawn.foo(); + let _: Result<(), u32> = spawn.bar(0); + let _: Result<(), (u32, u32)> = spawn.baz(0, 1); + } + + #[task] + fn bar(_x: u32) {} + + #[task] + fn baz(_x: u32, _y: u32) {} + + extern "C" { + fn UART1(); + } +}; diff --git a/tests/cpass/unsafe.rs b/tests/cpass/unsafe.rs new file mode 100644 index 0000000..86f461f --- /dev/null +++ b/tests/cpass/unsafe.rs @@ -0,0 +1,46 @@ +//! Check code generation of `unsafe` `init` / `idle` / `exception` / `interrupt` / `task` +#![feature(extern_crate_item_prelude)] // ??? +#![no_main] +#![no_std] + +extern crate lm3s6965; +extern crate panic_halt; +extern crate rtfm; + +use rtfm::app; + +unsafe fn foo() {} + +#[app(device = lm3s6965)] +const APP: () = { + #[init] + unsafe fn init() { + foo(); + } + + #[idle] + unsafe fn idle() -> ! { + foo(); + + loop {} + } + + #[exception] + unsafe fn SVCall() { + foo(); + } + + #[interrupt] + unsafe fn UART0() { + foo(); + } + + #[task] + unsafe fn bar() { + foo(); + } + + extern "C" { + fn UART1(); + } +}; -- cgit v1.2.3