ANDROID: Add kunit targets.

The kunit targets build in-tree kunit modules with a pre-set
defconfig fragment.

This is the defconfig fragment to be applied to enable kunit tests
as modules. Because we apply defconfig fragments after running
make defconfig, the individual tests must be enabled instead of
a global CONFIG_KUNIT_ALL_TESTS flag.

Test: manually build with
  bazel run //common:kunit_aarch64_dist
  bazel run //common:kunit_x86_64_dist
  bazel run //common:kunit_riscv64_dist
Bug: 296116800
Change-Id: If3b94f495aa64b657508781b12e3e0716c725f3f
Signed-off-by: Yifan Hong <elsk@google.com>
This commit is contained in:
Yifan Hong
2023-08-29 15:29:15 -07:00
parent b8a072ce7a
commit 8a3c247822
6 changed files with 146 additions and 0 deletions
+94
View File
@@ -553,6 +553,100 @@ kernel_build(
visibility = ["//visibility:private"],
)
# KUnit test targets
# Modules defined by tools/testing/kunit/configs/android/kunit_defconfig
_KUNIT_COMMON_MODULES = [
# keep sorted
"drivers/base/regmap/regmap-kunit.ko",
"drivers/base/regmap/regmap-ram.ko",
"drivers/base/regmap/regmap-raw-ram.ko",
"drivers/hid/hid-uclogic-test.ko",
"drivers/iio/test/iio-test-format.ko",
"drivers/input/tests/input_test.ko",
"drivers/rtc/lib_test.ko",
"fs/ext4/ext4-inode-test.ko",
"fs/fat/fat_test.ko",
"kernel/time/time_test.ko",
"lib/kunit/kunit-example-test.ko",
"lib/kunit/kunit-test.ko",
"mm/kfence/kfence_test.ko",
"net/core/dev_addr_lists_test.ko",
"sound/soc/soc-topology-test.ko",
"sound/soc/soc-utils-test.ko",
]
_KUNIT_CLK_MODULES = [
"drivers/clk/clk-gate_test.ko",
"drivers/clk/clk_test.ko",
]
kernel_build(
name = "kunit_aarch64",
outs = [],
arch = "arm64",
base_kernel = ":kernel_aarch64",
build_config = "build.config.kunit.aarch64",
defconfig_fragments = [
"tools/testing/kunit/configs/android/kunit_defconfig",
"tools/testing/kunit/configs/android/kunit_clk_defconfig",
],
make_goals = ["modules"],
module_outs = _KUNIT_COMMON_MODULES + _KUNIT_CLK_MODULES,
)
copy_to_dist_dir(
name = "kunit_aarch64_dist",
data = [":kunit_aarch64"],
dist_dir = "out/kunit_aarch64/dist",
flat = True,
log = "info",
)
kernel_build(
name = "kunit_x86_64",
outs = [],
arch = "x86_64",
base_kernel = ":kernel_x86_64",
build_config = "build.config.kunit.x86_64",
defconfig_fragments = [
"tools/testing/kunit/configs/android/kunit_defconfig",
# x86_64 does not set CONFIG_COMMON_CLK
],
make_goals = ["modules"],
module_outs = _KUNIT_COMMON_MODULES,
)
copy_to_dist_dir(
name = "kunit_x86_64_dist",
data = [":kunit_x86_64"],
dist_dir = "out/kunit_x86_64/dist",
flat = True,
log = "info",
)
kernel_build(
name = "kunit_riscv64",
outs = [],
arch = "riscv64",
base_kernel = ":kernel_riscv64",
build_config = "build.config.kunit.riscv64",
defconfig_fragments = [
"tools/testing/kunit/configs/android/kunit_defconfig",
"tools/testing/kunit/configs/android/kunit_clk_defconfig",
],
make_goals = ["modules"],
module_outs = _KUNIT_COMMON_MODULES + _KUNIT_CLK_MODULES,
)
copy_to_dist_dir(
name = "kunit_riscv64_dist",
data = [":kunit_riscv64"],
dist_dir = "out/kunit_riscv64/dist",
flat = True,
log = "info",
)
# DDK Headers
# All headers. These are the public targets for DDK modules to use.
alias(
+4
View File
@@ -0,0 +1,4 @@
. ${ROOT_DIR}/${KERNEL_DIR}/build.config.common
. ${ROOT_DIR}/${KERNEL_DIR}/build.config.aarch64
DEFCONFIG=gki_defconfig
+4
View File
@@ -0,0 +1,4 @@
. ${ROOT_DIR}/${KERNEL_DIR}/build.config.common
. ${ROOT_DIR}/${KERNEL_DIR}/build.config.riscv64
DEFCONFIG=gki_defconfig
+4
View File
@@ -0,0 +1,4 @@
. ${ROOT_DIR}/${KERNEL_DIR}/build.config.common
. ${ROOT_DIR}/${KERNEL_DIR}/build.config.x86_64
DEFCONFIG=gki_defconfig
@@ -0,0 +1,3 @@
# Only for architectures that set CONFIG_COMMON_CLK
CONFIG_CLK_KUNIT_TEST=m
CONFIG_CLK_GATE_KUNIT_TEST=m
@@ -0,0 +1,37 @@
# Defconfig fragment for Android Kunit targets
#
# Instead of setting CONFIG_KUNIT_ALL_TESTS=m, we enable individual tests
# because:
# - The defconfig fragment is applied after make defconfig
# - If additional tests are added to CONFIG_KUNIT_ALL_TESTS in the future,
# //common:kunit_* module_outs needs to be updated.
# CONFIG_MODULE_SIG_ALL is not set
# Corresponds to BUILD.bazel, _KUNIT_COMMON_MODULES
CONFIG_TIME_KUNIT_TEST=m
CONFIG_NETDEV_ADDR_LIST_TEST=m
CONFIG_REGMAP_KUNIT=m
CONFIG_INPUT_KUNIT_TEST=m
CONFIG_SND_SOC_TOPOLOGY_KUNIT_TEST=m
CONFIG_SND_SOC_UTILS_KUNIT_TEST=m
CONFIG_HID_KUNIT_TEST=m
CONFIG_RTC_LIB_KUNIT_TEST=m
CONFIG_IIO_FORMAT_KUNIT_TEST=m
CONFIG_EXT4_KUNIT_TESTS=m
CONFIG_FAT_KUNIT_TEST=m
CONFIG_KFENCE_KUNIT_TEST=m
CONFIG_KUNIT_TEST=m
CONFIG_KUNIT_EXAMPLE_TEST=m
# CONFIG_NET_HANDSHAKE is not enabled in gki_defconfig.
# CONFIG_NET_HANDSHAKE_KUNIT_TEST=m
# TODO(b/296116800): Enable these tests
# CONFIG_DRM_KUNIT_TEST=m
# CONFIG_KASAN_KUNIT_TEST=m
# TODO(b/296116800): These are booleans, not tristates.
# CONFIG_BINFMT_ELF_KUNIT_TEST=y
# CONFIG_PM_QOS_KUNIT_TEST=y
# CONFIG_DRIVER_PE_KUNIT_TEST=y