Skip to content

Commit 88ad0d7

Browse files
committed
flipperzero: Enable Miri to start running the tests
It doesn't *successfully* run the tests because Miri doesn't yet support FFI, but these changes enable the following command to actually start: MIRI_NO_STD=1 cargo miri test --target thumbv7em-none-eabihf Part of #100.
1 parent 4f76105 commit 88ad0d7

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

crates/.cargo/config.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# Equivalent to [target.thumbv7em-none-eabihf] but also disabing the runner for Miri.
2+
# Until target_abi is stable, this also permits thumbv7em-none-eabi.
3+
[target.'cfg(all(target_arch = "arm", target_feature = "thumb2", target_feature = "v7", target_feature = "dsp", target_os = "none", not(miri)))']
4+
runner = "python3 ../cargo-runner.py"
5+
16
[target.thumbv7em-none-eabihf]
27
linker = "./fap-lld.py"
3-
runner = "python3 ../cargo-runner.py"
48
rustflags = [
59
# CPU is Cortex-M4 (STM32WB55)
610
"-C", "target-cpu=cortex-m4",

crates/flipperzero/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//!
66
77
#![no_std]
8-
#![cfg_attr(test, no_main)]
8+
#![cfg_attr(all(test, not(miri)), no_main)]
9+
#![cfg_attr(all(test, miri), feature(start))]
910
#![cfg_attr(docsrs, feature(doc_cfg))]
1011
#![deny(rustdoc::broken_intra_doc_links)]
1112

crates/rt/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ macro_rules! entry {
3232
($path:path) => {
3333
// Force the section to `.text` instead of `.text.main`.
3434
// lld seems not to automatically rename `.rel.text.main` properly.
35+
#[cfg(not(miri))]
3536
#[export_name = "main"]
3637
pub unsafe fn __main(args: *mut u8) -> i32 {
3738
// type check the entry function

crates/sys/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
// Features that identify thumbv7em-none-eabihf.
77
// Until target_abi is stable, this also permits thumbv7em-none-eabi.
8-
#[cfg(not(all(
8+
#[cfg(not(any(all(
99
target_arch = "arm",
1010
target_feature = "thumb2",
1111
target_feature = "v7",
1212
target_feature = "dsp",
1313
target_os = "none",
1414
//target_abi = "eabihf",
15-
)))]
15+
), miri)))]
1616
core::compile_error!("This crate requires `--target thumbv7em-none-eabihf`");
1717

1818
pub mod furi;

crates/test/macros/src/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn tests_runner_impl(args: TokenStream) -> parse::Result<TokenStream> {
131131
}
132132

133133
// Test runner entry point
134-
fn main(args: *mut u8) -> i32 {
134+
pub(super) fn main(args: *mut u8) -> i32 {
135135
// SAFETY: Flipper Zero passes arguments to FAPs as a C string.
136136
let args = unsafe { ::flipperzero_test::__macro_support::Args::parse(args) };
137137
match ::flipperzero_test::__macro_support::run_tests(test_count(), test_list(), args) {
@@ -140,6 +140,17 @@ fn tests_runner_impl(args: TokenStream) -> parse::Result<TokenStream> {
140140
}
141141
}
142142
}
143+
144+
#[cfg(all(test, miri))]
145+
#[start]
146+
fn main(argc: isize, argv: *const *const u8) -> isize {
147+
let ret = __test_runner::main(::core::ptr::null_mut());
148+
149+
// Clean up app state.
150+
::flipperzero_rt::__macro_support::__wait_for_thread_completion();
151+
152+
ret.try_into().unwrap()
153+
}
143154
)
144155
.into())
145156
}

0 commit comments

Comments
 (0)