How to run a test where the test runner depends on the thing being tested?

This is kind of a problem like it existed a year ago, but more complicated.

So I am writing my kernel (loup-os/kernel: The Loup OS Kernel - Codeberg.org) and I want to run the tests. Until now, I had a custom test runner which would run in QEMU for every platform my kernel targets (currently risc-v and x86_64, but x86_64 is broken, so currently only risc-v) and then test everything from there. If you ask yourself why I did it that way: I have some conditional imports for e.g. different architectures.
Until now everything worked with the approach I described in a brainstorm about testing on freestanding in this forum, but recently somehow the file exists in multiple modules error started triggering. But it says file exists in modules 'root' and 'root', which is weird. Probably one time the test runner root is meant, and one time the actual test root is meant.
But how do I fix this? If I create a module for the things I need to share, the tests inside my ā€œkernel moduleā€ that shares things are not run. And if I point both the test runner source file and the test source file to src/main.zig, it says:

/some/path/to/zig/lib/std/std.zig:1:1: error: file exists in modules 'root' and 'root'
/some/path/to/zig/lib/std/std.zig:1:1: note: files must belong to only one module
/some/path/to/zig/lib/std/std.zig:1:1: note: file is the root of module 'root'
/some/path/to/zig/lib/std/std.zig:1:1: note: file is the root of module 'root'

Any ideas?

I solved it using a ā€œkernel moduleā€ which is both the root module of the test and imported via ā€œkmodā€. So I can import kmod and define public things in test_main from there, but I also can use it as my test base.

1 Like