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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [testsuite/] [config/] [default.exp] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 1996 Cygnus Support
2
 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-dejagnu@prep.ai.mit.edu
19
 
20
# This file was written by Tom Tromey 
21
 
22
set testdrv "unix/tktest"
23
set tprompt "%"
24
 
25
#
26
# Extract and print the version number of wish.
27
#
28
proc tk_version {} {
29
  global testdrv
30
  if {! [catch {exec $testdrv -version} output]
31
      && ! [regsub {^.*version } $output {} version]} then {
32
    clone_output "Tk library is version\t$version\n"
33
  }
34
}
35
 
36
#
37
# Source a file.
38
#
39
proc tk_load {file} {
40
  global subdir testdrv spawn_id
41
 
42
  if {! [file exists $file]} then {
43
    perror "$file does not exist."
44
    return -1
45
  }
46
 
47
  verbose "Sourcing $file..."
48
  send "source $file\n"
49
  return 0
50
}
51
 
52
#
53
# Exit the test driver.
54
#
55
proc tk_exit {} {
56
  # If we started Xvfb, we should kill it.  This doesn't happen right
57
  # now, so this proc does nothing.
58
  # xvfb_exit
59
}
60
 
61
#
62
# Find X display to use.  Return 0 if not found.  Set DISPLAY
63
# environment variable if display found.
64
#
65
proc find_x_display {} {
66
  global env
67
 
68
  if {[info exists env(TEST_DISPLAY)]} then {
69
    set env(DISPLAY) $env(TEST_DISPLAY)
70
    return 1
71
  }
72
 
73
  return 0
74
}
75
 
76
#
77
# Start the test driver.
78
#
79
proc tk_start {} {
80
  global testdrv objdir subdir srcdir spawn_id tprompt
81
 
82
  set testdrv "$objdir/$testdrv"
83
  set defs "$srcdir/../tests/defs"
84
 
85
  set timeout 100
86
  set timetol 0
87
 
88
  if {! [find_x_display]} then {
89
      return -1
90
  }
91
 
92
  spawn $testdrv
93
 
94
  if ![file exists ${srcdir}/../tests] {
95
    perror "The source for the test cases is missing." 0
96
    return -1
97
  }
98
 
99
  send "[list set srcdir ${srcdir}/../tests]\r"
100
  expect {
101
    -re "set VERBOSE 1\[\r\n\]*1\[\r\n\]*%" {
102
      verbose "Set verbose flag for tests"
103
      exp_continue
104
    }
105
    -re "${srcdir}/../tests\[\r\n\]*$tprompt" {
106
      verbose "Set srcdir to $srcdir/../tests" 2
107
    }
108
    -re "no files matched glob pattern" {
109
      warning "Didn't set srcdir to $srcdir/../tests"
110
    }
111
    timeout {
112
      perror "Couldn't set srcdir"
113
      return -1
114
    }
115
  }
116
 
117
  if ![file exists $defs] then {
118
    perror "$defs does not exist."
119
    return -1
120
  }
121
 
122
  verbose "Sourcing $defs..."
123
  send "source $defs\r\n"
124
 
125
  expect {
126
    -re ".*source $defs.*$" {
127
      verbose "Sourced $defs"
128
    }
129
    "Error: couldn't read file*" {
130
      perror "Couldn't source $defs"
131
      return -1
132
    }
133
    "%" {
134
      verbose "Got prompt, sourced $defs"
135
    }
136
    timeout {
137
      warning "Timed out sourcing $defs."
138
      if { $timetol <= 3 } {
139
        incr timetol
140
        exp_continue
141
      } else {
142
        return -1
143
      }
144
    }
145
  }
146
 
147
  set timetol 0
148
  sleep 2
149
  send "set VERBOSE 1\n"
150
  expect {
151
    -re "% 1.*%" {
152
      verbose "Set verbose flag for tests"
153
    }
154
    -re "set VERBOSE 1.*1.*%" {
155
      verbose "Set verbose flag for tests"
156
    }
157
    timeout {
158
      perror "Timed out setting verbose flag."
159
      if { $timetol <= 3 } {
160
        exp_continue
161
      } else {
162
        return -1
163
      }
164
    }
165
  }
166
  return $spawn_id
167
}
168
 
169
################################################################
170
#
171
# Utility functions.
172
#
173
 
174
proc read_file {name} {
175
  set id [open $name r]
176
  set contents [read $id]
177
  close $id
178
  return $contents
179
}
180
 
181
proc write_file {name contents} {
182
  set id [open $name w]
183
  puts -nonewline $id $contents
184
  close $id
185
}
186
 
187
# NOTE that this fails to copy files with NULs in them.  Change
188
# implementation to "exec cp" if required.
189
proc copy_file {from to} {
190
  write_file $to [read_file $from]
191
}
192
 
193
################################################################
194
#
195
# Start/stop Xvfb.  These procs aren't used right now; we assume Xvfb
196
# is already running.
197
#
198
 
199
#
200
# Stop Xvfb.
201
#
202
proc xvfb_exit {} {
203
  global Xvfb_spawn_id
204
 
205
  # Send C-c to kill it.
206
  send -i $Xvfb_spawn_id "\003"
207
}
208
 
209
#
210
# Start Xvfb.  Return 0 on error, 1 if started.  Set DISPLAY
211
# environment variable on successful start.
212
#
213
#
214
proc xvfb_start {} {
215
  global spawn_id Xvfb_spawn_id Xvfb_screen env
216
 
217
  # FIXME should look for Xvfb in build directory.  Do this later,
218
  # when we actually build Xvfb.
219
 
220
  set Xvfb [which Xvfb]
221
  # Why "0"?  I don't know, but that is what the manual says.
222
  if {$Xvfb == 0} then {
223
    perror "Couldn't find Xvfb"
224
    return 0
225
  }
226
  verbose "Xvfb is $Xvfb"
227
 
228
  # Pick a number at random...
229
  set Xvfb_screen 23
230
 
231
  while {$Xvfb_screen < 100} {
232
    spawn $Xvfb :$Xvfb_screen
233
 
234
    expect {
235
      "Server is already active" {
236
        incr Xvfb_screen
237
      }
238
 
239
      timeout {
240
        break
241
      }
242
    }
243
  }
244
 
245
  if {$Xvfb_screen == 100} then {
246
    perror "Xvfb screen is 100!"
247
    return 0
248
  }
249
 
250
  set Xvfb_spawn_id $spawn_id
251
  set env(DISPLAY) :$Xvfb_screen
252
  verbose "Screen is :$Xvfb_screen"
253
  return 1
254
}

powered by: WebSVN 2.1.0

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