Re: [RFC PATCH 00/12] rv: Add selftests to tools and KUnit tests

Wen Yang
2026-04-28T15:09:49Z

On 4/27/26 23:11, Gabriele Monaco wrote:
> This series adds support to the make check target in the rv userspace
> tool and the rvgen script, this allows to quickly validate its
> functionality. The selftest framework is inspired by the one used in
> RTLA.
>
> A few bugs in both tools were also discovered and are fixed as part of
> this series.
>
> Additionally it adds unit tests for models. This is achieved by running
> the handlers functions directly within KUnit, emulating all modules
> paths as if real kernel events fired.
>
> Unit tests emulate a series of events that are expected to trigger
> violations and checks that a reaction occurred, stub structs and
> functions are used so the kernel is not affected by the test.
>

Hi Gabriele,

Good direction overall. The approach of calling event handlers directly
inside KUnit is clean and avoids the complexity of setting up real
tracepoints. Patches 1-4 (bug fixes) look correct.

We are planning to build the KUnit and selftest coverage for the tlob
monitor on top of this infrastructure, so getting this merged would be
useful for us as well.

- One issue found in the KUnit patches:

patch 10: nomiss test
kernel/trace/rv/monitors/nomiss/nomiss.c:
udelay(10 / 1000);

The compiler folds it silently as udelay(0).
Presumably intended as udelay(10)?

- minor: copyright year range
rv_monitors_test.c: Copyright (C) 2025-2028
kunit_stubs.h: Copyright (C) 2026-2029

Kernel copyright entries conventionally use only the year(s) the work
was actually created，eg:
https://lkml.indiana.edu/2510.0/01897.html

Reviewed-by: Wen Yang <wen.yang@linux.dev>

--
Best wishes,
Wen

