| 1 |
set syscall_dir "" |
| 2 |
set current_dir "" |
| 3 |
|
| 4 |
proc syscall_cleanup {} { |
| 5 |
global syscall_dir current_dir |
| 6 |
if {$current_dir != ""} { |
| 7 |
cd $current_dir |
| 8 |
set current_dir "" |
| 9 |
} |
| 10 |
if {$syscall_dir != ""} { |
| 11 |
# puts "rm -rf $syscall_dir" |
| 12 |
exec rm -rf $syscall_dir |
| 13 |
set syscall_dir "" |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
proc syscall_cleanup_and_exit {} { |
| 18 |
# puts "syscall_cleanup_and_exit" |
| 19 |
syscall_cleanup |
| 20 |
exit 0 |
| 21 |
} |
| 22 |
|
| 23 |
proc bgerror {error} { |
| 24 |
puts "ERROR: $error" |
| 25 |
syscall_cleanup |
| 26 |
} |
| 27 |
trap {syscall_cleanup_and_exit} SIGINT |
| 28 |
|
| 29 |
proc run_one_test {filename flags bits suite} { |
| 30 |
global syscall_dir current_dir test_module |
| 31 |
|
| 32 |
set testname [file tail [string range $filename 0 end-2]] |
| 33 |
|
| 34 |
# execname() returns the first 15 chars of the test exe name. |
| 35 |
set re_testname [string range $testname 0 14] |
| 36 |
|
| 37 |
if {[catch {exec mktemp -d [pwd]/staptestXXXXXX} syscall_dir]} { |
| 38 |
send_log "$bits-bit $testname $suite : Failed to create temporary directory: $syscall_dir" |
| 39 |
untested "$bits-bit $testname $suite" |
| 40 |
syscall_cleanup |
| 41 |
return |
| 42 |
} |
| 43 |
|
| 44 |
set flags "$flags additional_flags=-lrt" |
| 45 |
# Newer compiler have -Werror set by default, disable various warnings |
| 46 |
set flags "$flags additional_flags=-Wno-stringop-overflow" |
| 47 |
set res [target_compile $filename $syscall_dir/$testname executable $flags ] |
| 48 |
if { $res != "" } { |
| 49 |
send_log "$bits-bit $testname $suite : no corresponding devel environment found\n" |
| 50 |
untested "$bits-bit $testname $suite" |
| 51 |
syscall_cleanup |
| 52 |
return |
| 53 |
} |
| 54 |
|
| 55 |
# Use -R here, in case a previous staprun hangs up or leaves the |
| 56 |
# syscall.ko module in memory, which would block all subsequent |
| 57 |
# invocations. |
| 58 |
set cmd "staprun -R ${test_module} -c $syscall_dir/${testname}" |
| 59 |
|
| 60 |
# Extract additional C flags needed to compile |
| 61 |
set add_flags "" |
| 62 |
foreach i $flags { |
| 63 |
if [regexp "^additional_flags=" $i] { |
| 64 |
regsub "^additional_flags=" $i "" tmp |
| 65 |
append add_flags " $tmp" |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
# Extract the expected results |
| 70 |
# Use the preprocessor so we can ifdef tests in and out |
| 71 |
|
| 72 |
set ccmd "gcc -E -C -P $add_flags $filename" |
| 73 |
# XXX: but note, this will expand all system headers too! |
| 74 |
catch {eval exec $ccmd} output |
| 75 |
|
| 76 |
set ind 0 |
| 77 |
foreach line [split $output "\n"] { |
| 78 |
if {[regsub {//staptest//} $line {} line]} { |
| 79 |
set line "^$re_testname: [string trimleft $line]" |
| 80 |
|
| 81 |
# We need to quote all these metacharacters |
| 82 |
regsub -all {\(} $line {\\(} line |
| 83 |
regsub -all {\)} $line {\\)} line |
| 84 |
regsub -all {\|} $line {\|} line |
| 85 |
# + and * are metacharacters, but should always be used |
| 86 |
# as metacharacters in the expressions, don't escape them. |
| 87 |
#regsub -all {\+} $line {\\+} line |
| 88 |
#regsub -all {\*} $line {\\*} line |
| 89 |
|
| 90 |
# Turn '[[[[' and ']]]]' into '(' and ')' respectively. |
| 91 |
# Because normally parens get quoted, this allows us to |
| 92 |
# have non-quoted parens. |
| 93 |
regsub -all {\[\[\[\[} $line {(} line |
| 94 |
regsub -all {\]\]\]\]} $line {)} line |
| 95 |
|
| 96 |
# Turn '!!!!' into '|'. Since normally pipe characters get |
| 97 |
# quoted, this allows us to have non-quoted pipes. |
| 98 |
regsub -all {!!!!} $line {|} line |
| 99 |
|
| 100 |
regsub -all NNNN $line {[\-0-9]+} line |
| 101 |
regsub -all XXXX $line {[x0-9a-fA-F]+} line |
| 102 |
|
| 103 |
set results($ind) $line |
| 104 |
incr ind |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
if {$ind == 0} { |
| 109 |
# unsupported |
| 110 |
syscall_cleanup |
| 111 |
unsupported "$bits-bit $testname $suite not supported on this arch" |
| 112 |
return |
| 113 |
} |
| 114 |
|
| 115 |
set current_dir [pwd] |
| 116 |
cd $syscall_dir |
| 117 |
|
| 118 |
catch {eval exec $cmd} output |
| 119 |
|
| 120 |
set i 0 |
| 121 |
foreach line [split $output "\n"] { |
| 122 |
# send_log "Comparing $results($i) against $line" |
| 123 |
if {[regexp $results($i) $line]} { |
| 124 |
incr i |
| 125 |
if {$i >= $ind} {break} |
| 126 |
} |
| 127 |
} |
| 128 |
if {$i >= $ind} { |
| 129 |
# puts "PASS $testname" |
| 130 |
pass "$bits-bit $testname $suite" |
| 131 |
} else { |
| 132 |
send_log "$testname FAILED. output of \"$cmd\" was:" |
| 133 |
# add $output at end, just in case it was empty somehow; send_log "" is not happy |
| 134 |
send_log "\n------------------------------------------\n$output" |
| 135 |
send_log "\n------------------------------------------\n" |
| 136 |
send_log "RESULTS: (\'*\' = MATCHED EXPECTED)\n" |
| 137 |
set i 0 |
| 138 |
foreach line [split $output "\n"] { |
| 139 |
if {[regexp "${re_testname}: " $line]} { |
| 140 |
if {[regexp $results($i) $line]} { |
| 141 |
send_log "*$line\n" |
| 142 |
incr i |
| 143 |
if {$i >= $ind} {break} |
| 144 |
} else { |
| 145 |
send_log "$line\n" |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
if {$i < $ind} { |
| 150 |
send_log -- "--------- EXPECTED and NOT MATCHED ----------\n" |
| 151 |
} |
| 152 |
for {} {$i < $ind} {incr i} { |
| 153 |
send_log "$results($i)\n" |
| 154 |
} |
| 155 |
fail "$bits-bit $testname $suite" |
| 156 |
} |
| 157 |
syscall_cleanup |
| 158 |
return |
| 159 |
} |