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
- See sample native test module setup at: frameworks/base/libs/hwui/tests/unit/
- Test module configuation should use the
BUILD_NATIVE_TEST
build rule so gtest dependencies are included automatically - Write a test configuration. See the simple and complex options.
Build the test module with
mmm
ormma
(depends on if it's an incremental or full build), e.g.:make hwui_unit_tests -j
Use Atest to run the test locally:
atest hwui_unit_tests
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 andnative-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
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
Manually install and run:
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
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.