We run unit tests as part of the build process using chromite's cros_run_unit_tests. In a nutshell, this script uses the portage method of building and running unit tests using
As an example, let's say you just want to run the unit tests for the metrics package. To do so, you can run:
For platform2 packages, see the platform2 testing section.
For other packages that use gtest:
To add unit tests to your packages, create a src_test stanza in your ebuild that builds and runs the unit tests (it is fine to have them build in the src_compile stage as well). See the metrics ebuild as a good example of adding your unit test.
It's discouraged to have unit tests that need to be blacklisted. However, if you really need to black list a package from running its unit tests as part of the build, use either
We support running unittests via qemu for non-native architectures (low level details can be found in this doc). The good news is that the process is the same as described above! Simply use
Sometimes qemu is not able to support your unittest due to using functionality not yet implemented. If you see errors like "qemu: unknown syscall: xxx", you'll need to filter that test (see below), and you should file a bug so we can update qemu.
Since qemu only works when run inside the chroot, only ebuilds that use the platform.eclass are supported currently.
Sometimes a test is flaky or requires special consideration before it'll work. You can do this by using the existing gtest filtering logic. For packages using platform.eclass, simply pass it as an argument to platform_test:
If you want to disable the tests for non-native arches, update the global knob:
If you want to filter gtests, you'll need to export the relevant gtest variables directly in your src_test function.
If you want to disable the tests for non-native arches, write your src_test like so: