Chromium OS Unit Testing

Running unit tests

We run unit tests as part of the build process using cros_run_unit_tests in ~/src/scripts (crostestutils.git). In a nutshell, this script uses the portage method of building and running unit tests using FEATURES="test". To run all the Chromium OS unit tests, you can run ./cros_run_unit_tests directly from within your chroot. If you want to run just the unit tests for specific packages, you can use ./cros_run_unit_tests --packages "space delimited list of portage package names". See ./cros_run_unit_tests --help for more information about other options.

As an example, let's say you just want to run the unit tests for the metrics package. To do so, you can run:

Running a single test

Adding unit tests

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.

Portage documentation of src_test (didn't find it that helpful though).

How to Blacklist a package from running its unit tests

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 RESTRCT="test" in your ebuild or add it to the unit tests blacklist in src/scripts/unit_test_black_list.txt.

Special Considerations

The unit tests are built for the target and run on the host. This means that unit tests only currently work on x86-* and amd64-* targets.