OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [gdb/] [testsuite/] [lib/] [insight-support.exp] - Blame information for rev 1181

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
# GDB Testsuite Support for Insight.
2
#
3
# Copyright 2001 Red Hat, Inc.
4
#
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.
9
#
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.
14
 
15
# Initializes the display for gdbtk testing.
16
# Returns 1 if tests should run, 0 otherwise.
17
proc gdbtk_initialize_display {} {
18
  global _using_windows
19
 
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}]}]
24
  }
25
 
26
  if {![_gdbtk_xvfb_init]} {
27
    if {$_using_windows} {
28
      untested "No GDB_DISPLAY -- skipping tests"
29
    } else {
30
      untested "No GDB_DISPLAY or Xvfb -- skipping tests"
31
    }
32
 
33
    return 0
34
  }
35
 
36
  return 1
37
}
38
 
39
# From dejagnu:
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)
43
#
44
# To 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} {
50
  global verbose
51
  global GDB
52
  global GDBFLAGS
53
  global env srcdir subdir objdir
54
 
55
  gdb_stop_suppressing_tests;
56
 
57
  # Need to convert ::GDB to use (-)?insight...
58
  if {[regsub {gdb$} $GDB insight newGDB]} {
59
    set INSIGHT $newGDB
60
  } else {
61
    perror "Cannot find Insight executable"
62
    exit 1
63
  }
64
 
65
  verbose "Starting $INSIGHT -nx -q --tclcommand=$test"
66
 
67
  set real_test [which $test]
68
  if {$real_test == 0} {
69
    perror "$test is not found"
70
    exit 1
71
  }
72
 
73
  if {![is_remote host]} {
74
    if { [which $INSIGHT] == 0 } {
75
      perror "$INSIGHT does not exist."
76
      exit 1
77
    }
78
  }
79
 
80
  set wd [pwd]
81
 
82
  # Find absolute path to test
83
  set test [to_tcl_path -abs $test]
84
 
85
  # Set some environment variables
86
  cd $srcdir
87
  set abs_srcdir [pwd]
88
  set env(DEFS) [to_tcl_path -abs [file join $abs_srcdir $subdir defs]]
89
 
90
  cd $wd
91
  cd [file join $objdir $subdir]
92
  set env(OBJDIR) [pwd]
93
  cd $wd
94
 
95
  # Set info about target into env
96
  _gdbtk_export_target_info
97
 
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
 
102
  set err [catch {exec $INSIGHT -nx -q --tclcommand=$test} res]
103
  if { $err } {
104
    perror "Execing $INSIGHT failed: $res"
105
    append res "\nERROR gdb-crash"
106
  }
107
  return $res
108
}
109
 
110
# Start xvfb when using it.
111
# The precedence is:
112
#   1. If GDB_DISPLAY is set (and not ""), use it
113
#   2. If Xvfb exists, use it (not on cygwin)
114
#   3. Skip tests
115
proc _gdbtk_xvfb_init {} {
116
  global env spawn_id _xvfb_spawn_id _using_windows
117
 
118
  if {[info exists env(GDB_DISPLAY)]} {
119
    if {$env(GDB_DISPLAY) != ""} {
120
      set env(DISPLAY) $env(GDB_DISPLAY)
121
    } else {
122
      # Suppress tests
123
      return 0
124
    }
125
  } elseif {!$_using_windows && [which Xvfb] != 0} {
126
    set screen ":[getpid]"
127
    set pid [spawn  Xvfb $screen -ac]
128
    set _xvfb_spawn_id $spawn_id
129
    set env(DISPLAY) localhost$screen
130
  } else {
131
    # No Xvfb found -- skip test
132
    return 0
133
  }
134
 
135
  return 1
136
}
137
 
138
# Kill xvfb
139
proc _gdbtk_xvfb_exit {} {
140
  global objdir subdir env _xvfb_spawn_id
141
 
142
  if {[info exists _xvfb_spawn_id]} {
143
    exec kill [exp_pid -i $_xvfb_spawn_id]
144
    wait -i $_xvfb_spawn_id
145
  }
146
}
147
 
148
# help proc for setting tcl-style paths from unix-style paths
149
# pass "-abs" to make it an absolute path
150
proc to_tcl_path {unix_path {arg {}}} {
151
  global _using_windows
152
 
153
  if {[string compare $unix_path "-abs"] == 0} {
154
    set unix_path $arg
155
    set wd [pwd]
156
    cd [file dirname $unix_path]
157
    set dirname [pwd]
158
    set unix_name [file join $dirname [file tail $unix_path]]
159
    cd $wd
160
  }
161
 
162
  if {$_using_windows} {
163
    set unix_path [exec cygpath -aw $unix_path]
164
    set unix_path [join [split $unix_path \\] /]
165
  }
166
 
167
  return $unix_path
168
}
169
 
