Commit | Line | Data |
---|---|---|
d193d762 | 1 | # Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
f70a4714 KR |
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 | # DejaGnu@cygnus.com | |
19 | ||
20 | # This file was written by Ken Raeburn (raeburn@cygnus.com). | |
21 | ||
22 | proc gas_version {} { | |
23 | global AS | |
fd9b8885 | 24 | catch "exec $AS -version < /dev/null" tmp |
f70a4714 KR |
25 | # Should find a way to discard constant parts, keep whatever's |
26 | # left, so the version string could be almost anything at all... | |
23c6150b | 27 | regexp "version (cygnus-|)\[-0-9.a-zA-Z-\]+" $tmp version |
f70a4714 | 28 | set tmp $version |
23c6150b | 29 | clone_output "[which $AS] $version\n" |
f70a4714 KR |
30 | unset tmp |
31 | unset version | |
32 | } | |
33 | ||
fd9b8885 | 34 | proc gas_run { prog as_opts redir } { |
f70a4714 KR |
35 | global AS |
36 | global ASFLAGS | |
37 | global comp_output | |
fd9b8885 RS |
38 | global srcdir |
39 | global subdir | |
f70a4714 | 40 | |
fd9b8885 RS |
41 | verbose "Executing $AS $ASFLAGS $as_opts $prog $redir" |
42 | catch "exec $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" comp_output | |
43 | } | |
44 | ||
45 | proc all_ones { args } { | |
46 | foreach x $args { if [expr $x!=1] { return 0 } } | |
47 | return 1 | |
48 | } | |
49 | ||
50 | proc gas_start { prog as_opts } { | |
51 | global AS | |
52 | global ASFLAGS | |
53 | global srcdir | |
54 | global subdir | |
55 | global spawn_id | |
56 | ||
57 | verbose "Starting $AS $ASFLAGS $as_opts $prog" 2 | |
58 | catch { | |
384b93b1 | 59 | spawn -noecho -nottycopy $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog |
fd9b8885 RS |
60 | } foo |
61 | if ![regexp {^[0-9]+} $foo] then { | |
d9ac0258 | 62 | perror "Can't run $subdir/$prog: $foo" |
f70a4714 | 63 | } |
fd9b8885 RS |
64 | } |
65 | ||
66 | proc gas_finish { } { | |
67 | global spawn_id | |
68 | ||
8cbd903e KR |
69 | catch "close" |
70 | catch "wait" | |
fd9b8885 RS |
71 | } |
72 | ||
73 | proc want_no_output { testname } { | |
74 | global comp_output | |
75 | ||
f70a4714 KR |
76 | if ![string match "" $comp_output] then { |
77 | send_log "$comp_output\n" | |
fd9b8885 RS |
78 | verbose "$comp_output" 3 |
79 | } | |
80 | if [string match "" $comp_output] then { | |
81 | pass "$testname" | |
82 | return 1 | |
83 | } else { | |
84 | fail "$testname" | |
85 | return 0 | |
86 | } | |
87 | } | |
88 | ||
89 | proc gas_test_old { file as_opts testname } { | |
90 | gas_run $file $as_opts "" | |
91 | return [want_no_output $testname] | |
92 | } | |
93 | ||
94 | proc gas_test { file as_opts var_opts testname } { | |
95 | global comp_output | |
96 | ||
97 | set i 0 | |
98 | foreach word $var_opts { | |
99 | set ignore_stdout($i) [string match "*>" $word] | |
100 | set opt($i) [string trim $word {>}] | |
101 | incr i | |
102 | } | |
103 | set max [expr 1<<$i] | |
104 | for {set i 0} {[expr $i<$max]} {incr i} { | |
105 | set maybe_ignore_stdout "" | |
106 | set extra_opts "" | |
107 | for {set bit 0} {(1<<$bit)<$max} {incr bit} { | |
108 | set num [expr 1<<$bit] | |
109 | if [expr $i&$num] then { | |
110 | set extra_opts "$extra_opts $opt($bit)" | |
111 | if $ignore_stdout($bit) then { | |
09a1cedb | 112 | set maybe_ignore_stdout ">/dev/null" |
fd9b8885 RS |
113 | } |
114 | } | |
115 | } | |
116 | set extra_opts [string trim $extra_opts] | |
117 | gas_run $file "$as_opts $extra_opts" $maybe_ignore_stdout | |
118 | ||
119 | # Should I be able to use a conditional expression here? | |
120 | if [string match "" $extra_opts] then { | |
121 | want_no_output $testname | |
122 | } else { | |
123 | want_no_output "$testname ($extra_opts)" | |
f70a4714 KR |
124 | } |
125 | } | |
23c6150b RS |
126 | if [info exists errorInfo] then { |
127 | unset errorInfo | |
128 | } | |
f70a4714 KR |
129 | } |
130 | ||
fd9b8885 | 131 | proc gas_test_ignore_stdout { file as_opts testname } { |
f70a4714 KR |
132 | global comp_output |
133 | ||
09a1cedb | 134 | gas_run $file $as_opts ">/dev/null" |
fd9b8885 RS |
135 | want_no_output $testname |
136 | } | |
137 | ||
138 | proc gas_test_error { file as_opts testname } { | |
139 | global comp_output | |
140 | ||
09a1cedb | 141 | gas_run $file $as_opts ">/dev/null" |
f70a4714 KR |
142 | if ![string match "" $comp_output] then { |
143 | send_log "$comp_output\n" | |
fd9b8885 | 144 | verbose "$comp_output" 3 |
f70a4714 KR |
145 | } |
146 | if [string match "" $comp_output] then { | |
f70a4714 | 147 | fail "$testname" |
fd9b8885 RS |
148 | } else { |
149 | pass "$testname" | |
150 | } | |
151 | } | |
152 | ||
153 | proc gas_exit {} {} | |
154 | ||
155 | proc gas_init {} { | |
156 | global target_cpu | |
157 | global target_cpu_family | |
158 | global target_family | |
159 | global target_vendor | |
160 | global target_os | |
161 | global stdoptlist | |
162 | ||
163 | case "$target_cpu" in { | |
164 | "m68???" { set target_cpu_family m68k } | |
165 | "i[34]86" { set target_cpu_family i386 } | |
166 | default { set target_cpu_family $target_cpu } | |
f70a4714 | 167 | } |
fd9b8885 RS |
168 | |
169 | set target_family "$target_cpu_family-$target_vendor-$target_os" | |
170 | set stdoptlist "-a>" | |
171 | # Need to return an empty string. | |
172 | return | |
173 | } | |
174 | ||
8cbd903e KR |
175 | # For easier reading. |
176 | proc fail_phase { name phase opts } { | |
177 | set opts [string trim $opts] | |
178 | if { $opts == "" } { | |
179 | fail "$name ($phase)" | |
180 | } else { | |
181 | fail "$name ($phase: $opts)" | |
182 | } | |
183 | } | |
184 | ||
185 | # This proc requires two input files -- the .s file containing the | |
186 | # assembly source, and a .d file containing the expected output from | |
187 | # objdump or nm or whatever, and leading comments indicating any options | |
188 | # to be passed to the assembler or dump program. | |
91e3b582 | 189 | |
8cbd903e KR |
190 | proc run_dump_test { name } { |
191 | global subdir srcdir | |
192 | global OBJDUMP NM AS | |
193 | global OBJDUMPFLAGS NMFLAGS ASFLAGS | |
194 | ||
91e3b582 DE |
195 | if [string match "*/*" $name] { |
196 | set file $name | |
197 | set name [file tail $name] | |
198 | } else { | |
199 | set file "$srcdir/$subdir/$name" | |
200 | } | |
8cbd903e | 201 | set opt_array [slurp_options "${file}.d"] |
91e3b582 DE |
202 | if { $opt_array == -1 } { |
203 | unresolved $subdir/$name | |
204 | return | |
205 | } | |
8cbd903e KR |
206 | set opts(as) {} |
207 | set opts(objdump) {} | |
208 | set opts(nm) {} | |
209 | set opts(name) {} | |
210 | set opts(PROG) {} | |
09a1cedb | 211 | set opts(source) {} |
8cbd903e KR |
212 | |
213 | foreach i $opt_array { | |
214 | set opt_name [lindex $i 0] | |
215 | set opt_val [lindex $i 1] | |
216 | if ![info exists opts($opt_name)] { | |
217 | perror "unknown option $opt_name in file $file.d" | |
91e3b582 | 218 | unresolved $subdir/$name |
8cbd903e KR |
219 | return |
220 | } | |
221 | if [string length $opts($opt_name)] { | |
222 | perror "option $opt_name multiply set in $file.d" | |
91e3b582 | 223 | unresolved $subdir/$name |
8cbd903e KR |
224 | return |
225 | } | |
226 | set opts($opt_name) $opt_val | |
227 | } | |
228 | ||
229 | if {$opts(PROG) != ""} { | |
230 | switch -- $opts(PROG) { | |
231 | objdump | |
232 | { set program objdump } | |
233 | nm | |
234 | { set program nm } | |
235 | default | |
236 | { perror "unrecognized program option $opts(PROG) in $file.d" | |
91e3b582 | 237 | unresolved $subdir/$name |
8cbd903e KR |
238 | return } |
239 | } | |
240 | } elseif {$opts(objdump) == "" && $opts(nm) != ""} { | |
241 | set program nm | |
242 | } elseif {$opts(objdump) != "" && $opts(nm) == ""} { | |
243 | set program objdump | |
244 | } else { | |
245 | perror "dump program unspecified in $file.d" | |
91e3b582 | 246 | unresolved $subdir/$name |
8cbd903e KR |
247 | return |
248 | } | |
249 | set progopts1 $opts($program) | |
250 | eval set progopts \$[string toupper $program]FLAGS | |
251 | eval set program \$[string toupper $program] | |
91e3b582 DE |
252 | if { $opts(name) == "" } { |
253 | set testname "$subdir/$name" | |
254 | } else { | |
255 | set testname $opts(name) | |
256 | } | |
8cbd903e | 257 | |
09a1cedb KR |
258 | if { $opts(source) == "" } { |
259 | set sourcefile ${file}.s | |
260 | } else { | |
261 | set sourcefile $srcdir/$subdir/$opts(source) | |
262 | } | |
263 | ||
264 | catch "exec $srcdir/lib/run $AS $ASFLAGS $opts(as) $sourcefile" comp_output | |
8cbd903e KR |
265 | |
266 | if ![string match "" $comp_output] then { | |
267 | send_log "$comp_output\n" | |
268 | verbose "$comp_output" 3 | |
269 | fail_phase $testname assembly "$ASFLAGS $opts(as)" | |
270 | return | |
271 | } | |
272 | ||
09a1cedb | 273 | if { $progopts1 == "" } { set $progopts1 "-r" } |
91e3b582 | 274 | verbose "running $program $progopts $progopts1" 3 |
09a1cedb KR |
275 | if [catch "exec $program $progopts $progopts1 > dump.out" comp_output] { |
276 | fail_phase $testname {running objdump} "$progopts $progopts1" | |
8cbd903e KR |
277 | return |
278 | } | |
279 | ||
91e3b582 | 280 | verbose_eval {[file_contents "dump.out"]} 3 |
8cbd903e KR |
281 | if { [regexp_diff "dump.out" "${file}.d"] } then { |
282 | fail_phase $testname {checking output} "$ASFLAGS $opts(as)" | |
283 | return | |
284 | } | |
285 | ||
286 | pass $testname | |
287 | } | |
288 | ||
289 | proc slurp_options { file } { | |
290 | if [catch { set f [open $file r] } x] { | |
91e3b582 DE |
291 | #perror "couldn't open `$file': $x" |
292 | perror "$x" | |
293 | return -1 | |
8cbd903e KR |
294 | } |
295 | set opt_array {} | |
296 | # whitespace expression | |
297 | set ws {[ ]*} | |
298 | set nws {[^ ]*} | |
299 | # whitespace is ignored anywhere except within the options list; | |
300 | # option names are alphabetic only | |
09a1cedb | 301 | set pat "^#${ws}(\[a-zA-Z\]*)$ws:${ws}(.*)$ws\$" |
8cbd903e KR |
302 | while { [gets $f line] != -1 } { |
303 | set line [string trim $line] | |
304 | # Whitespace here is space-tab. | |
305 | if [regexp $pat $line xxx opt_name opt_val] { | |
306 | # match! | |
307 | lappend opt_array [list $opt_name $opt_val] | |
308 | } else { | |
309 | break | |
310 | } | |
311 | } | |
312 | close $f | |
313 | return $opt_array | |
314 | } | |
315 | ||
d193d762 KR |
316 | proc objdump { opts } { |
317 | global OBJDUMP | |
318 | global comp_output | |
319 | ||
320 | catch "exec $OBJDUMP $opts" comp_output | |
321 | verbose "objdump output=$comp_output\n" 3 | |
322 | } | |
323 | ||
324 | proc objdump_start_no_subdir { prog opts } { | |
fd9b8885 RS |
325 | global OBJDUMP |
326 | global srcdir | |
327 | global spawn_id | |
328 | ||
d193d762 | 329 | verbose "Starting $OBJDUMP $opts $prog" 2 |
fd9b8885 | 330 | catch { |
d193d762 | 331 | spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog |
fd9b8885 RS |
332 | } foo |
333 | if ![regexp {^[0-9]+} $foo] then { | |
d9ac0258 | 334 | perror "Can't run $prog: $foo" |
fd9b8885 RS |
335 | } |
336 | } | |
337 | ||
fd9b8885 RS |
338 | proc objdump_finish { } { |
339 | global spawn_id | |
340 | ||
8cbd903e KR |
341 | catch "close" |
342 | catch "wait" | |
fd9b8885 RS |
343 | } |
344 | ||
09a1cedb KR |
345 | # Default timeout is 10 seconds, loses on a slow machine. But some |
346 | # configurations of dejagnu may override it. | |
347 | if {$timeout<120} then { set timeout 120 } | |
348 | ||
3c6dc75b | 349 | expect_after -i { |
858665b7 BC |
350 | timeout { perror "timeout" } |
351 | "virtual memory exhausted" { perror "virtual memory exhausted" } | |
352 | buffer_full { perror "buffer full" } | |
353 | eof { perror "eof" } | |
f70a4714 | 354 | } |
d193d762 KR |
355 | |
356 | # regexp_diff, based on simple_diff taken from ld test suite | |
357 | # compares two files line-by-line | |
358 | # file1 contains strings, file2 contains regexps and #-comments | |
359 | # blank lines are ignored in either file | |
360 | # returns non-zero if differences exist | |
361 | # | |
362 | proc regexp_diff { file_1 file_2 } { | |
363 | ||
364 | set eof -1 | |
365 | set end 0 | |
366 | set differences 0 | |
8cbd903e | 367 | |
d193d762 KR |
368 | if [file exists $file_1] then { |
369 | set file_a [open $file_1 r] | |
370 | } else { | |
371 | warning "$file_1 doesn't exist" | |
8cbd903e | 372 | return 1 |
d193d762 | 373 | } |
8cbd903e | 374 | |
d193d762 KR |
375 | if [file exists $file_2] then { |
376 | set file_b [open $file_2 r] | |
377 | } else { | |
378 | fail "$file_2 doesn't exist" | |
379 | close $file_a | |
8cbd903e | 380 | return 1 |
d193d762 | 381 | } |
8cbd903e | 382 | |
d193d762 | 383 | verbose " Regexp-diff'ing: $file_1 $file_2" 2 |
8cbd903e | 384 | |
d193d762 KR |
385 | while { $differences == 0 && $end == 0 } { |
386 | set line_a "" | |
387 | set line_b "" | |
388 | while { [string length $line_a] == 0 } { | |
389 | if { [gets $file_a line_a] == $eof } { | |
390 | set end 1 | |
391 | break | |
392 | } | |
393 | } | |
394 | while { [string length $line_b] == 0 || [string match "#*" $line_b] } { | |
395 | if { [gets $file_b line_b] == $eof } { | |
396 | set end 1 | |
397 | break | |
398 | } | |
399 | } | |
400 | if { $end } { break } | |
401 | verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3 | |
8cbd903e | 402 | if ![regexp "^$line_b$" "$line_a"] { |
09a1cedb KR |
403 | send_log "regexp_diff match failure\n" |
404 | send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n" | |
d193d762 KR |
405 | set differences 1 |
406 | } | |
407 | } | |
408 | ||
409 | if { $differences == 0 && [eof $file_a] != [eof $file_b] } { | |
09a1cedb | 410 | send_log "different lengths\n" |
d193d762 KR |
411 | verbose "different lengths" 3 |
412 | set differences 1 | |
413 | } | |
414 | ||
415 | close $file_a | |
416 | close $file_b | |
417 | ||
418 | return $differences | |
419 | } | |
91e3b582 DE |
420 | |
421 | proc file_contents { filename } { | |
422 | set file [open $filename r] | |
423 | set contents [read $file] | |
424 | close $file | |
425 | return $contents | |
426 | } | |
427 | ||
428 | proc verbose_eval { expr { level 1 } } { | |
429 | global verbose | |
430 | if $verbose>$level then { eval verbose "$expr" $level } | |
431 | } |