I'm working on a project that runs in an embedded system, and I'm working on setting up unit tests to work with it. I'd like to set the unit tests up to run in QEMU using a custom runner command, but I've run into a bit of an issue with this, namely that the unit tests binary is not exported to a common location the way a normal build is.
That is, when I run cargo build, I see the file target/whatever.elf generated, which I can then get and run in QEMU or whatever I want to do.
However, if I run cargo build --tests, I don't get a similar binary. I see that if I run cargo test, it does seem to be accessing a file like target/triple/debug/deps/whatever-abc123.elf, but it seems the abc123 portion of the path is not necessarily consistent between clean builds.
Is there a way to get the test binary/binaries to be placed in a consistent location so I can have a custom runner execute them in QEMU?
As a bonus question, is it at all possible to have cargo generate a single binary for all the tests, instead of separate ones for each test type/crate/etc?
No, but the path to the executable is passed as an argument to your runner. The runner should run the binary it is told to run.
As a bonus question, is it at all possible to have cargo generate a single binary for all the tests, instead of separate ones for each test type/crate/etc?
No — that might be possible in principle (by compiling each test crate into a library, and linking them into one binary), but Cargo isn't set up to do that.
If you need one test binary then you need to put all your tests in one test crate.