Created
May 18, 2025 20:41
-
-
Save novafacing/0ee46f5f75047b4aefa6d31d73bcf6c1 to your computer and use it in GitHub Desktop.
Adding plugin tests to QEMU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adding Plugin Tests to QEMU | |
I've been working on some enhancements to the QEMU TCG plugin API recently, and wouldn't you know it, when you change the | |
plugin API it's usually helpful to test your changes. So I've had to figure out how to add TCG plugin tests, which is not a particularly | |
self-explanatory process. | |
## Makefile System | |
If you run `make help` in your QEMU build directory after building QEMU with e.g. `./configure --enable-plugins --enable-capstone && make -C build` | |
you'll see a `check-tcg` target. This will run a lot of tests, but it won't run the ones you want. As it turns out, the | |
Makefiles for TCG eventually include `tests/tcg/Makefile.target`, which in turn includes all the specific targets like | |
`i386` and `x86_64` as well as the `multiarch` tests. It also defines the top-level make targets to actually run those | |
tests, like `run-plugin-%`. As it turns out, there are also targets for running all the tests for a specific QEMU target, | |
like `build-tcg-tests-x86_64-softmmu` and `run-tcg-tests-x86_64-softmmu`. | |
## Adding a test target | |
A test target should be a small program that just does the required thing, and it can be either linux-user or softmmu. For linux-user targets, just put them either in the multiarch/ directory or the directory for the target arch you care about. For | |
system targets, they'll need to go in the system subdirectory of multiarch or the target arch you care about. Both .S and .c files will get picked up and built, although keep in mind for system targets you can only use `minilib.h`. | |
## Adding test target rules | |
To add args or an output check command for your target and plugin, add something like this to e.g. multiarch/system/Makefile.softmmu-target: | |
``` | |
# Test plugin instruction patching | |
run-plugin-patch-target-with-libpatch.so: \ | |
PLUGIN_ARGS=$(COMMA)use_hwaddr=true$(COMMA)debug_insns=true | |
run-plugin-patch-target-with-libpatch.so: \ | |
CHECK_PLUGIN_OUTPUT_COMMAND=$(MULTIARCH_SYSTEM_SRC)/validate-patch.py [email protected] | |
``` | |
## Skipping a test | |
If you want a test built so people can manually run it but it only applies to specific architectures or some other special scenario, you can explicily skip it by setting this in tests/tcg/Makefile.target: | |
``` | |
run-plugin-%-with-libhypercalls.so: | |
$(call skip-test, $<, "MANUAL ONLY libhypercalls.so only valid on certain arches") | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment