220 lines · plain
1clear_trace() { # reset trace output2 echo > trace3}4 5disable_tracing() { # stop trace recording6 echo 0 > tracing_on7}8 9enable_tracing() { # start trace recording10 echo 1 > tracing_on11}12 13reset_tracer() { # reset the current tracer14 echo nop > current_tracer15}16 17reset_trigger_file() {18 # remove action triggers first19 grep -H ':on[^:]*(' $@ |20 while read line; do21 cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`22 file=`echo $line | cut -f1 -d:`23 echo "!$cmd" >> $file24 done25 grep -Hv ^# $@ |26 while read line; do27 cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`28 file=`echo $line | cut -f1 -d:`29 echo "!$cmd" > $file30 done31}32 33reset_trigger() { # reset all current setting triggers34 if [ -d events/synthetic ]; then35 reset_trigger_file events/synthetic/*/trigger36 fi37 reset_trigger_file events/*/*/trigger38}39 40reset_events_filter() { # reset all current setting filters41 grep -v ^none events/*/*/filter |42 while read line; do43 echo 0 > `echo $line | cut -f1 -d:`44 done45}46 47reset_ftrace_filter() { # reset all triggers in set_ftrace_filter48 if [ ! -f set_ftrace_filter ]; then49 return 050 fi51 echo > set_ftrace_filter52 grep -v '^#' set_ftrace_filter | while read t; do53 tr=`echo $t | cut -d: -f2`54 if [ "$tr" = "" ]; then55 continue56 fi57 if ! grep -q "$t" set_ftrace_filter; then58 continue;59 fi60 name=`echo $t | cut -d: -f1 | cut -d' ' -f1`61 if [ $tr = "enable_event" -o $tr = "disable_event" ]; then62 tr=`echo $t | cut -d: -f2-4`63 limit=`echo $t | cut -d: -f5`64 else65 tr=`echo $t | cut -d: -f2`66 limit=`echo $t | cut -d: -f3`67 fi68 if [ "$limit" != "unlimited" ]; then69 tr="$tr:$limit"70 fi71 echo "!$name:$tr" > set_ftrace_filter72 done73}74 75disable_events() {76 echo 0 > events/enable77}78 79clear_synthetic_events() { # reset all current synthetic events80 grep -v ^# synthetic_events |81 while read line; do82 echo "!$line" >> synthetic_events83 done84}85 86clear_dynamic_events() { # reset all current dynamic events87 again=188 stop=189 # loop mulitple times as some events require other to be removed first90 while [ $again -eq 1 ]; do91 stop=$((stop+1))92 # Prevent infinite loops93 if [ $stop -gt 10 ]; then94 break;95 fi96 again=297 grep -v '^#' dynamic_events|98 while read line; do99 del=`echo $line | sed -e 's/^.\([^ ]*\).*/-\1/'`100 if ! echo "$del" >> dynamic_events; then101 again=1102 fi103 done104 done105}106 107initialize_ftrace() { # Reset ftrace to initial-state108# As the initial state, ftrace will be set to nop tracer,109# no events, no triggers, no filters, no function filters,110# no probes, and tracing on.111 disable_tracing112 reset_tracer113 reset_trigger114 reset_events_filter115 reset_ftrace_filter116 disable_events117 clear_dynamic_events118 [ -f set_event_pid ] && echo > set_event_pid119 [ -f set_ftrace_pid ] && echo > set_ftrace_pid120 [ -f set_ftrace_notrace ] && echo > set_ftrace_notrace121 [ -f set_graph_function ] && echo | tee set_graph_*122 [ -f stack_trace_filter ] && echo > stack_trace_filter123 [ -f kprobe_events ] && echo > kprobe_events124 [ -f uprobe_events ] && echo > uprobe_events125 [ -f synthetic_events ] && echo > synthetic_events126 [ -f snapshot ] && echo 0 > snapshot127 128# Stop tracing while reading the trace file by default, to prevent129# the test results while checking it and to avoid taking a long time130# to check the result.131 [ -f options/pause-on-trace ] && echo 1 > options/pause-on-trace132 133 clear_trace134 enable_tracing135}136 137finish_ftrace() {138 initialize_ftrace139# And recover it to default.140 [ -f options/pause-on-trace ] && echo 0 > options/pause-on-trace141}142 143check_requires() { # Check required files and tracers144 for i in "$@" ; do145 p=${i%:program}146 r=${i%:README}147 t=${i%:tracer}148 if [ $p != $i ]; then149 if ! which $p ; then150 echo "Required program $p is not found."151 exit_unresolved152 fi153 elif [ $t != $i ]; then154 if ! grep -wq $t available_tracers ; then155 echo "Required tracer $t is not configured."156 exit_unsupported157 fi158 elif [ "$r" != "$i" ]; then159 if ! grep -Fq "$r" README ; then160 echo "Required feature pattern \"$r\" is not in README."161 exit_unsupported162 fi163 elif [ ! -e $i ]; then164 echo "Required feature interface $i doesn't exist."165 exit_unsupported166 fi167 done168}169 170LOCALHOST=127.0.0.1171 172yield() {173 ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1174}175 176# The fork function in the kernel was renamed from "_do_fork" to177# "kernel_fork". As older tests should still work with older kernels178# as well as newer kernels, check which version of fork is used on this179# kernel so that the tests can use the fork function for the running kernel.180FUNCTION_FORK=`(if grep '\bkernel_clone\b' /proc/kallsyms > /dev/null; then181 echo kernel_clone; else echo '_do_fork'; fi)`182 183# Since probe event command may include backslash, explicitly use printf "%s"184# to NOT interpret it.185ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file186 pos=$(printf "%s" "${2%^*}" | wc -c) # error position187 command=$(printf "%s" "$2" | tr -d ^)188 echo "Test command: $command"189 echo > error_log190 (! printf "%s" "$command" >> "$3" ) 2> /dev/null191 grep "$1: error:" -A 3 error_log192 N=$(tail -n 1 error_log | wc -c)193 # " Command: " and "^\n" => 13194 test $(expr 13 + $pos) -eq $N195}196 197# Helper to get the tracefs mount point198get_mount_point() {199 local mount_point=`stat -c '%m' .`200 201 # If stat -c '%m' does not work (e.g. busybox) or failed, try to use the202 # current working directory (which should be a tracefs) as the mount point.203 if [ ! -d "$mount_point" ]; then204 if mount | grep -qw "$PWD"; then205 mount_point=$PWD206 else207 # If PWD doesn't work, that is an environmental problem.208 exit_unresolved209 fi210 fi211 echo "$mount_point"212}213 214# Helper function to retrieve mount options for a given mount point215get_mnt_options() {216 local mnt_point="$1"217 local opts=$(mount | grep -m1 "$mnt_point" | sed -e 's/.*(\(.*\)).*/\1/')218 219 echo "$opts"220}