From b91cd36ca601d69f7b4e4a73315330f2eb5921a4 Mon Sep 17 00:00:00 2001 From: Sh3Rm4n Date: Thu, 10 Dec 2020 12:36:44 +0100 Subject: [PATCH] Test defmt-test --- firmware/qemu/Cargo.toml | 5 +++ firmware/qemu/src/bin/defmt-test.out | 6 ++++ firmware/qemu/src/bin/defmt-test.release.out | 6 ++++ firmware/qemu/src/bin/defmt-test.rs | 35 ++++++++++++++++++++ firmware/qemu/test.sh | 1 + 5 files changed, 53 insertions(+) create mode 100644 firmware/qemu/src/bin/defmt-test.out create mode 100644 firmware/qemu/src/bin/defmt-test.release.out create mode 100644 firmware/qemu/src/bin/defmt-test.rs diff --git a/firmware/qemu/Cargo.toml b/firmware/qemu/Cargo.toml index 540496ff..b19e9674 100644 --- a/firmware/qemu/Cargo.toml +++ b/firmware/qemu/Cargo.toml @@ -9,6 +9,7 @@ version = "0.1.0" [dependencies] defmt = { path = "../.." } defmt-semihosting = { path = "../defmt-semihosting" } +defmt-test = { path = "../defmt-test" } cortex-m = "0.6.0" cortex-m-rt = "0.6.10" cortex-m-semihosting = "0.3.3" @@ -56,3 +57,7 @@ test = false name = "alloc" test = false required-features = ["alloc"] + +[[bin]] +name = "defmt-test" +test = false diff --git a/firmware/qemu/src/bin/defmt-test.out b/firmware/qemu/src/bin/defmt-test.out new file mode 100644 index 00000000..24072240 --- /dev/null +++ b/firmware/qemu/src/bin/defmt-test.out @@ -0,0 +1,6 @@ +0.000000 INFO (1/3) running `assert_true`... +0.000000 INFO (2/3) running `assert_imported_max`... +0.000000 INFO (3/3) running `assert_eq`... +0.000000 ERROR panicked at 'assertion failed: `(left == right)`: TODO: write actual tests' + left: `24` +right: `42` diff --git a/firmware/qemu/src/bin/defmt-test.release.out b/firmware/qemu/src/bin/defmt-test.release.out new file mode 100644 index 00000000..24072240 --- /dev/null +++ b/firmware/qemu/src/bin/defmt-test.release.out @@ -0,0 +1,6 @@ +0.000000 INFO (1/3) running `assert_true`... +0.000000 INFO (2/3) running `assert_imported_max`... +0.000000 INFO (3/3) running `assert_eq`... +0.000000 ERROR panicked at 'assertion failed: `(left == right)`: TODO: write actual tests' + left: `24` +right: `42` diff --git a/firmware/qemu/src/bin/defmt-test.rs b/firmware/qemu/src/bin/defmt-test.rs new file mode 100644 index 00000000..981f0a19 --- /dev/null +++ b/firmware/qemu/src/bin/defmt-test.rs @@ -0,0 +1,35 @@ +#![no_std] +#![no_main] + +use defmt_semihosting as _; // global logger +use core::u8::MAX; + +#[defmt_test::tests] +mod tests { + use super::MAX; + #[test] + fn assert_true() { + defmt::assert!(true) + } + + #[test] + fn assert_imported_max() { + defmt::assert_eq!(255, MAX) + } + + #[test] + fn assert_eq() { + defmt::assert_eq!(24, 42, "TODO: write actual tests") + } +} + +// like `panic-semihosting` but doesn't print to stdout (that would corrupt the defmt stream) +#[cfg(target_os = "none")] +#[panic_handler] +fn panic(_: &core::panic::PanicInfo) -> ! { + use cortex_m_semihosting::debug; + + loop { + debug::exit(debug::EXIT_SUCCESS) + } +} diff --git a/firmware/qemu/test.sh b/firmware/qemu/test.sh index df9dcbd5..428b668d 100755 --- a/firmware/qemu/test.sh +++ b/firmware/qemu/test.sh @@ -18,6 +18,7 @@ test "assert-eq" test "assert-ne" test "double-write" test "unwrap" +test "defmt-test" if rustc -V | grep nightly; then test "alloc" "alloc" fi