> To: linux-trace-kernel@vger.kernel.org
> To: linux-kernel@vger.kernel.org
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Nam Cao <namcao@linutronix.de>
> Cc: Thomas Weissschuh <thomas.weissschuh@linutronix.de>
> Cc: Tomas Glozar <tglozar@redhat.com>
> Cc: John Kacur <jkacur@redhat.com>
> Cc: Wen Yang <wen.yang@linux.dev>
>
> Gabriele Monaco (12):
> tools/rv: Fix substring match bug in monitor name search
> tools/rv: Fix substring match when listing container monitors
> tools/rv: Fix exit status when monitor execution fails
> tools/rv: Fix cleanup after failed trace setup
> tools/rv: Add selftests
> verification/rvgen: Fix options shared among commands
> verification/rvgen: Add golden and spec folders for tests
> verification/rvgen: Add selftests
> rv: Add KUnit stub to rv_react() and rv_*_task_monitor_slot()
> rv: Add KUnit tests for some DA/HA monitors
> rv: Add KUnit stubs for current and smp_processor_id()
> rv: Add KUnit tests for some LTL monitors
>
> include/rv/da_monitor.h | 32 +++
> include/rv/kunit_stubs.h | 17 ++
> include/rv/ltl_monitor.h | 32 +++
> kernel/trace/rv/Kconfig | 14 +
> kernel/trace/rv/Makefile | 3 +
> kernel/trace/rv/monitors/nomiss/nomiss.c | 30 +++
> kernel/trace/rv/monitors/opid/opid.c | 27 ++
> .../trace/rv/monitors/pagefault/pagefault.c | 26 +-
> kernel/trace/rv/monitors/sco/sco.c | 23 ++
> kernel/trace/rv/monitors/sleep/sleep.c | 64 ++++-
> kernel/trace/rv/monitors/sssw/sssw.c | 27 ++
> kernel/trace/rv/monitors/sts/sts.c | 35 +++
> kernel/trace/rv/rv.c | 5 +
> kernel/trace/rv/rv_monitors_test.c | 99 +++++++
> kernel/trace/rv/rv_monitors_test.h | 90 +++++++
> kernel/trace/rv/rv_reactors.c | 3 +
> tools/verification/rv/Makefile | 5 +-
> tools/verification/rv/src/in_kernel.c | 58 ++--
> tools/verification/rv/src/rv.c | 2 +-
> tools/verification/rv/tests/rv_list.t | 48 ++++
> tools/verification/rv/tests/rv_mon.t | 95 +++++++
> tools/verification/rvgen/Makefile | 4 +
> tools/verification/rvgen/__main__.py | 10 +-
> .../rvgen/tests/golden/da_global/Kconfig | 9 +
> .../rvgen/tests/golden/da_global/da_global.c | 95 +++++++
> .../rvgen/tests/golden/da_global/da_global.h | 47 ++++
> .../tests/golden/da_global/da_global_trace.h | 15 ++
> .../tests/golden/da_perobj_parent/Kconfig | 11 +
> .../da_perobj_parent/da_perobj_parent.c | 110 ++++++++
> .../da_perobj_parent/da_perobj_parent.h | 64 +++++
> .../da_perobj_parent/da_perobj_parent_trace.h | 15 ++
> .../tests/golden/da_pertask_desc/Kconfig | 9 +
> .../golden/da_pertask_desc/da_pertask_desc.c | 105 ++++++++
> .../golden/da_pertask_desc/da_pertask_desc.h | 64 +++++
> .../da_pertask_desc/da_pertask_desc_trace.h | 15 ++
> .../rvgen/tests/golden/ha_percpu/Kconfig | 9 +
> .../rvgen/tests/golden/ha_percpu/ha_percpu.c | 244 +++++++++++++++++
> .../rvgen/tests/golden/ha_percpu/ha_percpu.h | 72 +++++
> .../tests/golden/ha_percpu/ha_percpu_trace.h | 19 ++
> .../rvgen/tests/golden/ltl_pertask/Kconfig | 9 +
> .../tests/golden/ltl_pertask/ltl_pertask.c | 107 ++++++++
> .../tests/golden/ltl_pertask/ltl_pertask.h | 108 ++++++++
> .../golden/ltl_pertask/ltl_pertask_trace.h | 14 +
> .../rvgen/tests/golden/test_container/Kconfig | 5 +
> .../golden/test_container/test_container.c | 35 +++
> .../golden/test_container/test_container.h | 3 +
> .../rvgen/tests/golden/test_da/Kconfig | 9 +
> .../rvgen/tests/golden/test_da/test_da.c | 95 +++++++
> .../rvgen/tests/golden/test_da/test_da.h | 47 ++++
> .../tests/golden/test_da/test_da_trace.h | 15 ++
> .../rvgen/tests/golden/test_ha/Kconfig | 9 +
> .../rvgen/tests/golden/test_ha/test_ha.c | 247 ++++++++++++++++++
> .../rvgen/tests/golden/test_ha/test_ha.h | 72 +++++
> .../tests/golden/test_ha/test_ha_trace.h | 19 ++
> .../rvgen/tests/golden/test_ltl/Kconfig | 11 +
> .../rvgen/tests/golden/test_ltl/test_ltl.c | 108 ++++++++
> .../rvgen/tests/golden/test_ltl/test_ltl.h | 108 ++++++++
> .../tests/golden/test_ltl/test_ltl_trace.h | 14 +
> .../rvgen/tests/rvgen_container.t | 20 ++
> .../verification/rvgen/tests/rvgen_monitor.t | 87 ++++++
> .../rvgen/tests/specs/test_da.dot | 16 ++
> .../rvgen/tests/specs/test_da2.dot | 18 ++
> .../rvgen/tests/specs/test_ha.dot | 27 ++
> .../rvgen/tests/specs/test_invalid.dot | 8 +
> .../rvgen/tests/specs/test_invalid.ltl | 1 +
> .../rvgen/tests/specs/test_invalid_ha.dot | 16 ++
> .../rvgen/tests/specs/test_ltl.ltl | 1 +
> tools/verification/tests/engine.sh | 156 +++++++++++
> 68 files changed, 2993 insertions(+), 44 deletions(-)
> create mode 100644 include/rv/kunit_stubs.h
> create mode 100644 kernel/trace/rv/rv_monitors_test.c
> create mode 100644 kernel/trace/rv/rv_monitors_test.h
> create mode 100644 tools/verification/rv/tests/rv_list.t
> create mode 100644 tools/verification/rv/tests/rv_mon.t
> create mode 100644 tools/verification/rvgen/tests/golden/da_global/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/da_global/da_global.c
> create mode 100644 tools/verification/rvgen/tests/golden/da_global/da_global.h
> create mode 100644 tools/verification/rvgen/tests/golden/da_global/da_global_trace.h
> create mode 100644 tools/verification/rvgen/tests/golden/da_perobj_parent/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent.c
> create mode 100644 tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent.h
> create mode 100644 tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent_trace.h
> create mode 100644 tools/verification/rvgen/tests/golden/da_pertask_desc/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc.c
> create mode 100644 tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc.h
> create mode 100644 tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc_trace.h
> create mode 100644 tools/verification/rvgen/tests/golden/ha_percpu/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.c
> create mode 100644 tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h
> create mode 100644 tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trace.h
> create mode 100644 tools/verification/rvgen/tests/golden/ltl_pertask/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask.c
> create mode 100644 tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask.h
> create mode 100644 tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_trace.h
> create mode 100644 tools/verification/rvgen/tests/golden/test_container/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/test_container/test_container.c
> create mode 100644 tools/verification/rvgen/tests/golden/test_container/test_container.h
> create mode 100644 tools/verification/rvgen/tests/golden/test_da/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/test_da/test_da.c
> create mode 100644 tools/verification/rvgen/tests/golden/test_da/test_da.h
> create mode 100644 tools/verification/rvgen/tests/golden/test_da/test_da_trace.h
> create mode 100644 tools/verification/rvgen/tests/golden/test_ha/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/test_ha/test_ha.c
> create mode 100644 tools/verification/rvgen/tests/golden/test_ha/test_ha.h
> create mode 100644 tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h
> create mode 100644 tools/verification/rvgen/tests/golden/test_ltl/Kconfig
> create mode 100644 tools/verification/rvgen/tests/golden/test_ltl/test_ltl.c
> create mode 100644 tools/verification/rvgen/tests/golden/test_ltl/test_ltl.h
> create mode 100644 tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.h
> create mode 100644 tools/verification/rvgen/tests/rvgen_container.t
> create mode 100644 tools/verification/rvgen/tests/rvgen_monitor.t
> create mode 100644 tools/verification/rvgen/tests/specs/test_da.dot
> create mode 100644 tools/verification/rvgen/tests/specs/test_da2.dot
> create mode 100644 tools/verification/rvgen/tests/specs/test_ha.dot
> create mode 100644 tools/verification/rvgen/tests/specs/test_invalid.dot
> create mode 100644 tools/verification/rvgen/tests/specs/test_invalid.ltl
> create mode 100644 tools/verification/rvgen/tests/specs/test_invalid_ha.dot
> create mode 100644 tools/verification/rvgen/tests/specs/test_ltl.ltl
> create mode 100644 tools/verification/tests/engine.sh
>
>
> base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731