OSDN Git Service

Merge tag 'drm-misc-fixes-2020-05-07' of git://anongit.freedesktop.org/drm/drm-misc...
[tomoyo/tomoyo-test1.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 check_filter_file set_ftrace_filter
20
21 do_function_fork=1
22
23 if [ ! -f options/function-fork ]; then
24     do_function_fork=0
25     echo "no option for function-fork found. Option will not be tested."
26 fi
27
28 read PID _ < /proc/self/stat
29
30 if [ $do_function_fork -eq 1 ]; then
31     # default value of function-fork option
32     orig_value=`grep function-fork trace_options`
33 fi
34
35 do_reset() {
36     if [ $do_function_fork -eq 0 ]; then
37         return
38     fi
39
40     echo $orig_value > trace_options
41 }
42
43 fail() { # msg
44     do_reset
45     echo $1
46     exit_fail
47 }
48
49 do_test() {
50     disable_tracing
51
52     echo do_execve* > set_ftrace_filter
53     echo *do_fork >> set_ftrace_filter
54
55     echo $PID > set_ftrace_pid
56     echo function > current_tracer
57
58     if [ $do_function_fork -eq 1 ]; then
59         # don't allow children to be traced
60         echo nofunction-fork > trace_options
61     fi
62
63     enable_tracing
64     yield
65
66     count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
67     count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
68
69     # count_other should be 0
70     if [ $count_pid -eq 0 -o $count_other -ne 0 ]; then
71         fail "PID filtering not working?"
72     fi
73
74     disable_tracing
75     clear_trace
76
77     if [ $do_function_fork -eq 0 ]; then
78         return
79     fi
80
81     # allow children to be traced
82     echo function-fork > trace_options
83
84     enable_tracing
85     yield
86
87     count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
88     count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
89
90     # count_other should NOT be 0
91     if [ $count_pid -eq 0 -o $count_other -eq 0 ]; then
92         fail "PID filtering not following fork?"
93     fi
94 }
95
96 do_test
97 do_reset
98
99 exit 0