Merge tag 'zynqmp-soc-for-v5.7' of https://github.com/Xilinx/linux-xlnx into arm/soc
[linux-2.6-microblaze.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 # flags: instance
5
6 # Make sure that function pid matching filter works.
7 # Also test it on an instance directory
8
9 if ! grep -q function available_tracers; then
10     echo "no function tracer configured"
11     exit_unsupported
12 fi
13
14 if [ ! -f set_ftrace_pid ]; then
15     echo "set_ftrace_pid not found? Is function tracer not set?"
16     exit_unsupported
17 fi
18
19 if [ ! -f set_ftrace_filter ]; then
20     echo "set_ftrace_filter not found? Is function tracer not set?"
21     exit_unsupported
22 fi
23
24 do_function_fork=1
25
26 if [ ! -f options/function-fork ]; then
27     do_function_fork=0
28     echo "no option for function-fork found. Option will not be tested."
29 fi
30
31 read PID _ < /proc/self/stat
32
33 if [ $do_function_fork -eq 1 ]; then
34     # default value of function-fork option
35     orig_value=`grep function-fork trace_options`
36 fi
37
38 do_reset() {
39     if [ $do_function_fork -eq 0 ]; then
40         return
41     fi
42
43     echo $orig_value > trace_options
44 }
45
46 fail() { # msg
47     do_reset
48     echo $1
49     exit_fail
50 }
51
52 do_test() {
53     disable_tracing
54
55     echo do_execve* > set_ftrace_filter
56     echo *do_fork >> set_ftrace_filter
57
58     echo $PID > set_ftrace_pid
59     echo function > current_tracer
60
61     if [ $do_function_fork -eq 1 ]; then
62         # don't allow children to be traced
63         echo nofunction-fork > trace_options
64     fi
65
66     enable_tracing
67     yield
68
69     count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
70     count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
71
72     # count_other should be 0
73     if [ $count_pid -eq 0 -o $count_other -ne 0 ]; then
74         fail "PID filtering not working?"
75     fi
76
77     disable_tracing
78     clear_trace
79
80     if [ $do_function_fork -eq 0 ]; then
81         return
82     fi
83
84     # allow children to be traced
85     echo function-fork > trace_options
86
87     enable_tracing
88     yield
89
90     count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
91     count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
92
93     # count_other should NOT be 0
94     if [ $count_pid -eq 0 -o $count_other -eq 0 ]; then
95         fail "PID filtering not following fork?"
96     fi
97 }
98
99 do_test
100 do_reset
101
102 exit 0