|
| 1 | +#!/bin/sh |
| 2 | +# SPDX-License-Identifier: GPL-2.0 |
| 3 | +# description: ftrace - function graph filters |
| 4 | +# requires: set_ftrace_filter function_graph:tracer |
| 5 | + |
| 6 | +# Make sure that function graph filtering works |
| 7 | + |
| 8 | +INSTANCE1="instances/test1_$$" |
| 9 | +INSTANCE2="instances/test2_$$" |
| 10 | + |
| 11 | +WD=`pwd` |
| 12 | + |
| 13 | +do_reset() { |
| 14 | + cd $WD |
| 15 | + if [ -d $INSTANCE1 ]; then |
| 16 | + echo nop > $INSTANCE1/current_tracer |
| 17 | + rmdir $INSTANCE1 |
| 18 | + fi |
| 19 | + if [ -d $INSTANCE2 ]; then |
| 20 | + echo nop > $INSTANCE2/current_tracer |
| 21 | + rmdir $INSTANCE2 |
| 22 | + fi |
| 23 | +} |
| 24 | + |
| 25 | +mkdir $INSTANCE1 |
| 26 | +if ! grep -q function_graph $INSTANCE1/available_tracers; then |
| 27 | + echo "function_graph not allowed with instances" |
| 28 | + rmdir $INSTANCE1 |
| 29 | + exit_unsupported |
| 30 | +fi |
| 31 | + |
| 32 | +mkdir $INSTANCE2 |
| 33 | + |
| 34 | +fail() { # msg |
| 35 | + do_reset |
| 36 | + echo $1 |
| 37 | + exit_fail |
| 38 | +} |
| 39 | + |
| 40 | +disable_tracing |
| 41 | +clear_trace |
| 42 | + |
| 43 | +function_count() { |
| 44 | + search=$1 |
| 45 | + vsearch=$2 |
| 46 | + |
| 47 | + if [ -z "$search" ]; then |
| 48 | + cat enabled_functions | wc -l |
| 49 | + elif [ -z "$vsearch" ]; then |
| 50 | + grep $search enabled_functions | wc -l |
| 51 | + else |
| 52 | + grep $search enabled_functions | grep $vsearch| wc -l |
| 53 | + fi |
| 54 | +} |
| 55 | + |
| 56 | +set_fgraph() { |
| 57 | + instance=$1 |
| 58 | + filter="$2" |
| 59 | + notrace="$3" |
| 60 | + |
| 61 | + echo "$filter" > $instance/set_ftrace_filter |
| 62 | + echo "$notrace" > $instance/set_ftrace_notrace |
| 63 | + echo function_graph > $instance/current_tracer |
| 64 | +} |
| 65 | + |
| 66 | +check_functions() { |
| 67 | + orig_cnt=$1 |
| 68 | + test=$2 |
| 69 | + |
| 70 | + cnt=`function_count $test` |
| 71 | + if [ $cnt -gt $orig_cnt ]; then |
| 72 | + fail |
| 73 | + fi |
| 74 | +} |
| 75 | + |
| 76 | +check_cnt() { |
| 77 | + orig_cnt=$1 |
| 78 | + search=$2 |
| 79 | + vsearch=$3 |
| 80 | + |
| 81 | + cnt=`function_count $search $vsearch` |
| 82 | + if [ $cnt -gt $orig_cnt ]; then |
| 83 | + fail |
| 84 | + fi |
| 85 | +} |
| 86 | + |
| 87 | +reset_graph() { |
| 88 | + instance=$1 |
| 89 | + echo nop > $instance/current_tracer |
| 90 | +} |
| 91 | + |
| 92 | +# get any functions that were enabled before the test |
| 93 | +total_cnt=`function_count` |
| 94 | +sched_cnt=`function_count sched` |
| 95 | +lock_cnt=`function_count lock` |
| 96 | +time_cnt=`function_count time` |
| 97 | +clock_cnt=`function_count clock` |
| 98 | +locks_clock_cnt=`function_count locks clock` |
| 99 | +clock_locks_cnt=`function_count clock locks` |
| 100 | + |
| 101 | +# Trace functions with "sched" but not "time" |
| 102 | +set_fgraph $INSTANCE1 '*sched*' '*time*' |
| 103 | + |
| 104 | +# Make sure "time" isn't listed |
| 105 | +check_functions $time_cnt 'time' |
| 106 | +instance1_cnt=`function_count` |
| 107 | + |
| 108 | +# Trace functions with "lock" but not "clock" |
| 109 | +set_fgraph $INSTANCE2 '*lock*' '*clock*' |
| 110 | +instance1_2_cnt=`function_count` |
| 111 | + |
| 112 | +# Turn off the first instance |
| 113 | +reset_graph $INSTANCE1 |
| 114 | + |
| 115 | +# The second instance doesn't trace "clock" functions |
| 116 | +check_functions $clock_cnt 'clock' |
| 117 | +instance2_cnt=`function_count` |
| 118 | + |
| 119 | +# Start from a clean slate |
| 120 | +reset_graph $INSTANCE2 |
| 121 | +check_functions $total_cnt |
| 122 | + |
| 123 | +# Trace functions with "lock" but not "clock" |
| 124 | +set_fgraph $INSTANCE2 '*lock*' '*clock*' |
| 125 | + |
| 126 | +# This should match the last time instance 2 was by itself |
| 127 | +cnt=`function_count` |
| 128 | +if [ $instance2_cnt -ne $cnt ]; then |
| 129 | + fail |
| 130 | +fi |
| 131 | + |
| 132 | +# And it should not be tracing "clock" functions |
| 133 | +check_functions $clock_cnt 'clock' |
| 134 | + |
| 135 | +# Trace functions with "sched" but not "time" |
| 136 | +set_fgraph $INSTANCE1 '*sched*' '*time*' |
| 137 | + |
| 138 | +# This should match the last time both instances were enabled |
| 139 | +cnt=`function_count` |
| 140 | +if [ $instance1_2_cnt -ne $cnt ]; then |
| 141 | + fail |
| 142 | +fi |
| 143 | + |
| 144 | +# Turn off the second instance |
| 145 | +reset_graph $INSTANCE2 |
| 146 | + |
| 147 | +# This should match the last time instance 1 was by itself |
| 148 | +cnt=`function_count` |
| 149 | +if [ $instance1_cnt -ne $cnt ]; then |
| 150 | + fail |
| 151 | +fi |
| 152 | + |
| 153 | +# And it should not be tracing "time" functions |
| 154 | +check_functions $time_cnt 'time' |
| 155 | + |
| 156 | +# Start from a clean slate |
| 157 | +reset_graph $INSTANCE1 |
| 158 | +check_functions $total_cnt |
| 159 | + |
| 160 | +# Enable all functions but those that have "locks" |
| 161 | +set_fgraph $INSTANCE1 '' '*locks*' |
| 162 | + |
| 163 | +# Enable all functions but those that have "clock" |
| 164 | +set_fgraph $INSTANCE2 '' '*clock*' |
| 165 | + |
| 166 | +# If a function has "locks" it should not have "clock" |
| 167 | +check_cnt $locks_clock_cnt locks clock |
| 168 | + |
| 169 | +# If a function has "clock" it should not have "locks" |
| 170 | +check_cnt $clock_locks_cnt clock locks |
| 171 | + |
| 172 | +reset_graph $INSTANCE1 |
| 173 | +reset_graph $INSTANCE2 |
| 174 | + |
| 175 | +do_reset |
| 176 | + |
| 177 | +exit 0 |
0 commit comments