| 1 |
#!/usr/bin/env wish |
| 2 |
package require Expect |
| 3 |
|
| 4 |
set syscall_dir "" |
| 5 |
set current_dir "" |
| 6 |
|
| 7 |
proc syscall_cleanup {} { |
| 8 |
global syscall_dir current_dir |
| 9 |
if {$current_dir != ""} { |
| 10 |
cd $current_dir |
| 11 |
if {$syscall_dir != ""} {exec rm -rf $syscall_dir} |
| 12 |
set current_dir "" |
| 13 |
} |
| 14 |
exit 0 |
| 15 |
} |
| 16 |
|
| 17 |
proc usage {progname} { |
| 18 |
puts "Usage: $progname testname" |
| 19 |
syscall_cleanup |
| 20 |
} |
| 21 |
|
| 22 |
proc bgerror {error} { |
| 23 |
puts "ERROR: $error" |
| 24 |
syscall_cleanup |
| 25 |
} |
| 26 |
trap {syscall_cleanup} SIGINT |
| 27 |
set testname [lindex $argv 0] |
| 28 |
if {$testname == ""} { |
| 29 |
usage $argv0 |
| 30 |
exit |
| 31 |
} |
| 32 |
|
| 33 |
set filename [lindex $argv 1] |
| 34 |
if {$filename == ""} { |
| 35 |
set filename "${testname}.c" |
| 36 |
set sys_prog "../sys.stp" |
| 37 |
} else { |
| 38 |
set sys_prog "[file dirname [file normalize $filename]]/sys.stp" |
| 39 |
} |
| 40 |
set cmd "stap -c ../${testname} ${sys_prog}" |
| 41 |
|
| 42 |
# extract the expected results |
| 43 |
# Use the preprocessor so we can ifdef tests in and out |
| 44 |
|
| 45 |
set ccmd "gcc -E -C -P $filename" |
| 46 |
catch {eval exec $ccmd} output |
| 47 |
|
| 48 |
set ind 0 |
| 49 |
foreach line [split $output "\n"] { |
| 50 |
if {[regsub {//staptest//} $line {} line]} { |
| 51 |
set line "$testname: [string trimleft $line]" |
| 52 |
|
| 53 |
# We need to quote all these metacharacters |
| 54 |
regsub -all {\(} $line {\\(} line |
| 55 |
regsub -all {\)} $line {\\)} line |
| 56 |
regsub -all {\|} $line {\|} line |
| 57 |
# + and * are metacharacters, but should always be used |
| 58 |
# as metacharacters in the expressions, don't escape them. |
| 59 |
#regsub -all {\+} $line {\\+} line |
| 60 |
#regsub -all {\*} $line {\\*} line |
| 61 |
|
| 62 |
# Turn '[[[[' and ']]]]' into '(' and ')' respectively. |
| 63 |
# Because normally parens get quoted, this allows us to |
| 64 |
# have non-quoted parens. |
| 65 |
regsub -all {\[\[\[\[} $line {(} line |
| 66 |
regsub -all {\]\]\]\]} $line {)} line |
| 67 |
|
| 68 |
regsub -all NNNN $line {[\-0-9]+} line |
| 69 |
regsub -all XXXX $line {[x0-9a-fA-F]+} line |
| 70 |
|
| 71 |
set results($ind) $line |
| 72 |
incr ind |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if {$ind == 0} { |
| 77 |
puts "UNSUPP" |
| 78 |
syscall_cleanup |
| 79 |
exit |
| 80 |
} |
| 81 |
|
| 82 |
if {[catch {exec mktemp -d staptestXXXXXX} syscall_dir]} { |
| 83 |
puts stderr "Failed to create temporary directory: $syscall_dir" |
| 84 |
syscall_cleanup |
| 85 |
} |
| 86 |
|
| 87 |
set current_dir [pwd] |
| 88 |
cd $syscall_dir |
| 89 |
catch {eval exec $cmd} output |
| 90 |
|
| 91 |
set i 0 |
| 92 |
foreach line [split $output "\n"] { |
| 93 |
if {[regexp $results($i) $line]} { |
| 94 |
incr i |
| 95 |
if {$i >= $ind} {break} |
| 96 |
} |
| 97 |
} |
| 98 |
if {$i >= $ind} { |
| 99 |
puts "PASS" |
| 100 |
} else { |
| 101 |
puts "FAIL" |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
text .t1 -width 60 -height 20 -wrap none \ |
| 106 |
-xscrollcommand {.x1bar set} \ |
| 107 |
-yscrollcommand {.ybar set} |
| 108 |
text .t2 -width 60 -height 20 -wrap none \ |
| 109 |
-xscrollcommand {.x2bar set} \ |
| 110 |
-yscrollcommand {.ybar set} |
| 111 |
|
| 112 |
scrollbar .x1bar -orient horizontal -command {.t1 xview} |
| 113 |
scrollbar .x2bar -orient horizontal -command {.t2 xview} |
| 114 |
scrollbar .ybar -orient vertical -command [list bindyview [list .t1 .t2]] |
| 115 |
|
| 116 |
proc bindyview {lists args} { |
| 117 |
foreach l $lists { |
| 118 |
eval {$l yview} $args |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
grid .t1 .t2 .ybar -sticky nsew |
| 123 |
grid .x1bar .x2bar -sticky nsew |
| 124 |
grid columnconfigure . 0 -weight 1 |
| 125 |
grid columnconfigure . 1 -weight 1 |
| 126 |
grid rowconfigure . 0 -weight 1 |
| 127 |
.t1 tag configure blue -foreground blue |
| 128 |
.t2 tag configure blue -foreground blue |
| 129 |
.t1 tag configure red -foreground red |
| 130 |
.t2 tag configure red -foreground red |
| 131 |
|
| 132 |
set i 0 |
| 133 |
foreach line [split $output "\n"] { |
| 134 |
if {[regexp "${testname}: " $line]} { |
| 135 |
if {[regexp $results($i) $line]} { |
| 136 |
.t1 insert end ${line} blue |
| 137 |
.t2 insert end $results($i) blue |
| 138 |
incr i |
| 139 |
if {$i >= $ind} {break} |
| 140 |
} else { |
| 141 |
.t1 insert end ${line} |
| 142 |
} |
| 143 |
.t1 insert end "\n" |
| 144 |
.t2 insert end "\n" |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
for {} {$i < $ind} {incr i} { |
| 149 |
.t2 insert end $results($i) red |
| 150 |
.t1 insert end "\n" |
| 151 |
.t2 insert end "\n" |
| 152 |
} |
| 153 |
|
| 154 |
bind . <Destroy> {syscall_cleanup} |
| 155 |
|