Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v4 15/17] selftests/verification: Fix wrong errexit assumption
       [not found] <20260717154638.220789-1-gmonaco@redhat.com>
@ 2026-07-17 15:46 ` Gabriele Monaco
  2026-07-17 15:46 ` [PATCH v4 16/17] selftests/verification: Rearrange the wwnr_printk test Gabriele Monaco
  2026-07-17 15:46 ` [PATCH v4 17/17] selftests/verification: Add selftests for deadline and stall monitors Gabriele Monaco
  2 siblings, 0 replies; 6+ messages in thread
From: Gabriele Monaco @ 2026-07-17 15:46 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, Steven Rostedt, Gabriele Monaco,
	Shuah Khan, linux-kselftest
  Cc: Wen Yang, Nam Cao, Thomas Weissschuh, Tomas Glozar, John Kacur

RV selftest rely on bash errexit (set -e) to terminate with error, when
a step is expected to return false, the following syntax is used:

  ! cmd

This however prevents the test from exiting when cmd is false (desired)
but doesn't exit if cmd is true, since commands prefixed with ! are
explicitly excluded from errexit.

Use the syntax

  ! cmd || false

Which ends up checking the exit value of ! cmd and supplies a false
command for errexit to evaluate.

Reviewed-by: Wen Yang <wen.yang@linux.dev>
Acked-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
 .../verification/test.d/rv_monitor_enable_disable.tc   | 10 +++++-----
 .../verification/test.d/rv_monitor_reactor.tc          |  4 ++--
 .../selftests/verification/test.d/rv_wwnr_printk.tc    |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/verification/test.d/rv_monitor_enable_disable.tc b/tools/testing/selftests/verification/test.d/rv_monitor_enable_disable.tc
index f29236defb5a..61e2c8b54d9a 100644
--- a/tools/testing/selftests/verification/test.d/rv_monitor_enable_disable.tc
+++ b/tools/testing/selftests/verification/test.d/rv_monitor_enable_disable.tc
@@ -10,7 +10,7 @@ test_simple_monitor() {
     grep -q "$monitor$" enabled_monitors
 
     echo 0 > "monitors/$prefix$monitor/enable"
-    ! grep -q "$monitor$" enabled_monitors
+    ! grep -q "$monitor$" enabled_monitors || false
 
     echo "$monitor" >> enabled_monitors
     grep -q 1 "monitors/$prefix$monitor/enable"
@@ -34,12 +34,12 @@ test_container_monitor() {
 	test -n "$nested"
 
     echo 0 > "monitors/$monitor/enable"
-    ! grep -q "^$monitor$" enabled_monitors
+    ! grep -q "^$monitor$" enabled_monitors || false
 
     for nested_dir in "monitors/$monitor"/*; do
         [ -d "$nested_dir" ] || continue
         nested=$(basename "$nested_dir")
-        ! grep -q "^$monitor:$nested$" enabled_monitors
+        ! grep -q "^$monitor:$nested$" enabled_monitors || false
     done
 
     echo "$monitor" >> enabled_monitors
@@ -71,5 +71,5 @@ for monitor_dir in monitors/*; do
     fi
 done
 
-! echo non_existent_monitor > enabled_monitors
-! grep -q "^non_existent_monitor$" enabled_monitors
+! echo non_existent_monitor > enabled_monitors || false
+! grep -q "^non_existent_monitor$" enabled_monitors || false
diff --git a/tools/testing/selftests/verification/test.d/rv_monitor_reactor.tc b/tools/testing/selftests/verification/test.d/rv_monitor_reactor.tc
index 2958bf849338..516a20971390 100644
--- a/tools/testing/selftests/verification/test.d/rv_monitor_reactor.tc
+++ b/tools/testing/selftests/verification/test.d/rv_monitor_reactor.tc
@@ -64,5 +64,5 @@ done
 
 monitor=$(ls /sys/kernel/tracing/rv/monitors -1 | head -n 1)
 test -f "monitors/$monitor/reactors"
-! echo non_existent_reactor > "monitors/$monitor/reactors"
-! grep -q "\\[non_existent_reactor\\]" "monitors/$monitor/reactors"
+! echo non_existent_reactor > "monitors/$monitor/reactors" || false
+! grep -q "\\[non_existent_reactor\\]" "monitors/$monitor/reactors" || false
diff --git a/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc b/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc
index 5a59432b1d93..96de95edb530 100644
--- a/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc
+++ b/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc
@@ -17,13 +17,13 @@ echo printk > monitors/wwnr/reactors
 load
 
 echo 0 > monitoring_on
-! load
+! load || false
 echo 1 > monitoring_on
 
 load
 
 echo 0 > reacting_on
-! load
+! load || false
 echo 1 > reacting_on
 
 echo nop > monitors/wwnr/reactors
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 16/17] selftests/verification: Rearrange the wwnr_printk test
       [not found] <20260717154638.220789-1-gmonaco@redhat.com>
  2026-07-17 15:46 ` [PATCH v4 15/17] selftests/verification: Fix wrong errexit assumption Gabriele Monaco
