xref: /linux/tools/verification/rv/tests/rv_mon.t (revision 55ee4b931a7ffedc886175d265dd6e6d08fd4151)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3source ../tests/engine.sh
4test_begin
5
6set_timeout 30s
7
8RVDIR=/sys/kernel/tracing/rv/
9
10# Help and basic tests
11check "verify mon subcommand help" \
12	"$RV mon --help" 0 "run a monitor"
13
14# Error handling tests
15check "mon without monitor name" \
16	"$RV mon" 1 "usage: rv mon"
17
18check "invalid monitor name" \
19	"$RV mon invalid" 1 "monitor invalid does not exist"
20
21if [ -d $RVDIR/monitors/wwnr ]; then
22
23check "invalid reactor name" \
24	"$RV mon wwnr -r invalid" 1 "failed to set invalid reactor, is it available?"
25
26check "monitor name is substring of another monitor" \
27	"$RV mon nr" 1 "monitor nr does not exist"
28
29check "already enabled monitor returns error" \
30	"echo 1 > $RVDIR/monitors/wwnr/enable; $RV mon wwnr" 1 \
31	"monitor wwnr (in-kernel) is already enabled"
32echo 0 > $RVDIR/monitors/wwnr/enable
33
34fi
35
36# rv mon runs until terminated
37set_expected_timeout 2s
38
39# Run monitors with different configurations
40check_if_exists "run the monitor without parameters" \
41	"$RV mon wwnr" "$RVDIR/monitors/wwnr" "" "."
42
43check_if_exists "run the monitor as verbose" \
44	"$RV mon wwnr -v" "$RVDIR/monitors/wwnr" \
45	"my pid is \$pid" "\(event\|error\)"
46
47check_if_exists "run the monitor with a reactor" \
48	"$RV mon wwnr -r printk & sleep .5 && cat $RVDIR/monitors/wwnr/reactors && wait" \
49	"$RVDIR/monitors/wwnr/reactors" "\[printk\]"
50
51check_if_exists "reactor is restored after exit" \
52	"cat $RVDIR/monitors/wwnr/reactors" \
53	"$RVDIR/monitors/wwnr/reactors" "\[nop\]"
54
55check_if_exists "run a nested monitor with a reactor" \
56	"$RV mon snroc -r printk & sleep .5 && cat $RVDIR/monitors/sched/snroc/reactors && wait" \
57	"$RVDIR/monitors/sched/snroc/reactors" "\[printk\]"
58
59check_if_exists "run an explicitly nested monitor with a reactor" \
60	"$RV mon sched:sssw -r printk & sleep .5 && cat $RVDIR/monitors/sched/sssw/reactors && wait" \
61	"$RVDIR/monitors/sched/sssw/reactors" "\[printk\]"
62
63check_if_exists "run container monitor" \
64	"$RV mon sched & sleep .5 && cat $RVDIR/monitors/sched/{sssw,sco}/enable && wait" \
65	"$RVDIR/monitors/sched" "1" "0" "^1$"
66
67# Regexes for the trace
68header="^[[:space:]]\+\(\([][A-Z_x<>-]\+\||\)[[:space:]]*\)\+$"
69type="\(event\|error\)[[:space:]]\+"
70genpid="[0-9]\+[[:space:]]\+"
71selfpid="\$pid[[:space:]]\+"
72cpu="\[[0-9]\{3\}\][[:space:]]\+"
73state="[a-z_]\+ "
74trace_task="${genpid}${cpu}${type}${genpid}${state}"
75trace_task_self="${genpid}${cpu}${type}${selfpid}${state}"
76trace_cpu="${genpid}${cpu}${type}${state}"
77trace_cpu_self="${selfpid}${cpu}${type}${state}"
78
79check_if_exists "run per-task monitor with tracing" \
80	"$RV mon sssw -t" "$RVDIR/monitors/sched/sssw" \
81	"$header" "$trace_task_self" "\($header\|$trace_task\)"
82
83check_if_exists "run per-task monitor tracing also self" \
84	"$RV mon sched:sssw -t -s" "$RVDIR/monitors/sched/sssw" \
85	"$trace_task_self" "" "\($header\|$trace_task\)"
86
87check_if_exists "run per-cpu monitor with tracing" \
88	"$RV mon sched:sco -t" "$RVDIR/monitors/sched/sco" \
89	"$header" "$trace_cpu_self" "\($header\|$trace_cpu\)"
90
91check_if_exists "run per-cpu monitor tracing also self" \
92	"$RV mon sco -t -s" "$RVDIR/monitors/sched/sco" \
93	"$trace_cpu_self" "" "\($header\|$trace_cpu\)"
94
95test_end
96