Chromium OS‎ > ‎Testing Home‎ > ‎

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:

./cros_run_unit_tests --packages "metrics"


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 http://git.chromium.org/cgi-bin/gitweb.cgi?p=chromiumos-overlay.git;a=blob_plain;f=chromeos-base/metrics/metrics-9999.ebuild;hb=HEAD 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. 
  • By default, cros_run_unit_tests will only use FEATURES="test" on packages that exist in the chromeos-base package and are in the dependency tree of chromeos.
Comments