blob: b9d3c0d97568fce8545a735a26e238c60c16e5f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
set dir ""
set current_dir ""
proc cleanup {} {
global dir current_dir
if {$current_dir != ""} {
cd $current_dir
set current_dir ""
}
if {$dir != ""} {
# puts "rm -rf $dir"
exec rm -rf $dir
set dir ""
}
}
proc cleanup_and_exit {} {
# puts "cleanup_and_exit"
cleanup
exit 0
}
proc bgerror {error} {
puts "ERROR: $error"
cleanup
}
trap {cleanup_and_exit} SIGINT
proc run_one_test {filename flags bits} {
global dir current_dir
set testname [file tail [string range $filename 0 end-2]]
if {[catch {exec mktemp -d [pwd]/staptestXXXXXX} dir]} {
puts stderr "Failed to create temporary directory: $dir"
cleanup
}
set res [target_compile $filename $dir/$testname executable $flags]
if { $res != "" } {
send_log "$bits-bit $testname : no corresponding devel environment found\n"
untested "$bits-bit $testname"
return
}
set sys_prog "[file dirname [file normalize $filename]]/sys.stp"
set cmd "stap --skip-badvars -c $dir/${testname} ${sys_prog}"
# Extract the expected results
# Use the preprocessor so we can ifdef tests in and out
set ccmd "gcc -E -C -P $filename"
# XXX: but note, this will expand all system headers too!
catch {eval exec $ccmd} output
set ind 0
foreach line [split $output "\n"] {
if {[regsub {//staptest//} $line {} line]} {
set line "$testname: [string trimleft $line]"
# We need to quote all these metacharacters
regsub -all {\(} $line {\\(} line
regsub -all {\)} $line {\\)} line
regsub -all {\|} $line {\|} line
# + and * are metacharacters, but should always be used
# as metacharacters in the expressions, don't escape them.
#regsub -all {\+} $line {\\+} line
#regsub -all {\*} $line {\\*} line
regsub -all NNNN $line {[\-0-9]+} line
regsub -all XXXX $line {[x0-9a-fA-F]+} line
set results($ind) $line
incr ind
}
}
if {$ind == 0} {
# unsupported
cleanup
unsupported "$bits-bit $testname not supported on this arch"
return
}
set current_dir [pwd]
cd $dir
catch {eval exec $cmd} output
set i 0
foreach line [split $output "\n"] {
# send_log "Comparing $results($i) against $line"
if {[regexp $results($i) $line]} {
incr i
if {$i >= $ind} {break}
}
}
if {$i >= $ind} {
# puts "PASS $testname"
pass "$bits-bit $testname"
} else {
send_log "$testname FAILED. output of \"$cmd\" was:"
send_log "\n------------------------------------------\n"
send_log $output
send_log "\n------------------------------------------\n"
send_log "RESULTS: (\'*\' = MATCHED EXPECTED)\n"
set i 0
foreach line [split $output "\n"] {
if {[regexp "${testname}: " $line]} {
if {[regexp $results($i) $line]} {
send_log "*$line\n"
incr i
if {$i >= $ind} {break}
} else {
send_log "$line\n"
}
}
}
if {$i < $ind} {
send_log -- "--------- EXPECTED and NOT MATCHED ----------\n"
}
for {} {$i < $ind} {incr i} {
send_log "$results($i)\n"
}
fail "$bits-bit $testname"
}
cleanup
return
}
|