aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cortex-m-rt/tests')
-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
25 files changed, 452 insertions, 0 deletions
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");
+}