Skip to content

Commit fbd29fc

Browse files
committed
add compile-fail tests; test only on nightly
we'll test on beta when 1.30-beta is out
1 parent fc592e4 commit fbd29fc

29 files changed

+488
-22
lines changed

cortex-m-rt/.travis.yml

+21-16
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ language: rust
33
matrix:
44
include:
55
- env: TARGET=x86_64-unknown-linux-gnu
6-
rust: stable
7-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
8-
9-
- env: TARGET=thumbv6m-none-eabi
10-
rust: stable
11-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
12-
13-
- env: TARGET=thumbv7m-none-eabi
14-
rust: stable
15-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
16-
17-
- env: TARGET=thumbv7em-none-eabi
18-
rust: stable
6+
# TODO switch to 1.30-beta
7+
rust: nightly
198
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
209

21-
- env: TARGET=thumbv7em-none-eabihf
22-
rust: stable
23-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
10+
# TODO enable when 1.30-beta is out
11+
# - env: TARGET=thumbv6m-none-eabi
12+
# rust: beta
13+
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
14+
15+
# TODO enable when 1.30-beta is out
16+
# - env: TARGET=thumbv7m-none-eabi
17+
# rust: beta
18+
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
19+
20+
# TODO enable when 1.30-beta is out
21+
# - env: TARGET=thumbv7em-none-eabi
22+
# rust: beta
23+
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
24+
25+
# TODO enable when 1.30-beta is out
26+
# - env: TARGET=thumbv7em-none-eabihf
27+
# rust: beta
28+
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
2429

2530
- env: TARGET=thumbv6m-none-eabi
2631
rust: nightly

cortex-m-rt/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ r0 = "0.2.1"
1515
cortex-m-rt-macros = { path = "macros", version = "0.1.0" }
1616

1717
[dev-dependencies]
18-
panic-semihosting = "0.3.0"
19-
panic-abort = "0.2.0"
2018
cortex-m = "0.5.4"
19+
panic-abort = "0.3.0"
20+
panic-semihosting = "0.4.0"
21+
22+
[target.'cfg(not(target_os = "none"))'.dev-dependencies]
23+
compiletest_rs = "0.3.14"
2124

2225
[features]
2326
device = []

cortex-m-rt/ci/script.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ main() {
55

66
cargo check --target $TARGET --features device
77

8-
( cd macros && cargo check && cargo test )
8+
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
9+
( cd macros && cargo check && cargo test )
10+
11+
cargo test --test compiletest
12+
fi
913

1014
local examples=(
1115
alignment
@@ -18,7 +22,7 @@ main() {
1822
local fail_examples=(
1923
data_overflow
2024
)
21-
if [ $TRAVIS_RUST_VERSION = nightly ]; then
25+
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
2226
# linking with GNU LD
2327
for ex in "${examples[@]}"; do
2428
cargo rustc --target $TARGET --example $ex -- \

cortex-m-rt/macros/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
124124
}).collect::<Vec<_>>();
125125

126126
quote!(
127+
// TODO(forbid) see tests/compile-fail/entry-hidden.rs
128+
// #[forbid(dead_code)]
127129
#[export_name = "main"]
128130
#(#attrs)*
129131
pub fn #ident() -> ! {
@@ -297,7 +299,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
297299
_ => false,
298300
},
299301
},
300-
"`#DefaultHandler` function must have signature `fn(i16)`"
302+
"`DefaultHandler` exception must have signature `fn(i16)`"
301303
);
302304

303305
let arg = match f.decl.inputs[0] {
@@ -345,7 +347,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
345347
_ => false,
346348
},
347349
},
348-
"`#[exception(HardFault)]` function must have signature `fn(&ExceptionFrame) -> !`"
350+
"`HardFault` exception must have signature `fn(&ExceptionFrame) -> !`"
349351
);
350352

351353
let arg = match f.decl.inputs[0] {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception] //~ ERROR custom attribute panicked
15+
//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
16+
fn DefaultHandler(_irqn: i16, undef: u32) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception] //~ ERROR custom attribute panicked
15+
//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
16+
unsafe fn DefaultHandler(_irqn: i16) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception] //~ ERROR custom attribute panicked
15+
//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
16+
fn DefaultHandler(_irqn: i16) -> ! {
17+
loop {}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// ignore-test :sadface: it's not possible to prevent this user error at compile time
2+
// see rust-lang/rust#53975 for details
3+
4+
#![no_main]
5+
#![no_std]
6+
7+
extern crate cortex_m_rt;
8+
extern crate panic_semihosting;
9+
10+
use cortex_m_rt::{entry, exception};
11+
12+
#[entry]
13+
fn foo() -> ! {
14+
loop {}
15+
}
16+
17+
mod hidden {
18+
use cortex_m_rt::exception;
19+
20+
#[exception]
21+
fn DefaultHandler(_irqn: i16) {}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception]
15+
fn DefaultHandler(_irqn: i16) {}
16+
17+
pub mod reachable {
18+
use cortex_m_rt::exception;
19+
20+
#[exception] //~ ERROR symbol `DefaultHandler` is already defined
21+
fn DefaultHandler(_irqn: i16) {}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::entry;
8+
9+
#[entry] //~ ERROR custom attribute panicked
10+
//~^ HELP `#[entry]` function must have signature `fn() -> !`
11+
fn foo() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::entry;
8+
9+
#[entry] //~ ERROR custom attribute panicked
10+
//~^ HELP `#[entry]` function must have signature `fn() -> !`
11+
fn foo(undef: i32) -> ! {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::entry;
8+
9+
#[entry] //~ ERROR custom attribute panicked
10+
//~^ HELP `#[entry]` function must have signature `fn() -> !`
11+
unsafe fn foo() -> ! {
12+
loop {}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::entry;
8+
9+
#[entry] //~ ERROR custom attribute panicked
10+
//~^ HELP `#[entry]` function must have signature `fn() -> !`
11+
extern "C" fn foo() -> ! {
12+
loop {}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ignore-test :sadface: it's not possible to prevent this user error at compile time
2+
// see rust-lang/rust#53975 for details
3+
4+
#![no_main]
5+
#![no_std]
6+
7+
extern crate cortex_m_rt;
8+
extern crate panic_semihosting;
9+
10+
mod hidden {
11+
use cortex_m_rt::entry;
12+
13+
// this function needs to be "reachable" (all modules between it and the crate root must be
14+
// `pub`) or linking will fail
15+
#[entry]
16+
fn foo() -> ! { //~ ERROR function is never used
17+
loop {}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::entry;
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[entry] //~ ERROR symbol `main` is already defined
15+
fn bar() -> ! {
16+
loop {}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception] //~ ERROR custom attribute panicked
15+
//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
16+
fn SysTick(undef: u32) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception] //~ ERROR custom attribute panicked
15+
//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
16+
unsafe fn SysTick() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception] //~ ERROR custom attribute panicked
15+
//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
16+
fn SysTick() -> ! {
17+
loop {}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// ignore-test :sadface: it's not possible to prevent this user error at compile time
2+
// see rust-lang/rust#53975 for details
3+
4+
#![no_main]
5+
#![no_std]
6+
7+
extern crate cortex_m_rt;
8+
extern crate panic_semihosting;
9+
10+
use cortex_m_rt::{entry, exception};
11+
12+
#[entry]
13+
fn foo() -> ! {
14+
loop {}
15+
}
16+
17+
mod hidden {
18+
use cortex_m_rt::exception;
19+
20+
#[exception]
21+
fn SysTick() {}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_semihosting;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception]
15+
fn SysTick() {}
16+
17+
pub mod reachable {
18+
use cortex_m_rt::exception;
19+
20+
#[exception] //~ ERROR symbol `SysTick` is already defined
21+
fn SysTick() {}
22+
}

0 commit comments

Comments
 (0)