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.

Examples

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
    
  6. Run the test with the Trade Federation test harness:

    make tradefed-all -j
    tradefed.sh 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 \
        /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.