Skip to contentSkip to conversation

selftests: harness: Support KCOV.

PATCH Superseded Kuniyuki Iwashima 2 participants 4 messages Oct 17, 2025 – Oct 28, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: harness: Support KCOV.

While writing a selftest with kselftest_harness.h, I often want to check which paths are actually exercised.

Let's support generating KCOV coverage data.

We can specify the output directory via the KCOV_OUTPUT environment variable, and the number of instructions to collect via the KCOV_SLOTS environment variable.

# KCOV_OUTPUT=$PWD/kcov KCOV_SLOTS=$((4096 * 2)) \
./tools/testing/selftests/net/af_unix/scm_inq

Both variables can also be specified as the make variable.

  # make -C tools/testing/selftests/ \
    KCOV_OUTPUT=$PWD/kcov KCOV_SLOTS=$((4096 * 4)) \
    kselftest_override_timeout=60 TARGETS=net/af_unix run_tests

The coverage data can be simply decoded with addr2line:

  $ cat kcov/* | sort | uniq | addr2line -e vmlinux | grep unix
  net/unix/af_unix.c:1056
  net/unix/af_unix.c:3138
  net/unix/af_unix.c:3834
  net/unix/af_unix.c:3838
  net/unix/af_unix.c:311 (discriminator 2)
  ...

or more nicely with a script embedded in vock [0]:

  $ cat kcov/* | sort | uniq > local.log
  $ python3 ~/kernel/tools/vock/report.py \
    --kernel-src ./ --vmlinux ./vmlinux \
    --mode local --local-log local.log --filter unix
  ...
  ------------------------------- Coverage Report --------------------------------
  📄 net/unix/af_unix.c (276 lines)
   ...
  942 | static int unix_setsockopt(struct socket *sock, int level, int optname,
  943 | 			   sockptr_t optval, unsigned int optlen)
  944 | {
   ...
  961 | 	switch (optname) {
  962 | 	case SO_INQ:
  963 > 		if (sk->sk_type != SOCK_STREAM)
  964 | 			return -EINVAL;
  965 |
  966 > 		if (val > 1 || val < 0)
  967 | 			return -EINVAL;
  968 |
  969 > 		WRITE_ONCE(u->recvmsg_inq, val);
  970 | 		break;
---
 Documentation/dev-tools/kselftest.rst       |  41 +++++++
 tools/testing/selftests/Makefile            |  14 ++-
 tools/testing/selftests/kselftest_harness.h | 128 +++++++++++++++++++-
 3 files changed, 174 insertions(+), 9 deletions(-)
Documentation/dev-tools/kselftest.rst +41 -0
index 18c2da67fae42..5c2b92ac4a300 100644
@@ -200,6 +200,47 @@ You can look at the TAP output to see if you ran into the timeout. Test
 runners which know a test must run under a specific time can then optionally
 treat these timeouts then as fatal.
 
+KCOV for selftests
+==================
+
+Selftests built with `kselftest_harness.h` natively support generating
+KCOV coverage data.  See :doc:`KCOV: code coverage for fuzzing </dev-tools/kcov>`
+for prerequisites.
+
+You can specify the output directory with the `KCOV_OUTPUT` environment
+variable.  Additionally, you can specify the number of instructions to
+collect with the `KCOV_SLOTS` environment variable ::
+
+  # KCOV_OUTPUT=$PWD/kcov KCOV_SLOTS=$((4096 * 2)) \
+        ./tools/testing/selftests/net/af_unix/scm_inq
+
+In the output directory, a coverage file is generated for each test
+case in the selftest ::
+
+  $ ls kcov/
+  scm_inq.dgram.basic  scm_inq.seqpacket.basic  scm_inq.stream.basic
+
+The default value of `KCOV_SLOTS` is `4096`, and `KCOV_SLOTS` multiplied
+by `sizeof(unsigned long)` must be multiple of `4096`, so the smallest
+value is `512`.
+
+Both `KCOV_OUTPUT` and `KCOV_SLOTS` can be specified as the variables
+on the `make` command line ::
+
+  # make -C tools/testing/selftests/ \
+        kselftest_override_timeout=60 \
+        KCOV_OUTPUT=$PWD/kcov KCOV_SLOTS=$((4096 * 4)) \
+        TARGETS=net/af_unix run_tests
+
+The collected data can be decoded with `addr2line` ::
+
+  $ cat kcov/* | sort | uniq | addr2line -e vmlinux | grep unix
+  net/unix/af_unix.c:1056
+  net/unix/af_unix.c:3138
+  net/unix/af_unix.c:3834
+  net/unix/af_unix.c:3838
+  ...
+
 Packaging selftests
 ===================
 
tools/testing/selftests/Makefile +8 -6
index c46ebdb9b8ef7..40e70fb1a3478 100644
@@ -218,12 +218,14 @@ all:
 	done; exit $$ret;
 
 run_tests: all
-	@for TARGET in $(TARGETS); do \
-		BUILD_TARGET=$$BUILD/$$TARGET;	\
-		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
-				SRC_PATH=$(shell readlink -e $$(pwd)) \
-				OBJ_PATH=$(BUILD)                   \
-				O=$(abs_objtree);		    \
+	@for TARGET in $(TARGETS); do				\
+		BUILD_TARGET=$$BUILD/$$TARGET;			\
+		$(MAKE) OUTPUT=$$BUILD_TARGET			\
+			KCOV_OUTPUT=$(abspath $(KCOV_OUTPUT))	\
+			-C $$TARGET run_tests			\
+			SRC_PATH=$(shell readlink -e $$(pwd))	\
+			OBJ_PATH=$(BUILD)			\
+			O=$(abs_objtree);			\
 	done;
 
 hotplug:
tools/testing/selftests/kselftest_harness.h +125 -3

184 lines not on this page · raw message

Signature · 1 line
2.51.0.858.gf9c4a03a3a-goog
#1 lore raw

Hi Shuah,

Could you take a look at this patch?

Thanks!

Quoted 339 lines · Kuniyuki Iwashima

While writing a selftest with kselftest_harness.h, I often want to check which paths are actually exercised.

Let's support generating KCOV coverage data.

We can specify the output directory via the KCOV_OUTPUT environment variable, and the number of instructions to collect via the KCOV_SLOTS environment variable.

# KCOV_OUTPUT=$PWD/kcov KCOV_SLOTS=$((4096 * 2)) \
./tools/testing/selftests/net/af_unix/scm_inq

Both variables can also be specified as the make variable.

  # make -C tools/testing/selftests/ \
    KCOV_OUTPUT=$PWD/kcov KCOV_SLOTS=$((4096 * 4)) \
    kselftest_override_timeout=60 TARGETS=net/af_unix run_tests

The coverage data can be simply decoded with addr2line:

  $ cat kcov/* | sort | uniq | addr2line -e vmlinux | grep unix
  net/unix/af_unix.c:1056
  net/unix/af_unix.c:3138
  net/unix/af_unix.c:3834
  net/unix/af_unix.c:3838
  net/unix/af_unix.c:311 (discriminator 2)
  ...

or more nicely with a script embedded in vock [0]:

  $ cat kcov/* | sort | uniq > local.log
  $ python3 ~/kernel/tools/vock/report.py \
    --kernel-src ./ --vmlinux ./vmlinux \
    --mode local --local-log local.log --filter unix
  ...
  ------------------------------- Coverage Report --------------------------------
  📄 net/unix/af_unix.c (276 lines)
   ...
  942 | static int unix_setsockopt(struct socket *sock, int level, int optname,
  943 |                            sockptr_t optval, unsigned int optlen)
  944 | {
   ...
  961 |         switch (optname) {
  962 |         case SO_INQ:
  963 >                 if (sk->sk_type != SOCK_STREAM)
  964 |                         return -EINVAL;
  965 |
  966 >                 if (val > 1 || val < 0)
  967 |                         return -EINVAL;
  968 |
  969 >                 WRITE_ONCE(u->recvmsg_inq, val);
  970 |                 break;
---
 Documentation/dev-tools/kselftest.rst       |  41 +++++++
 tools/testing/selftests/Makefile            |  14 ++-
 tools/testing/selftests/kselftest_harness.h | 128 +++++++++++++++++++-
 3 files changed, 174 insertions(+), 9 deletions(-)
Documentation/dev-tools/kselftest.rst +41 -0
index 18c2da67fae42..5c2b92ac4a300 100644
@@ -200,6 +200,47 @@ You can look at the TAP output to see if you ran into the timeout. Test
 runners which know a test must run under a specific time can then optionally
 treat these timeouts then as fatal.
 
+KCOV for selftests
+==================
+
+Selftests built with `kselftest_harness.h` natively support generating
+KCOV coverage data.  See :doc:`KCOV: code coverage for fuzzing </dev-tools/kcov>`
+for prerequisites.
+
+You can specify the output directory with the `KCOV_OUTPUT` environment
+variable.  Additionally, you can specify the number of instructions to
+collect with the `KCOV_SLOTS` environment variable ::
+
+  # KCOV_OUTPUT=$PWD/kcov KCOV_SLOTS=$((4096 * 2)) \
+        ./tools/testing/selftests/net/af_unix/scm_inq
+
+In the output directory, a coverage file is generated for each test
+case in the selftest ::
+
+  $ ls kcov/
+  scm_inq.dgram.basic  scm_inq.seqpacket.basic  scm_inq.stream.basic
+
+The default value of `KCOV_SLOTS` is `4096`, and `KCOV_SLOTS` multiplied
+by `sizeof(unsigned long)` must be multiple of `4096`, so the smallest
+value is `512`.
+
+Both `KCOV_OUTPUT` and `KCOV_SLOTS` can be specified as the variables
+on the `make` command line ::
+
+  # make -C tools/testing/selftests/ \
+        kselftest_override_timeout=60 \
+        KCOV_OUTPUT=$PWD/kcov KCOV_SLOTS=$((4096 * 4)) \
+        TARGETS=net/af_unix run_tests
+
+The collected data can be decoded with `addr2line` ::
+
+  $ cat kcov/* | sort | uniq | addr2line -e vmlinux | grep unix
+  net/unix/af_unix.c:1056
+  net/unix/af_unix.c:3138
+  net/unix/af_unix.c:3834
+  net/unix/af_unix.c:3838
+  ...
+
 Packaging selftests
 ===================
 
tools/testing/selftests/Makefile +8 -6
index c46ebdb9b8ef7..40e70fb1a3478 100644
@@ -218,12 +218,14 @@ all:
        done; exit $$ret;
 
 run_tests: all
-       @for TARGET in $(TARGETS); do \
-               BUILD_TARGET=$$BUILD/$$TARGET;  \
-               $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
-                               SRC_PATH=$(shell readlink -e $$(pwd)) \
-                               OBJ_PATH=$(BUILD)                   \
-                               O=$(abs_objtree);                   \
+       @for TARGET in $(TARGETS); do                           \
+               BUILD_TARGET=$$BUILD/$$TARGET;                  \
+               $(MAKE) OUTPUT=$$BUILD_TARGET                   \
+                       KCOV_OUTPUT=$(abspath $(KCOV_OUTPUT))   \
+                       -C $$TARGET run_tests                   \
+                       SRC_PATH=$(shell readlink -e $$(pwd))   \
+                       OBJ_PATH=$(BUILD)                       \
+                       O=$(abs_objtree);                       \
        done;
 
 hotplug:
tools/testing/selftests/kselftest_harness.h +125 -4
index 3f66e862e83eb..cba8020853b5d 100644
@@ -56,6 +56,8 @@
 #include <asm/types.h>
 #include <ctype.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <linux/kcov.h>
 #include <linux/unistd.h>
 #include <poll.h>
 #include <stdbool.h>
@@ -63,7 +65,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
@@ -401,7 +405,8 @@
                const FIXTURE_VARIANT(fixture_name) *variant); \
        static void wrapper_##fixture_name##_##test_name( \
                struct __test_metadata *_metadata, \
-               struct __fixture_variant_metadata *variant) \
+               struct __fixture_variant_metadata *variant, \
+               char *test_full_name) \
        { \
                /* fixture data is alloced, setup, and torn down per call. */ \
                FIXTURE_DATA(fixture_name) self_private, *self = NULL; \