@ 2026-07-17 15:46 ` Gabriele Monaco
  2026-07-20 11:01   ` Nam Cao
  2026-07-21  6:24   ` Gabriele Monaco
  2026-07-17 15:46 ` [PATCH v4 17/17] selftests/verification: Add selftests for deadline and stall monitors Gabriele Monaco
  2 siblings, 2 replies; 6+ messages in thread
From: Gabriele Monaco @ 2026-07-17 15:46 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, Steven Rostedt, Gabriele Monaco,
	Shuah Khan, linux-kselftest
  Cc: Wen Yang, Nam Cao, Thomas Weissschuh, Tomas Glozar, John Kacur

The wwnr_printk test expects no reactions in some situations, after
fixing the bash assertion, the test is failing because expecting no
reaction after a previous step had reactions is flaky without making
sure all buffers are flushed.

Wait for reactions to be over when expected by polling dmesg for an
interval without any rv message.
Also simplify the load function to stop loads as soon as a reaction
occurs, this limits the number of lines to flush and makes tests overall
faster and more stable.

Reviewed-by: Wen Yang <wen.yang@linux.dev>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---

Notes:
    V4:
    * Wait for dmesg to flush all messages after reactions

 .../verification/test.d/rv_wwnr_printk.tc     | 23 ++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc b/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc
index 96de95edb530..37d96e1ae93b 100644
--- a/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc
+++ b/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc
@@ -4,23 +4,40 @@
 # requires: available_reactors wwnr:monitor printk:reactor stress-ng:program
 
 load() { # returns true if there was a reaction
-	local lines_before num
+	local lines_before num load_pid ret
 	num=$((($(nproc) + 1) / 2))
 	lines_before=$(dmesg | wc -l)
-	stress-ng --cpu-sched "$num" --timer "$num" -t 5 -q
-	dmesg | tail -n $((lines_before + 1)) | grep -q "rv: monitor wwnr does not allow event"
+	stress-ng --cpu-sched "$num" --timer "$num" -t 5 -q &
+	load_pid=$!
+	timeout 5 dmesg -w | tail -n +$((lines_before + 1)) | grep -m 1 -q "rv: monitor wwnr does not allow event"
+	ret=$?
+	kill "$load_pid" || true
+	wait "$load_pid" || true
+	return $ret
+}
+
+# loads may flood the ringbuffer, wait for all pending printks
+wait_dmesg_flush() {
+	local last_before last_after=$(dmesg | grep "rv:" | tail -n 1 || true)
+	while [ "$last_before" != "$last_after" ]; do
+		last_before=$last_after
+		sleep .3
+		last_after=$(dmesg | grep "rv:" | tail -n 1 || true)
+	done
 }
 
 echo 1 > monitors/wwnr/enable
 echo printk > monitors/wwnr/reactors
 
 load
+wait_dmesg_flush
 
 echo 0 > monitoring_on
 ! load || false
 echo 1 > monitoring_on
 
 load
+wait_dmesg_flush
 
 echo 0 > reacting_on
 ! load || false
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 17/17] selftests/verification: Add selftests for deadline and stall monitors
       [not found] <20260717154638.220789-1-gmonaco@redhat.com>
  2026-07-17 15:46 ` [PATCH v4 15/17] selftests/verification: Fix wrong errexit assumption Gabriele Monaco
  2026-07-17 15:46 ` [PATCH v4 16/17] selftests/verification: Rearrange the wwnr_printk test Gabriele Monaco
