I would like to use the generated test harness in the context of a custom test framework for a kernel. I'm using #![reexport_test_harness_main = test_main]
to reexport the test harness main function under a different symbol, however when calling the function I get:
error[E0425]: cannot find function `test_main` in this scope
--> tests/basic_math.rs:46:3
|
46 | test_main();
| ^^^^^^^^^ not found in this scope
I've made my integration test as similar as possible to the integration test in phill opp's blog post about testing with custom test frameworks: GitHub - phil-opp/blog_os at post-04. Running his tests works for me, so I know that reexport_test_harness_main
isn't directly broken.
Are there any implicit requirements that might prevent the test harness from being generated? How can I get some more information on what might be the root cause behind the missing test_main symbol?
This is my integration test:
//tests/basic_math.rs
#![feature(test)]
#![no_std]
#![no_main]
#![test_runner(test_runner)]
#![feature(custom_test_frameworks)]
#![reexport_test_harness_main = "test_main"]
use hermit::{print, println};
pub trait Testable {
fn run(&self) -> ();
}
impl<T> Testable for T
where
T: Fn(),
{
fn run(&self) {
print!("{}...\t", core::any::type_name::<T>());
self();
println!("[ok]");
}
}
pub fn test_runner(tests: &[&dyn Testable]) {
println!("Running {} tests", tests.len());
for test in tests {
test.run();
}
}
#[test_case]
fn add_one() {
let x = 1 + 2;
assert_eq!(x, 3);
}
// After initializing the kernel calls this function
#[no_mangle]
extern "C" fn runtime_entry(_argc: i32, _argv: *const *const u8, _env: *const *const u8) -> ! {
//Toggling this changes the error from compile time to link time
// extern "Rust" {
// fn test_main();
// }
unsafe {
test_main();
}
hermit::sys_exit(0)
}
The integration test itself runs fine if I remove the #[test_case]
and test_main()
and manually call my tests, but ideally I'd like to use the rust test harness.
Any ideas for how I can get closer to the root issue are appreciated.