In our environment we run tests in qemu. But the same test, often, we want to run in different qemu environments (eg: different kernel, different OS, different CPU, ...).
And at times we need multiple qemus to run for a test (eg, moral equivalent of one qemu running a service, another qemu trying to exercise it).
The approach we used is to create a set of rules that allow to define a qemu environment, and a set of targets (or preparation steps) to run in that environment.
The qemu rules can then be used as `bazel test`, or `bazel run`. Collect logs and outputs in a format that's bazel compatible, so BES endpoints, pass/fail, all work correctly.
The rules are open source, defined in the directory here:
Unfortunately we don't have much documentation (yet) other than what is in the .bzl files, and using the rules requires some buy in in terms of having a kernel/rootfs available in the WORKSPACE.
Ramping up on our rules may be a non trivial cost as is, but they are fairly complete and generic. May serve as inspiration to create your own (or help grow ours, PRs welcome).
Here's an example of what a target looks like:
```
py_binary(
name = "hello-world"
...
)
vm_bundle(
name = "hello-world-testing",
run = ":hello-world",
run_cmds = [
"export ENVIRONMENT=testing",
],
# can have pre-run and post-run steps or checks.
)
qemu_test(
name = "hello-world-x86-64",
kernel_image = "@minimal-latest-kernel//:image",
run = [ # one or more binary targets or vm_bundle targets
":hello-world-testing",
],
setup = COMMON_TEST_SETUP + [ # arbitrary executable or bundle steps to run before the target.
"//vm/setup:bring-up-db",
"//vm/setup:create-users",
],
# can define tear down steps, and things to check after the VM runs.
)
```