|
| 1 | +#!/bin/sh |
| 2 | +# SPDX-License-Identifier: GPL-2.0 |
| 3 | +# description: ftrace - function pid notrace filters |
| 4 | +# flags: instance |
| 5 | + |
| 6 | +# Make sure that function pid matching filter with notrace works. |
| 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_notrace_pid ]; then |
| 14 | + echo "set_ftrace_notrace_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 > set_ftrace_notrace_pid |
| 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_notrace_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_pid should be 0 |
| 73 | + if [ $count_pid -ne 0 -o $count_other -eq 0 ]; then |
| 74 | + fail "PID filtering not working? traced task = $count_pid; other tasks = $count_other " |
| 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 | + # With pid in both set_ftrace_pid and set_ftrace_notrace_pid |
| 88 | + # there should not be any tasks traced. |
| 89 | + |
| 90 | + echo $PID > set_ftrace_pid |
| 91 | + |
| 92 | + enable_tracing |
| 93 | + yield |
| 94 | + |
| 95 | + count_pid=`cat trace | grep -v ^# | grep $PID | wc -l` |
| 96 | + count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l` |
| 97 | + |
| 98 | + # both should be zero |
| 99 | + if [ $count_pid -ne 0 -o $count_other -ne 0 ]; then |
| 100 | + fail "PID filtering not following fork? traced task = $count_pid; other tasks = $count_other " |
| 101 | + fi |
| 102 | +} |
| 103 | + |
| 104 | +do_test |
| 105 | + |
| 106 | +do_reset |
| 107 | + |
| 108 | +exit 0 |
0 commit comments