From 845c4bdb210d6380c2841afc4466c98fc20cfc9a Mon Sep 17 00:00:00 2001
From: Chase Qi <chase.qi@linaro.org>
Date: Thu, 31 Mar 2022 17:56:58 +0800
Subject: [PATCH] Add kernel-selftest to oniro-image-base-tests image

Add the recipe to `-base-tests` image for kselftest.

Add kernel-selftest.bbappend to install the kselftest runner scripts
and also make it compatible with libc-musl.

Signed-off-by: Chase Qi <chase.qi@linaro.org>
---
 .../images/oniro-image-base-tests.bb          |  1 +
 .../kernel-selftest/kernel-selftest.bbappend  | 23 +++++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 meta-oniro-core/recipes-kernel/kernel-selftest/kernel-selftest.bbappend

diff --git a/meta-oniro-core/recipes-core/images/oniro-image-base-tests.bb b/meta-oniro-core/recipes-core/images/oniro-image-base-tests.bb
index 92c63c0f..5669da3f 100644
--- a/meta-oniro-core/recipes-core/images/oniro-image-base-tests.bb
+++ b/meta-oniro-core/recipes-core/images/oniro-image-base-tests.bb
@@ -10,6 +10,7 @@ IMAGE_INSTALL:append = "\
     packagegroup-oniro-tests \
     ltp \
     perf \
+    kernel-selftest \
 "
 
 # This adds ptest packages to the image
diff --git a/meta-oniro-core/recipes-kernel/kernel-selftest/kernel-selftest.bbappend b/meta-oniro-core/recipes-kernel/kernel-selftest/kernel-selftest.bbappend
new file mode 100644
index 00000000..cb29ce98
--- /dev/null
+++ b/meta-oniro-core/recipes-kernel/kernel-selftest/kernel-selftest.bbappend
@@ -0,0 +1,23 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+COMPATIBLE_HOST:libc-musl = "(i.86|x86_64|arm|aarch64).*-linux"
+
+RDEPENDS:${PN} += "perl"
+
+# bpf depends on clang/llvm. It is removed on x86 and arm by default for backward compatibility.
+# Reference: http://cgit.openembedded.org/meta-openembedded/tree/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest.bb?h=master#n22
+# clang/llvm is not needed until we want to enable bpf.
+DEPENDS:remove = "clang-native llvm-native"
+
+TEST_LIST = "\
+    rtc \
+    cpufreq \
+    cpu-hotplug \
+"
+
+do_install:append() {
+    cp ${S}/tools/testing/selftests/run_kselftest.sh ${D}/usr/kernel-selftest
+    cp -R ${S}/tools/testing/selftests/kselftest ${D}/usr/kernel-selftest
+}
-- 
GitLab