Back to home page

OSCL-LXR

 
 

    


0001 clear_trace() { # reset trace output
0002     echo > trace
0003 }
0004 
0005 disable_tracing() { # stop trace recording
0006     echo 0 > tracing_on
0007 }
0008 
0009 enable_tracing() { # start trace recording
0010     echo 1 > tracing_on
0011 }
0012 
0013 reset_tracer() { # reset the current tracer
0014     echo nop > current_tracer
0015 }
0016 
0017 reset_trigger_file() {
0018     # remove action triggers first
0019     grep -H ':on[^:]*(' $@ |
0020     while read line; do
0021         cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`
0022         file=`echo $line | cut -f1 -d:`
0023         echo "!$cmd" >> $file
0024     done
0025     grep -Hv ^# $@ |
0026     while read line; do
0027         cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`
0028         file=`echo $line | cut -f1 -d:`
0029         echo "!$cmd" > $file
0030     done
0031 }
0032 
0033 reset_trigger() { # reset all current setting triggers
0034     if [ -d events/synthetic ]; then
0035         reset_trigger_file events/synthetic/*/trigger
0036     fi
0037     reset_trigger_file events/*/*/trigger
0038 }
0039 
0040 reset_events_filter() { # reset all current setting filters
0041     grep -v ^none events/*/*/filter |
0042     while read line; do
0043         echo 0 > `echo $line | cut -f1 -d:`
0044     done
0045 }
0046 
0047 reset_ftrace_filter() { # reset all triggers in set_ftrace_filter
0048     if [ ! -f set_ftrace_filter ]; then
0049       return 0
0050     fi
0051     echo > set_ftrace_filter
0052     grep -v '^#' set_ftrace_filter | while read t; do
0053         tr=`echo $t | cut -d: -f2`
0054         if [ "$tr" = "" ]; then
0055             continue
0056         fi
0057         if ! grep -q "$t" set_ftrace_filter; then
0058                 continue;
0059         fi
0060         name=`echo $t | cut -d: -f1 | cut -d' ' -f1`
0061         if [ $tr = "enable_event" -o $tr = "disable_event" ]; then
0062             tr=`echo $t | cut -d: -f2-4`
0063             limit=`echo $t | cut -d: -f5`
0064         else
0065             tr=`echo $t | cut -d: -f2`
0066             limit=`echo $t | cut -d: -f3`
0067         fi
0068         if [ "$limit" != "unlimited" ]; then
0069             tr="$tr:$limit"
0070         fi
0071         echo "!$name:$tr" > set_ftrace_filter
0072     done
0073 }
0074 
0075 disable_events() {
0076     echo 0 > events/enable
0077 }
0078 
0079 clear_synthetic_events() { # reset all current synthetic events
0080     grep -v ^# synthetic_events |
0081     while read line; do
0082         echo "!$line" >> synthetic_events
0083     done
0084 }
0085 
0086 clear_dynamic_events() { # reset all current dynamic events
0087     again=1
0088     stop=1
0089     # loop mulitple times as some events require other to be removed first
0090     while [ $again -eq 1 ]; do
0091         stop=$((stop+1))
0092         # Prevent infinite loops
0093         if [ $stop -gt 10 ]; then
0094             break;
0095         fi
0096         again=2
0097         grep -v '^#' dynamic_events|
0098         while read line; do
0099             del=`echo $line | sed -e 's/^.\([^ ]*\).*/-\1/'`
0100             if ! echo "$del" >> dynamic_events; then
0101                 again=1
0102             fi
0103         done
0104     done
0105 }
0106 
0107 initialize_ftrace() { # Reset ftrace to initial-state
0108 # As the initial state, ftrace will be set to nop tracer,
0109 # no events, no triggers, no filters, no function filters,
0110 # no probes, and tracing on.
0111     disable_tracing
0112     reset_tracer
0113     reset_trigger
0114     reset_events_filter
0115     reset_ftrace_filter
0116     disable_events
0117     clear_dynamic_events
0118     [ -f set_event_pid ] && echo > set_event_pid
0119     [ -f set_ftrace_pid ] && echo > set_ftrace_pid
0120     [ -f set_ftrace_notrace ] && echo > set_ftrace_notrace
0121     [ -f set_graph_function ] && echo | tee set_graph_*
0122     [ -f stack_trace_filter ] && echo > stack_trace_filter
0123     [ -f kprobe_events ] && echo > kprobe_events
0124     [ -f uprobe_events ] && echo > uprobe_events
0125     [ -f synthetic_events ] && echo > synthetic_events
0126     [ -f snapshot ] && echo 0 > snapshot
0127 
0128 # Stop tracing while reading the trace file by default, to prevent
0129 # the test results while checking it and to avoid taking a long time
0130 # to check the result.
0131     [ -f options/pause-on-trace ] && echo 1 > options/pause-on-trace
0132 
0133     clear_trace
0134     enable_tracing
0135 }
0136 
0137 finish_ftrace() {
0138     initialize_ftrace
0139 # And recover it to default.
0140     [ -f options/pause-on-trace ] && echo 0 > options/pause-on-trace
0141 }
0142 
0143 check_requires() { # Check required files and tracers
0144     for i in "$@" ; do
0145         r=${i%:README}
0146         t=${i%:tracer}
0147         if [ $t != $i ]; then
0148             if ! grep -wq $t available_tracers ; then
0149                 echo "Required tracer $t is not configured."
0150                 exit_unsupported
0151             fi
0152         elif [ "$r" != "$i" ]; then
0153             if ! grep -Fq "$r" README ; then
0154                 echo "Required feature pattern \"$r\" is not in README."
0155                 exit_unsupported
0156             fi
0157         elif [ ! -e $i ]; then
0158             echo "Required feature interface $i doesn't exist."
0159             exit_unsupported
0160         fi
0161     done
0162 }
0163 
0164 LOCALHOST=127.0.0.1
0165 
0166 yield() {
0167     ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
0168 }
0169 
0170 # The fork function in the kernel was renamed from "_do_fork" to
0171 # "kernel_fork". As older tests should still work with older kernels
0172 # as well as newer kernels, check which version of fork is used on this
0173 # kernel so that the tests can use the fork function for the running kernel.
0174 FUNCTION_FORK=`(if grep '\bkernel_clone\b' /proc/kallsyms > /dev/null; then
0175                 echo kernel_clone; else echo '_do_fork'; fi)`
0176 
0177 # Since probe event command may include backslash, explicitly use printf "%s"
0178 # to NOT interpret it.
0179 ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
0180     pos=$(printf "%s" "${2%^*}" | wc -c) # error position
0181     command=$(printf "%s" "$2" | tr -d ^)
0182     echo "Test command: $command"
0183     echo > error_log
0184     (! printf "%s" "$command" >> "$3" ) 2> /dev/null
0185     grep "$1: error:" -A 3 error_log
0186     N=$(tail -n 1 error_log | wc -c)
0187     # "  Command: " and "^\n" => 13
0188     test $(expr 13 + $pos) -eq $N
0189 }