170
# Set information about the target into the environment
171
# variable TARGET_INFO. This array will contain a list
172
# of commands that are necessary to run a target.
173
#
174
# This is mostly devined from how dejagnu works, what
175
# procs are defined, and analyzing unix.exp, monitor.exp,
176
# and sim.exp.
177
#
178
# Array elements exported:
179
# Index   Meaning
180
# -----   -------
181
# init    list of target/board initialization commands
182
# target  target command for target/board
183
# load    load command for target/board
184
# run     run command for target_board
185
proc _gdbtk_export_target_info {} {
186
  global env
187
 
188
  # Figure out what "target class" the testsuite is using,
189
  # i.e., sim, monitor, native
190
  if {[string compare [info proc gdb_target_monitor] gdb_target_monitor] == 0} {
191
    # Using a monitor/remote target
192
    set target monitor
193
  } elseif {[string compare [info proc gdb_target_sim] gdb_target_sim] == 0} {
194
    # Using a simulator target
195
    set target simulator
196
  } elseif {[string compare [info proc gdb_target_sid] gdb_target_sid] == 0} {
197
    # Using sid
198
    set target sid
199
  } else {
200
    # Assume native
201
    set target native
202
  }
203
 
204
  # Now setup the array to be exported.
205
  set info(init) {}
206
  set info(target) {}
207
  set info(load) {}
208
  set info(run) {}
209
 
210
  switch $target {
211
    simulator {
212
      set opts "[target_info gdb,target_sim_options]"
213
      set info(target) "target sim $opts"
214
      set info(load) "load"
215
      set info(run) "run"
216
    }
217
 
218
    monitor {
219
      # Setup options for the connection
220
      if {[target_info exists baud]} {
221
        lappend info(init) "set remotebaud [target_info baud]"
222
      }
223
      if {[target_info exists binarydownload]} {
224
        lappend info(init) "set remotebinarydownload [target_info binarydownload]"
225
      }
226
      if {[target_info exists disable_x_packet]} {
227
        lappend info(init) "set remote X-packet disable"
228
      }
229
      if {[target_info exists disable_z_packet]} {
230
        lappend info(init) "set remote Z-packet disable"
231
      }
232
 
233
      # Get target name and connection info
234
      if {[target_info exists gdb_protocol]} {
235
        set targetname "[target_info gdb_protocol]"
236
      } else {
237
        set targetname "not_specified"
238
      }
239
      if {[target_info exists gdb_serial]} {
240
        set serialport "[target_info gdb_serial]"
241
      } elseif {[target_info exists netport]} {
242
        set serialport "[target_info netport]"
243
      } else {
244
        set serialport "[target_info serial]"
245
      }
246
 
247
      set info(target) "target $targetname $serialport"
248
      set info(load) "load"
249
      set info(run) "continue"
250
    }
251
 
252
    sid {
253
      # We must start sid first, since Insight won't have a clue
254
      # about how to do this.
255
      sid_start
256
      set info(target) "target [target_info gdb_protocol] [target_info netport]"
257
      set info(load) "load"
258
      set info(run) "continue"
259
    }
260
 
261
    native {
262
      set info(run) "run"
263
    }
264
  }
265
 
266
  # Export the array to the environment
267
  set env(TARGET_INFO) [array get info]
268
}
269
 
270
# gdbtk tests call this function to print out the results of the
271
# tests. The argument is a proper list of lists of the form:
272
# {status name description msg}. All of these things typically
273
# come from the testsuite harness.
274
proc gdbtk_analyze_results {results} {
275
  foreach test $results {
276
    set status [lindex $test 0]
277
    set name [lindex $test 1]
278
    set description [lindex $test 2]
279
    set msg [lindex $test 3]
280
 
281
    switch $status {
282
      PASS {
283
        pass "$description ($name)"
284
      }
285
 
286
      FAIL {
287
        fail "$description ($name)"
288
      }
289
 
290
      ERROR {
291
        perror "$name"
292
      }
293
 
294
      XFAIL {
295
        xfail "$description ($name)"
296
      }
297
 
298
      XPASS {
299
        xpass "$description ($name)"
300
      }
301
    }
302
  }
303
}
304
 
305
proc gdbtk_done {{results {}}} {
306
  global _xvfb_spawn_id
307
  gdbtk_analyze_results $results
308
 
309
  # Kill off xvfb if using it
310
  if {[info exists _xvfb_spawn_id]} {
311
    _gdbtk_xvfb_exit
312
  }
313
 
314
  # Yich. If we're using sid, we must kill it
315
  if {[string compare [info proc gdb_target_sid] gdb_target_sid] == 0} {
316
    sid_exit
317
  }
318
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.