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