Google is committed to advancing racial equity for Black communities. See how.

Native Tests

A native test for the platform typically accesses lower-level HALs or performs raw IPC against various system services. Therefore, the testing approach is usually tightly coupled with the service under test.

Build native tests using the gtest framework. This is a prerequisite for integration with continuous testing infrastructure.


Here are some examples of native tests in the platform source:

Summary of steps

  1. See sample native test module setup at: frameworks/base/libs/hwui/tests/unit/
  2. Test module configuation should use the BUILD_NATIVE_TEST build rule so gtest dependencies are included automatically
  3. Write a test configuration. See the simple and complex options.
  4. Build the test module with mmm or mma (depends on if it's an incremental or full build), e.g.:

    make hwui_unit_tests -j
  5. Use Atest to run the test locally:

    atest hwui_unit_tests
    1. You can also add arguments to your native tests. Some particularly useful flags are native-test-flag, which specifies additional flag values to pass to the native test's shell command and native-test-timeout, which allows you to specify a test timeout value in microseconds.

      atest test-name -- --module-arg test-name:native-test-flag:"\"argument1 argument2\"" \
      --module-arg test-name:native-test-timeout:60000
  6. Run the test with the Trade Federation test harness:

    make tradefed-all -j run template/local_min --template:map test=hwui_unit_tests
  7. Manually install and run:

    1. Push the generated test binary onto device:

      adb push ${OUT}/data/nativetest/hwui_unit_tests/hwui_unit_tests \
    2. Execute the test by invoking test binary on device:

      adb shell /data/nativetest/hwui_unit_tests/hwui_unit_tests

    This launches the native test. You can also add the --help parameter to your test binary to find out more about the different ways to customize test execution. Finally, see the gtest advanced guide for more parameters and their use.