]>
Commit | Line | Data |
---|---|---|
254ca641 SM |
1 | # bpf.exp |
2 | # | |
3 | # To restrict scripts to test, set the CHECK_ONLY environment variable. | |
4 | # For example, to only test the printf and uprobes scripts, run: | |
5 | # | |
6 | # make installcheck RUNTESTFLAGS="bpf.exp" CHECK_ONLY="printf uprobes" | |
7 | ||
d2a7d58e AM |
8 | set testdir "$srcdir/$subdir/bpf_tests" |
9 | ||
1832b8f5 MC |
10 | # Skip irrelevant environment. |
11 | if {![bpf_p]} { | |
12 | untested "bpf.exp" | |
a9b0aa4d | 13 | return |
1832b8f5 MC |
14 | } |
15 | ||
16 | # This testcase takes long time on s390x and fails after that. Skip it. | |
17 | if { "$::tcl_platform(machine)" == "s390x" } { | |
18 | untested "bpf.exp" | |
a9b0aa4d | 19 | return |
1832b8f5 MC |
20 | } |
21 | ||
d2a7d58e AM |
22 | # All tests should start by printing "BEGIN". If OUTPUT_STR is "", then |
23 | # the test passes if "END PASS" is read and fails if "END FAIL" is read. Otherwise | |
24 | # the test passes when "${OUTPUT_STR}END" is read and fails if END is read without | |
25 | # OUTPUT_STR preceeding it. | |
fcdd71ba | 26 | proc stapbpf_run { TEST_NAME OUTPUT_STR options args } { |
d2a7d58e AM |
27 | global rc |
28 | set rc -1 | |
29 | set begin_str "BEGIN" | |
30 | set pass_str [expr { $OUTPUT_STR == "" ? "END PASS" : "${OUTPUT_STR}END" }] | |
31 | set fail_str [expr { $OUTPUT_STR == "" ? "END FAIL" : "END" }] | |
32 | ||
33 | # return codes | |
34 | set pass 0 | |
35 | set fail 1 | |
36 | set bad_output 2 | |
37 | set eof_start 3 | |
38 | set eof_end 4 | |
39 | set timeout_start 5 | |
40 | set timeout_end 6 | |
41 | set invalid_prog 7 | |
42 | set comp_err 8 | |
43 | ||
fcdd71ba | 44 | set cmd [concat stap -v --runtime=bpf -x 12345 $options $args] |
d2a7d58e AM |
45 | # don't the following: ... $test_file_name could be some transient or leftover file |
46 | # if [file readable $test_file_name] { lappend cmd $test_file_name } | |
47 | ||
e12b3291 SM |
48 | # child process, only for some commands |
49 | set mypid2 0 | |
50 | ||
d2a7d58e AM |
51 | send_log "executing: $cmd\n" |
52 | eval spawn $cmd | |
53 | set mypid [exp_pid -i $spawn_id] | |
54 | expect { | |
fcdd71ba WC |
55 | # increased timeout due to slow uncached query for bpf tracepoints |
56 | -timeout 300 | |
d2a7d58e AM |
57 | -re {^WARNING: cannot find module [^\r]*DWARF[^\r]*\r\n} {exp_continue} |
58 | -re {^WARNING: No unwind data for /.+\r\n} {exp_continue} | |
59 | -re {^Pass\ ([1234]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms\.\r\n} | |
60 | {set pass$expect_out(1,string) "\t$expect_out(2,string)\t$expect_out(3,string)\t$expect_out(4,string)"; exp_continue} | |
61 | -re {^Pass\ ([34]): using cached [^\r]+\r\n} | |
62 | {set pass$expect_out(1,string) "\t0\t0\t0"; exp_continue} | |
63 | -re {^Passes: via server [^\r]* using [^\r]* in [0-9]+usr/[0-9]+sys/[0-9]+real ms\.\r\n} {exp_continue} | |
64 | -re {^Pass 5: starting run.\r\n} {exp_continue} | |
65 | -re $begin_str { | |
66 | # By default, "expect -re" will match up to 2000 chars. | |
67 | # Increase this to 8K worth of data. | |
68 | exp_match_max 8192 | |
69 | ||
e12b3291 SM |
70 | # create a child process for the tests that require one |
71 | switch $TEST_NAME { | |
72 | user_string.stp { | |
73 | eval exec /usr/bin/sleep 2 | |
74 | } | |
75 | } | |
76 | ||
d2a7d58e AM |
77 | # Avoid PR17274 to propagate |
78 | set origexpinternal 1 | |
79 | if {"[exp_internal -info]" == "0"} {set origexpinternal 0} | |
80 | #exp_internal 0 | |
81 | ||
82 | expect { | |
83 | -timeout 20 | |
584d61dc SM |
84 | -re "stack smashing detected" { |
85 | set rc $bad_output | |
86 | } | |
d2a7d58e AM |
87 | -re $pass_str { |
88 | set rc $pass | |
89 | } | |
90 | -re $fail_str { | |
91 | set rc $fail | |
92 | } | |
93 | default { | |
94 | set rc $bad_output | |
95 | } | |
96 | timeout { | |
97 | set rc $timeout_end | |
98 | kill -INT -$mypid | |
99 | } | |
100 | eof { set rc $eof_end } | |
101 | } | |
102 | exp_internal $origexpinternal | |
103 | } | |
104 | -re "semantic error:" { set rc $comp_err } | |
105 | -re "bpf program load failed:" { set rc $invalid_prog } | |
106 | timeout { | |
107 | set rc $timeout_start | |
108 | kill -INT -$mypid | |
109 | } | |
110 | eof { set rc $eof_start } | |
111 | } | |
112 | # again for good measure with KILL after 3s | |
113 | kill -INT -$mypid 3 | |
114 | catch close | |
115 | wait | |
116 | return $rc | |
117 | } | |
118 | ||
119 | proc get_output_str { test } { | |
120 | global res | |
2ec607a3 | 121 | switch -glob $test { |
2ba29405 AM |
122 | printf.stp { set res [string repeat "abcd123456" 3] } |
123 | sprintf.stp { set res [string repeat "0123456789" 2] } | |
5ae7463e | 124 | string1.stp { set res {begin\[str0str1str2str3\]probe\[str0str1str2str3\]end\[str0str1str2str3\]} } |
2ec607a3 | 125 | string*.stp { set res {probe0\[str0str1str2str3\]probe1\[str0str1str2str3\]end\[str0str1str2str3\]} } |
a0e25b48 | 126 | target.stp { set res {[12345]} } |
d2a7d58e AM |
127 | default { set res "" } |
128 | } | |
129 | return $res | |
254ca641 | 130 | } |
d2a7d58e | 131 | |
254ca641 SM |
132 | if {[info exists env(CHECK_ONLY)]} { |
133 | set all_files [lsort [glob -nocomplain $testdir/*.stp]] | |
134 | set stap_files "" | |
135 | foreach file $env(CHECK_ONLY) { | |
136 | if {[lsearch $all_files $testdir/$file.stp] >= 0} { | |
137 | set stap_files "$stap_files $testdir/$file.stp" | |
138 | } | |
139 | } | |
140 | } else { | |
141 | set stap_files [lsort [glob -nocomplain $testdir/*.stp]] | |
142 | } | |
3530e7a7 | 143 | |
254ca641 | 144 | foreach file $stap_files { |
3530e7a7 AM |
145 | global mypid |
146 | set mypid 0 | |
d2a7d58e AM |
147 | set test [file tail $file] |
148 | if {! [installtest_p]} { untested $test; continue } | |
d0e2589d | 149 | if {! [bpf_p]} { untested $test; continue } |
d2a7d58e | 150 | |
3530e7a7 AM |
151 | # create a process for the tests that require one |
152 | switch $test { | |
153 | uprobes.stp { | |
154 | eval spawn /usr/bin/sleep 20 | |
155 | set mypid [exp_pid -i $spawn_id] | |
156 | } | |
157 | } | |
158 | ||
fcdd71ba WC |
159 | # Add compatible option for some tests that require them |
160 | switch $test { | |
161 | cast_op_tracepoint.stp { set options "--compatible=4.1" } | |
162 | reg_alloc3.stp { set options "--compatible=4.1" } | |
163 | tracepoint1.stp { set options "--compatible=4.1" } | |
164 | default { set options "" } | |
165 | } | |
166 | ||
d2a7d58e AM |
167 | set output_str [get_output_str $test] |
168 | verbose -log "Running $file" | |
fcdd71ba | 169 | set rc [stapbpf_run $test $output_str $options $file] |
1832b8f5 MC |
170 | if {$rc != 0} { |
171 | if { "$::tcl_platform(machine)" == "s390x" } { | |
172 | # The s390x part seems broken at the moment: | |
173 | _setup_kfail BPF s390x rhel | |
174 | } else { | |
175 | # Known failures in other environments: | |
176 | switch $test { | |
177 | array.stp { | |
178 | _setup_kfail BPF ppc64le rhel | |
179 | _setup_kfail BPF x86_64 fedora | |
180 | } | |
181 | array_preinit.stp { _setup_kfail BPF ppc64le rhel } | |
182 | bigmap1.stp { | |
183 | _setup_kfail BPF x86_64,aarch64 rhel | |
184 | _setup_kfail BPF x86_64 fedora | |
185 | } | |
186 | cast_op_tracepoint.stp { _setup_kfail BPF x86_64 rhel,fedora } | |
187 | context_vars1.stp - | |
188 | context_vars2.stp - | |
189 | context_vars3.stp { _setup_kfail BPF ppc64le rhel } | |
190 | globals2.stp { | |
191 | _setup_kfail BPF ppc64le rhel | |
192 | _setup_kfail BPF x86_64 fedora | |
193 | } | |
194 | globals3.stp { _setup_kfail BPF ppc64le rhel } | |
195 | kprobes.stp { _setup_kfail BPF ppc64le rhel } | |
196 | logging1.stp { _setup_kfail BPF x86_64,aarch64,ppc64le rhel } | |
197 | no_begin_no_end.stp { _setup_kfail BPF x86_64 fedora } | |
198 | no_end.stp { _setup_kfail BPF x86_64 fedora } | |
199 | perf1.stp { _setup_kfail BPF x86_64,aarch64,ppc64le rhel } | |
200 | perf2.stp { _setup_kfail BPF aarch64,ppc64le rhel } | |
1832b8f5 MC |
201 | printf.stp { _setup_kfail BPF x86_64 fedora } |
202 | reg_alloc3.stp { | |
203 | _setup_kfail BPF x86_64,aarch64,ppc64le rhel | |
204 | _setup_kfail BPF x86_64 fedora | |
205 | } | |
1832b8f5 MC |
206 | timer1.stp { _setup_kfail BPF x86_64 rhel } |
207 | timer2.stp { _setup_kfail BPF aarch64,ppc64le rhel } | |
208 | tracepoint1.stp { | |
209 | _setup_kfail BPF x86_64,aarch64,ppc64le rhel | |
210 | _setup_kfail BPF x86_64 fedora | |
211 | } | |
212 | } | |
213 | } | |
214 | } | |
215 | switch $rc { | |
d2a7d58e AM |
216 | 0 { pass $test } |
217 | 1 { fail "$test incorrect result" } | |
218 | 2 { fail "$test unexpected output" } | |
219 | 3 { fail "$test eof (startup)" } | |
220 | 4 { fail "$test eof (shutdown)" } | |
221 | 5 { fail "$test timeout (startup)" } | |
222 | 6 { fail "$test timeout (startup)" } | |
223 | 7 { fail "$test invalid bpf program" } | |
224 | 8 { fail "$test compilation" } | |
225 | default { fail "$test unknown return value" } | |
226 | } | |
3530e7a7 AM |
227 | |
228 | if { $mypid > 0 } { | |
229 | kill -INT -$mypid 3 | |
230 | catch close | |
231 | wait | |
232 | } | |
d2a7d58e AM |
233 | } |
234 | ||
235 |