rtla: add tests for tracefs instance cleanup
Subsystems (2)
PATCH 1/1 rtla: add tests for tracefs instance cleanup
rtla creates one of four tracefs instances per run (osnoise_top, osnoise_hist, timerlat_top, timerlat_hist) and removes it on exit. A cleanup failure only shows up as the next run failing with -EEXIST or stale tracer state. tests/engine.sh already removes leftover instances before each test, so the failure mode is known but not tested.
Add cleanup.t and a helper script covering the abnormal exits: SIGINT, SIGTERM, the -d timer, a failing --on-threshold shell action, and three interrupted runs followed by a normal run.
rtla did not handle SIGTERM, so killing it left the tracefs instance behind. Install stop_trace as the SIGTERM handler, matching SIGINT and the -d timer.
The helper needs to start rtla in the background and signal it, which engine.sh's foreground check() cannot express. cleanup.t drives the helper and emits the TAP result itself.
The test needs root, a writable tracefs and CONFIG_OSNOISE_TRACER. It skips when any of those are missing. The action-failure case also skips if the stop-total threshold is not crossed, since an idle machine may never generate a sample above the limit.
--- tools/tracing/rtla/src/common.c | 2 + tools/tracing/rtla/tests/cleanup.t | 71 +++++++ .../rtla/tests/scripts/check-cleanup.sh | 197 ++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 tools/tracing/rtla/tests/cleanup.t create mode 100755 tools/tracing/rtla/tests/scripts/check-cleanup.sh
tools/tracing/rtla/src/common.c +2 -0
@@ -39,6 +39,7 @@ static void stop_trace(int sig)static void set_signals (struct common_params *params) {signal (SIGINT , stop_trace); +signal (SIGTERM , stop_trace);if (params->duration) {signal (SIGALRM , stop_trace);alarm (params->duration);
@@ -51,6 +52,7 @@ static void set_signals(struct common_params *params)static void unset_signals (struct common_params *params) {signal (SIGINT ,SIG_DFL ); +signal (SIGTERM ,SIG_DFL );if (params->duration) {alarm (0 );signal (SIGALRM ,SIG_DFL );
tools/tracing/rtla/tests/cleanup.t new file +71 -0
71 lines not on this page · raw message
tools/tracing/rtla/tests/scripts/check-cleanup.sh new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] rtla: subcase SKIP treated as group skip in run_cleanup_cases() - [Medium] rtla: tests: invalid…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] rtla: subcase SKIP treated as group skip in run_cleanup_cases()
- [Medium] rtla: tests: invalid --version check in check-cleanup.sh skips all tests --
commit 39ad3784406cff716e91c58adc60f6311f089ea0
Author: Chaosheng Qu <[email protected]>
rtla: add tests for tracefs instance cleanup
This commit adds a SIGTERM handler to rtla so tracefs instances are cleaned up on termination, along with a new test suite verifying tracefs instance cleanup across abnormal exit paths.
Quoted 6 lines
tools/tracing/rtla/tests/cleanup.t new file +0
-0@@ -0,0 +1,71 @@
[ ... ]
Quoted 1 line
+run_cleanup_cases() {
[ ... ]
Quoted 4 lines
tools/tracing/rtla/tests/cleanup.t new file +4
-0+ out=$($timeout_cmd "$helper" "$RTLA" 2>&1) + rc=$? + if [ $rc -eq 0 ]; then + # The helper may skip individual cases; a group-level SKIP means it
tools/tracing/rtla/tests/cleanup.t line 56
Quoted 10 lines
tools/tracing/rtla/tests/cleanup.t new file +10
-0+ # could not run at all. + skip=$(printf '%s\n' "$out" | sed -n 's/^SKIP: //p' | head -n 1) + if [ -n "$skip" ]; then + echo "ok $ctr - instances cleaned up on SIGINT, timeout and action failure # SKIP $skip" + return + fi + printf '%s\n' "$out" | grep '^SKIP: ' | while read -r line; do + echo "# ${line}" + done + echo "ok $ctr - instances cleaned up on SIGINT, timeout and action failure"
[Severity: Medium]
In run_cleanup_cases(), sed -n 's/^SKIP: //p' matches any line in $out starting with "SKIP: ". When the action-failure subtest in tools/tracing/rtla/tests/scripts/check-cleanup.sh does not cross the stop-total threshold on an idle system, it logs:
if [ "$action_rc" -eq 0 ]; then log "SKIP: action-failure: stop-total threshold was not crossed"
Won't $skip be populated from that subtest skip even when all other subtests ran and passed, causing run_cleanup_cases() to report the entire TAP test as skipped and leaving the grep '^SKIP: ' loop right below it unreachable?
[ ... ]
Quoted 6 lines
tools/tracing/rtla/tests/scripts/check-cleanup.sh new file +0
-0@@ -0,0 +1,197 @@
[ ... ]
tools/tracing/rtla/tests/scripts/check-cleanup.sh line 64
Quoted 7 lines
tools/tracing/rtla/tests/scripts/check-cleanup.sh new file +7
-0+# Leave nothing behind from the test before it starts, and make sure the +# command under test is actually usable. +cleanup_all +if ! "$RTLA" --version >/dev/null 2>&1; then + log "SKIP: $RTLA is not usable" + exit 0 +fi
[Severity: Medium]
Does rtla support the --version flag? Looking at main() in tools/tracing/rtla/src/cli.c:
if (strcmp(argv[1], "-h") == 0) rtla_usage(129); else if (strcmp(argv[1], "--help") == 0) rtla_usage(129); retval = run_tool_command(argc, argv, 1); if (retval) exit(0);
usage:
rtla_usage(129);
It looks like passing --version falls through to rtla_usage(129) and exits with status 129. Won't this check always fail and cause check-cleanup.sh to skip the entire test suite on every run?
[ ... ]
────
To understand more about how the conclusions weredrawn,Normally:
- Stage 1 (goal): VF1
- Stage 2 (implementation): PVF1
────
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1