]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools/rtla: Add basic test suite
authorTomas Glozar <tglozar@redhat.com>
Mon, 20 Jan 2025 13:56:30 +0000 (14:56 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Thu, 23 Jan 2025 17:21:45 +0000 (12:21 -0500)
Implement a simple TAP-based test engine in bash and a few basic tests
using it, to be used to check for bugs and regressions.

A new "check" target is added to the rtla Makefile that runs the test suite
using the "prove" command implemented by Test::Harness.

The only test format currently supported is running rtla with defined
command arguments per test, checking its exit code. In case the exit
code is non-zero, the output of rtla is displayed, together with the
exit code.

The test cases are adopted from rtla tests in the Continuous Kernel
Integration (CKI) project [1] with the authors' approval.

[1] https://gitlab.com/redhat/centos-stream/tests/kernel/kernel-tests/-/blob/main/rt-tests/us/rtla/

Cc: John Kacur <jkacur@redhat.com>
Cc: Luis Goncalves <lgoncalv@redhat.com>
Cc: Chang Yin <cyin@redhat.com>
Cc: Qiao Zhao <qzhao@redhat.com>
Link: https://lore.kernel.org/20250120135630.802111-1-tglozar@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
tools/tracing/rtla/Makefile
tools/tracing/rtla/tests/engine.sh [new file with mode: 0644]
tools/tracing/rtla/tests/hwnoise.t [new file with mode: 0644]
tools/tracing/rtla/tests/osnoise.t [new file with mode: 0644]
tools/tracing/rtla/tests/timerlat.t [new file with mode: 0644]

index a6a7dee16622d2b916de34c19b4960dafc113978..8b5101457c70b48e9c720f1ba53293f1307c15a2 100644 (file)
@@ -85,4 +85,6 @@ clean: doc_clean fixdep-clean
        $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
        $(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
        $(Q)rm -rf feature
-.PHONY: FORCE clean
+check: $(RTLA)
+       RTLA=$(RTLA) prove -o -f tests/
+.PHONY: FORCE clean check
diff --git a/tools/tracing/rtla/tests/engine.sh b/tools/tracing/rtla/tests/engine.sh
new file mode 100644 (file)
index 0000000..64d0446
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+test_begin() {
+       # Count tests to allow the test harness to double-check if all were
+       # included correctly.
+       ctr=0
+       [ -z "$RTLA" ] && RTLA="./rtla"
+       [ -n "$TEST_COUNT" ] && echo "1..$TEST_COUNT"
+}
+
+check() {
+       # Simple check: run rtla with given arguments and test exit code.
+       # If TEST_COUNT is set, run the test. Otherwise, just count.
+       ctr=$(($ctr + 1))
+       if [ -n "$TEST_COUNT" ]
+       then
+               # Run rtla; in case of failure, include its output as comment
+               # in the test results.
+               result=$(stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$?
+               if [ $exitcode -eq 0 ]
+               then
+                       echo "ok $ctr - $1"
+               else
+                       echo "not ok $ctr - $1"
+                       # Add rtla output and exit code as comments in case of failure
+                       echo "$result" | col -b | while read line; do echo "# $line"; done
+                       printf "#\n# exit code %s\n" $exitcode
+               fi
+       fi
+}
+
+set_timeout() {
+       TIMEOUT="timeout -v -k 15s $1"
+}
+
+unset_timeout() {
+       unset TIMEOUT
+}
+
+test_end() {
+       # If running without TEST_COUNT, tests are not actually run, just
+       # counted. In that case, re-run the test with the correct count.
+       [ -z "$TEST_COUNT" ] && TEST_COUNT=$ctr exec bash $0 || true
+}
+
+# Avoid any environmental discrepancies
+export LC_ALL=C
+unset_timeout
diff --git a/tools/tracing/rtla/tests/hwnoise.t b/tools/tracing/rtla/tests/hwnoise.t
new file mode 100644 (file)
index 0000000..bbed175
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+source tests/engine.sh
+test_begin
+
+set_timeout 2m
+
+check "verify help page" \
+       "hwnoise --help"
+check "detect noise higher than one microsecond" \
+       "hwnoise -c 0 -T 1 -d 5s -q"
+check "set the automatic trace mode" \
+       "hwnoise -a 5 -d 30s"
+check "set scheduling param to the osnoise tracer threads" \
+       "hwnoise -P F:1 -c 0 -r 900000 -d 1M -q"
+check "stop the trace if a single sample is higher than 1 us" \
+       "hwnoise -s 1 -T 1 -t -d 30s"
+check "enable a trace event trigger" \
+       "hwnoise -t -e osnoise:irq_noise trigger=\"hist:key=desc,duration:sort=desc,duration:vals=hitcount\" -d 1m"
+
+test_end
diff --git a/tools/tracing/rtla/tests/osnoise.t b/tools/tracing/rtla/tests/osnoise.t
new file mode 100644 (file)
index 0000000..86596e5
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+source tests/engine.sh
+test_begin
+
+set_timeout 2m
+
+check "verify help page" \
+       "osnoise --help"
+check "verify the --priority/-P param" \
+       "osnoise top -P F:1 -c 0 -r 900000 -d 1M -q"
+check "verify the --stop/-s param" \
+       "osnoise top -s 30 -T 1 -t"
+check "verify the  --trace param" \
+       "osnoise hist -s 30 -T 1 -t"
+check "verify the --entries/-E param" \
+       "osnoise hist -P F:1 -c 0 -r 900000 -d 1M -b 10 -E 25"
+
+test_end
diff --git a/tools/tracing/rtla/tests/timerlat.t b/tools/tracing/rtla/tests/timerlat.t
new file mode 100644 (file)
index 0000000..e86f40e
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+source tests/engine.sh
+test_begin
+
+set_timeout 2m
+
+check "verify help page" \
+       "timerlat --help"
+check "verify -s/--stack" \
+       "timerlat top -s 3 -T 10 -t"
+check "verify -P/--priority" \
+       "timerlat top -P F:1 -c 0 -d 1M -q"
+check "test in nanoseconds" \
+       "timerlat top -i 2 -c 0 -n -d 30s"
+check "set the automatic trace mode" \
+       "timerlat top -a 5 --dump-tasks"
+check "print the auto-analysis if hits the stop tracing condition" \
+       "timerlat top --aa-only 5"
+check "disable auto-analysis" \
+       "timerlat top -s 3 -T 10 -t --no-aa"
+check "verify -c/--cpus" \
+       "timerlat hist -c 0 -d 30s"
+check "hist test in nanoseconds" \
+       "timerlat hist -i 2 -c 0 -n -d 30s"
+
+test_end