closes #32
closes #33
This commit is contained in:
Jorge Aparicio 2018-11-03 17:02:41 +01:00
parent 653338e799
commit c631049efc
154 changed files with 7538 additions and 3276 deletions

View file

@ -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);
}

View file

@ -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) {}

View file

@ -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() -> ! {}

View file

@ -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 {}
}
};

View file

@ -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()`
}
};

View file

@ -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
}
};

View file

@ -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
}
};

View file

@ -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
}
};

View file

@ -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 {}
}

19
tests/cfail/idle-input.rs Normal file
View file

@ -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() -> !`
}
};

View file

@ -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() -> !`
}
};

View file

@ -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() {}

View file

@ -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 {}
}
};

16
tests/cfail/init-input.rs Normal file
View file

@ -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()`
}
};

View file

@ -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<NotSend> = None;
#[init(resources = [X])]
fn init() {
*resources.X = Some(NotSend { _0: PhantomData })
}
#[interrupt(resources = [X])]
fn UART0() {}
};

View file

@ -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
}
};

View file

@ -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 {}
}

View file

@ -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() {}

View file

@ -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 {}
}

View file

@ -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() {}
};

View file

@ -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 {}
}
};

View file

@ -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()`
}
};

View file

@ -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
}
};

View file

@ -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() {}

View file

@ -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() {}
};

View file

@ -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() {}
};

View file

@ -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) {}

View file

@ -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() {}
};

View file

@ -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) {}

30
tests/cfail/needs-send.rs Normal file
View file

@ -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();
}
};

36
tests/cfail/needs-sync.rs Normal file
View file

@ -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();
}
};

View file

@ -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 {}
}

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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 {}
}

View file

@ -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() {}
};

View file

@ -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>(_: &T) where T: Send {}
fn is_sync<T>(_: &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) {
}

View file

@ -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() {}
};

View file

@ -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();
}
};

23
tests/cfail/task-idle.rs Normal file
View file

@ -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();
}
};

View file

@ -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() {}
};

View file

@ -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) {}

View file

@ -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<Threshold> = 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) {}

View file

@ -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();
}
};

View file

@ -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) {}

59
tests/compiletest.rs Normal file
View file

@ -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);
}

View file

@ -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<NotSend> = None;
#[init(resources = [Y])]
fn init() {
*resources.Y = Some(NotSend { _0: PhantomData });
X = NotSend { _0: PhantomData };
}
#[idle(resources = [X, Y])]
fn idle() -> ! {
loop {}
}
};

View file

@ -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;
}
};

19
tests/cpass/peripheral.rs Normal file
View file

@ -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;
}
};

80
tests/cpass/resource.rs Normal file
View file

@ -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;
}
};

59
tests/cpass/schedule.rs Normal file
View file

@ -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();
}
};

67
tests/cpass/singleton.rs Normal file
View file

@ -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;
}
};

60
tests/cpass/spawn.rs Normal file
View file

@ -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();
}
};

46
tests/cpass/unsafe.rs Normal file
View file

@ -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();
}
};