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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
# GDB Testsuite Support for Insight.
#
# Copyright 2001 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License (GPL) as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Initializes the display for gdbtk testing.
# Returns 1 if tests should run, 0 otherwise.
proc gdbtk_initialize_display {} {
global _using_windows
# This is hacky, but, we don't have much choice. When running
# expect under Windows, tcl_platform(platform) is "unix".
if {![info exists _using_windows]} {
set _using_windows [expr {![catch {exec cygpath --help}]}]
}
if {![_gdbtk_xvfb_init]} {
if {$_using_windows} {
untested "No GDB_DISPLAY -- skipping tests"
} else {
untested "No GDB_DISPLAY or Xvfb -- skipping tests"
}
return 0
}
return 1
}
# From dejagnu:
# srcdir = testsuite src dir (e.g., devo/gdb/testsuite)
# objdir = testsuite obj dir (e.g., gdb/testsuite)
# subdir = subdir of testsuite (e.g., gdb.gdbtk)
#
# To gdbtk:
# env(DEFS)=the "defs" files (e.g., devo/gdb/testsuite/gdb.gdbtk/defs)
# env(SRCDIR)=directory containing the test code (e.g., *.test)
# env(OBJDIR)=directory which contains any executables
# (e.g., gdb/testsuite/gdb.gdbtk)
proc gdbtk_start {test} {
global verbose
global GDB
global GDBFLAGS
global env srcdir subdir objdir
gdb_stop_suppressing_tests;
# Need to convert ::GDB to use (-)?insight...
if {[regsub {gdb$} $GDB insight newGDB]} {
set INSIGHT $newGDB
} else {
perror "Cannot find Insight executable"
exit 1
}
verbose "Starting $INSIGHT -nx -q --tclcommand=$test"
set real_test [which $test]
if {$real_test == 0} {
perror "$test is not found"
exit 1
}
if {![is_remote host]} {
if { [which $INSIGHT] == 0 } {
perror "$INSIGHT does not exist."
exit 1
}
}
set wd [pwd]
# Find absolute path to test
set test [to_tcl_path -abs $test]
# Set some environment variables
cd $srcdir
set abs_srcdir [pwd]
set env(DEFS) [to_tcl_path -abs [file join $abs_srcdir $subdir defs]]
cd $wd
cd [file join $objdir $subdir]
set env(OBJDIR) [pwd]
cd $wd
# Set info about target into env
_gdbtk_export_target_info
set env(SRCDIR) $abs_srcdir
set env(GDBTK_VERBOSE) 1
set env(GDBTK_LOGFILE) [to_tcl_path [file join $objdir gdb.log]]
set err [catch {exec $INSIGHT -nx -q --tclcommand=$test} res]
if { $err } {
perror "Execing $INSIGHT failed: $res"
append res "\nERROR gdb-crash"
}
return $res
}
# Start xvfb when using it.
# The precedence is:
# 1. If GDB_DISPLAY is set (and not ""), use it
# 2. If Xvfb exists, use it (not on cygwin)
# 3. Skip tests
proc _gdbtk_xvfb_init {} {
global env spawn_id _xvfb_spawn_id _using_windows
if {[info exists env(GDB_DISPLAY)]} {
if {$env(GDB_DISPLAY) != ""} {
set env(DISPLAY) $env(GDB_DISPLAY)
} else {
# Suppress tests
return 0
}
} elseif {!$_using_windows && [which Xvfb] != 0} {
set screen ":[getpid]"
set pid [spawn Xvfb $screen -ac]
set _xvfb_spawn_id $spawn_id
set env(DISPLAY) localhost$screen
} else {
# No Xvfb found -- skip test
return 0
}
return 1
}
# Kill xvfb
proc _gdbtk_xvfb_exit {} {
global objdir subdir env _xvfb_spawn_id
if {[info exists _xvfb_spawn_id]} {
exec kill [exp_pid -i $_xvfb_spawn_id]
wait -i $_xvfb_spawn_id
}
}
# help proc for setting tcl-style paths from unix-style paths
# pass "-abs" to make it an absolute path
proc to_tcl_path {unix_path {arg {}}} {
global _using_windows
if {[string compare $unix_path "-abs"] == 0} {
set unix_path $arg
set wd [pwd]
cd [file dirname $unix_path]
set dirname [pwd]
set unix_name [file join $dirname [file tail $unix_path]]
cd $wd
}
if {$_using_windows} {
set unix_path [exec cygpath -aw $unix_path]
set unix_path [join [split $unix_path \\] /]
}
return $unix_path
}
# Set information about the target into the environment
# variable TARGET_INFO. This array will contain a list
# of commands that are necessary to run a target.
#
# This is mostly devined from how dejagnu works, what
# procs are defined, and analyzing unix.exp, monitor.exp,
# and sim.exp.
#
# Array elements exported:
# Index Meaning
# ----- -------
# init list of target/board initialization commands
# target target command for target/board
# load load command for target/board
# run run command for target_board
proc _gdbtk_export_target_info {} {
global env
# Figure out what "target class" the testsuite is using,
# i.e., sim, monitor, native
if {[string compare [info proc gdb_target_monitor] gdb_target_monitor] == 0} {
# Using a monitor/remote target
set target monitor
} elseif {[string compare [info proc gdb_target_sim] gdb_target_sim] == 0} {
# Using a simulator target
set target simulator
} elseif {[string compare [info proc gdb_target_sid] gdb_target_sid] == 0} {
# Using sid
set target sid
} else {
# Assume native
set target native
}
# Now setup the array to be exported.
set info(init) {}
set info(target) {}
set info(load) {}
set info(run) {}
switch $target {
simulator {
set opts "[target_info gdb,target_sim_options]"
set info(target) "target sim $opts"
set info(load) "load"
set info(run) "run"
}
monitor {
# Setup options for the connection
if {[target_info exists baud]} {
lappend info(init) "set remotebaud [target_info baud]"
}
if {[target_info exists binarydownload]} {
lappend info(init) "set remotebinarydownload [target_info binarydownload]"
}
if {[target_info exists disable_x_packet]} {
lappend info(init) "set remote X-packet disable"
}
if {[target_info exists disable_z_packet]} {
lappend info(init) "set remote Z-packet disable"
}
# Get target name and connection info
if {[target_info exists gdb_protocol]} {
set targetname "[target_info gdb_protocol]"
} else {
set targetname "not_specified"
}
if {[target_info exists gdb_serial]} {
set serialport "[target_info gdb_serial]"
} elseif {[target_info exists netport]} {
set serialport "[target_info netport]"
} else {
set serialport "[target_info serial]"
}
set info(target) "target $targetname $serialport"
set info(load) "load"
set info(run) "continue"
}
sid {
# We must start sid first, since Insight won't have a clue
# about how to do this.
sid_start
set info(target) "target [target_info gdb_protocol] [target_info netport]"
set info(load) "load"
set info(run) "continue"
}
native {
set info(run) "run"
}
}
# Export the array to the environment
set env(TARGET_INFO) [array get info]
}
# gdbtk tests call this function to print out the results of the
# tests. The argument is a proper list of lists of the form:
# {status name description msg}. All of these things typically
# come from the testsuite harness.
proc gdbtk_analyze_results {results} {
foreach test $results {
set status [lindex $test 0]
set name [lindex $test 1]
set description [lindex $test 2]
set msg [lindex $test 3]
switch $status {
PASS {
pass "$description ($name)"
}
FAIL {
fail "$description ($name)"
}
ERROR {
perror "$name"
}
XFAIL {
xfail "$description ($name)"
}
XPASS {
xpass "$description ($name)"
}
}
}
}
proc gdbtk_done {{results {}}} {
global _xvfb_spawn_id
gdbtk_analyze_results $results
# Kill off xvfb if using it
if {[info exists _xvfb_spawn_id]} {
_gdbtk_xvfb_exit
}
# Yich. If we're using sid, we must kill it
if {[string compare [info proc gdb_target_sid] gdb_target_sid] == 0} {
sid_exit
}
}
|