| 1 |
#!/bin/bash |
| 2 |
# SPDX-License-Identifier: GPL-2.0 |
| 3 |
source tests/engine.sh |
| 4 |
test_begin |
| 5 |
|
| 6 |
set_timeout 2m |
| 7 |
timerlat_sample_event='/sys/kernel/tracing/events/osnoise/timerlat_sample' |
| 8 |
|
| 9 |
if ldd $RTLA | grep libbpf >/dev/null && [ -d "$timerlat_sample_event" ] |
| 10 |
then |
| 11 |
# rtla build with BPF and system supports BPF mode |
| 12 |
no_bpf_options='0 1' |
| 13 |
else |
| 14 |
no_bpf_options='1' |
| 15 |
fi |
| 16 |
|
| 17 |
# Do every test with and without BPF |
| 18 |
for option in $no_bpf_options |
| 19 |
do |
| 20 |
export RTLA_NO_BPF=$option |
| 21 |
|
| 22 |
# Basic tests |
| 23 |
check "verify help page" \ |
| 24 |
"timerlat --help" 0 "timerlat version" |
| 25 |
check "verify -s/--stack" \ |
| 26 |
"timerlat top -s 3 -T 10 -t" 2 "Blocking thread stack trace" |
| 27 |
check "verify -P/--priority" \ |
| 28 |
"timerlat top -P F:1 -c 0 -d 10s -q -T 1 --on-threshold shell,command=\"tests/scripts/check-priority.sh timerlatu/ SCHED_FIFO 1\"" \ |
| 29 |
2 "Priorities are set correctly" |
| 30 |
check "test in nanoseconds" \ |
| 31 |
"timerlat top -i 2 -c 0 -n -d 10s" 2 "ns" |
| 32 |
check "set the automatic trace mode" \ |
| 33 |
"timerlat top -a 5" 2 "analyzing it" |
| 34 |
check "dump tasks" \ |
| 35 |
"timerlat top -a 5 --dump-tasks" 2 "Printing CPU tasks" |
| 36 |
check "print the auto-analysis if hits the stop tracing condition" \ |
| 37 |
"timerlat top --aa-only 5" 2 |
| 38 |
check "disable auto-analysis" \ |
| 39 |
"timerlat top -s 3 -T 10 -t --no-aa" 2 |
| 40 |
check "verify -c/--cpus" \ |
| 41 |
"timerlat hist -c 0 -d 10s" |
| 42 |
check "hist test in nanoseconds" \ |
| 43 |
"timerlat hist -i 2 -c 0 -n -d 10s" 2 "ns" |
| 44 |
|
| 45 |
# Actions tests |
| 46 |
check "trace output through -t" \ |
| 47 |
"timerlat hist -T 2 -t" 2 "^ Saving trace to timerlat_trace.txt$" |
| 48 |
check "trace output through -t with custom filename" \ |
| 49 |
"timerlat hist -T 2 -t custom_filename.txt" 2 "^ Saving trace to custom_filename.txt$" |
| 50 |
check "trace output through --on-threshold trace" \ |
| 51 |
"timerlat hist -T 2 --on-threshold trace" 2 "^ Saving trace to timerlat_trace.txt$" |
| 52 |
check "trace output through --on-threshold trace with custom filename" \ |
| 53 |
"timerlat hist -T 2 --on-threshold trace,file=custom_filename.txt" 2 "^ Saving trace to custom_filename.txt$" |
| 54 |
check "exec command" \ |
| 55 |
"timerlat hist -T 2 --on-threshold shell,command='echo TestOutput'" 2 "^TestOutput$" |
| 56 |
check "multiple actions" \ |
| 57 |
"timerlat hist -T 2 --on-threshold shell,command='echo -n 1' --on-threshold shell,command='echo 2'" 2 "^12$" |
| 58 |
check "hist stop at failed action" \ |
| 59 |
"timerlat hist -T 2 --on-threshold shell,command='echo -n 1; false' --on-threshold shell,command='echo -n 2'" 2 "^1# RTLA timerlat histogram$" |
| 60 |
check "top stop at failed action" \ |
| 61 |
"timerlat top -T 2 --on-threshold shell,command='echo -n abc; false' --on-threshold shell,command='echo -n defgh'" 2 "^abc" "defgh" |
| 62 |
check "hist with continue" \ |
| 63 |
"timerlat hist -T 2 -d 5s --on-threshold shell,command='echo TestOutput' --on-threshold continue" 0 "^TestOutput$" |
| 64 |
check "top with continue" \ |
| 65 |
"timerlat top -q -T 2 -d 5s --on-threshold shell,command='echo TestOutput' --on-threshold continue" 0 "^TestOutput$" |
| 66 |
check "hist with trace output at end" \ |
| 67 |
"timerlat hist -d 1s --on-end trace" 0 "^ Saving trace to timerlat_trace.txt$" |
| 68 |
check "top with trace output at end" \ |
| 69 |
"timerlat top -d 1s --on-end trace" 0 "^ Saving trace to timerlat_trace.txt$" |
| 70 |
|
| 71 |
# BPF action program tests |
| 72 |
if [ "$option" -eq 0 ] |
| 73 |
then |
| 74 |
# Test BPF action program properly in BPF mode |
| 75 |
[ -z "$BPFTOOL" ] && BPFTOOL=bpftool |
| 76 |
check "hist with BPF action program (BPF mode)" \ |
| 77 |
"timerlat hist -T 2 --bpf-action tests/bpf/bpf_action_map.o --on-threshold shell,command='$BPFTOOL map dump name rtla_test_map'" \ |
| 78 |
2 '"value": 42' |
| 79 |
else |
| 80 |
# Test BPF action program failure in non-BPF mode |
| 81 |
check "hist with BPF action program (non-BPF mode)" \ |
| 82 |
"timerlat hist -T 2 --bpf-action tests/bpf/bpf_action_map.o" \ |
| 83 |
1 "BPF actions are not supported in tracefs-only mode" |
| 84 |
fi |
| 85 |
done |
| 86 |
|
| 87 |
test_end |