ui tests added

This commit is contained in:
Per Lindgren 2021-10-26 19:35:41 +02:00
parent 6c3d94d73b
commit fbd7fe9a08
17 changed files with 229 additions and 227 deletions

View file

@ -0,0 +1,24 @@
#![no_main]
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
mod app {
#[shared]
struct Shared {
a: u32,
}
#[local]
struct Local {}
#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
(Shared { a: 0 }, Local {}, init::Monotonics())
}
#[task(shared = [a])]
fn foo(mut c: foo::Context) {
c.shared.lock(|_| {
c.shared.lock(|_| {}); // borrow error
});
}
}

View file

@ -0,0 +1,25 @@
error[E0499]: cannot borrow `c.shared` as mutable more than once at a time
--> ui/lockall_borrow_shared.rs:20:9
|
20 | c.shared.lock(|_| {
| ^ ---- --- first mutable borrow occurs here
| | |
| _________| first borrow later used by call
| |
21 | | c.shared.lock(|_| {}); // borrow error
| | -------- first borrow occurs due to use of `c` in closure
22 | | });
| |__________^ second mutable borrow occurs here
error[E0499]: cannot borrow `c` as mutable more than once at a time
--> ui/lockall_borrow_shared.rs:20:23
|
20 | c.shared.lock(|_| {
| - ---- ^^^ second mutable borrow occurs here
| | |
| _________| first borrow later used by call
| |
21 | | c.shared.lock(|_| {}); // borrow error
| | -------- second borrow occurs due to use of `c` in closure
22 | | });
| |__________- first mutable borrow occurs here

View file

@ -0,0 +1,24 @@
#![no_main]
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
mod app {
#[shared]
struct Shared {
a: u32,
}
#[local]
struct Local {}
#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
(Shared { a: 0 }, Local {}, init::Monotonics())
}
#[task(shared = [a])]
fn foo(mut c: foo::Context) {
c.shared.lock(|_| {
c.shared.a.lock(|_| {}); // borrow error
});
}
}

View file

@ -0,0 +1,25 @@
error[E0499]: cannot borrow `c.shared` as mutable more than once at a time
--> ui/lockall_borrow_shared_a.rs:20:9
|
20 | c.shared.lock(|_| {
| ^ ---- --- first mutable borrow occurs here
| | |
| _________| first borrow later used by call
| |
21 | | c.shared.a.lock(|_| {}); // borrow error
| | ---------- first borrow occurs due to use of `c` in closure
22 | | });
| |__________^ second mutable borrow occurs here
error[E0499]: cannot borrow `c` as mutable more than once at a time
--> ui/lockall_borrow_shared_a.rs:20:23
|
20 | c.shared.lock(|_| {
| - ---- ^^^ second mutable borrow occurs here
| | |
| _________| first borrow later used by call
| |
21 | | c.shared.a.lock(|_| {}); // borrow error
| | ---------- second borrow occurs due to use of `c` in closure
22 | | });
| |__________- first mutable borrow occurs here

22
ui/lockall_lifetime.rs Normal file
View file

@ -0,0 +1,22 @@
#![no_main]
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
mod app {
#[shared]
struct Shared {
a: u32,
}
#[local]
struct Local {}
#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
(Shared { a: 0 }, Local {}, init::Monotonics())
}
#[task(shared = [a])]
fn foo(mut c: foo::Context) {
let _ = c.shared.lock(|s| s); // lifetime
}
}

View file

@ -0,0 +1,8 @@
error: lifetime may not live long enough
--> ui/lockall_lifetime.rs:20:35
|
20 | let _ = c.shared.lock(|s| s); // lifetime
| -- ^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is &'2 mut __rtic_internal_fooShared
| has type `&'1 mut __rtic_internal_fooShared`

View file

@ -0,0 +1,31 @@
//! examples/lockall_soundness.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
mod app {
#[shared]
struct Shared {
a: u32,
}
#[local]
struct Local {}
#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
(Shared { a: 0 }, Local {}, init::Monotonics())
}
#[task(shared = [a])]
fn foo(mut c: foo::Context) {
let _ = c.shared.lock(|foo::Shared { a }| {
a // lifetime
});
}
}

View file

@ -0,0 +1,9 @@
error: lifetime may not live long enough
--> ui/lockall_lifetime_destruct_field.rs:28:13
|
27 | let _ = c.shared.lock(|foo::Shared { a }| {
| ------------------ return type of closure is &'2 mut &mut u32
| |
| has type `&'1 mut __rtic_internal_fooShared`
28 | a // lifetime
| ^ returning this value requires that `'1` must outlive `'2`

View file

@ -0,0 +1,22 @@
#![no_main]
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
mod app {
#[shared]
struct Shared {
a: u32,
}
#[local]
struct Local {}
#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
(Shared { a: 0 }, Local {}, init::Monotonics())
}
#[task(shared = [a])]
fn foo(mut c: foo::Context) {
let _ = c.shared.lock(|s| &mut *s.a); // lifetime
}
}

View file

@ -0,0 +1,8 @@
error: lifetime may not live long enough
--> ui/lockall_lifetime_reborrow.rs:20:35
|
20 | let _ = c.shared.lock(|s| &mut *s.a); // lifetime
| -- ^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is &'2 mut u32
| has type `&'1 mut __rtic_internal_fooShared`

View file

@ -0,0 +1,24 @@
#![no_main]
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
mod app {
#[shared]
struct Shared {
a: u32,
}
#[local]
struct Local {}
#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
foo::spawn().unwrap();
(Shared { a: 0 }, Local {}, init::Monotonics())
}
#[task(shared = [a])]
fn foo(mut c: foo::Context) {
let _ = c.shared.lock(|s| s.a);
}
}

View file

@ -0,0 +1,5 @@
error[E0507]: cannot move out of `s.a` which is behind a mutable reference
--> ui/lockall_move_out_field.rs:22:35
|
22 | let _ = c.shared.lock(|s| s.a);
| ^^^ move occurs because `s.a` has type `&mut u32`, which does not implement the `Copy` trait