forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/tools/testing/selftests/ftrace/test.d/functions
....@@ -1,4 +1,3 @@
1
-
21 clear_trace() { # reset trace output
32 echo > trace
43 }
....@@ -46,6 +45,9 @@
4645 }
4746
4847 reset_ftrace_filter() { # reset all triggers in set_ftrace_filter
48
+ if [ ! -f set_ftrace_filter ]; then
49
+ return 0
50
+ fi
4951 echo > set_ftrace_filter
5052 grep -v '^#' set_ftrace_filter | while read t; do
5153 tr=`echo $t | cut -d: -f2`
....@@ -89,12 +91,65 @@
8991 reset_tracer
9092 reset_trigger
9193 reset_events_filter
94
+ reset_ftrace_filter
9295 disable_events
93
- echo > set_event_pid # event tracer is always on
94
- [ -f set_ftrace_filter ] && echo | tee set_ftrace_*
96
+ [ -f set_event_pid ] && echo > set_event_pid
97
+ [ -f set_ftrace_pid ] && echo > set_ftrace_pid
98
+ [ -f set_ftrace_notrace ] && echo > set_ftrace_notrace
9599 [ -f set_graph_function ] && echo | tee set_graph_*
96100 [ -f stack_trace_filter ] && echo > stack_trace_filter
97101 [ -f kprobe_events ] && echo > kprobe_events
98102 [ -f uprobe_events ] && echo > uprobe_events
103
+ [ -f synthetic_events ] && echo > synthetic_events
104
+ [ -f snapshot ] && echo 0 > snapshot
105
+ clear_trace
99106 enable_tracing
100107 }
108
+
109
+check_requires() { # Check required files and tracers
110
+ for i in "$@" ; do
111
+ r=${i%:README}
112
+ t=${i%:tracer}
113
+ if [ $t != $i ]; then
114
+ if ! grep -wq $t available_tracers ; then
115
+ echo "Required tracer $t is not configured."
116
+ exit_unsupported
117
+ fi
118
+ elif [ "$r" != "$i" ]; then
119
+ if ! grep -Fq "$r" README ; then
120
+ echo "Required feature pattern \"$r\" is not in README."
121
+ exit_unsupported
122
+ fi
123
+ elif [ ! -e $i ]; then
124
+ echo "Required feature interface $i doesn't exist."
125
+ exit_unsupported
126
+ fi
127
+ done
128
+}
129
+
130
+LOCALHOST=127.0.0.1
131
+
132
+yield() {
133
+ ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
134
+}
135
+
136
+# The fork function in the kernel was renamed from "_do_fork" to
137
+# "kernel_fork". As older tests should still work with older kernels
138
+# as well as newer kernels, check which version of fork is used on this
139
+# kernel so that the tests can use the fork function for the running kernel.
140
+FUNCTION_FORK=`(if grep '\bkernel_clone\b' /proc/kallsyms > /dev/null; then
141
+ echo kernel_clone; else echo '_do_fork'; fi)`
142
+
143
+# Since probe event command may include backslash, explicitly use printf "%s"
144
+# to NOT interpret it.
145
+ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
146
+ pos=$(printf "%s" "${2%^*}" | wc -c) # error position
147
+ command=$(printf "%s" "$2" | tr -d ^)
148
+ echo "Test command: $command"
149
+ echo > error_log
150
+ (! printf "%s" "$command" >> "$3" ) 2> /dev/null
151
+ grep "$1: error:" -A 3 error_log
152
+ N=$(tail -n 1 error_log | wc -c)
153
+ # " Command: " and "^\n" => 13
154
+ test $(expr 13 + $pos) -eq $N
155
+}