From ed768b65c90ea5b8aaee038e8549cbd6138d79c1 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Thu, 26 Jun 2025 15:56:27 +1000 Subject: [PATCH 1/4] lkl: tests: drop unused lkl_test.fn() parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing t.fn(t->arg1, t->arg2, t->arg3) call can lead to build failures: tests/test.c: In function ‘lkl_test_run’: tests/test.c:93:23: error: too many arguments to function ‘t->fn’; expected 0, have 3 The parameters don't appear to be used, so can be removed. Signed-off-by: David Disseldorp --- tools/lkl/tests/test.c | 2 +- tools/lkl/tests/test.h | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/lkl/tests/test.c b/tools/lkl/tests/test.c index 38784ab4ad14..1ff6abeac82e 100644 --- a/tools/lkl/tests/test.c +++ b/tools/lkl/tests/test.c @@ -90,7 +90,7 @@ int lkl_test_run(const struct lkl_test *tests, int nr, const char *fmt, ...) start = clock(); - ret = t->fn(t->arg1, t->arg2, t->arg3); + ret = t->fn(); stop = clock(); diff --git a/tools/lkl/tests/test.h b/tools/lkl/tests/test.h index 653a967df066..e772d9c47d1b 100644 --- a/tools/lkl/tests/test.h +++ b/tools/lkl/tests/test.h @@ -9,16 +9,14 @@ struct lkl_test { const char *name; - int (*fn)(); - void *arg1, *arg2, *arg3; + int (*fn)(void); }; /** * Simple wrapper to initialize a test entry. - * @name - test name, it assume test function is named test_@name - * @vargs - arguments to be passed to the function + * @name - test name; assume existing test function named lkl_test_@name */ -#define LKL_TEST(name, ...) { #name, lkl_test_##name, __VA_ARGS__ } +#define LKL_TEST(name) { #name, lkl_test_##name } /** * lkl_test_run - run a test suite From 88a4280e012eecccd5d584f916342dc1382e1fdc Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Fri, 13 Jun 2025 07:33:35 +0200 Subject: [PATCH 2/4] lkl: define LKL_CONFIG_KASAN_KUNIT_TEST and use for test CONFIG_KASAN_KUNIT_TEST is a kernel specific build option, so expose it via the arch config.h instead of the tools-generated lkl_autoconf.h. Both LKL_HOST_CONFIG_KASAN and LKL_HOST_CONFIG_KASAN_KUNIT_TEST are now unused so can be removed. Signed-off-by: David Disseldorp --- arch/lkl/Makefile | 1 + tools/lkl/Makefile.autoconf | 2 -- tools/lkl/tests/boot.c | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/lkl/Makefile b/arch/lkl/Makefile index 0a4aaad2263b..f615869a2814 100644 --- a/arch/lkl/Makefile +++ b/arch/lkl/Makefile @@ -68,6 +68,7 @@ core-y += arch/lkl/drivers/ configh-y = printf "/* this header is autogenerated */\n" configh-$(CONFIG_64BIT) += && printf '\#define LKL_CONFIG_64BIT 1\n' configh-$(CONFIG_CPU_BIG_ENDIAN) += && printf '\#define LKL_CONFIG_CPU_BIG_ENDIAN 1\n' +configh-$(CONFIG_KASAN_KUNIT_TEST) += && printf '\#define LKL_CONFIG_KASAN_KUNIT_TEST 1\n' quiet_cmd_gen_configh = GEN $@ cmd_gen_configh = mkdir -p $(dir $@); ($(configh-y)) > $@ diff --git a/tools/lkl/Makefile.autoconf b/tools/lkl/Makefile.autoconf index 61df6d35980d..af14b36cf5af 100644 --- a/tools/lkl/Makefile.autoconf +++ b/tools/lkl/Makefile.autoconf @@ -111,14 +111,12 @@ define nt_host endef define kasan_test_enable - $(call set_autoconf_var,KASAN_TEST,y) $(call set_kernel_config,KUNIT,y) $(call set_kernel_config,BUILTIN_CMDLINE,\"kunit.filter_glob=\") $(call set_kernel_config,KASAN_KUNIT_TEST,y) endef define kasan_enable - $(call set_autoconf_var,KASAN,y) $(call set_kernel_config,KASAN,y) $(if $(filter yes,$(kasan_test)), $(call kasan_test_enable)) endef diff --git a/tools/lkl/tests/boot.c b/tools/lkl/tests/boot.c index a5eefc6b76d4..aae49d3ce0ff 100644 --- a/tools/lkl/tests/boot.c +++ b/tools/lkl/tests/boot.c @@ -555,7 +555,7 @@ static int lkl_test_join(void) static const char *boot_log; -#ifdef LKL_HOST_CONFIG_KASAN_TEST +#ifdef LKL_CONFIG_KASAN_KUNIT_TEST #define KASAN_CMD_LINE "kunit.filter_glob=kasan* " @@ -707,7 +707,7 @@ struct lkl_test tests[] = { LKL_TEST(semaphore), LKL_TEST(join), LKL_TEST(start_kernel), -#ifdef LKL_HOST_CONFIG_KASAN_TEST +#ifdef LKL_CONFIG_KASAN_KUNIT_TEST LKL_TEST(kasan), #endif LKL_TEST(getpid), From 2f1311c00523db4c614cd09b9702ac6023763b65 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Thu, 19 Jun 2025 13:23:24 +0200 Subject: [PATCH 3/4] lkl: tests: minor lkl_test_kasan changes Grep for the kunit kasan group summary so that we can log the test + fail count. Use a common exit path to ensure log is always freed. Signed-off-by: David Disseldorp --- tools/lkl/tests/boot.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/lkl/tests/boot.c b/tools/lkl/tests/boot.c index aae49d3ce0ff..4cecf482298b 100644 --- a/tools/lkl/tests/boot.c +++ b/tools/lkl/tests/boot.c @@ -563,22 +563,26 @@ static int lkl_test_kasan(void) { char *log = strdup(boot_log); char *line = NULL; - char c, d; + int p, f, s, t; + int num_lines, result = TEST_FAILURE; line = strtok(log, "\n"); - while (line) { - if (sscanf(line, "[ %*f] ok %*d kasa%c%c", &c, &d) == 1 && - c == 'n') { + for (num_lines = 0; line; num_lines++) { + if (sscanf(line, + "[ %*f] # kasan: pass:%d fail:%d skip:%d total:%d", + &p, &f, &s, &t) == 4) { lkl_test_logf("%s", line); - return TEST_SUCCESS; + result = (f == 0 ? TEST_SUCCESS : TEST_FAILURE); + goto out; } line = strtok(NULL, "\n"); } + lkl_test_logf("no kasan test output in %d log lines\n", num_lines); +out: free(log); - - return TEST_FAILURE; + return result; } #else #define KASAN_CMD_LINE From bd30a15647247495b9b472b2a05c23e007e1a32a Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Thu, 26 Jun 2025 17:24:32 +1000 Subject: [PATCH 4/4] lkl: hijack: explicitly build with -std=gnu11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HOST_CALL() uses a (*host_##name)() function pointer while callers provide regular syscall parameters. With gcc -std=gnu23 this results in: lib/hijack/hijack.c: In function ‘hijack_setsockopt’: lib/hijack/hijack.c:176:24: error: too many arguments to function ‘host_setsockopt’; expected 0, have 5 176 | return host_setsockopt(fd, level, optname, optval, optlen); | ^~~~~~~~~~~~~~~ ~~ Signed-off-by: David Disseldorp --- tools/lkl/lib/hijack/Build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/lkl/lib/hijack/Build b/tools/lkl/lib/hijack/Build index eb9872ae5c29..b42239e47d8e 100644 --- a/tools/lkl/lib/hijack/Build +++ b/tools/lkl/lib/hijack/Build @@ -9,3 +9,6 @@ liblkl-zpoline-y += hijack.o liblkl-zpoline-y += init.o liblkl-zpoline-y += xlate.o liblkl-zpoline-y += dbg_handler.o + +# -std=gnu23/c23 fails due to HOST_CALL (*host_##name)() +CFLAGS_hijack.o += -std=gnu11