]> git.ipfire.org Git - thirdparty/linux.git/blob - tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc
selftests/ftrace: Use loopback address instead of localhost
[thirdparty/linux.git] / tools / testing / selftests / ftrace / test.d / ftrace / func-filter-pid.tc
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
3 # description: ftrace - function pid filters
4
5 # Make sure that function pid matching filter works.
6 # Also test it on an instance directory
7
8 if ! grep -q function available_tracers; then
9 echo "no function tracer configured"
10 exit_unsupported
11 fi
12
13 if [ ! -f set_ftrace_pid ]; then
14 echo "set_ftrace_pid not found? Is function tracer not set?"
15 exit_unsupported
16 fi
17
18 if [ ! -f set_ftrace_filter ]; then
19 echo "set_ftrace_filter not found? Is function tracer not set?"
20 exit_unsupported
21 fi
22
23 do_function_fork=1
24
25 if [ ! -f options/function-fork ]; then
26 do_function_fork=0
27 echo "no option for function-fork found. Option will not be tested."
28 fi
29
30 read PID _ < /proc/self/stat
31
32 if [ $do_function_fork -eq 1 ]; then
33 # default value of function-fork option
34 orig_value=`grep function-fork trace_options`
35 fi
36
37 do_reset() {
38 if [ $do_function_fork -eq 0 ]; then
39 return
40 fi
41
42 echo $orig_value > trace_options
43 }
44
45 fail() { # msg
46 do_reset
47 echo $1
48 exit_fail
49 }
50
51 do_test() {
52 disable_tracing
53
54 echo do_execve* > set_ftrace_filter
55 echo *do_fork >> set_ftrace_filter
56
57 echo $PID > set_ftrace_pid
58 echo function > current_tracer
59
60 if [ $do_function_fork -eq 1 ]; then
61 # don't allow children to be traced
62 echo nofunction-fork > trace_options
63 fi
64
65 enable_tracing
66 yield
67
68 count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
69 count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
70
71 # count_other should be 0
72 if [ $count_pid -eq 0 -o $count_other -ne 0 ]; then
73 fail "PID filtering not working?"
74 fi
75
76 disable_tracing
77 clear_trace
78
79 if [ $do_function_fork -eq 0 ]; then
80 return
81 fi
82
83 # allow children to be traced
84 echo function-fork > trace_options
85
86 enable_tracing
87 yield
88
89 count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
90 count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
91
92 # count_other should NOT be 0
93 if [ $count_pid -eq 0 -o $count_other -eq 0 ]; then
94 fail "PID filtering not following fork?"
95 fi
96 }
97
98 do_test
99
100 mkdir instances/foo
101 cd instances/foo
102 do_test
103 cd ../../
104 rmdir instances/foo
105
106 do_reset
107
108 exit 0