Building kernel tests result in a binary with one symbol

I have been working on writing a kernel in rust. It has gone pretty well, but I can't seem to get testing to work. I want to avoid using the bootimage crate because I'm mainly writing this kernel for the learning experience.

I have written a custom test framework, then creating a test binary with cargo test --no-run --target x86_64-unknown-none and then putting it into a .iso with the associated stuff for booting. I figured this would just work, but it would not boot. I tried running nm on the kernel binary, and saw that it had one symbol.

Here's the output that running nm on the kernel binary has:

ffffffff80000000 d _DYNAMIC

I'm hoping someone either A. knows how to fix this, or B. knows a better alternative.

Here is a link to a stripped down version of the kernel with the same issue. The build script should attempt to generate the test binary and iso in target/artifacts.

I don't know much about feature(custom_test_frameworks); the only kind of custom test harnesses I've used are on stable using harness = false and an ordinary explicit main().

But, the thing I notice first is that you are running cargo test --no-run on a package (kernel) that contains two crates/targets, a src/lib.rs and a src/main.rs, and there is test-harness-related stuff in both of them. If your goal is to have one test-binary that you can copy and run, then that doesn't make sense, because if you run the lib.rs test binary then none of the main.rs test code ever runs, and if you run the main.rs test binary, then the lib will have been compiled without cfg(test).

Thank you so much for the info! I realized that and removed the test harness code in src/main.rs and added a test main to the library part, and it fixed it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.