@ 2026-07-17 15:46 ` Gabriele Monaco
  2026-07-20 11:03   ` Nam Cao
  2 siblings, 1 reply; 6+ messages in thread
From: Gabriele Monaco @ 2026-07-17 15:46 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, Steven Rostedt, Gabriele Monaco,
	Shuah Khan, linux-kselftest
  Cc: Nam Cao, Thomas Weissschuh, Tomas Glozar, John Kacur, Wen Yang

Add selftests to verify deadline monitors don't fail under expected
conditions and the stall monitor report violations only when expected.

Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---

Notes:
    V4:
    * Restore original stall threshold after selftest

 .../verification/test.d/rv_deadline.tc        | 21 ++++++++++++
 .../selftests/verification/test.d/rv_stall.tc | 33 +++++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 tools/testing/selftests/verification/test.d/rv_deadline.tc
 create mode 100644 tools/testing/selftests/verification/test.d/rv_stall.tc

diff --git a/tools/testing/selftests/verification/test.d/rv_deadline.tc b/tools/testing/selftests/verification/test.d/rv_deadline.tc
new file mode 100644
index 000000000000..b583096beda6
--- /dev/null
+++ b/tools/testing/selftests/verification/test.d/rv_deadline.tc
@@ -0,0 +1,21 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# description: Test deadline monitors trigger no reaction
+# requires: available_reactors deadline:monitor printk:reactor stress-ng:program
+
+load() { # returns true if there was a reaction
+	local lines_before
+	lines_before=$(dmesg | wc -l)
+	stress-ng --cpu 2 --sched deadline --sched-period 100000000 --sched-deadline 100000000 --sched-runtime 20000000 -t 5 &
+	stress-ng --cpu 2 --sched rr --sched-prio 50 --cyclic 1 --cyclic-policy rr --cyclic-prio 50 -t 5 &
+	wait
+	dmesg | tail -n +$((lines_before + 1)) | grep -q "rv: monitor [a-z]\+ does not allow event"
+}
+
+echo 1 > monitors/deadline/enable
+echo printk > monitors/deadline/reactors
+
+! load || false
+
+echo nop > monitors/deadline/reactors
+echo 0 > monitors/deadline/enable
diff --git a/tools/testing/selftests/verification/test.d/rv_stall.tc b/tools/testing/selftests/verification/test.d/rv_stall.tc
new file mode 100644
index 000000000000..515a10263ca1
--- /dev/null
+++ b/tools/testing/selftests/verification/test.d/rv_stall.tc
@@ -0,0 +1,33 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# description: Test stall monitor
+# requires: available_reactors stall:monitor printk:reactor stress-ng:program
+
+THRESHOLD=/sys/module/stall/parameters/threshold_jiffies
+ORIG_THRESHOLD=$(cat $THRESHOLD)
+trap 'echo $ORIG_THRESHOLD > $THRESHOLD' EXIT
+
+load() { # returns true if there was a reaction
+	local lines_before cpu
+	cpu=$(($(nproc) - 1))
+	lines_before=$(dmesg | wc -l)
+	stress-ng --cpu 1 --taskset "$cpu" --sched rr --sched-prio 1 -t 3 &
+	stress-ng --cpu 5 --taskset "$cpu" -t 3 &
+	wait
+	dmesg | tail -n +$((lines_before + 1)) | grep -q "rv: monitor stall does not allow event"
+}
+
+echo 5000 > $THRESHOLD
+echo 1 > monitors/stall/enable
+echo printk > monitors/stall/reactors
+
+! load || false
+
+echo 0 > monitors/stall/enable
+echo 70 > $THRESHOLD
+echo 1 > monitors/stall/enable
+
+load
+
+echo nop > monitors/stall/reactors
+echo 0 > monitors/stall/enable
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 16/17] selftests/verification: Rearrange the wwnr_printk test
  2026-07-17 15:46 ` [PATCH v4 16/17] selftests/verification: Rearrange the wwnr_printk test Gabriele Monaco
@ 2026-07-20 11:01   ` Nam Cao
  2026-07-21  6:24   ` Gabriele Monaco
  1 sibling, 0 replies; 6+ messages in thread
From: Nam Cao @ 2026-07-20 11:01 UTC (permalink / raw)
  To: Gabriele Monaco, linux-kernel, linux-trace-kernel, Steven Rostedt,
	Gabriele Monaco, Shuah Khan, linux-kselftest
  Cc: Wen Yang, Thomas Weissschuh, Tomas Glozar, John Kacur

Gabriele Monaco <gmonaco@redhat.com> writes:

> The wwnr_printk test expects no reactions in some situations, after
> fixing the bash assertion, the test is failing because expecting no
> reaction after a previous step had reactions is flaky without making
> sure all buffers are flushed.
>
> Wait for reactions to be over when expected by polling dmesg for an
> interval without any rv message.
> Also simplify the load function to stop loads as soon as a reaction
> occurs, this limits the number of lines to flush and makes tests overall
> faster and more stable.
>
> Reviewed-by: Wen Yang <wen.yang@linux.dev>
> Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>

Reviewed-by: Nam Cao <namcao@linutronix.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 17/17] selftests/verification: Add selftests for deadline and stall monitors
  2026-07-17 15:46 ` [PATCH v4 17/17] selftests/verification: Add selftests for deadline and stall monitors Gabriele Monaco
