Files
linux/tools/tracing/rtla/tests/engine.sh
Tomas Glozar ab16714fcb 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>
2025-01-23 12:21:45 -05:00

49 lines
1.2 KiB
Bash

#!/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