| 1 |
#!/usr/bin/env tclsh |
| 2 |
package require Expect |
| 3 |
|
| 4 |
##################### |
| 5 |
# |
| 6 |
# This script tests a single syscall test executable against the |
| 7 |
# syscall tapset. To use, do the following: |
| 8 |
# |
| 9 |
# # gcc -o TESTNAME TESTNAME.c |
| 10 |
# # test-debug-cmd.tcl TESTNAME |
| 11 |
# |
| 12 |
# The script output will appear on stdout. |
| 13 |
# |
| 14 |
##################### |
| 15 |
|
| 16 |
set syscall_dir "" |
| 17 |
set current_dir "" |
| 18 |
|
| 19 |
proc syscall_cleanup {} { |
| 20 |
global syscall_dir current_dir |
| 21 |
if {$current_dir != ""} { |
| 22 |
cd $current_dir |
| 23 |
if {$syscall_dir != ""} {exec rm -rf $syscall_dir} |
| 24 |
set current_dir "" |
| 25 |
} |
| 26 |
exit 0 |
| 27 |
} |
| 28 |
|
| 29 |
proc usage {progname} { |
| 30 |
puts "Usage: $progname testname [C filename]" |
| 31 |
syscall_cleanup |
| 32 |
} |
| 33 |
|
| 34 |
proc bgerror {error} { |
| 35 |
puts "ERROR: $error" |
| 36 |
syscall_cleanup |
| 37 |
} |
| 38 |
trap {syscall_cleanup} SIGINT |
| 39 |
set testname [lindex $argv 0] |
| 40 |
if {$testname == ""} { |
| 41 |
usage $argv0 |
| 42 |
exit |
| 43 |
} |
| 44 |
|
| 45 |
set filename [lindex $argv 1] |
| 46 |
if {$filename == ""} { |
| 47 |
set filename "${testname}.c" |
| 48 |
set sys_prog "../sys.stp" |
| 49 |
} else { |
| 50 |
set sys_prog "[file dirname [file normalize $filename]]/sys.stp" |
| 51 |
} |
| 52 |
set cmd "stap -c ../${testname} ${sys_prog}" |
| 53 |
|
| 54 |
# extract the expected results |
| 55 |
# Use the preprocessor so we can ifdef tests in and out |
| 56 |
|
| 57 |
set ccmd "gcc -E -C -P $filename" |
| 58 |
catch {eval exec $ccmd} output |
| 59 |
|
| 60 |
set ind 0 |
| 61 |
foreach line [split $output "\n"] { |
| 62 |
if {[regsub {//staptest//} $line {} line]} { |
| 63 |
set line "$testname: [string trimleft $line]" |
| 64 |
|
| 65 |
# We need to quote all these metacharacters |
| 66 |
regsub -all {\(} $line {\\(} line |
| 67 |
regsub -all {\)} $line {\\)} line |
| 68 |
regsub -all {\|} $line {\|} line |
| 69 |
# + and * are metacharacters, but should always be used |
| 70 |
# as metacharacters in the expressions, don't escape them. |
| 71 |
#regsub -all {\+} $line {\\+} line |
| 72 |
#regsub -all {\*} $line {\\*} line |
| 73 |
|
| 74 |
# Turn '[[[[' and ']]]]' into '(' and ')' respectively. |
| 75 |
# Because normally parens get quoted, this allows us to |
| 76 |
# have non-quoted parens. |
| 77 |
regsub -all {\[\[\[\[} $line {(} line |
| 78 |
regsub -all {\]\]\]\]} $line {)} line |
| 79 |
|
| 80 |
# Turn '!!!!' into '|'. Since normally pipe characters get |
| 81 |
# quoted, this allows us to have non-quoted pipes. |
| 82 |
regsub -all {!!!!} $line {|} line |
| 83 |
|
| 84 |
regsub -all NNNN $line {[\-0-9]+} line |
| 85 |
regsub -all XXXX $line {[x0-9a-fA-F]+} line |
| 86 |
|
| 87 |
set results($ind) $line |
| 88 |
incr ind |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
if {$ind == 0} { |
| 93 |
puts "UNSUPP" |
| 94 |
syscall_cleanup |
| 95 |
exit |
| 96 |
} |
| 97 |
|
| 98 |
if {[catch {exec mktemp -d staptestXXXXXX} syscall_dir]} { |
| 99 |
puts stderr "Failed to create temporary directory: $syscall_dir" |
| 100 |
syscall_cleanup |
| 101 |
} |
| 102 |
|
| 103 |
set current_dir [pwd] |
| 104 |
cd $syscall_dir |
| 105 |
catch {eval exec $cmd} output |
| 106 |
|
| 107 |
set i 0 |
| 108 |
foreach line [split $output "\n"] { |
| 109 |
if {[regexp $results($i) $line]} { |
| 110 |
incr i |
| 111 |
if {$i >= $ind} {break} |
| 112 |
} |
| 113 |
} |
| 114 |
if {$i >= $ind} { |
| 115 |
puts "PASS" |
| 116 |
} else { |
| 117 |
puts "FAIL" |
| 118 |
} |
| 119 |
|
| 120 |
puts "RESULTS: (\'*\' = MATCHED EXPECTED)\n" |
| 121 |
set i 0 |
| 122 |
foreach line [split $output "\n"] { |
| 123 |
if {[regexp "${testname}: " $line]} { |
| 124 |
if {[regexp $results($i) $line]} { |
| 125 |
puts "*$line" |
| 126 |
incr i |
| 127 |
if {$i >= $ind} {break} |
| 128 |
} else { |
| 129 |
puts "$line" |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
if {$i < $ind} { |
| 134 |
puts "--------- EXPECTED and NOT MATCHED ----------\n" |
| 135 |
} |
| 136 |
for {} {$i < $ind} {incr i} { |
| 137 |
puts "$results($i)" |
| 138 |
} |
| 139 |
|