1 # GDB Testsuite Support for Insight.
3 # Copyright 2001, 2004 Red Hat, Inc.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License (GPL) as published by
7 # the Free Software Foundation; either version 2 of the License, or (at
8 # your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # Initializes the display for gdbtk testing.
16 # Returns 1 if tests should run, 0 otherwise.
17 proc gdbtk_initialize_display {} {
20 # This is hacky, but, we don't have much choice. When running
21 # expect under Windows, tcl_platform(platform) is "unix".
22 if {![info exists _using_windows]} {
23 set _using_windows [expr {![catch {exec cygpath --help}]}]
26 if {![_gdbtk_xvfb_init]} {
27 if {$_using_windows} {
28 untested "No GDB_DISPLAY -- skipping tests"
30 untested "No GDB_DISPLAY or Xvfb -- skipping tests"
40 # srcdir = testsuite src dir (e.g., devo/gdb/testsuite)
41 # objdir = testsuite obj dir (e.g., gdb/testsuite)
42 # subdir = subdir of testsuite (e.g., gdb.gdbtk)
45 # env(DEFS)=the "defs" files (e.g., devo/gdb/testsuite/gdb.gdbtk/defs)
46 # env(SRCDIR)=directory containing the test code (e.g., *.test)
47 # env(OBJDIR)=directory which contains any executables
48 # (e.g., gdb/testsuite/gdb.gdbtk)
49 proc gdbtk_start {test} {
53 global env srcdir subdir objdir
55 gdb_stop_suppressing_tests;
57 # Need to convert ::GDB to use (-)?insight...
58 if {[regsub {gdb$} $GDB insight newGDB]} {
61 perror "Cannot find Insight executable"
62 return "ERROR gdbtk_start"
65 verbose "Starting $INSIGHT -nx -q --tclcommand=$test"
67 set real_test [which $test]
68 if {$real_test == 0} {
69 perror "$test is not found"
70 return "ERROR gdbtk_start"
73 if {![is_remote host]} {
74 if { [which $INSIGHT] == 0 } {
75 perror "$INSIGHT does not exist."
76 return "ERROR gdbtk_start"
82 # Find absolute path to test
83 set test [to_tcl_path -abs $test]
85 # Set some environment variables
88 set env(DEFS) [to_tcl_path -abs [file join $abs_srcdir $subdir defs]]
91 cd [file join $objdir $subdir]
95 # Set info about target into env
96 _gdbtk_export_target_info
98 set env(SRCDIR) $abs_srcdir
99 set env(GDBTK_VERBOSE) 1
100 set env(GDBTK_LOGFILE) [to_tcl_path [file join $objdir gdb.log]]
101 if {[info exists env(TCL_LIBRARY)]} {
102 unset -nocomplain env(TCL_LIBRARY)
105 set err [catch {exec $INSIGHT -nx -q --tclcommand=$test} res]
107 perror "Execing $INSIGHT failed: $res"
108 append res "\nERROR gdb-crash"
113 # Start xvfb when using it.
115 # 1. If GDB_DISPLAY is set (and not ""), use it
116 # 2. If Xvfb exists, use it (not on cygwin)
118 proc _gdbtk_xvfb_init {} {
119 global env spawn_id _xvfb_spawn_id _using_windows
121 if {[info exists env(GDB_DISPLAY)]} {
122 if {$env(GDB_DISPLAY) != ""} {
123 set env(DISPLAY) $env(GDB_DISPLAY)
128 } elseif {!$_using_windows && [which Xvfb] != 0} {
129 set screen ":[getpid]"
130 set pid [spawn Xvfb $screen -ac]
131 set _xvfb_spawn_id $spawn_id
132 set env(DISPLAY) localhost$screen
134 # No Xvfb found -- skip test
142 proc _gdbtk_xvfb_exit {} {
143 global objdir subdir env _xvfb_spawn_id
145 if {[info exists _xvfb_spawn_id]} {
146 exec kill [exp_pid -i $_xvfb_spawn_id]
147 wait -i $_xvfb_spawn_id
151 # help proc for setting tcl-style paths from unix-style paths
152 # pass "-abs" to make it an absolute path
153 proc to_tcl_path {unix_path {arg {}}} {
154 global _using_windows
156 if {[string compare $unix_path "-abs"] == 0} {
159 cd [file dirname $unix_path]
161 set unix_name [file join $dirname [file tail $unix_path]]
165 if {$_using_windows} {
166 set unix_path [exec cygpath -aw $unix_path]
167 set unix_path [join [split $unix_path \\] /]
173 # Set information about the target into the environment
174 # variable TARGET_INFO. This array will contain a list
175 # of commands that are necessary to run a target.
177 # This is mostly devined from how dejagnu works, what
178 # procs are defined, and analyzing unix.exp, monitor.exp,
181 # Array elements exported:
184 # init list of target/board initialization commands
185 # target target command for target/board
186 # load load command for target/board
187 # run run command for target_board
188 proc _gdbtk_export_target_info {} {
191 # Figure out what "target class" the testsuite is using,
192 # i.e., sim, monitor, native
193 if {[string compare [info proc gdb_target_monitor] gdb_target_monitor] == 0} {
194 # Using a monitor/remote target
196 } elseif {[string compare [info proc gdb_target_sim] gdb_target_sim] == 0} {
197 # Using a simulator target
199 } elseif {[string compare [info proc gdb_target_sid] gdb_target_sid] == 0} {
207 # Now setup the array to be exported.
215 set opts "[target_info gdb,target_sim_options]"
216 set info(target) "target sim $opts"
217 set info(load) "load"
222 # Setup options for the connection
223 if {[target_info exists baud]} {
224 lappend info(init) "set remotebaud [target_info baud]"
226 if {[target_info exists binarydownload]} {
227 lappend info(init) "set remotebinarydownload [target_info binarydownload]"
229 if {[target_info exists disable_x_packet]} {
230 lappend info(init) "set remote X-packet disable"
232 if {[target_info exists disable_z_packet]} {
233 lappend info(init) "set remote Z-packet disable"
236 # Get target name and connection info
237 if {[target_info exists gdb_protocol]} {
238 set targetname "[target_info gdb_protocol]"
240 set targetname "not_specified"
242 if {[target_info exists gdb_serial]} {
243 set serialport "[target_info gdb_serial]"
244 } elseif {[target_info exists netport]} {
245 set serialport "[target_info netport]"
247 set serialport "[target_info serial]"
250 set info(target) "target $targetname $serialport"
251 set info(load) "load"
252 set info(run) "continue"
256 # We must start sid first, since Insight won't have a clue
257 # about how to do this.
259 set info(target) "target [target_info gdb_protocol] [target_info netport]"
260 set info(load) "load"
261 set info(run) "continue"
269 # Export the array to the environment
270 set env(TARGET_INFO) [array get info]
273 # gdbtk tests call this function to print out the results of the
274 # tests. The argument is a proper list of lists of the form:
275 # {status name description msg}. All of these things typically
276 # come from the testsuite harness.
277 proc gdbtk_analyze_results {results} {
278 foreach test $results {
279 set status [lindex $test 0]
280 set name [lindex $test 1]
281 set description [lindex $test 2]
282 set msg [lindex $test 3]
286 pass "$description ($name)"
290 fail "$description ($name)"
298 xfail "$description ($name)"
302 xpass "$description ($name)"
308 proc gdbtk_done {{results {}}} {
309 global _xvfb_spawn_id
310 gdbtk_analyze_results $results
312 # Kill off xvfb if using it
313 if {[info exists _xvfb_spawn_id]} {
317 # Yich. If we're using sid, we must kill it
318 if {[string compare [info proc gdb_target_sid] gdb_target_sid] == 0} {