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