License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / tools / testing / selftests / ftrace / test.d / ftrace / func-filter-pid.tc
CommitLineData
093be89a 1#!/bin/sh
b2441318 2# SPDX-License-Identifier: GPL-2.0
093be89a
NK
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
8if ! grep -q function available_tracers; then
9 echo "no function tracer configured"
10 exit_unsupported
11fi
12
13if [ ! -f set_ftrace_pid ]; then
14 echo "set_ftrace_pid not found? Is function tracer not set?"
15 exit_unsupported
16fi
17
18if [ ! -f set_ftrace_filter ]; then
19 echo "set_ftrace_filter not found? Is function tracer not set?"
20 exit_unsupported
21fi
22
9ed19c76
SRV
23do_function_fork=1
24
25if [ ! -f options/function-fork ]; then
26 do_function_fork=0
27 echo "no option for function-fork found. Option will not be tested."
28fi
29
093be89a
NK
30read PID _ < /proc/self/stat
31
9ed19c76
SRV
32if [ $do_function_fork -eq 1 ]; then
33 # default value of function-fork option
34 orig_value=`grep function-fork trace_options`
35fi
093be89a
NK
36
37do_reset() {
38 reset_tracer
39 clear_trace
40 enable_tracing
41 echo > set_ftrace_filter
42 echo > set_ftrace_pid
43
9ed19c76
SRV
44 if [ $do_function_fork -eq 0 ]; then
45 return
46 fi
47
093be89a
NK
48 echo $orig_value > trace_options
49}
50
51fail() { # msg
52 do_reset
53 echo $1
54 exit $FAIL
55}
56
57yield() {
58 ping localhost -c 1 || sleep .001 || usleep 1 || sleep 1
59}
60
61do_test() {
62 disable_tracing
63
64 echo do_execve* > set_ftrace_filter
65 echo *do_fork >> set_ftrace_filter
66
67 echo $PID > set_ftrace_pid
68 echo function > current_tracer
69
9ed19c76
SRV
70 if [ $do_function_fork -eq 1 ]; then
71 # don't allow children to be traced
72 echo nofunction-fork > trace_options
73 fi
093be89a
NK
74
75 enable_tracing
76 yield
77
78 count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
79 count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
80
81 # count_other should be 0
82 if [ $count_pid -eq 0 -o $count_other -ne 0 ]; then
83 fail "PID filtering not working?"
84 fi
85
86 disable_tracing
87 clear_trace
88
9ed19c76
SRV
89 if [ $do_function_fork -eq 0 ]; then
90 return
91 fi
92
093be89a
NK
93 # allow children to be traced
94 echo function-fork > trace_options
95
96 enable_tracing
97 yield
98
99 count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
100 count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
101
102 # count_other should NOT be 0
103 if [ $count_pid -eq 0 -o $count_other -eq 0 ]; then
104 fail "PID filtering not following fork?"
105 fi
106}
107
108do_test
109
110mkdir instances/foo
111cd instances/foo
112do_test
113cd ../../
114rmdir instances/foo
115
116do_reset
117
118exit 0