Commit Graph
20 Commits
Author SHA1 Message Date
Costa Shulyupin 115b06a008 tools/rtla: Consolidate nr_cpus usage across all tools
sysconf(_SC_NPROCESSORS_CONF) (via get_nprocs_conf) reflects
cpu_possible_mask, which is fixed at boot time, so querying it
repeatedly is unnecessary.

Replace multiple calls to sysconf(_SC_NPROCESSORS_CONF) with a single
global nr_cpus variable initialized once at startup.

`#pragma once` in timerlat_u.h is needed for pre-C23 compilers to avoid
redefinition errors.

Signed-off-by: Costa Shulyupin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
2026-03-09 08:49:16 +01:00
Costa Shulyupin 3a4080e5e4 tools/rtla: Add unit tests for utils.c
Add unit tests for utility functions in src/utils.c using the Check
testing framework. The tests verify parse_cpu_set(), strtoi(), and
parse_prio() functions.

Unit tests are built conditionally when libcheck is available.
Run tests with 'make unit-test'.

The test framework uses the Check library which provides process
isolation for each test, preventing failures in one test from
affecting others.

Signed-off-by: Costa Shulyupin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
2026-03-04 15:51:56 +01:00
Tomas Glozar fbb8ed6682 rtla/tests: Run Test::Harness in verbose mode
Add -v flag to prove command to also print the names of tests that
succeeded, not only those that failed, to allow easier debugging of the
test suite.

Also, drop printing the option and value to stdout in
check_with_osnoise_options, which was a debugging print that was
accidentally left in the final commit, and which would be otherwise now
visible in make check output, as stdout is no longer suppressed.

Suggested-by: Crystal Wood <[email protected]>
Reviewed-by: Wander Lairson Costa <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
2026-01-07 15:57:16 +01:00
Tomas Glozar 5525aebd4e rtla/tests: Test BPF action program
Add a test that implements a BPF program writing to a test map, which
is attached to RTLA via --bpf-action to be executed on theshold
overflow.

A combination of --on-threshold shell with bpftool (which is always
present if BPF support is enabled) is used to check whether the BPF
program has executed successfully.

Suggested-by: Crystal Wood <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
2026-01-07 15:57:16 +01:00
Crystal Wood 61f1fd5d69 rtla/tests: Don't rely on matching ^1ALL
The timerlat "top stop at failed action" test was relying on "ALL" being
printed immediately after the "1" from the threshold action.  Besides being
fragile, this depends on stdbuf behavior, which is easy to miss when
recreating the test outside of the framework for debugging purposes.

Instead, use the expected/unexpected text mechanism from the
corresponding osnoise test.

Signed-off-by: Crystal Wood <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
2025-11-21 10:30:27 +01:00
Tomas Glozar 34c170ae5c rtla/tests: Fix osnoise test calling timerlat
osnoise test "top stop at failed action" is calling timerlat instead of
osnoise by mistake.

Fix it so that it calls the correct RTLA subcommand.

Fixes: 05b7e10687 ("tools/rtla: Add remaining support for osnoise actions")
Reviewed-by: Wander Lairson Costa <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
2025-11-21 10:30:00 +01:00
Tomas Glozar d649e9f04c rtla/tests: Extend action tests to 5s
In non-BPF mode, it takes up to 1 second for RTLA to notice that tracing
has been stopped. That means that action tests cannot have a 1 second
duration, as the SIGALRM will be racing with the threshold overflow.

Previously, non-BPF mode actions were buggy and always executed
the action, even when stopping on duration or SIGINT, preventing
this issue from manifesting. Now that this has been fixed, the tests
have become flaky, and this has to be adjusted.

Fixes: 4e26f84abf ("rtla/tests: Add tests for actions")
Fixes: 05b7e10687 ("tools/rtla: Add remaining support for osnoise actions")
Reviewed-by: Wander Lairson Costa <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
2025-11-21 10:29:01 +01:00
Crystal Wood 05b7e10687 tools/rtla: Add remaining support for osnoise actions
The basic functionality came with the consolidation; now hook up the
command line options, and add documentation and tests.

Cc: John Kacur <[email protected]>
Cc: Costa Shulyupin <[email protected]>
Link: https://lore.kernel.org/[email protected]
Reviewed-by: Tomas Glozar  <[email protected]>
Signed-off-by: Crystal Wood <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-09-27 04:53:48 -04:00
Crystal Wood 3cd6b18d10 tools/rtla: Add test engine support for unexpected output
Add a check() parameter to indicate which text must not appear in the
output.

Simplify the code so that we can print failures as they happen rather
than trying to figure out what went wrong after printing "not ok".  This
also means that "not ok" gets printed after the info rather than before,
which seems more intuitive anyway.

Cc: John Kacur <[email protected]>
Cc: Costa Shulyupin <[email protected]>
Link: https://lore.kernel.org/[email protected]
Reviewed-by: Tomas Glozar  <[email protected]>
Signed-off-by: Crystal Wood <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-09-27 04:53:21 -04:00
Crystal Wood c4e30c22ba tools/rtla: Fix -A option name in test comment
This was changed to --on-threshold when the patches were applied.

Cc: John Kacur <[email protected]>
Cc: Costa Shulyupin <[email protected]>
Link: https://lore.kernel.org/[email protected]
Reviewed-by: Tomas Glozar  <[email protected]>
Signed-off-by: Crystal Wood <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-09-27 04:53:07 -04:00
Tomas Glozar a80db1f857 rtla/tests: Test timerlat -P option using actions
The -P option is used to set priority of osnoise and timerlat threads.

Extend the test for -P with --on-threshold calling a script that looks
for running timerlat threads and checks if their priority is set
correctly.

