Skip to content

Commit ab16714

Browse files
lenticularis39rostedt
authored andcommitted
tools/rtla: Add basic test suite
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>
1 parent 87c5d7f commit ab16714

File tree

5 files changed

+118
-1
lines changed

5 files changed

+118
-1
lines changed

tools/tracing/rtla/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@ clean: doc_clean fixdep-clean
8585
$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
8686
$(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
8787
$(Q)rm -rf feature
88-
.PHONY: FORCE clean
88+
check: $(RTLA)
89+
RTLA=$(RTLA) prove -o -f tests/
90+
.PHONY: FORCE clean check

tools/tracing/rtla/tests/engine.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
test_begin() {
4+
# Count tests to allow the test harness to double-check if all were
5+
# included correctly.
6+
ctr=0
7+
[ -z "$RTLA" ] && RTLA="./rtla"
8+
[ -n "$TEST_COUNT" ] && echo "1..$TEST_COUNT"
9+
}
10+
11+
check() {
12+
# Simple check: run rtla with given arguments and test exit code.
13+
# If TEST_COUNT is set, run the test. Otherwise, just count.
14+
ctr=$(($ctr + 1))
15+
if [ -n "$TEST_COUNT" ]
16+
then
17+
# Run rtla; in case of failure, include its output as comment
18+
# in the test results.
19+
result=$(stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$?
20+
if [ $exitcode -eq 0 ]
21+
then
22+
echo "ok $ctr - $1"
23+
else
24+
echo "not ok $ctr - $1"
25+
# Add rtla output and exit code as comments in case of failure
26+
echo "$result" | col -b | while read line; do echo "# $line"; done
27+
printf "#\n# exit code %s\n" $exitcode
28+
fi
29+
fi
30+
}
31+
32+
set_timeout() {
33+
TIMEOUT="timeout -v -k 15s $1"
34+
}
35+
36+
unset_timeout() {
37+
unset TIMEOUT
38+
}
39+
40+
test_end() {
41+
# If running without TEST_COUNT, tests are not actually run, just
42+
# counted. In that case, re-run the test with the correct count.
43+
[ -z "$TEST_COUNT" ] && TEST_COUNT=$ctr exec bash $0 || true
44+
}
45+
46+
# Avoid any environmental discrepancies
47+
export LC_ALL=C
48+
unset_timeout

tools/tracing/rtla/tests/hwnoise.t

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
source tests/engine.sh
4+
test_begin
5+
6+
set_timeout 2m
7+
8+
check "verify help page" \
9+
"hwnoise --help"
10+
check "detect noise higher than one microsecond" \
11+
"hwnoise -c 0 -T 1 -d 5s -q"
12+
check "set the automatic trace mode" \
13+
"hwnoise -a 5 -d 30s"
14+
check "set scheduling param to the osnoise tracer threads" \
15+
"hwnoise -P F:1 -c 0 -r 900000 -d 1M -q"
16+
check "stop the trace if a single sample is higher than 1 us" \
17+
"hwnoise -s 1 -T 1 -t -d 30s"
18+
check "enable a trace event trigger" \
19+
"hwnoise -t -e osnoise:irq_noise trigger=\"hist:key=desc,duration:sort=desc,duration:vals=hitcount\" -d 1m"
20+
21+
test_end

tools/tracing/rtla/tests/osnoise.t

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
source tests/engine.sh
4+
test_begin
5+
6+
set_timeout 2m
7+
8+
check "verify help page" \
9+
"osnoise --help"
10+
check "verify the --priority/-P param" \
11+
"osnoise top -P F:1 -c 0 -r 900000 -d 1M -q"
12+
check "verify the --stop/-s param" \
13+
"osnoise top -s 30 -T 1 -t"
14+
check "verify the --trace param" \
15+
"osnoise hist -s 30 -T 1 -t"
16+
check "verify the --entries/-E param" \
17+
"osnoise hist -P F:1 -c 0 -r 900000 -d 1M -b 10 -E 25"
18+
19+
test_end

tools/tracing/rtla/tests/timerlat.t

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
source tests/engine.sh
4+
test_begin
5+
6+
set_timeout 2m
7+
8+
check "verify help page" \
9+
"timerlat --help"
10+
check "verify -s/--stack" \
11+
"timerlat top -s 3 -T 10 -t"
12+
check "verify -P/--priority" \
13+
"timerlat top -P F:1 -c 0 -d 1M -q"
14+
check "test in nanoseconds" \
15+
"timerlat top -i 2 -c 0 -n -d 30s"
16+
check "set the automatic trace mode" \
17+
"timerlat top -a 5 --dump-tasks"
18+
check "print the auto-analysis if hits the stop tracing condition" \
19+
"timerlat top --aa-only 5"
20+
check "disable auto-analysis" \
21+
"timerlat top -s 3 -T 10 -t --no-aa"
22+
check "verify -c/--cpus" \
23+
"timerlat hist -c 0 -d 30s"
24+
check "hist test in nanoseconds" \
25+
"timerlat hist -i 2 -c 0 -n -d 30s"
26+
27+
test_end

0 commit comments

Comments
 (0)