[PATCH 13/17] rcutorture: Test NMI coverage result classification
From: Kunwu Chan
Date: Tue Dec 01 2026 - 11:21:39 EST
Verify the NMI checker in readers, calls and both modes. Cover
unexercised paths, readers that did not sample an object, too-old object
samples and callback counts that disagree after cleanup.
Signed-off-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
---
.../rcutorture/bin/kvm-recheck-nmi-test.sh | 80 +++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
new file mode 100755
index 000000000000..5a3acea8c60b
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck-nmi-test.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+# Exercise the NMI coverage checker, including untested and broken cases.
+#
+# Author: Kunwu Chan <kunwu.chan@xxxxxxxxx>
+
+bindir="$(dirname "$0")"
+t="$(mktemp -d "${TMPDIR-/tmp}/kvm-recheck-nmi-test.XXXXXX")" || exit 1
+trap 'rm -rf "$t"' EXIT
+nfailed=0
+ntested=0
+
+check () {
+ local name="$1" expected="$2" mode="$3" actual
+ ntested=$((ntested + 1))
+ cat > "$t/console.log"
+ bash "$bindir/kvm-recheck-nmi.sh" "$t" "$mode" > "$t/output" 2>&1
+ actual=$?
+ if test "$actual" -ne "$expected"
+ then
+ echo "FAIL: $name returned $actual, expected $expected"
+ cat "$t/output"
+ nfailed=$((nfailed + 1))
+ fi
+}
+
+check covered 0 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check no-nmi 4 both <<'EOF'
+srcud-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=0 callbacks=0
+srcud-torture:--- End of test: SUCCESS
+EOF
+check callbacks-only-not-readers 4 both <<'EOF'
+srcud-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check readers-only-not-callbacks 4 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=0 callbacks=0
+srcud-torture:--- End of test: SUCCESS
+EOF
+check no-object-sample 4 readers <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=0 too-old=0 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check readers-only 0 readers <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=0 callbacks=0
+srcud-torture:--- End of test: SUCCESS
+EOF
+check callbacks-only 0 calls <<'EOF'
+rcu-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=2 callbacks=2
+rcu-torture:--- End of test: SUCCESS
+EOF
+check too-old 1 readers <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=1 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check too-old-in-calls-mode 1 calls <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=1 calls=2 callbacks=2
+srcud-torture:--- End of test: SUCCESS
+EOF
+check missing-callback 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=2 callbacks=1
+srcud-torture:--- End of test: SUCCESS
+EOF
+check missing-callback-without-readers 1 both <<'EOF'
+srcud-torture: NMI coverage: reads=0 samples=0 too-old=0 calls=2 callbacks=1
+srcud-torture:--- End of test: SUCCESS
+EOF
+check excess-callback 1 calls <<'EOF'
+srcud-torture: NMI coverage: reads=3 samples=3 too-old=0 calls=0 callbacks=1
+srcud-torture:--- End of test: SUCCESS
+EOF
+
+if test "$nfailed" -ne 0
+then
+ exit 1
+fi
+echo "PASS: $ntested NMI coverage checker cases"
--
2.43.0