aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-09-06 00:25:45 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-09-06 00:25:45 +0200
commitfbd29fc7fe75ec9e906d8e961ab08cf66794d305 (patch)
treedccaf7ff25f4e3cc64ce5d63cd30a36cd59af7f3
parentfc592e4960d99ca8f33c6414ca9903bf0cb6df73 (diff)
downloadcortex-m-fbd29fc7fe75ec9e906d8e961ab08cf66794d305.tar.gz
cortex-m-fbd29fc7fe75ec9e906d8e961ab08cf66794d305.tar.zst
cortex-m-fbd29fc7fe75ec9e906d8e961ab08cf66794d305.zip
add compile-fail tests; test only on nightly
we'll test on beta when 1.30-beta is out
-rw-r--r--cortex-m-rt/.travis.yml37
-rw-r--r--cortex-m-rt/Cargo.toml7
-rw-r--r--cortex-m-rt/ci/script.sh8
-rw-r--r--cortex-m-rt/macros/src/lib.rs6
-rw-r--r--cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs16
-rw-r--r--cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs16
-rw-r--r--cortex-m-rt/tests/compile-fail/default-handler-bad-signature-3.rs18
-rw-r--r--cortex-m-rt/tests/compile-fail/default-handler-hidden.rs22
-rw-r--r--cortex-m-rt/tests/compile-fail/default-handler-twice.rs22
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs11
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs11
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs13
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-bad-signature-4.rs13
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-hidden.rs19
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-twice.rs17
-rw-r--r--cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs16
-rw-r--r--cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs16
-rw-r--r--cortex-m-rt/tests/compile-fail/exception-bad-signature-3.rs18
-rw-r--r--cortex-m-rt/tests/compile-fail/exception-hidden.rs22
-rw-r--r--cortex-m-rt/tests/compile-fail/exception-twice.rs22
-rw-r--r--cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs18
-rw-r--r--cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-2.rs18
-rw-r--r--cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs24
-rw-r--r--cortex-m-rt/tests/compile-fail/hard-fault-twice.rs26
-rw-r--r--cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs16
-rw-r--r--cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs16
-rw-r--r--cortex-m-rt/tests/compile-fail/pre-init-hidden.rs23
-rw-r--r--cortex-m-rt/tests/compile-fail/pre-init-twice.rs18
-rw-r--r--cortex-m-rt/tests/compiletest.rs21
29 files changed, 488 insertions, 22 deletions
diff --git a/cortex-m-rt/.travis.yml b/cortex-m-rt/.travis.yml
index caa29ef..fd45f63 100644
--- a/cortex-m-rt/.travis.yml
+++ b/cortex-m-rt/.travis.yml
@@ -3,24 +3,29 @@ language: rust
matrix:
include:
- env: TARGET=x86_64-unknown-linux-gnu
- rust: stable
- if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
-
- - env: TARGET=thumbv6m-none-eabi
- rust: stable
- if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
-
- - env: TARGET=thumbv7m-none-eabi
- rust: stable
- if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
-
- - env: TARGET=thumbv7em-none-eabi
- rust: stable
+ # TODO switch to 1.30-beta
+ rust: nightly
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
- - env: TARGET=thumbv7em-none-eabihf
- rust: stable
- if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
+ # TODO enable when 1.30-beta is out
+ # - env: TARGET=thumbv6m-none-eabi
+ # rust: beta
+ # if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
+
+ # TODO enable when 1.30-beta is out
+ # - env: TARGET=thumbv7m-none-eabi
+ # rust: beta
+ # if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
+
+ # TODO enable when 1.30-beta is out
+ # - env: TARGET=thumbv7em-none-eabi
+ # rust: beta
+ # if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
+
+ # TODO enable when 1.30-beta is out
+ # - env: TARGET=thumbv7em-none-eabihf
+ # rust: beta
+ # if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
- env: TARGET=thumbv6m-none-eabi
rust: nightly
diff --git a/cortex-m-rt/Cargo.toml b/cortex-m-rt/Cargo.toml
index 016cdc9..9cf2c14 100644
--- a/cortex-m-rt/Cargo.toml
+++ b/cortex-m-rt/Cargo.toml
@@ -15,9 +15,12 @@ r0 = "0.2.1"
cortex-m-rt-macros = { path = "macros", version = "0.1.0" }
[dev-dependencies]
-panic-semihosting = "0.3.0"
-panic-abort = "0.2.0"
cortex-m = "0.5.4"
+panic-abort = "0.3.0"
+panic-semihosting = "0.4.0"
+
+[target.'cfg(not(target_os = "none"))'.dev-dependencies]
+compiletest_rs = "0.3.14"
[features]
device = []
diff --git a/cortex-m-rt/ci/script.sh b/cortex-m-rt/ci/script.sh
index 8443046..0a28641 100644
--- a/cortex-m-rt/ci/script.sh
+++ b/cortex-m-rt/ci/script.sh
@@ -5,7 +5,11 @@ main() {
cargo check --target $TARGET --features device
- ( cd macros && cargo check && cargo test )
+ if [ $TARGET = x86_64-unknown-linux-gnu ]; then
+ ( cd macros && cargo check && cargo test )
+
+ cargo test --test compiletest
+ fi
local examples=(
alignment
@@ -18,7 +22,7 @@ main() {
local fail_examples=(
data_overflow
)
- if [ $TRAVIS_RUST_VERSION = nightly ]; then
+ if [ $TARGET != x86_64-unknown-linux-gnu ]; then
# linking with GNU LD
for ex in "${examples[@]}"; do
cargo rustc --target $TARGET --example $ex -- \
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs
index 5d6a603..7d3c61a 100644
--- a/cortex-m-rt/macros/src/lib.rs
+++ b/cortex-m-rt/macros/src/lib.rs
@@ -124,6 +124,8 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
}).collect::<Vec<_>>();
quote!(
+ // TODO(forbid) see tests/compile-fail/entry-hidden.rs
+ // #[forbid(dead_code)]
#[export_name = "main"]
#(#attrs)*
pub fn #ident() -> ! {
@@ -297,7 +299,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
_ => false,
},
},
- "`#DefaultHandler` function must have signature `fn(i16)`"
+ "`DefaultHandler` exception must have signature `fn(i16)`"
);
let arg = match f.decl.inputs[0] {
@@ -345,7 +347,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
_ => false,
},
},
- "`#[exception(HardFault)]` function must have signature `fn(&ExceptionFrame) -> !`"
+ "`HardFault` exception must have signature `fn(&ExceptionFrame) -> !`"
);
let arg = match f.decl.inputs[0] {
diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs
new file mode 100644
index 0000000..a2c16c1
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs
@@ -0,0 +1,16 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception] //~ ERROR custom attribute panicked
+//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
+fn DefaultHandler(_irqn: i16, undef: u32) {}
diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs
new file mode 100644
index 0000000..ec74993
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs
@@ -0,0 +1,16 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception] //~ ERROR custom attribute panicked
+//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
+unsafe fn DefaultHandler(_irqn: i16) {}
diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-3.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-3.rs
new file mode 100644
index 0000000..c827b6a
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-3.rs
@@ -0,0 +1,18 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception] //~ ERROR custom attribute panicked
+//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
+fn DefaultHandler(_irqn: i16) -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs b/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs
new file mode 100644
index 0000000..059c10b
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs
@@ -0,0 +1,22 @@
+// ignore-test :sadface: it's not possible to prevent this user error at compile time
+// see rust-lang/rust#53975 for details
+
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+mod hidden {
+ use cortex_m_rt::exception;
+
+ #[exception]
+ fn DefaultHandler(_irqn: i16) {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/default-handler-twice.rs b/cortex-m-rt/tests/compile-fail/default-handler-twice.rs
new file mode 100644
index 0000000..7d6ad98
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/default-handler-twice.rs
@@ -0,0 +1,22 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception]
+fn DefaultHandler(_irqn: i16) {}
+
+pub mod reachable {
+ use cortex_m_rt::exception;
+
+ #[exception] //~ ERROR symbol `DefaultHandler` is already defined
+ fn DefaultHandler(_irqn: i16) {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs
new file mode 100644
index 0000000..c4914db
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs
@@ -0,0 +1,11 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::entry;
+
+#[entry] //~ ERROR custom attribute panicked
+//~^ HELP `#[entry]` function must have signature `fn() -> !`
+fn foo() {}
diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs
new file mode 100644
index 0000000..88ffd34
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs
@@ -0,0 +1,11 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::entry;
+
+#[entry] //~ ERROR custom attribute panicked
+//~^ HELP `#[entry]` function must have signature `fn() -> !`
+fn foo(undef: i32) -> ! {}
diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs
new file mode 100644
index 0000000..0f2ddca
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs
@@ -0,0 +1,13 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::entry;
+
+#[entry] //~ ERROR custom attribute panicked
+//~^ HELP `#[entry]` function must have signature `fn() -> !`
+unsafe fn foo() -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-4.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-4.rs
new file mode 100644
index 0000000..2077f41
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-4.rs
@@ -0,0 +1,13 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::entry;
+
+#[entry] //~ ERROR custom attribute panicked
+//~^ HELP `#[entry]` function must have signature `fn() -> !`
+extern "C" fn foo() -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/entry-hidden.rs b/cortex-m-rt/tests/compile-fail/entry-hidden.rs
new file mode 100644
index 0000000..7d74063
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/entry-hidden.rs
@@ -0,0 +1,19 @@
+// ignore-test :sadface: it's not possible to prevent this user error at compile time
+// see rust-lang/rust#53975 for details
+
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+mod hidden {
+ use cortex_m_rt::entry;
+
+ // this function needs to be "reachable" (all modules between it and the crate root must be
+ // `pub`) or linking will fail
+ #[entry]
+ fn foo() -> ! { //~ ERROR function is never used
+ loop {}
+ }
+}
diff --git a/cortex-m-rt/tests/compile-fail/entry-twice.rs b/cortex-m-rt/tests/compile-fail/entry-twice.rs
new file mode 100644
index 0000000..b2819f6
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/entry-twice.rs
@@ -0,0 +1,17 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::entry;
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[entry] //~ ERROR symbol `main` is already defined
+fn bar() -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs
new file mode 100644
index 0000000..1f4b707
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs
@@ -0,0 +1,16 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception] //~ ERROR custom attribute panicked
+//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
+fn SysTick(undef: u32) {}
diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs
new file mode 100644
index 0000000..8b1011d
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs
@@ -0,0 +1,16 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception] //~ ERROR custom attribute panicked
+//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
+unsafe fn SysTick() {}
diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-3.rs b/cortex-m-rt/tests/compile-fail/exception-bad-signature-3.rs
new file mode 100644
index 0000000..546ef90
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/exception-bad-signature-3.rs
@@ -0,0 +1,18 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception] //~ ERROR custom attribute panicked
+//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
+fn SysTick() -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/exception-hidden.rs b/cortex-m-rt/tests/compile-fail/exception-hidden.rs
new file mode 100644
index 0000000..053c81c
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/exception-hidden.rs
@@ -0,0 +1,22 @@
+// ignore-test :sadface: it's not possible to prevent this user error at compile time
+// see rust-lang/rust#53975 for details
+
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+mod hidden {
+ use cortex_m_rt::exception;
+
+ #[exception]
+ fn SysTick() {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/exception-twice.rs b/cortex-m-rt/tests/compile-fail/exception-twice.rs
new file mode 100644
index 0000000..5377fce
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/exception-twice.rs
@@ -0,0 +1,22 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception]
+fn SysTick() {}
+
+pub mod reachable {
+ use cortex_m_rt::exception;
+
+ #[exception] //~ ERROR symbol `SysTick` is already defined
+ fn SysTick() {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs
new file mode 100644
index 0000000..7c61240
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs
@@ -0,0 +1,18 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception, ExceptionFrame};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception] //~ ERROR custom attribute panicked
+//~^ HELP `HardFault` exception must have signature `fn(&ExceptionFrame) -> !`
+fn HardFault(_ef: &ExceptionFrame, undef: u32) -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-2.rs
new file mode 100644
index 0000000..add6943
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-2.rs
@@ -0,0 +1,18 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception, ExceptionFrame};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception] //~ ERROR custom attribute panicked
+//~^ HELP `HardFault` exception must have signature `fn(&ExceptionFrame) -> !`
+unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs b/cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs
new file mode 100644
index 0000000..31237c4
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs
@@ -0,0 +1,24 @@
+// ignore-test :sadface: it's not possible to prevent this user error at compile time
+// see rust-lang/rust#53975 for details
+
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception, ExceptionFrame};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+mod hidden {
+ use cortex_m_rt::{exception, ExceptionFrame};
+
+ #[exception]
+ fn HardFault(_ef: &ExceptionFrame) -> ! {
+ loop {}
+ }
+}
diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs b/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs
new file mode 100644
index 0000000..90270e5
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs
@@ -0,0 +1,26 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, exception, ExceptionFrame};
+
+#[entry]
+fn foo() -> ! {
+ loop {}
+}
+
+#[exception]
+fn HardFault(_ef: &ExceptionFrame) -> ! {
+ loop {}
+}
+
+pub mod reachable {
+ use cortex_m_rt::{exception, ExceptionFrame};
+
+ #[exception] //~ ERROR symbol `UserHardFault` is already defined
+ fn HardFault(_ef: &ExceptionFrame) -> ! {
+ loop {}
+ }
+}
diff --git a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs
new file mode 100644
index 0000000..58d3022
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs
@@ -0,0 +1,16 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, pre_init};
+
+#[pre_init] //~ ERROR custom attribute panicked
+//~^ HELP `#[pre_init]` function must have signature `unsafe fn()`
+fn foo() {}
+
+#[entry]
+fn bar() -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs
new file mode 100644
index 0000000..e47ed59
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs
@@ -0,0 +1,16 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, pre_init};
+
+#[pre_init] //~ ERROR custom attribute panicked
+//~^ HELP `#[pre_init]` function must have signature `unsafe fn()`
+unsafe fn foo(undef: i32) {}
+
+#[entry]
+fn bar() -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/pre-init-hidden.rs b/cortex-m-rt/tests/compile-fail/pre-init-hidden.rs
new file mode 100644
index 0000000..f512d62
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/pre-init-hidden.rs
@@ -0,0 +1,23 @@
+// ignore-test :sadface: it's not possible to prevent this user error at compile time
+// see rust-lang/rust#53975 for details
+
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+mod hidden {
+ use cortex_m_rt::pre_init;
+
+ // this function needs to be "reachable" (all modules between it and the crate root must be
+ // `pub`) or the function will be ignored
+ #[entry]
+ unsafe fn pre_init() {} //~ ERROR function is never used
+}
+
+#[entry]
+fn foo() -> ! {
+ //~ ERROR function is never used
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/pre-init-twice.rs b/cortex-m-rt/tests/compile-fail/pre-init-twice.rs
new file mode 100644
index 0000000..5fb1ade
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/pre-init-twice.rs
@@ -0,0 +1,18 @@
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::{entry, pre_init};
+
+#[pre_init]
+unsafe fn foo() {}
+
+#[pre_init] //~ ERROR symbol `__pre_init` is already defined
+unsafe fn bar() {}
+
+#[entry]
+fn baz() -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compiletest.rs b/cortex-m-rt/tests/compiletest.rs
new file mode 100644
index 0000000..6cea3ac
--- /dev/null
+++ b/cortex-m-rt/tests/compiletest.rs
@@ -0,0 +1,21 @@
+extern crate compiletest_rs as compiletest;
+
+use std::path::PathBuf;
+
+fn run_mode(mode: &'static str) {
+ let mut config = compiletest::Config::default();
+
+ config.mode = mode.parse().expect("Invalid mode");
+ config.src_base = PathBuf::from(format!("tests/{}", mode));
+ // config.link_deps(); // Populate config.target_rustcflags with dependencies on the path
+ config.target_rustcflags =
+ Some("-L target/debug -L target/debug/deps -C panic=abort".to_owned());
+ // config.clean_rmeta(); // If your tests import the parent crate, this helps with E0464
+
+ compiletest::run_tests(&config);
+}
+
+#[test]
+fn compile_test() {
+ run_mode("compile-fail");
+}