Add compilation of examples with new features to test suite
diff --git a/Cargo.toml b/Cargo.toml index 549e72a..5641d3c 100644 --- a/Cargo.toml +++ b/Cargo.toml
@@ -24,22 +24,27 @@ [[example]] name = "alloc_error" -path = "examples-alloc/alloc_error.rs" -required-features = ["alloc"] +path = "examples-features/alloc_error.rs" +required-features = ["alloc", "custom_alloc_error_handler"] [[example]] name = "ble_scanning" -path = "examples-alloc/ble_scanning.rs" +path = "examples-features/ble_scanning.rs" required-features = ["alloc"] [[example]] name = "libtock_test" -path = "examples-alloc/libtock_test.rs" +path = "examples-features/libtock_test.rs" required-features = ["alloc"] [[example]] +name = "panic" +path = "examples-features/panic.rs" +required-features = ["custom_panic_handler"] + +[[example]] name = "simple_ble" -path = "examples-alloc/simple_ble.rs" +path = "examples-features/simple_ble.rs" required-features = ["alloc"] [profile.dev]
diff --git a/Makefile b/Makefile index 34d223e..7d87c28 100644 --- a/Makefile +++ b/Makefile
@@ -42,7 +42,9 @@ examples: PLATFORM=nrf52 cargo build --release --target=thumbv7em-none-eabi --examples PLATFORM=nrf52 cargo build --release --target=thumbv7em-none-eabi --examples --features=alloc - PLATFORM=opentitan cargo build --release --target=riscv32imc-unknown-none-elf --examples + PLATFORM=nrf52 cargo build --release --target=thumbv7em-none-eabi --example panic --features=custom_panic_handler,custom_alloc_error_handler + PLATFORM=nrf52 cargo build --release --target=thumbv7em-none-eabi --example alloc_error --features=alloc,custom_alloc_error_handler + PLATFORM=opentitan cargo build --release --target=riscv32imc-unknown-none-elf --examples # Important: This is testing a platform without atomics support cd core && cargo build --release --target=thumbv7em-none-eabi --examples --features=custom_panic_handler && cd .. .PHONY: test
diff --git a/examples-alloc/alloc_error.rs b/examples-alloc/alloc_error.rs deleted file mode 100644 index ec42b5a..0000000 --- a/examples-alloc/alloc_error.rs +++ /dev/null
@@ -1,16 +0,0 @@ -// Triggers the out-of-memory handler. Should make all LEDs cycle. - -#![no_std] - -extern crate alloc; - -use alloc::vec::Vec; -use libtock::result::TockResult; - -#[libtock::main] -fn main() -> TockResult<()> { - let mut vec = Vec::new(); - loop { - vec.push(0); - } -}
diff --git a/examples-features/alloc_error.rs b/examples-features/alloc_error.rs new file mode 100644 index 0000000..40ae939 --- /dev/null +++ b/examples-features/alloc_error.rs
@@ -0,0 +1,31 @@ +// Triggers the out-of-memory handler. Should print an error message. + +#![no_std] +#![feature(alloc_error_handler)] + +extern crate alloc; + +use alloc::vec::Vec; +use core::alloc::Layout; +use core::fmt::Write; +use libtock::result::TockResult; +use libtock::syscalls; + +#[libtock::main] +fn main() -> TockResult<()> { + let mut vec = Vec::new(); + loop { + vec.push(0); + } +} + +#[alloc_error_handler] +unsafe fn alloc_error_handler(_: Layout) -> ! { + if let Ok(drivers) = libtock::retrieve_drivers() { + let mut console = drivers.console.create_console(); + let _ = writeln!(console, "alloc_error_handler called"); + } + loop { + syscalls::raw::yieldk(); + } +}
diff --git a/examples-alloc/ble_scanning.rs b/examples-features/ble_scanning.rs similarity index 100% rename from examples-alloc/ble_scanning.rs rename to examples-features/ble_scanning.rs
diff --git a/examples-alloc/libtock_test.rs b/examples-features/libtock_test.rs similarity index 100% rename from examples-alloc/libtock_test.rs rename to examples-features/libtock_test.rs
diff --git a/examples-features/panic.rs b/examples-features/panic.rs new file mode 100644 index 0000000..5a9123a --- /dev/null +++ b/examples-features/panic.rs
@@ -0,0 +1,24 @@ +// Triggers the panic handler. Should print an error message. + +#![no_std] + +use core::fmt::Write; +use core::panic::PanicInfo; +use libtock::result::TockResult; +use libtock::syscalls; + +#[libtock::main] +async fn main() -> TockResult<()> { + panic!("Bye world!"); +} + +#[panic_handler] +unsafe fn panic_handler(_info: &PanicInfo) -> ! { + if let Ok(drivers) = libtock::retrieve_drivers() { + let mut console = drivers.console.create_console(); + let _ = writeln!(console, "panic_handler called"); + } + loop { + syscalls::raw::yieldk(); + } +}
diff --git a/examples-alloc/simple_ble.rs b/examples-features/simple_ble.rs similarity index 100% rename from examples-alloc/simple_ble.rs rename to examples-features/simple_ble.rs
diff --git a/examples/panic.rs b/examples/panic.rs deleted file mode 100644 index 5abc01a..0000000 --- a/examples/panic.rs +++ /dev/null
@@ -1,10 +0,0 @@ -// Triggers the panic handler. Should make all LEDs flash. - -#![no_std] - -use libtock::result::TockResult; - -#[libtock::main] -async fn main() -> TockResult<()> { - panic!("Bye world!"); -}