diff options
author | 2017-07-18 20:03:22 -0500 | |
---|---|---|
committer | 2017-07-18 20:03:22 -0500 | |
commit | 97a7e38db7eb0643a6334aba30077622d09e5c85 (patch) | |
tree | a561e574a8cb36b748c84f69ee679fe0e61f1899 /tests/cfail | |
parent | a2b0c9e0d077870441ecdea00108c3a3a394fd9b (diff) | |
download | rtic-97a7e38db7eb0643a6334aba30077622d09e5c85.tar.gz rtic-97a7e38db7eb0643a6334aba30077622d09e5c85.tar.zst rtic-97a7e38db7eb0643a6334aba30077622d09e5c85.zip |
tasks / idle have exclusive access to Threshold, but do not own the token
Diffstat (limited to 'tests/cfail')
-rw-r--r-- | tests/cfail/duplicated-handler.rs | 4 | ||||
-rw-r--r-- | tests/cfail/local-token.rs | 44 | ||||
-rw-r--r-- | tests/cfail/lock.rs | 4 | ||||
-rw-r--r-- | tests/cfail/priority-too-high.rs | 2 | ||||
-rw-r--r-- | tests/cfail/priority-too-low.rs | 2 | ||||
-rw-r--r-- | tests/cfail/token-outlive.rs | 4 | ||||
-rw-r--r-- | tests/cfail/token-transfer.rs | 2 | ||||
-rw-r--r-- | tests/cfail/wrong-threshold.rs | 4 |
8 files changed, 55 insertions, 11 deletions
diff --git a/tests/cfail/duplicated-handler.rs b/tests/cfail/duplicated-handler.rs index cae5d8a5..dc902041 100644 --- a/tests/cfail/duplicated-handler.rs +++ b/tests/cfail/duplicated-handler.rs @@ -28,8 +28,8 @@ fn idle() -> ! { task!(EXTI0, exti0); -fn exti0(_t: Threshold, _r: EXTI0::Resources) {} +fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} task!(EXTI0, exti1); -fn exti1(_t: Threshold, _r: EXTI0::Resources) {} +fn exti1(_t: &mut Threshold, _r: EXTI0::Resources) {} diff --git a/tests/cfail/local-token.rs b/tests/cfail/local-token.rs new file mode 100644 index 00000000..4c98956b --- /dev/null +++ b/tests/cfail/local-token.rs @@ -0,0 +1,44 @@ +#![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, + + tasks: { + EXTI0: { + enabled: true, + priority: 1, + }, + } +} + +fn init(_p: init::Peripherals) {} + +fn idle() -> ! { + loop {} +} + +task!(EXTI0, exti0, Old { + token: Option<Threshold> = None; +}); + +fn exti0(nt: &mut Threshold, old: &mut Old, _r: EXTI0::Resources) { + if let Some(ot) = old.token.take() { + let _: (Threshold, Threshold) = (*nt, ot); + //~^ error cannot move out of borrowed content + + return + } + + // ERROR can't store a threshold token in a local variable, otherwise you + // would end up with two threshold tokens in a task (see `if let` above) + old.token = Some(*nt); + //~^ error cannot move out of borrowed content +} diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs index f93b79aa..736027e2 100644 --- a/tests/cfail/lock.rs +++ b/tests/cfail/lock.rs @@ -45,7 +45,7 @@ fn idle() -> ! { task!(EXTI0, exti0); -fn exti0(mut t: Threshold, r: EXTI0::Resources) { +fn exti0(mut t: &mut Threshold, r: EXTI0::Resources) { // OK need to lock to access the resource if r.STATE.claim(&mut t, |state, _| **state) {} @@ -55,7 +55,7 @@ fn exti0(mut t: Threshold, r: EXTI0::Resources) { task!(EXTI1, exti1); -fn exti1(mut t: Threshold, r: EXTI1::Resources) { +fn exti1(mut t: &mut 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 diff --git a/tests/cfail/priority-too-high.rs b/tests/cfail/priority-too-high.rs index ac3a7043..c76b7a6b 100644 --- a/tests/cfail/priority-too-high.rs +++ b/tests/cfail/priority-too-high.rs @@ -26,4 +26,4 @@ fn idle() -> ! { task!(SYS_TICK, sys_tick); -fn sys_tick(_: Threshold, _: SYS_TICK::Resources) {} +fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {} diff --git a/tests/cfail/priority-too-low.rs b/tests/cfail/priority-too-low.rs index 8bb08017..1e0c8e92 100644 --- a/tests/cfail/priority-too-low.rs +++ b/tests/cfail/priority-too-low.rs @@ -26,4 +26,4 @@ fn idle() -> ! { task!(SYS_TICK, sys_tick); -fn sys_tick(_: Threshold, _: SYS_TICK::Resources) {} +fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {} diff --git a/tests/cfail/token-outlive.rs b/tests/cfail/token-outlive.rs index 9bcd2882..93d1c604 100644 --- a/tests/cfail/token-outlive.rs +++ b/tests/cfail/token-outlive.rs @@ -38,7 +38,7 @@ fn idle() -> ! { task!(EXTI0, exti0); -fn exti0(mut t: Threshold, r: EXTI0::Resources) { +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 @@ -46,4 +46,4 @@ fn exti0(mut t: Threshold, r: EXTI0::Resources) { task!(EXTI1, exti1); -fn exti1(_t: Threshold, _r: EXTI1::Resources) {} +fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} diff --git a/tests/cfail/token-transfer.rs b/tests/cfail/token-transfer.rs index e517a6bf..91e74bdf 100644 --- a/tests/cfail/token-transfer.rs +++ b/tests/cfail/token-transfer.rs @@ -32,4 +32,4 @@ fn idle() -> ! { task!(EXTI0, exti0); -fn exti0(_t: Threshold, _r: EXTI0::Resources) {} +fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} diff --git a/tests/cfail/wrong-threshold.rs b/tests/cfail/wrong-threshold.rs index af8bb05d..39d3a57b 100644 --- a/tests/cfail/wrong-threshold.rs +++ b/tests/cfail/wrong-threshold.rs @@ -39,7 +39,7 @@ fn idle() -> ! { task!(EXTI0, exti0); -fn exti0(mut ot: Threshold, r: EXTI0::Resources) { +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 cannot borrow `ot` as mutable more than once at a time @@ -50,4 +50,4 @@ fn exti0(mut ot: Threshold, r: EXTI0::Resources) { task!(EXTI1, exti1); -fn exti1(_t: Threshold, r: EXTI1::Resources) {} +fn exti1(_t: &mut Threshold, r: EXTI1::Resources) {} |