xref: /linux/tools/testing/selftests/ftrace/test.d/event/event-no-pid.tc (revision 103f528d3bc35d2b6e726a3fffd879e492d191c2)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: event tracing - restricts events based on pid notrace filtering
4# requires: set_event events/sched set_event_pid set_event_notrace_pid
5# flags: instance
6
7do_reset() {
8    echo > set_event
9    echo > set_event_pid
10    echo > set_event_notrace_pid
11    echo 0 > options/event-fork
12    echo 0 > events/enable
13    clear_trace
14    echo 1 > tracing_on
15}
16
17fail() { #msg
18    cat trace
19    do_reset
20    echo $1
21    exit_fail
22}
23
24count_pid() {
25    pid=$@
26    cat trace | grep -v '^#' | sed -e 's/[^-]*-\([0-9]*\).*/\1/' | grep $pid | wc -l
27}
28
29count_no_pid() {
30    pid=$1
31    cat trace | grep -v '^#' | sed -e 's/[^-]*-\([0-9]*\).*/\1/' | grep -v $pid | wc -l
32}
33
34enable_system() {
35    system=$1
36
37    if [ -d events/$system ]; then
38	echo 1 > events/$system/enable
39    fi
40}
41
42enable_events() {
43    echo 0 > tracing_on
44    # Enable common groups of events, as all events can allow for
45    # events to be traced via scheduling that we don't care to test.
46    enable_system syscalls
47    enable_system rcu
48    enable_system block
49    enable_system exceptions
50    enable_system irq
51    enable_system net
52    enable_system power
53    enable_system signal
54    enable_system sock
55    enable_system timer
56    enable_system thermal
57    echo 1 > tracing_on
58}
59
60echo 0 > options/event-fork
61
62do_reset
63
64read mypid rest < /proc/self/stat
65
66echo $mypid > set_event_notrace_pid
67grep -q $mypid set_event_notrace_pid
68
69enable_events
70
71yield
72
73echo 0 > tracing_on
74
75cnt=`count_pid $mypid`
76if [ $cnt -ne 0 ]; then
77    fail "Filtered out task has events"
78fi
79
80cnt=`count_no_pid $mypid`
81if [ $cnt -eq 0 ]; then
82    fail "No other events were recorded"
83fi
84
85do_reset
86
87echo $mypid > set_event_notrace_pid
88echo 1 > options/event-fork
89
90enable_events
91
92yield &
93child=$!
94echo "child = $child"
95wait $child
96
97echo 0 > tracing_on
98
99cnt=`count_pid $mypid`
100if [ $cnt -ne 0 ]; then
101    fail "Filtered out task has events"
102fi
103
104cnt=`count_pid $child`
105if [ $cnt -ne 0 ]; then
106    fail "Child of filtered out taskhas events"
107fi
108
109cnt=`count_no_pid $mypid`
110if [ $cnt -eq 0 ]; then
111    fail "No other events were recorded"
112fi
113
114do_reset
115
116exit 0
117