@@ -430,7 +435,9 @@
                        if (_metadata->exit_code) \
                                _exit(0); \
                        *_metadata->no_teardown = false; \
+                       enable_kcov(_metadata); \
                        fixture_name##_##test_name(_metadata, self, variant->data); \
+                       disable_kcov(_metadata, test_full_name); \
                        _metadata->teardown_fn(false, _metadata, self, variant->data); \
                        _exit(0); \
                } else if (child < 0 || child != waitpid(child, &status, 0)) { \
@@ -470,6 +477,8 @@
                object->teardown_fn = &wrapper_##fixture_name##_##test_name##_teardown; \
                object->termsig = signal; \
                object->timeout = tmout; \
+               object->kcov_fd = -1; \
+               object->kcov_slots = -1; \
                _##fixture_name##_##test_name##_object = object; \
                __register_test(object); \
        } \
@@ -908,7 +917,8 @@ __register_fixture_variant(struct __fixture_metadata *f,
 struct __test_metadata {
        const char *name;
        void (*fn)(struct __test_metadata *,
-                  struct __fixture_variant_metadata *);
+                  struct __fixture_variant_metadata *,
+                  char *test_name);
        pid_t pid;      /* pid of test when being run */
        struct __fixture_metadata *fixture;
        void (*teardown_fn)(bool in_parent, struct __test_metadata *_metadata,
@@ -923,6 +933,10 @@ struct __test_metadata {
        const void *variant;
        struct __test_results *results;
        struct __test_metadata *prev, *next;
+       int kcov_fd;
+       int kcov_slots;
+       char *kcov_dir;
+       unsigned long *kcov_mem;
 };
 
 static inline bool __test_passed(struct __test_metadata *metadata)
@@ -1185,6 +1199,114 @@ static bool test_enabled(int argc, char **argv,
        return !has_positive;
 }
 
+#define KCOV_SLOTS 4096
+
+static void enable_kcov(struct __test_metadata *t)
+{
+       char *slots;
+       int err;
+
+       t->kcov_dir = getenv("KCOV_OUTPUT");
+       if (!t->kcov_dir || *t->kcov_dir == '\0')
+               return;
+
+       slots = getenv("KCOV_SLOTS");
+       if (slots && *slots != '\0')
+               sscanf(slots, "%d", &t->kcov_slots);
+       if (t->kcov_slots <= 0)
+               t->kcov_slots = KCOV_SLOTS;
+
+       t->kcov_fd = open("/sys/kernel/debug/kcov", O_RDWR);
+       if (t->kcov_fd < 0) {
+               ksft_print_msg("ERROR OPENING KCOV FD\n");
+               goto err;
+       }
+
+       err = ioctl(t->kcov_fd, KCOV_INIT_TRACE, t->kcov_slots);
+       if (err) {
+               ksft_print_msg("ERROR INITIALISING KCOV\n");
+               goto err;
+       }
+
+       t->kcov_mem = mmap(NULL, sizeof(unsigned long) * t->kcov_slots,
+                          PROT_READ | PROT_WRITE, MAP_SHARED, t->kcov_fd, 0);
+       if ((void *)t->kcov_mem == MAP_FAILED) {
+               ksft_print_msg("ERROR ALLOCATING MEMORY FOR KCOV\n");
+               goto err;
+       }
+
+       err = ioctl(t->kcov_fd, KCOV_ENABLE, KCOV_TRACE_PC);
+       if (err) {
+               ksft_print_msg("ERROR ENABLING KCOV\n");
+               goto err;
+       }
+
+       __atomic_store_n(&t->kcov_mem[0], 0, __ATOMIC_RELAXED);
+       return;
+err:
+       t->exit_code = KSFT_FAIL;
+       _exit(KSFT_FAIL);
+}
+
+static void disable_kcov(struct __test_metadata *t, char *test_name)
+{
+       int slots, err, dir, fd, i;
+
+       if (t->kcov_fd == -1)
+               return;
+
+       slots = __atomic_load_n(&t->kcov_mem[0], __ATOMIC_RELAXED);
+       if (slots == t->kcov_slots - 1)
+               ksft_print_msg("Set KCOV_SLOTS to a value greater than %d\n", t->kcov_slots);
+
+       err = ioctl(t->kcov_fd, KCOV_DISABLE, 0);
+       if (err) {
+               ksft_print_msg("ERROR DISABLING KCOV\n");
+               goto out;
+       }
+
+       err = mkdir(t->kcov_dir, 0755);
+       if (err == -1 && errno != EEXIST) {
+               ksft_print_msg("ERROR CREATING '%s'\n", t->kcov_dir);
+               goto out;
+       }
+       err = 0;
+
+       dir = open(t->kcov_dir, O_DIRECTORY);
+       if (dir < 0) {
+               ksft_print_msg("ERROR OPENING %s\n", t->kcov_dir);
+               err = dir;
+               goto out;
+       }
+
+       fd = openat(dir, test_name, O_RDWR | O_CREAT | O_TRUNC);
+
+       close(dir);
+
+       if (fd == -1) {
+               ksft_print_msg("ERROR CREATING '%s' at '%s'\n", test_name, t->kcov_dir);
+               err = fd;
+               goto out;
+       }
+
+       for (i = 0; i < slots; i++) {
+               char buf[64];
+               int size;
+
+               size = snprintf(buf, 64, "0x%lx\n", t->kcov_mem[i + 1]);
+               write(fd, buf, size);
+       }
+
+out:
+       munmap(t->kcov_mem, sizeof(t->kcov_mem[0]) * t->kcov_slots);
+       close(t->kcov_fd);
+
+       if (err) {
+               t->exit_code = KSFT_FAIL;
+               _exit(KSFT_FAIL);
+       }
+}
+
 static void __run_test(struct __fixture_metadata *f,
                       struct __fixture_variant_metadata *variant,
                       struct __test_metadata *t)
@@ -1216,7 +1338,7 @@ static void __run_test(struct __fixture_metadata *f,
                t->exit_code = KSFT_FAIL;
        } else if (child == 0) {
                setpgrp();
-               t->fn(t, variant);
+               t->fn(t, variant, test_name);
                _exit(t->exit_code);
        } else {
                t->pid = child;
--

2.51.0.858.gf9c4a03a3a-goog

#2 lore raw
In reply to Kuniyuki Iwashima
kernel test robot noticed the following build warnings:

Hi Kuniyuki,

kernel test robot noticed the following build warnings:

[auto build test WARNING on shuah-kselftest/next]
[also build test WARNING on shuah-kselftest/fixes kees/for-next/seccomp linus/master v6.18-rc2 next-20251024] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/selftests-harness-Support-KCOV/20251017-164507
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link:    https://lore.kernel.org/r/20251017084022.3721950-1-kuniyu%40google.com
patch subject: [PATCH] selftests: harness: Support KCOV.

:::::: branch date: 9 days ago
:::::: commit date: 9 days ago
config: x86_64-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20251026/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251026/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

All warnings (new ones prefixed by >>):

In file included from listmount_test.c:14:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   listmount_test.c:23:1: note: in expansion of macro 'TEST'
      23 | TEST(listmount_forward)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_listmount_forward_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   listmount_test.c:23:1: note: in expansion of macro 'TEST'
      23 | TEST(listmount_forward)
         | ^~~~
   ../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   listmount_test.c:45:1: note: in expansion of macro 'TEST'
      45 | TEST(listmount_backward)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_listmount_backward_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   listmount_test.c:45:1: note: in expansion of macro 'TEST'
      45 | TEST(listmount_backward)
         | ^~~~
>> ../../kselftest_harness.h:1251:13: warning: 'disable_kcov' defined but not used [-Wunused-function]
    1251 | static void disable_kcov(struct __test_metadata *t, char *test_name)
         |             ^~~~~~~~~~~~
>> ../../kselftest_harness.h:1204:13: warning: 'enable_kcov' defined but not used [-Wunused-function]

1204 | static void enable_kcov(struct __test_metadata *t)
| ^~~~~~~~~~~
--
In file included from futex_wait_timeout.c:22:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_timeout.c:82:1: note: in expansion of macro 'TEST'
      82 | TEST(wait_bitset)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_wait_bitset_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_timeout.c:82:1: note: in expansion of macro 'TEST'
      82 | TEST(wait_bitset)
         | ^~~~
   ../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_timeout.c:108:1: note: in expansion of macro 'TEST'
     108 | TEST(requeue_pi)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_requeue_pi_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_timeout.c:108:1: note: in expansion of macro 'TEST'
     108 | TEST(requeue_pi)
         | ^~~~
   ../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_timeout.c:128:1: note: in expansion of macro 'TEST'
     128 | TEST(lock_pi)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_lock_pi_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_timeout.c:128:1: note: in expansion of macro 'TEST'
     128 | TEST(lock_pi)
         | ^~~~
   ../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_timeout.c:162:1: note: in expansion of macro 'TEST'
     162 | TEST(waitv)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_waitv_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_timeout.c:162:1: note: in expansion of macro 'TEST'
     162 | TEST(waitv)
         | ^~~~
>> ../../kselftest_harness.h:1251:13: warning: 'disable_kcov' defined but not used [-Wunused-function]
    1251 | static void disable_kcov(struct __test_metadata *t, char *test_name)
         |             ^~~~~~~~~~~~
>> ../../kselftest_harness.h:1204:13: warning: 'enable_kcov' defined but not used [-Wunused-function]

1204 | static void enable_kcov(struct __test_metadata *t)
| ^~~~~~~~~~~
--
In file included from futex_wait_wouldblock.c:27:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_wouldblock.c:31:1: note: in expansion of macro 'TEST'
      31 | TEST(futex_wait_wouldblock)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_futex_wait_wouldblock_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_wouldblock.c:31:1: note: in expansion of macro 'TEST'
      31 | TEST(futex_wait_wouldblock)
         | ^~~~
   ../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_wouldblock.c:48:1: note: in expansion of macro 'TEST'
      48 | TEST(futex_waitv_wouldblock)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_futex_waitv_wouldblock_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_wouldblock.c:48:1: note: in expansion of macro 'TEST'
      48 | TEST(futex_waitv_wouldblock)
         | ^~~~
>> ../../kselftest_harness.h:1251:13: warning: 'disable_kcov' defined but not used [-Wunused-function]
    1251 | static void disable_kcov(struct __test_metadata *t, char *test_name)
         |             ^~~~~~~~~~~~
>> ../../kselftest_harness.h:1204:13: warning: 'enable_kcov' defined but not used [-Wunused-function]

1204 | static void enable_kcov(struct __test_metadata *t)
| ^~~~~~~~~~~
--
In file included from futex_requeue_pi_signal_restart.c:30:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_requeue_pi_signal_restart.c:98:1: note: in expansion of macro 'TEST'
      98 | TEST(futex_requeue_pi_signal_restart)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_futex_requeue_pi_signal_restart_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_requeue_pi_signal_restart.c:98:1: note: in expansion of macro 'TEST'
      98 | TEST(futex_requeue_pi_signal_restart)
         | ^~~~
>> ../../kselftest_harness.h:1251:13: warning: 'disable_kcov' defined but not used [-Wunused-function]
    1251 | static void disable_kcov(struct __test_metadata *t, char *test_name)
         |             ^~~~~~~~~~~~
>> ../../kselftest_harness.h:1204:13: warning: 'enable_kcov' defined but not used [-Wunused-function]

1204 | static void enable_kcov(struct __test_metadata *t)
| ^~~~~~~~~~~
--
In file included from futex_requeue_pi_mismatched_ops.c:28:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_requeue_pi_mismatched_ops.c:44:1: note: in expansion of macro 'TEST'
      44 | TEST(requeue_pi_mismatched_ops)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_requeue_pi_mismatched_ops_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_requeue_pi_mismatched_ops.c:44:1: note: in expansion of macro 'TEST'
      44 | TEST(requeue_pi_mismatched_ops)
         | ^~~~
>> ../../kselftest_harness.h:1251:13: warning: 'disable_kcov' defined but not used [-Wunused-function]
    1251 | static void disable_kcov(struct __test_metadata *t, char *test_name)
         |             ^~~~~~~~~~~~
>> ../../kselftest_harness.h:1204:13: warning: 'enable_kcov' defined but not used [-Wunused-function]

1204 | static void enable_kcov(struct __test_metadata *t)
| ^~~~~~~~~~~
--
In file included from futex_wait_uninitialized_heap.c:33:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_uninitialized_heap.c:56:1: note: in expansion of macro 'TEST'
      56 | TEST(futex_wait_uninitialized_heap)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_futex_wait_uninitialized_heap_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_uninitialized_heap.c:56:1: note: in expansion of macro 'TEST'
      56 | TEST(futex_wait_uninitialized_heap)
         | ^~~~
>> ../../kselftest_harness.h:1251:13: warning: 'disable_kcov' defined but not used [-Wunused-function]
    1251 | static void disable_kcov(struct __test_metadata *t, char *test_name)
         |             ^~~~~~~~~~~~
>> ../../kselftest_harness.h:1204:13: warning: 'enable_kcov' defined but not used [-Wunused-function]

1204 | static void enable_kcov(struct __test_metadata *t)
| ^~~~~~~~~~~
--
In file included from futex_wait_private_mapped_file.c:31:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_private_mapped_file.c:59:1: note: in expansion of macro 'TEST'
      59 | TEST(wait_private_mapped_file)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_wait_private_mapped_file_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait_private_mapped_file.c:59:1: note: in expansion of macro 'TEST'
      59 | TEST(wait_private_mapped_file)
         | ^~~~
>> ../../kselftest_harness.h:1251:13: warning: 'disable_kcov' defined but not used [-Wunused-function]
    1251 | static void disable_kcov(struct __test_metadata *t, char *test_name)
         |             ^~~~~~~~~~~~
>> ../../kselftest_harness.h:1204:13: warning: 'enable_kcov' defined but not used [-Wunused-function]

1204 | static void enable_kcov(struct __test_metadata *t)
| ^~~~~~~~~~~
--
In file included from futex_wait.c:14:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait.c:39:1: note: in expansion of macro 'TEST'
      39 | TEST(private_futex)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_private_futex_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait.c:39:1: note: in expansion of macro 'TEST'
      39 | TEST(private_futex)
         | ^~~~
   ../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait.c:65:1: note: in expansion of macro 'TEST'
      65 | TEST(anon_page)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_anon_page_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait.c:65:1: note: in expansion of macro 'TEST'
      65 | TEST(anon_page)
         | ^~~~
   ../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait.c:101:1: note: in expansion of macro 'TEST'
     101 | TEST(file_backed)
         | ^~~~
   ../../kselftest_harness.h:188:25: note: (near initialization for '_file_backed_object.fn')
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~
   futex_wait.c:101:1: note: in expansion of macro 'TEST'
     101 | TEST(file_backed)
         | ^~~~
>> ../../kselftest_harness.h:1251:13: warning: 'disable_kcov' defined but not used [-Wunused-function]
    1251 | static void disable_kcov(struct __test_metadata *t, char *test_name)
         |             ^~~~~~~~~~~~
>> ../../kselftest_harness.h:1204:13: warning: 'enable_kcov' defined but not used [-Wunused-function]

1204 | static void enable_kcov(struct __test_metadata *t)
| ^~~~~~~~~~~
..

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

From: kernel test robot <[email protected]>
Date: Tue, 28 Oct 2025 09:59:29 +0800

Quoted 29 lines

Hi Kuniyuki,

kernel test robot noticed the following build warnings:

[auto build test WARNING on shuah-kselftest/next]
[also build test WARNING on shuah-kselftest/fixes kees/for-next/seccomp linus/master v6.18-rc2 next-20251024] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/selftests-harness-Support-KCOV/20251017-164507
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link:    https://lore.kernel.org/r/20251017084022.3721950-1-kuniyu%40google.com
patch subject: [PATCH] selftests: harness: Support KCOV.

:::::: branch date: 9 days ago
:::::: commit date: 9 days ago
config: x86_64-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20251026/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251026/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

All warnings (new ones prefixed by >>):

In file included from listmount_test.c:14:
../../kselftest_harness.h:188:25: error: initialization of 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *, char *)' from incompatible pointer type 'void (*)(struct __test_metadata *, struct __fixture_variant_metadata *)' [-Wincompatible-pointer-types]

Quoted 8 lines
     188 |                   .fn = &wrapper_##test_name, \
         |                         ^
   ../../kselftest_harness.h:157:25: note: in expansion of macro '__TEST_IMPL'
     157 | #define TEST(test_name) __TEST_IMPL(test_name, -1)
         |                         ^~~~~~~~~~~

listmount_test.c:23:1: note: in expansion of macro 'TEST'
23 | TEST(listmount_forward)
| ^~~~

Oh sorry, I missed TEST() as af_unix didn't use it, but I should've compiled all tests.

Will squash this diff to v2.

Thanks!

---8<---

tools/testing/selftests/kselftest_harness.h +4 -1
index cba8020853b5..5b7a01722981 100644
@@ -179,9 +179,12 @@
 	static void test_name(struct __test_metadata *_metadata); \
 	static void wrapper_##test_name( \
 		struct __test_metadata *_metadata, \
-		struct __fixture_variant_metadata __attribute__((unused)) *variant) \
+		struct __fixture_variant_metadata __attribute__((unused)) *variant, \
+		char *test_full_name) \
 	{ \
+		enable_kcov(_metadata); \
 		test_name(_metadata); \
+		disable_kcov(_metadata, test_full_name); \
 	} \
 	static struct __test_metadata _##test_name##_object = \
 		{ .name = #test_name, \

---8<---