| 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="nonbpf.exp" CHECK_ONLY="printf uprobes" |
| 7 |
|
| 8 |
set testdir "$srcdir/$subdir/bpf_tests" |
| 9 |
|
| 10 |
# All tests should start by printing "BEGIN". If OUTPUT_STR is "", then |
| 11 |
# the test passes if "END PASS" is read and fails if "END FAIL" is read. Otherwise |
| 12 |
# the test passes when "${OUTPUT_STR}END" is read and fails if END is read without |
| 13 |
# OUTPUT_STR preceeding it. |
| 14 |
proc stapnonbpf_run { TEST_NAME OUTPUT_STR args } { |
| 15 |
global rc |
| 16 |
set rc -1 |
| 17 |
set begin_str "BEGIN" |
| 18 |
set pass_str [expr { $OUTPUT_STR == "" ? "END PASS" : "${OUTPUT_STR}END" }] |
| 19 |
set fail_str [expr { $OUTPUT_STR == "" ? "END FAIL" : "END" }] |
| 20 |
|
| 21 |
# return codes |
| 22 |
set pass 0 |
| 23 |
set fail 1 |
| 24 |
set bad_output 2 |
| 25 |
set eof_start 3 |
| 26 |
set eof_end 4 |
| 27 |
set timeout_start 5 |
| 28 |
set timeout_end 6 |
| 29 |
set invalid_prog 7 |
| 30 |
set comp_err 8 |
| 31 |
|
| 32 |
set cmd [concat stap -v $args] |
| 33 |
# don't the following: ... $test_file_name could be some transient or leftover file |
| 34 |
# if [file readable $test_file_name] { lappend cmd $test_file_name } |
| 35 |
|
| 36 |
send_log "executing: $cmd\n" |
| 37 |
eval spawn $cmd |
| 38 |
set mypid [exp_pid -i $spawn_id] |
| 39 |
expect { |
| 40 |
-timeout 30 |
| 41 |
-re {^WARNING: cannot find module [^\r]*DWARF[^\r]*\r\n} {exp_continue} |
| 42 |
-re {^WARNING: No unwind data for /.+\r\n} {exp_continue} |
| 43 |
-re {^Pass\ ([1234]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms\.\r\n} |
| 44 |
{set pass$expect_out(1,string) "\t$expect_out(2,string)\t$expect_out(3,string)\t$expect_out(4,string)"; exp_continue} |
| 45 |
-re {^Pass\ ([34]): using cached [^\r]+\r\n} |
| 46 |
{set pass$expect_out(1,string) "\t0\t0\t0"; exp_continue} |
| 47 |
-re {^Passes: via server [^\r]* using [^\r]* in [0-9]+usr/[0-9]+sys/[0-9]+real ms\.\r\n} {exp_continue} |
| 48 |
-re {^Pass 5: starting run.\r\n} {exp_continue} |
| 49 |
-re $begin_str { |
| 50 |
# By default, "expect -re" will match up to 2000 chars. |
| 51 |
# Increase this to 8K worth of data. |
| 52 |
exp_match_max 8192 |
| 53 |
|
| 54 |
# Avoid PR17274 to propagate |
| 55 |
set origexpinternal 1 |
| 56 |
if {"[exp_internal -info]" == "0"} {set origexpinternal 0} |
| 57 |
#exp_internal 0 |
| 58 |
|
| 59 |
expect { |
| 60 |
-timeout 20 |
| 61 |
-re $pass_str { |
| 62 |
set rc $pass |
| 63 |
} |
| 64 |
-re $fail_str { |
| 65 |
set rc $fail |
| 66 |
} |
| 67 |
default { |
| 68 |
set rc $bad_output |
| 69 |
} |
| 70 |
timeout { |
| 71 |
set rc $timeout_end |
| 72 |
kill -INT -$mypid |
| 73 |
} |
| 74 |
eof { set rc $eof_end } |
| 75 |
} |
| 76 |
exp_internal $origexpinternal |
| 77 |
} |
| 78 |
-re "semantic error:" { set rc $comp_err } |
| 79 |
timeout { |
| 80 |
set rc $timeout_start |
| 81 |
kill -INT -$mypid |
| 82 |
} |
| 83 |
eof { set rc $eof_start } |
| 84 |
} |
| 85 |
# again for good measure with KILL after 3s |
| 86 |
kill -INT -$mypid 3 |
| 87 |
catch close |
| 88 |
wait |
| 89 |
return $rc |
| 90 |
} |
| 91 |
|
| 92 |
proc get_output_str { test } { |
| 93 |
global res |
| 94 |
switch -glob $test { |
| 95 |
printf.stp { set res [string repeat "abcd123456" 3] } |
| 96 |
sprintf.stp { set res [string repeat "0123456789" 2] } |
| 97 |
string1.stp { set res {begin\[str0str1str2str3\]probe\[str0str1str2str3\]end\[str0str1str2str3\]} } |
| 98 |
string*.stp { set res {probe0\[str0str1str2str3\]probe1\[str0str1str2str3\]end\[str0str1str2str3\]} } |
| 99 |
default { set res "" } |
| 100 |
} |
| 101 |
return $res |
| 102 |
} |
| 103 |
|
| 104 |
if {[info exists env(CHECK_ONLY)]} { |
| 105 |
set all_files [lsort [glob -nocomplain $testdir/*.stp]] |
| 106 |
set stap_files "" |
| 107 |
foreach file $env(CHECK_ONLY) { |
| 108 |
if {[lsearch $all_files $testdir/$file.stp] >= 0} { |
| 109 |
set stap_files "$stap_files $testdir/$file.stp" |
| 110 |
} |
| 111 |
} |
| 112 |
} else { |
| 113 |
set stap_files [lsort [glob -nocomplain $testdir/*.stp]] |
| 114 |
} |
| 115 |
|
| 116 |
foreach file $stap_files { |
| 117 |
global mypid |
| 118 |
set mypid 0 |
| 119 |
set test [file tail $file] |
| 120 |
if {! [installtest_p]} { untested $test; continue } |
| 121 |
|
| 122 |
# create a process for the tests that require one |
| 123 |
switch $test { |
| 124 |
uprobes.stp { |
| 125 |
eval spawn /usr/bin/sleep 20 |
| 126 |
set mypid [exp_pid -i $spawn_id] |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
set output_str [get_output_str $test] |
| 131 |
verbose -log "Running $file" |
| 132 |
set rc [stapnonbpf_run $test $output_str $file] |
| 133 |
if {$rc != 0} { |
| 134 |
# Known failures |
| 135 |
switch $test { |
| 136 |
bigmap1.stp { _setup_kfail NONBPF x86_64,s390x,aarch64 rhel } |
| 137 |
cast_op_tracepoint.stp { |
| 138 |
_setup_kfail NONBPF x86_64,s390x rhel |
| 139 |
_setup_kfail NONBPF x86_64 fedora |
| 140 |
} |
| 141 |
context_vars1.stp - |
| 142 |
context_vars2.stp - |
| 143 |
context_vars3.stp - |
| 144 |
kprobes.stp { _setup_kfail NONBPF ppc64le rhel } |
| 145 |
logging1.stp { _setup_kfail NONBPF - rhel,fedora } |
| 146 |
perf1.stp { _setup_kfail NONBPF x86_64,ppc64le,s390x,aarch64 rhel } |
| 147 |
perf2.stp { _setup_kfail NONBPF ppc64le,s390x,aarch64 rhel } |
| 148 |
reg_alloc3.stp - |
| 149 |
tracepoint1.stp - |
| 150 |
timer2.stp { _setup_kfail NONBPF - rhel,fedora } |
| 151 |
timer1.stp { _setup_kfail NONBPF x86_64 rhel,fedora } |
| 152 |
} |
| 153 |
} |
| 154 |
switch $rc { |
| 155 |
0 { pass $test } |
| 156 |
1 { fail "$test incorrect result" } |
| 157 |
2 { fail "$test unexpected output" } |
| 158 |
3 { fail "$test eof (startup)" } |
| 159 |
4 { fail "$test eof (shutdown)" } |
| 160 |
5 { fail "$test timeout (startup)" } |
| 161 |
6 { fail "$test timeout (startup)" } |
| 162 |
7 { fail "$test invalid bpf program" } |
| 163 |
8 { fail "$test compilation" } |
| 164 |
default { fail "$test unknown return value" } |
| 165 |
} |
| 166 |
|
| 167 |
if { $mypid > 0 } { |
| 168 |
kill -INT -$mypid 3 |
| 169 |
catch close |
| 170 |
wait |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
|