diff --git a/BUILD.bazel b/BUILD.bazel index d2372bd48534..daa5efaeecae 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -795,9 +795,9 @@ pkg_files( pkg_files( name = "kunit_arm64_test_config", - srcs = [":tools/testing/kunit/android/config_arm64.xml"], + srcs = [":tools/testing/kunit/android/tradefed_configs/config_arm64.xml"], renames = { - "tools/testing/kunit/android/config_arm64.xml": "kunit.config", + "tools/testing/kunit/android/tradefed_configs/config_arm64.xml": "kunit.config", }, visibility = ["//visibility:private"], ) @@ -825,9 +825,9 @@ pkg_files( pkg_files( name = "kunit_x86_64_test_config", - srcs = [":tools/testing/kunit/android/config_x86_64.xml"], + srcs = [":tools/testing/kunit/android/tradefed_configs/config_x86_64.xml"], renames = { - "tools/testing/kunit/android/config_x86_64.xml": "kunit.config", + "tools/testing/kunit/android/tradefed_configs/config_x86_64.xml": "kunit.config", }, visibility = ["//visibility:private"], ) @@ -839,7 +839,7 @@ pkg_filegroup( ":kunit_x86_64_test_config", ], prefix = _KUNIT_DIR, - visibility = ["//visibility:private"], + #visibility = ["//visibility:private"], ) # DDK Headers diff --git a/tools/testing/kunit/android/README b/tools/testing/kunit/android/README new file mode 100644 index 000000000000..301664991eaa --- /dev/null +++ b/tools/testing/kunit/android/README @@ -0,0 +1,90 @@ +HOW TO RUN KUNIT TESTS IN ANDROID +================================= + +Prerequisites + * Pass kunit.enable=1 as a kernel command line argument + * This should be done in either userdebug or eng build configs. See + the following examples: + * https://android-review.git.corp.google.com/c/device/google/cuttlefish/+/2085612 + * https://android-review.git.corp.google.com/c/kernel/google-modules/raviole-device/+/2095369 + * For a local device you can run the following: + $ fastboot oem cmdline add "kunit.enable=1" + * Run a "no trim" kernel (e.g. add `--notrim` to bazel build command) + +Run a test module + * Push the KUnit test module over to the device. For example using adb: + $ adb push kunit-test-example.ko /data + + * (Optional) - Mount debugfs on device: + $ mount -t debugfs debugfs /sys/kernel/debug + + * Load test module on device: + $ cd /data + $ insmod kunit-test-example.ko + +View test results + * If debugfs is mounted: + $ cat /sys/kernel/debug/kunit//results + KTAP version 1 + 1..1 + KTAP version 1 + # Subtest: example + 1..4 + # example_simple_test: initializing + + ok 1 example_simple_test + + + * Via dmesg (check before log cycles out): + $ dmesg + .... + [172434.032618] 1..1 + [172434.032618] KTAP version 1 + [172434.032618] # Subtest: example + [172434.032618] 1..4 + [172434.032618] # example_simple_test: initializing + [172434.032618] + [172434.032618] ok 1 example_simple_test + + .... + +Run ACK KUnit tests via tradefed + * Build ACK KUnit tests: + $ tools/bazel build //common:tests_zip_arm64_dist + + * Unzip tests.zip (e.g. in local tmp directory): + $ unzip bazel-bin/common/arm64/tests.zip -d tmp + + * With device connected and accessible via adb run the tests: + $ prebuilts/tradefed/filegroups/tradefed/tradefed.sh run commandAndExit \ + template/local_min --template:map test=suite/test_mapping_suite \ + --include-filter kunit --tests-dir=tmp/testcases --primary-abi-only + .... + ======================================================= + =============== Summary =============== + Total Run time: 23s + 1/1 modules completed + Total Tests : 9 + PASSED : 9 + FAILED : 0 + ============== End of Results ============== + ============================================ + .... + + +TROUBLESHOOTING +=============== + +1. Test module fails to load. + +Check dmesg for load errors. If undefined symbol errors are shown, you're +likely running with a trimmed kernel where the symbols are not available. +Run with a "no trim" kernel. + +2. Test module loaded but no test results + +Check dmesg for KUnit errors. + $ dmesg | grep kunit + +If "kunit: disabled" is shown then `kunit.enable=1` has not been set. + diff --git a/tools/testing/kunit/android/config_arm64.xml b/tools/testing/kunit/android/tradefed_configs/config_arm64.xml similarity index 100% rename from tools/testing/kunit/android/config_arm64.xml rename to tools/testing/kunit/android/tradefed_configs/config_arm64.xml diff --git a/tools/testing/kunit/android/config_x86_64.xml b/tools/testing/kunit/android/tradefed_configs/config_x86_64.xml similarity index 100% rename from tools/testing/kunit/android/config_x86_64.xml rename to tools/testing/kunit/android/tradefed_configs/config_x86_64.xml