Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Kuniyuki Iwashima <kuniyu@google.com>, Shuah Khan <shuah@kernel.org>
Cc: Kuniyuki Iwashima <kuni1840@gmail.com>,
	linux-kselftest@vger.kernel.org,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH v2] selftests: harness: Support KCOV.
Date: Thu, 6 Nov 2025 14:42:06 -0700	[thread overview]
Message-ID: <84faddcb-07c5-4031-a56d-6785d49bf663@linuxfoundation.org> (raw)
In-Reply-To: <20251028024339.2028774-1-kuniyu@google.com>

On 10/27/25 20:42, Kuniyuki Iwashima wrote:
> 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;
> 
> Link: https://github.com/kzall0c/vock/blob/f3d97de9954f9df758c0ab287ca7e24e654288c7/report.py #[0]
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
> ---
> v2: Support TEST()
> v1: https://lore.kernel.org/linux-kselftest/20251017084022.3721950-1-kuniyu@google.com/
> ---
>   Documentation/dev-tools/kselftest.rst       |  41 ++++++
>   tools/testing/selftests/Makefile            |  14 ++-
>   tools/testing/selftests/kselftest_harness.h | 133 +++++++++++++++++++-
>   3 files changed, 178 insertions(+), 10 deletions(-)
> 

I am okay with kcov support being added. You probably have to fix a few things.
kernel test robot is still complaining on v2.

thanks,
-- Shuah

  parent reply	other threads:[~2025-11-06 21:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28  2:42 [PATCH v2] selftests: harness: Support KCOV Kuniyuki Iwashima
2025-11-06  8:50 ` kernel test robot
2025-11-06 21:42 ` Shuah Khan [this message]
2025-11-07  7:08   ` Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84faddcb-07c5-4031-a56d-6785d49bf663@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=kuni1840@gmail.com \
    --cc=kuniyu@google.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox