Re: [PATCH v4 2/2] rtla/tests: cover cleanup on abnormal exits
From: Tomas Glozar
Date: Thu Dec 03 2026 - 05:31:15 EST
On Sat, Nov 21, 2026 at 1:04 PM Chaosheng Qu
<chaosheng.qu.linux@xxxxxxxxx> wrote:
>
> rtla creates a tracefs instance for each run and removes it on the way
> out. Nothing verifies that, and a leaked instance only shows up as a
> confusing failure of the next run.
>
> Add a test for the paths users actually hit: SIGINT, SIGTERM, rtla's own
> -d timer, a failing --on-threshold action, and several interrupted runs
> followed by a normal one. These need rtla running in the background
> while the test signals it, which engine.sh's check() cannot express, so
> cleanup.t drives a helper script and emits TAP itself.
>
> The instance directory is created before set_signals() runs, so the
> helper waits until /proc/<pid>/status reports SIGTERM in SigCgt before it
> signals; waiting for the directory alone races startup.
>
> The test needs root, tracefs and CONFIG_OSNOISE_TRACER, and skips when
> tracefs is not writable.
>
> Signed-off-by: Chaosheng Qu <chaosheng.qu.linux@xxxxxxxxx>
> ---
> tools/tracing/rtla/tests/cleanup.t | 70 ++++++
> .../rtla/tests/scripts/check-cleanup.sh | 219 ++++++++++++++++++
> 2 files changed, 289 insertions(+)
> create mode 100644 tools/tracing/rtla/tests/cleanup.t
> create mode 100755 tools/tracing/rtla/tests/scripts/check-cleanup.sh
>
> [cut]
engine.sh's check() already uses the timeout command, which sends a
signal to the child rtla process after a set time elapses.
set_timeout() / unset_timeout() functions set the TIMEOUT variable,
which determines the exact timeout command used by check(). An
extended function, e.g. set_timeout_signal() taking the signal as a
second argument, can be used to pass a different signal to timeout.
I suggest checking for the instance clean-up unconditionally for all
test cases in check(), to make sure all kinds of combinations clean up
the instances (this will not catch instances left over from before the
tests run, as check() cleans up instances in the beginning with
reset_osnoise()). All of the paths you mention will then be testable
using check():
- SIGINT will use set_timeout_signal().
- SIGTERM will use a run without -d/--duration and with a lower
timeout (e.g. 10s, just to make sure rtla gets to starting the
measurement).
- for rtla's own -d timer, a general test case for the -d/--duration
option, combined with a timeout slightly larger than the duration,
will now also check cleanup automatically.
- a failing --on-threshold action is covered by "... stop at failed
action" tests.
- Several interrupted runs followed by a normal one should already be
covered by reset_osnoise().
Overall, this should cover all of your cleanup cases and more, without
duplicating functionality that already exists in either the test code
or the timeout command. The only downside I can see is that relying on
the timeout might be racy, but that is unlikely in practice, and a
small price to pay for much simpler test implementation. This should
be doable in three steps / patches:
- Test instance cleanup in check() - covers cleanup in existing test cases.
- -d/--duration test.
- set_timeout_signal() implementation.
- SIGINT test using set_timeout_signal().
Does that sound reasonable?
Tomas