As --on-threshold is only supported by timerlat at the moment, this is
only implemented there so far.

Cc: John Kacur <[email protected]>
Cc: Luis Goncalves <[email protected]>
Cc: Chang Yin <[email protected]>
Cc: Costa Shulyupin <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-07-28 10:22:39 -04:00
Tomas Glozar 892ae5f806 rtla/tests: Add grep checks for base test cases
Checking for patterns in rtla output with grep was added to test rtla
actions. Add grep checks also for base tests where applicable.

Also fix trace event histogram trigger check to use the correct syntax
for the command-line option so that the test passes with the grep check.

Cc: John Kacur <[email protected]>
Cc: Luis Goncalves <[email protected]>
Cc: Chang Yin <[email protected]>
Cc: Costa Shulyupin <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-07-28 10:22:38 -04:00
Tomas Glozar 04f837165b rtla/tests: Limit duration to maximum of 10s
Many of the original rtla tests included durations of 1 minute and 30
seconds. Experience has shown this is unnecessary, since 10 seconds as
waiting time for samples to appear.

Change duration of all rtla tests to at most 10 seconds. This speeds up
testing significantly.

Before:
$ make check
All tests successful.
Files=3, Tests=54, 536 wallclock secs
( 0.03 usr  0.00 sys + 20.31 cusr 22.02 csys = 42.36 CPU)
Result: PASS

After:
$ make check
...
All tests successful.
Files=3, Tests=54, 196 wallclock secs
( 0.03 usr  0.01 sys + 20.28 cusr 20.68 csys = 41.00 CPU)
Result: PASS

Cc: John Kacur <[email protected]>
Cc: Luis Goncalves <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Chang Yin <[email protected]>
Cc: Costa Shulyupin <[email protected]>
Cc: Crystal Wood <[email protected]>
Cc: Gabriele Monaco <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-07-25 16:43:57 -04:00
Tomas Glozar 4e26f84abf rtla/tests: Add tests for actions
Add a bunch of tests covering most of both --on-threshold and --on-end.
Parts sensitive to implementation of hist/top are tested for both.

Cc: John Kacur <[email protected]>
Cc: Luis Goncalves <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Chang Yin <[email protected]>
Cc: Costa Shulyupin <[email protected]>
Cc: Crystal Wood <[email protected]>
Cc: Gabriele Monaco <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-07-25 16:43:57 -04:00
Tomas Glozar 916a9c5b03 rtla/tests: Check rtla output with grep
Add argument to the check command in the test suite that takes a regular
expression that the output of rtla command is checked against. This
allows testing for specific information in rtla output in addition
to checking the return value.

Two minor improvements are included: running rtla with "eval" so that
arguments with spaces can be passed to it via shell quotations, and
the stdout of pushd and popd is suppressed to clean up the test output.

Cc: John Kacur <[email protected]>
Cc: Luis Goncalves <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Chang Yin <[email protected]>
Cc: Costa Shulyupin <[email protected]>
Cc: Crystal Wood <[email protected]>
Cc: Gabriele Monaco <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-07-25 16:43:57 -04:00
Costa Shulyupin 18682166f6 rtla: Set distinctive exit value for failed tests
A test is considered failed when a sample trace exceeds the threshold.
Failed tests return the same exit code as passed tests, requiring test
frameworks to determine the result by searching for "hit stop tracing"
in the output.

Assign a distinct exit code for failed tests to enable the use of shell
expressions and seamless integration with testing frameworks without the
need to parse output.

Add enum type for return value.

Update `make check`.

Cc: Daniel Bristot de Oliveira <[email protected]>
Cc: John Kacur <[email protected]>
Cc: "Luis Claudio R. Goncalves" <[email protected]>
Cc: Eder Zulian <[email protected]>
Cc: Dan Carpenter <[email protected]>
Cc: Jan Stancek <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Costa Shulyupin <[email protected]>
Reviewed-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-05-07 15:36:19 -04:00
Tomas Glozar a86150f310 rtla/tests: Test setting default options
Add function to test engine to test with pre-set osnoise options, and
use it to test whether osnoise period (as an example) is set correctly.

The test works by pre-setting a high period of 10 minutes and stop on
threshold. Thus, it is easy to check whether rtla is properly resetting
the period to default: if it is, the test will complete on time, since
the first sample will overflow the threshold. If not, it will time out.

Cc: Luis Goncalves <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Reviewed-by: John Kacur <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-03-26 10:36:39 -04:00
Tomas Glozar 6c6182728a rtla/tests: Reset osnoise options before check
Remove any dangling tracing instances from previous improperly exited
runs of rtla, and reset osnoise options to default before running a test
case.

This ensures that the test results are deterministic. Specific test
cases checked that rtla behaves correctly even when the tracer state is
not clean will be added later.

Cc: John Kacur <[email protected]>
Cc: Luis Goncalves <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-03-26 10:36:39 -04:00
Tomas Glozar 005682b403 rtla/timerlat: Test BPF mode
Using the RTLA_NO_BPF environmental variable, execute rtla-timerlat
tests both with and without BPF support to cover both paths.

If rtla is built without BPF or the osnoise:timerlat_sample trace event
is not available, test only the non-BPF path.

Cc: John Kacur <[email protected]>
Cc: Luis Goncalves <[email protected]>
Cc: Gabriele Monaco <[email protected]>
Cc: Clark Williams <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-03-04 12:35:18 -05:00
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 <[email protected]>
Cc: Luis Goncalves <[email protected]>
Cc: Chang Yin <[email protected]>
Cc: Qiao Zhao <[email protected]>
Link: https://lore.kernel.org/[email protected]
Signed-off-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
2025-01-23 12:21:45 -05:00