From 832fb491a0557e930184e0f19ca0b50dd1206fd1 Mon Sep 17 00:00:00 2001
From: Chase Qi <chase.qi@linaro.org>
Date: Tue, 12 Jul 2022 09:33:33 +0000
Subject: [PATCH] zephyr-kernel-test-twister: build all buildable kernel tests

Build all kernel tests by default. Tests that doesn't build can be
excluded with tags or deleted before image building with twister.

This closes #25.

Signed-off-by: Chase Qi <chase.qi@linaro.org>
---
 .../zephyr-kernel-test-twister.bb             | 26 +++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-test-twister.bb b/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-test-twister.bb
index f0e10fc..82451bc 100644
--- a/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-test-twister.bb
+++ b/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-test-twister.bb
@@ -24,13 +24,34 @@ DEPENDS += "\
     python3-ply-native \
 "
 
+# Base directory for twister to recursively search for test cases.
+# Build all available kernel tests by default.
+ZEPHYRTESTS = "kernel"
+# Specify tags of tests that does not build.
+ZEPHYRTESTS_EXCLUDE_TAGS = ""
+ZEPHYRTESTS_EXCLUDE_TAGS:96b-nitrogen = "fpu"
+# Specify tests that should be deleted before image building using twister.
+# This can be used when test tags not well defined to exclude specific tests.
+# Relative path of 'tests/' at the base of zephyr tree should be used.
+ZEPHYRTESTS_DELETE = ""
+ZEPHYRTESTS_DELETE:96b-nitrogen = "\
+    kernel/profiling \
+    kernel/fatal \
+"
+
 do_compile() {
     if test -n "${ZEPHYRTESTS}"; then
-        tc_root_options="${@' '.join(['-T tests/kernel/' + i + ' ' for i in d.getVar('ZEPHYRTESTS').split()])}"
+        tc_root_options="${@' '.join(['-T tests/' + i + ' ' for i in d.getVar('ZEPHYRTESTS').split()])}"
         bbnote "Test case root options: ${tc_root_options}"
-        bbnote "Generating twister-out ..."
+        bbnote "Excluded test tags: ${ZEPHYRTESTS_EXCLUDE_TAGS}"
+        exclude_tags="${@' '.join(['--exclude-tag ' + i + ' ' for i in d.getVar('ZEPHYRTESTS_EXCLUDE_TAGS').split()])}"
         cd ${S}
+        for test in ${ZEPHYRTESTS_DELETE}; do
+            rm -rf tests/${test}
+            bbnote "Deleted ${test} defined in ZEPHYRTESTS_DELETE ..."
+        done
         rm -rf twister-out
+        bbnote "Generating twister-out ..."
         # Twister runs both 'cmake' and 'cmake --build' itself to configure and
         # compile test images respectively. All the flags using in cmake.bbclass
         # should be passed to twister so that tests are configured properly.
@@ -70,6 +91,7 @@ do_compile() {
             -p ${@d.getVar('MACHINE').replace("-", "_")} \
             --build-only \
             ${tc_root_options} \
+            ${exclude_tags} \
             -vvv
     else
         bbnote "Do nothing as ZEPHYRTESTS is empty."
-- 
GitLab