@ 2026-07-20 11:03   ` Nam Cao
  0 siblings, 0 replies; 6+ messages in thread
From: Nam Cao @ 2026-07-20 11:03 UTC (permalink / raw)
  To: Gabriele Monaco, linux-kernel, linux-trace-kernel, Steven Rostedt,
	Gabriele Monaco, Shuah Khan, linux-kselftest
  Cc: Thomas Weissschuh, Tomas Glozar, John Kacur, Wen Yang

Gabriele Monaco <gmonaco@redhat.com> writes:
> +	stress-ng --cpu 2 --sched deadline --sched-period 100000000 --sched-deadline 100000000 --sched-runtime 20000000 -t 5 &
> +	stress-ng --cpu 2 --sched rr --sched-prio 50 --cyclic 1 --cyclic-policy rr --cyclic-prio 50 -t 5 &

These exceed the 100 column limit.

Other than that:
Reviewed-by: Nam Cao <namcao@linutronix.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 16/17] selftests/verification: Rearrange the wwnr_printk test
  2026-07-17 15:46 ` [PATCH v4 16/17] selftests/verification: Rearrange the wwnr_printk test Gabriele Monaco
  2026-07-20 11:01   ` Nam Cao
@ 2026-07-21  6:24   ` Gabriele Monaco
  1 sibling, 0 replies; 6+ messages in thread
From: Gabriele Monaco @ 2026-07-21  6:24 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, Steven Rostedt, Shuah Khan,
	linux-kselftest
  Cc: Wen Yang, Nam Cao, Thomas Weissschuh, Tomas Glozar, John Kacur

On Fri, 2026-07-17 at 17:46 +0200, Gabriele Monaco wrote:
> +# loads may flood the ringbuffer, wait for all pending printks
> +wait_dmesg_flush() {
> +	local last_before last_after=$(dmesg | grep "rv:" | tail -n 1 ||
> true)
> +	while [ "$last_before" != "$last_after" ]; do
> +		last_before=$last_after
> +		sleep .3
> +		last_after=$(dmesg | grep "rv:" | tail -n 1 || true)
> +	done
>  }
>  
>  echo 1 > monitors/wwnr/enable
>  echo printk > monitors/wwnr/reactors
>  
>  load
> +wait_dmesg_flush

On some systems this may trigger wwnr's reactions and run indefinitely, I'm
going to send a V5 moving this after turning monitoring/reacting of and adding a
timeout, just in case those switches don't work.

>  
>  echo 0 > monitoring_on
>  ! load || false
>  echo 1 > monitoring_on
>  
>  load
> +wait_dmesg_flush
>  
>  echo 0 > reacting_on
>  ! load || false


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-21  6:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260717154638.220789-1-gmonaco@redhat.com>
2026-07-17 15:46 ` [PATCH v4 15/17] selftests/verification: Fix wrong errexit assumption Gabriele Monaco
2026-07-17 15:46 ` [PATCH v4 16/17] selftests/verification: Rearrange the wwnr_printk test Gabriele Monaco
2026-07-20 11:01   ` Nam Cao
2026-07-21  6:24   ` Gabriele Monaco
2026-07-17 15:46 ` [PATCH v4 17/17] selftests/verification: Add selftests for deadline and stall monitors Gabriele Monaco
2026-07-20 11:03   ` Nam Cao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox