These examples demonstrate how to run Kunit tests for the Android kernel. Kleaf is able to support both in-tree and out-of-tree (DDK) Kunit test modules.
Tests with both in-tree and out-of-tree test modules can be set up with the help of the kunit_test Bazel rule. Examples of in-tree and out-of-tree tests can be found in in_tree/ and out_of_tree/ directories respectively.
A couple of things need to be ensured before running a Kunit test with Kleaf.
insmod kunit.ko enable=1.Once the test setup is complete, Kunit tests can simply be run with the help of bazel test verb as follows:
bazel test //path/to/kunit/test:target --test_arg=--device="<device_serial>"
Bazel outputs the outcome of the test and prints the full Kunit test report in case of a test failure.
Note that the device test argument can be skipped if only 1 device is connected to the host machine.