2008-09-05 Tristan Gingold <gingold@adacore.com>
[deliverable/binutils-gdb.git] / gas / testsuite / lib / gas-defs.exp
CommitLineData
ba7f26d2 1# Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
dfeb0666 2# 2004, 2005, 2007 Free Software Foundation, Inc.
252b5132
RH
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
ec2655a6 6# the Free Software Foundation; either version 3 of the License, or
252b5132 7# (at your option) any later version.
139e4a70 8#
252b5132
RH
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
139e4a70 13#
252b5132
RH
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
ec2655a6
NC
16# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
17# MA 02110-1301, USA.
252b5132
RH
18
19# Please email any bugs, comments, and/or additions to this file to:
fc697c14 20# dejagnu@gnu.org
252b5132
RH
21
22# This file was written by Ken Raeburn (raeburn@cygnus.com).
23
24proc gas_version {} {
25 global AS
7f6a71ff
JM
26 if [is_remote host] then {
27 remote_exec host "$AS -version < /dev/null" "" "" "gas.version"
28 remote_exec host "which $AS" "" "" "gas.which"
29
30 remote_upload host "gas.version"
31 remote_upload host "gas.which"
32
33 set which_as [file_contents "gas.which"]
34 set tmp [file_contents "gas.version"]
35
36 remote_file build delete "gas.version"
37 remote_file build delete "gas.which"
38 remote_file host delete "gas.version"
39 remote_file host delete "gas.which"
40 } else {
41 set which_as [which $AS]
42 catch "exec $AS -version < /dev/null" tmp
43 }
44
252b5132
RH
45 # Should find a way to discard constant parts, keep whatever's
46 # left, so the version string could be almost anything at all...
47 regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number
48 if ![info exists number] then {
7f6a71ff 49 return "$which_as (no version number)\n"
252b5132 50 }
7f6a71ff 51 clone_output "$which_as $number\n"
252b5132
RH
52 unset version
53}
54
7f6a71ff
JM
55proc gas_host_run { cmd redir } {
56 verbose "Executing $cmd $redir"
57 set return_contents_of ""
58 if [regexp ">& */dev/null" $redir] then {
59 set output_file ""
60 set command "$cmd $redir"
61 } elseif [regexp "> */dev/null" $redir] then {
62 set output_file ""
63 set command "$cmd 2>gas.stderr"
64 set return_contents_of "gas.stderr"
65 } elseif [regexp ">&.*" $redir] then {
9396508d
NC
66 # See PR 5322 for why the following line is used.
67 regsub ">&" $redir "" output_file
7f6a71ff
JM
68 set command "$cmd 2>&1"
69 } elseif [regexp "2>.*" $redir] then {
70 set output_file "gas.out"
71 set command "$cmd $redir"
72 set return_contents_of "gas.out"
73 } elseif [regexp ">.*" $redir] then {
74 set output_file ""
75 set command "$cmd $redir 2>gas.stderr"
76 set return_contents_of "gas.stderr"
77 } elseif { "$redir" == "" } then {
78 set output_file "gas.out"
79 set command "$cmd 2>&1"
80 set return_contents_of "gas.out"
81 } else {
82 fail "gas_host_run: unknown form of redirection string"
83 }
84
85 set status [remote_exec host [concat sh -c [list $command]] "" "/dev/null" "$output_file"]
86 set to_return ""
87 if { "$return_contents_of" != "" } then {
88 remote_upload host "$return_contents_of"
89 set to_return [file_contents "$return_contents_of"]
90 regsub "\n$" $to_return "" to_return
91 }
92
93 if { [lindex $status 0] == 0 && "$output_file" != ""
94 && "$output_file" != "$return_contents_of" } then {
95 remote_upload host "$output_file"
96 }
97
98 return [list [lindex $status 0] "$to_return"]
99}
100
252b5132
RH
101proc gas_run { prog as_opts redir } {
102 global AS
103 global ASFLAGS
104 global comp_output
105 global srcdir
106 global subdir
107 global host_triplet
108
7f6a71ff
JM
109 set status [gas_host_run "$AS $ASFLAGS $as_opts $srcdir/$subdir/$prog" "$redir"]
110 set comp_output [lindex $status 1]
111 if { [lindex $status 0] != 0 && [regexp "2>.*" $redir] } then {
112 append comp_output "child process exited abnormally"
113 }
252b5132
RH
114 set comp_output [prune_warnings $comp_output]
115 verbose "output was $comp_output"
c0b22597 116 return [list $comp_output ""]
252b5132
RH
117}
118
119proc all_ones { args } {
120 foreach x $args { if [expr $x!=1] { return 0 } }
121 return 1
122}
123
412cc54e
L
124# ${tool}_finish (gas_finish) will be called by runtest.exp. But
125# gas_finish should only be used with gas_start. We use gas_started
126# to tell gas_finish if gas_start has been called so that runtest.exp
127# can call gas_finish without closing the wrong fd.
128set gas_started 0
129
252b5132
RH
130proc gas_start { prog as_opts } {
131 global AS
132 global ASFLAGS
133 global srcdir
134 global subdir
135 global spawn_id
412cc54e
L
136 global gas_started
137
138 set gas_started 1
252b5132 139
04248055 140 verbose -log "Starting $AS $ASFLAGS $as_opts $prog" 2
7f6a71ff
JM
141 set status [gas_host_run "$AS $ASFLAGS $as_opts $srcdir/$subdir/$prog" ">&gas.out"]
142 spawn -noecho -nottycopy cat gas.out
252b5132
RH
143}
144
145proc gas_finish { } {
146 global spawn_id
412cc54e 147 global gas_started
252b5132 148
412cc54e
L
149 if { $gas_started == 1 } {
150 catch "close"
151 catch "wait"
152 set gas_started 0
153 }
252b5132
RH
154}
155
156proc want_no_output { testname } {
157 global comp_output
158
159 if ![string match "" $comp_output] then {
160 send_log "$comp_output\n"
161 verbose "$comp_output" 3
162 }
163 if [string match "" $comp_output] then {
164 pass "$testname"
165 return 1
166 } else {
167 fail "$testname"
168 return 0
169 }
170}
171
172proc gas_test_old { file as_opts testname } {
173 gas_run $file $as_opts ""
174 return [want_no_output $testname]
175}
176
177proc gas_test { file as_opts var_opts testname } {
178 global comp_output
179
180 set i 0
181 foreach word $var_opts {
182 set ignore_stdout($i) [string match "*>" $word]
183 set opt($i) [string trim $word {>}]
184 incr i
185 }
186 set max [expr 1<<$i]
187 for {set i 0} {[expr $i<$max]} {incr i} {
188 set maybe_ignore_stdout ""
189 set extra_opts ""
190 for {set bit 0} {(1<<$bit)<$max} {incr bit} {
191 set num [expr 1<<$bit]
192 if [expr $i&$num] then {
193 set extra_opts "$extra_opts $opt($bit)"
194 if $ignore_stdout($bit) then {
195 set maybe_ignore_stdout ">/dev/null"
196 }
197 }
198 }
199 set extra_opts [string trim $extra_opts]
200 gas_run $file "$as_opts $extra_opts" $maybe_ignore_stdout
201
202 # Should I be able to use a conditional expression here?
203 if [string match "" $extra_opts] then {
204 want_no_output $testname
205 } else {
206 want_no_output "$testname ($extra_opts)"
207 }
208 }
209 if [info exists errorInfo] then {
210 unset errorInfo
211 }
212}
213
214proc gas_test_ignore_stdout { file as_opts testname } {
215 global comp_output
216
217 gas_run $file $as_opts ">/dev/null"
218 want_no_output $testname
219}
220
221proc gas_test_error { file as_opts testname } {
222 global comp_output
223
224 gas_run $file $as_opts ">/dev/null"
225 if ![string match "" $comp_output] then {
226 send_log "$comp_output\n"
227 verbose "$comp_output" 3
228 }
229 if [string match "" $comp_output] then {
230 fail "$testname"
231 } else {
232 pass "$testname"
233 }
234}
235
236proc gas_exit {} {}
237
238proc gas_init { args } {
239 global target_cpu
240 global target_cpu_family
241 global target_family
242 global target_vendor
243 global target_os
244 global stdoptlist
245
246 case "$target_cpu" in {
247 "m68???" { set target_cpu_family m68k }
80c7c40a 248 "i[3-7]86" { set target_cpu_family i386 }
252b5132
RH
249 default { set target_cpu_family $target_cpu }
250 }
251
252 set target_family "$target_cpu_family-$target_vendor-$target_os"
253 set stdoptlist "-a>"
254
255 if ![istarget "*-*-*"] {
256 perror "Target name [istarget] is not a triple."
257 }
258 # Need to return an empty string.
259 return
260}
261
d04428bd
AM
262#
263# is_elf_format
264# true if the object format is known to be ELF
265#
266proc is_elf_format {} {
267 if { ![istarget *-*-sysv4*] \
268 && ![istarget *-*-unixware*] \
269 && ![istarget *-*-elf*] \
270 && ![istarget *-*-eabi*] \
271 && ![istarget hppa*64*-*-hpux*] \
272 && ![istarget *-*-linux*] \
fee5fcc5 273 && ![istarget frv-*-uclinux*] \
d04428bd
AM
274 && ![istarget *-*-irix5*] \
275 && ![istarget *-*-irix6*] \
276 && ![istarget *-*-netbsd*] \
d9943e50 277 && ![istarget *-*-openbsd*] \
d04428bd
AM
278 && ![istarget *-*-solaris2*] } {
279 return 0
280 }
281
282 if { [istarget *-*-linux*aout*] \
283 || [istarget *-*-linux*oldld*] } {
284 return 0
285 }
286
287 if { ![istarget *-*-netbsdelf*] \
288 && ([istarget *-*-netbsd*aout*] \
289 || [istarget *-*-netbsdpe*] \
290 || [istarget arm*-*-netbsd*] \
291 || [istarget sparc-*-netbsd*] \
292 || [istarget i*86-*-netbsd*] \
293 || [istarget m68*-*-netbsd*] \
294 || [istarget vax-*-netbsd*] \
295 || [istarget ns32k-*-netbsd*]) } {
296 return 0
297 }
d9943e50
MK
298
299 if { [istarget arm-*-openbsd*] \
300 || [istarget i386-*-openbsd\[0-2\].*] \
301 || [istarget i386-*-openbsd3.\[0-3\]] \
302 || [istarget m68*-*-openbsd*] \
303 || [istarget ns32k-*-openbsd*] \
304 || [istarget sparc-*-openbsd\[0-2\].*] \
305 || [istarget sparc-*-openbsd3.\[0-1\]] \
306 || [istarget vax-*-openbsd*] } {
307 return 0
308 }
309
d04428bd
AM
310 return 1
311}
312
9a5c4b9e
PB
313# run_dump_tests TESTCASES EXTRA_OPTIONS
314# Wrapper for run_dump_test, which is suitable for invoking as
315# run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
316# EXTRA_OPTIONS are passed down to run_dump_test. Honors runtest_file_p.
317# Body cribbed from dg-runtest.
318
319proc run_dump_tests { testcases {extra_options {}} } {
320 global runtests
321
322 foreach testcase $testcases {
323 # If testing specific files and this isn't one of them, skip it.
324 if ![runtest_file_p $runtests $testcase] {
325 continue
326 }
327 run_dump_test [file rootname [file tail $testcase]] $extra_options
328 }
329}
330
252b5132 331
e8119602 332# run_dump_test FILE (optional:) EXTRA_OPTIONS
252b5132
RH
333#
334# Assemble a .s file, then run some utility on it and check the output.
139e4a70 335#
252b5132
RH
336# There should be an assembly language file named FILE.s in the test
337# suite directory, and a pattern file called FILE.d. `run_dump_test'
338# will assemble FILE.s, run some tool like `objdump', `objcopy', or
339# `nm' on the .o file to produce textual output, and then analyze that
340# with regexps. The FILE.d file specifies what program to run, and
341# what to expect in its output.
342#
343# The FILE.d file begins with zero or more option lines, which specify
344# flags to pass to the assembler, the program to run to dump the
345# assembler's output, and the options it wants. The option lines have
346# the syntax:
139e4a70 347#
252b5132 348# # OPTION: VALUE
139e4a70 349#
252b5132
RH
350# OPTION is the name of some option, like "name" or "objdump", and
351# VALUE is OPTION's value. The valid options are described below.
352# Whitespace is ignored everywhere, except within VALUE. The option
9a5c4b9e
PB
353# list ends with the first line that doesn't match the above syntax.
354# However, a line within the options that begins with a #, but doesn't
355# have a recognizable option name followed by a colon, is considered a
356# comment and entirely ignored.
252b5132 357#
e8119602
CD
358# The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
359# two-element lists. The first element of each is an option name, and
360# the second additional arguments to be added on to the end of the
361# option list as given in FILE.d. (If omitted, no additional options
362# are added.)
363#
252b5132 364# The interesting options are:
139e4a70 365#
252b5132
RH
366# name: TEST-NAME
367# The name of this test, passed to DejaGNU's `pass' and `fail'
368# commands. If omitted, this defaults to FILE, the root of the
369# .s and .d files' names.
139e4a70 370#
252b5132
RH
371# as: FLAGS
372# When assembling FILE.s, pass FLAGS to the assembler.
139e4a70 373#
252b5132
RH
374# PROG: PROGRAM-NAME
375# The name of the program to run to analyze the .o file produced
376# by the assembler. This can be omitted; run_dump_test will guess
377# which program to run by seeing which of the flags options below
378# is present.
139e4a70 379#
252b5132
RH
380# objdump: FLAGS
381# nm: FLAGS
382# objcopy: FLAGS
383# Use the specified program to analyze the .o file, and pass it
139e4a70
AM
384# FLAGS, in addition to the .o file name. Note that they are run
385# with LC_ALL=C in the environment to give consistent sorting
386# of symbols.
252b5132
RH
387#
388# source: SOURCE
389# Assemble the file SOURCE.s. If omitted, this defaults to FILE.s.
390# This is useful if several .d files want to share a .s file.
391#
9a5c4b9e
PB
392# target: GLOBS...
393# Run this test only on a specified list of targets. More precisely,
394# each glob in the space-separated list is passed to "istarget"; if
395# it evaluates true for any of them, the test will be run, otherwise
396# it will be marked unsupported.
397#
398# not-target: GLOBS...
399# Do not run this test on a specified list of targets. Again,
400# the each glob in the space-separated list is passed to
401# "istarget", and the test is run if it evaluates *false* for
402# *all* of them. Otherwise it will be marked unsupported.
403#
404# skip: GLOBS...
405# not-skip: GLOBS...
406# These are exactly the same as "not-target" and "target",
407# respectively, except that they do nothing at all if the check
408# fails. They should only be used in groups, to construct a single
409# test which is run on all targets but with variant options or
410# expected output on some targets. (For example, see
411# gas/arm/inst.d and gas/arm/wince_inst.d.)
412#
8c2784a5
TR
413# error: REGEX
414# An error with message matching REGEX must be emitted for the test
415# to pass. The PROG, objdump, nm and objcopy options have no
416# meaning and need not supplied if this is present.
417#
cfdf4aaa
HPN
418# warning: REGEX
419# Expect a gas warning matching REGEX. It is an error to issue
420# both "error" and "warning".
421#
9a5c4b9e
PB
422# stderr: FILE
423# FILE contains regexp lines to be matched against the diagnostic
424# output of the assembler. This does not preclude the use of
425# PROG, nm, objdump, or objcopy.
426#
427# error-output: FILE
428# Means the same as 'stderr', but also indicates that the assembler
429# is expected to exit unsuccessfully (therefore PROG, objdump, nm,
430# and objcopy have no meaning and should not be supplied).
431#
252b5132
RH
432# Each option may occur at most once.
433#
434# After the option lines come regexp lines. `run_dump_test' calls
435# `regexp_diff' to compare the output of the dumping tool against the
436# regexps in FILE.d. `regexp_diff' is defined later in this file; see
437# further comments there.
438
e8119602 439proc run_dump_test { name {extra_options {}} } {
252b5132 440 global subdir srcdir
4b0d96c2
HPN
441 global OBJDUMP NM AS OBJCOPY READELF
442 global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS
252b5132 443 global host_triplet
139e4a70 444 global env
252b5132
RH
445
446 if [string match "*/*" $name] {
447 set file $name
448 set name [file tail $name]
449 } else {
450 set file "$srcdir/$subdir/$name"
451 }
452 set opt_array [slurp_options "${file}.d"]
453 if { $opt_array == -1 } {
61feeec2 454 perror "error reading options from $file.d"
252b5132
RH
455 unresolved $subdir/$name
456 return
457 }
458 set opts(as) {}
459 set opts(objdump) {}
460 set opts(nm) {}
461 set opts(objcopy) {}
4b0d96c2 462 set opts(readelf) {}
252b5132
RH
463 set opts(name) {}
464 set opts(PROG) {}
465 set opts(source) {}
ff970196 466 set opts(stderr) {}
8c2784a5 467 set opts(error) {}
9a5c4b9e 468 set opts(error-output) {}
cfdf4aaa 469 set opts(warning) {}
9a5c4b9e
PB
470 set opts(target) {}
471 set opts(not-target) {}
472 set opts(skip) {}
473 set opts(not-skip) {}
252b5132
RH
474
475 foreach i $opt_array {
476 set opt_name [lindex $i 0]
477 set opt_val [lindex $i 1]
478 if ![info exists opts($opt_name)] {
479 perror "unknown option $opt_name in file $file.d"
480 unresolved $subdir/$name
481 return
482 }
483 if [string length $opts($opt_name)] {
484 perror "option $opt_name multiply set in $file.d"
485 unresolved $subdir/$name
486 return
487 }
7f6a71ff
JM
488 if { $opt_name == "as" } {
489 set opt_val [subst $opt_val]
490 }
252b5132
RH
491 set opts($opt_name) $opt_val
492 }
493
e8119602
CD
494 foreach i $extra_options {
495 set opt_name [lindex $i 0]
496 set opt_val [lindex $i 1]
497 if ![info exists opts($opt_name)] {
498 perror "unknown option $opt_name given in extra_opts"
499 unresolved $subdir/$name
500 return
501 }
502 # add extra option to end of existing option, adding space
503 # if necessary.
504 if [string length $opts($opt_name)] {
505 append opts($opt_name) " "
506 }
507 append opts($opt_name) $opt_val
508 }
509
9a5c4b9e
PB
510 if { $opts(name) == "" } {
511 set testname "$subdir/$name"
512 } else {
513 set testname $opts(name)
514 }
515 verbose "Testing $testname"
516
ba7f26d2 517 if { (($opts(warning) != "") && ($opts(error) != "")) \
9a5c4b9e
PB
518 || (($opts(warning) != "") && ($opts(stderr) != "")) \
519 || (($opts(error-output) != "") && ($opts(stderr) != "")) \
520 || (($opts(error-output) != "") && ($opts(error) != "")) \
521 || (($opts(error-output) != "") && ($opts(warning) != "")) } {
522 perror "$testname: bad mix of stderr, error-output, error, and warning test-directives"
523 unresolved $testname
ba7f26d2
AM
524 return
525 }
9a5c4b9e
PB
526 if { $opts(error-output) != "" } then {
527 set opts(stderr) $opts(error-output)
528 }
ba7f26d2
AM
529
530 set program ""
531 # It's meaningless to require an output-testing method when we
532 # expect an error.
9a5c4b9e 533 if { $opts(error) == "" && $opts(error-output) == "" } {
ba7f26d2
AM
534 if {$opts(PROG) != ""} {
535 switch -- $opts(PROG) {
536 objdump { set program objdump }
537 nm { set program nm }
538 objcopy { set program objcopy }
539 readelf { set program readelf }
540 default {
541 perror "unrecognized program option $opts(PROG) in $file.d"
9a5c4b9e 542 unresolved $testname
ba7f26d2
AM
543 return }
544 }
545 } else {
546 # Guess which program to run, by seeing which option was specified.
547 foreach p {objdump objcopy nm readelf} {
548 if {$opts($p) != ""} {
549 if {$program != ""} {
550 perror "ambiguous dump program in $file.d"
9a5c4b9e 551 unresolved $testname
ba7f26d2
AM
552 return
553 } else {
554 set program $p
555 }
252b5132
RH
556 }
557 }
558 }
ba7f26d2 559 if { $program == "" && $opts(warning) == "" } {
252b5132 560 perror "dump program unspecified in $file.d"
9a5c4b9e 561 unresolved $testname
252b5132
RH
562 return
563 }
564 }
565
9a5c4b9e
PB
566 # Handle skipping the test on specified targets.
567 # You can have both skip/not-skip and target/not-target, but you can't
568 # have both skip and not-skip, or target and not-target, in the same file.
569 if { $opts(skip) != "" } then {
570 if { $opts(not-skip) != "" } then {
571 perror "$testname: mixing skip and not-skip directives is invalid"
572 unresolved $testname
573 return
574 }
575 foreach glob $opts(skip) {
576 if {[istarget $glob]} { return }
577 }
578 }
579 if { $opts(not-skip) != "" } then {
580 set skip 1
581 foreach glob $opts(not-skip) {
582 if {[istarget $glob]} {
583 set skip 0
584 break
585 }
586 }
587 if {$skip} { return }
588 }
589 if { $opts(target) != "" } then {
590 if { $opts(not-target) != "" } then {
591 perror "$testname: mixing target and not-target directives is invalid"
592 unresolved $testname
593 return
594 }
595 set skip 1
596 foreach glob $opts(target) {
597 if {[istarget $glob]} {
598 set skip 0
599 break
600 }
601 }
602 if {$skip} {
603 unsupported $testname
604 return
605 }
252b5132 606 }
9a5c4b9e
PB
607 if { $opts(not-target) != "" } then {
608 foreach glob $opts(not-target) {
609 if {[istarget $glob]} {
610 unsupported $testname
611 return
612 }
613 }
614 }
615
252b5132
RH
616
617 if { $opts(source) == "" } {
618 set sourcefile ${file}.s
619 } else {
620 set sourcefile $srcdir/$subdir/$opts(source)
621 }
622
7f6a71ff 623 set cmd "$AS $ASFLAGS $opts(as) -o dump.o $sourcefile"
cfdf4aaa 624 send_log "$cmd\n"
7f6a71ff
JM
625 set status [gas_host_run $cmd ""]
626 set cmdret [lindex $status 0]
627 set comp_output [prune_warnings [lindex $status 1]]
252b5132 628
ba7f26d2
AM
629 set expmsg $opts(error)
630 if { $opts(warning) != "" } {
631 set expmsg $opts(warning)
632 }
633 if { $cmdret != 0 || $comp_output != "" || $expmsg != "" } then {
cfdf4aaa
HPN
634 # If the executed program writes to stderr and stderr is not
635 # redirected, exec *always* returns failure, regardless of the
636 # program exit code. Thankfully, we can retrieve the true
637 # return status from a special variable. Redirection would
638 # cause a tcl-specific message to be appended, and we'd rather
639 # not deal with that if we can help it.
640 global errorCode
641 if { $cmdret != 0 && [lindex $errorCode 0] == "NONE" } {
642 set cmdret 0
643 }
644
645 set exitstat "succeeded"
646 if { $cmdret != 0 } { set exitstat "failed" }
647
9a5c4b9e
PB
648 send_log "$comp_output\n"
649 verbose "$comp_output" 3
ff970196 650 if { $opts(stderr) == "" } then {
ba7f26d2 651 if { [regexp $expmsg $comp_output] \
cfdf4aaa 652 && (($cmdret == 0) == ($opts(warning) != "")) } {
ba7f26d2
AM
653 # We have the expected output from gas.
654 # Return if there's nothing more to do.
655 if { $opts(error) != "" || $program == "" } {
8c2784a5
TR
656 pass $testname
657 return
658 }
ba7f26d2
AM
659 } else {
660 verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
661
cfdf4aaa
HPN
662 fail $testname
663 return
8c2784a5 664 }
ff970196
CD
665 } else {
666 catch {write_file dump.stderr "$comp_output"} write_output
667 if ![string match "" $write_output] then {
668 send_log "error writing dump.stderr: $write_output\n"
669 verbose "error writing dump.stderr: $write_output" 3
670 send_log "$comp_output\n"
671 verbose "$comp_output" 3
672 fail $testname
673 return
674 }
675 set stderrfile $srcdir/$subdir/$opts(stderr)
ff970196
CD
676 verbose "wrote pruned stderr to dump.stderr" 3
677 if { [regexp_diff "dump.stderr" "$stderrfile"] } then {
8c2784a5 678 if { $opts(error) != "" } {
cfdf4aaa 679 verbose -log "$exitstat with: <$comp_output>, expected: <$opts(error)>"
8c2784a5
TR
680 if [regexp $opts(error) $comp_output] {
681 pass $testname
682 return
683 }
684 }
ff970196
CD
685 fail $testname
686 verbose "pruned stderr is [file_contents "dump.stderr"]" 2
687 return
9a5c4b9e
PB
688 } elseif { $opts(error-output) != "" } then {
689 pass $testname
690 return
ff970196
CD
691 }
692 }
252b5132
RH
693 }
694
ba7f26d2
AM
695 if { $program == "" } {
696 return
697 }
698 set progopts1 $opts($program)
699 eval set progopts \$[string toupper $program]FLAGS
700 eval set binary \$[string toupper $program]
701
7f6a71ff 702 if { ![is_remote host] && [which $binary] == 0 } {
252b5132
RH
703 untested $testname
704 return
705 }
706
707 if { $progopts1 == "" } { set $progopts1 "-r" }
708 verbose "running $binary $progopts $progopts1" 3
709
710 # Objcopy, unlike the other two, won't send its output to stdout,
711 # so we have to run it specially.
7f6a71ff
JM
712 set cmd "$binary $progopts $progopts1 dump.o"
713 set redir ">dump.out"
252b5132 714 if { $program == "objcopy" } {
139e4a70 715 set cmd "$binary $progopts $progopts1 dump.o dump.out"
7f6a71ff 716 set redir ""
139e4a70
AM
717 }
718
719 # Ensure consistent sorting of symbols
720 if {[info exists env(LC_ALL)]} {
721 set old_lc_all $env(LC_ALL)
722 }
723 set env(LC_ALL) "C"
724 send_log "$cmd\n"
7f6a71ff
JM
725 set status [gas_host_run "$cmd" "$redir"]
726 set comp_output [prune_warnings [lindex $status 1]]
139e4a70
AM
727 if {[info exists old_lc_all]} {
728 set env(LC_ALL) $old_lc_all
252b5132 729 } else {
139e4a70
AM
730 unset env(LC_ALL)
731 }
732 set comp_output [prune_warnings $comp_output]
733 if ![string match "" $comp_output] then {
734 send_log "$comp_output\n"
735 fail $testname
736 return
252b5132
RH
737 }
738
739 verbose_eval {[file_contents "dump.out"]} 3
740 if { [regexp_diff "dump.out" "${file}.d"] } then {
741 fail $testname
742 verbose "output is [file_contents "dump.out"]" 2
743 return
744 }
745
746 pass $testname
747}
748
749proc slurp_options { file } {
750 if [catch { set f [open $file r] } x] {
751 #perror "couldn't open `$file': $x"
752 perror "$x"
753 return -1
754 }
755 set opt_array {}
756 # whitespace expression
757 set ws {[ ]*}
758 set nws {[^ ]*}
759 # whitespace is ignored anywhere except within the options list;
9a5c4b9e
PB
760 # option names are alphabetic plus dash
761 set pat "^#${ws}(\[a-zA-Z-\]*)$ws:${ws}(.*)$ws\$"
252b5132
RH
762 while { [gets $f line] != -1 } {
763 set line [string trim $line]
764 # Whitespace here is space-tab.
765 if [regexp $pat $line xxx opt_name opt_val] {
766 # match!
767 lappend opt_array [list $opt_name $opt_val]
9a5c4b9e 768 } elseif {![regexp "^#" $line ]} {
252b5132
RH
769 break
770 }
771 }
772 close $f
773 return $opt_array
774}
775
776proc objdump { opts } {
777 global OBJDUMP
778 global comp_output
779 global host_triplet
780
7f6a71ff
JM
781 set status [gas_host_run "$OBJDUMP $opts" ""]
782 set comp_output [prune_warnings [lindex $status 1]]
252b5132
RH
783 verbose "objdump output=$comp_output\n" 3
784}
785
786proc objdump_start_no_subdir { prog opts } {
787 global OBJDUMP
788 global srcdir
789 global spawn_id
790
791 verbose "Starting $OBJDUMP $opts $prog" 2
7f6a71ff
JM
792 set status [gas_host_run "$OBJDUMP $opts $prog" ">&gas.out"]
793 spawn -noecho -nottycopy cat gas.out
252b5132
RH
794}
795
796proc objdump_finish { } {
797 global spawn_id
798
799 catch "close"
800 catch "wait"
801}
802
803# Default timeout is 10 seconds, loses on a slow machine. But some
804# configurations of dejagnu may override it.
805if {$timeout<120} then { set timeout 120 }
806
807expect_after -i {
808 timeout { perror "timeout" }
809 "virtual memory exhausted" { perror "virtual memory exhausted" }
810 buffer_full { perror "buffer full" }
811 eof { perror "eof" }
812}
813
814# regexp_diff, based on simple_diff taken from ld test suite
815# compares two files line-by-line
816# file1 contains strings, file2 contains regexps and #-comments
817# blank lines are ignored in either file
818# returns non-zero if differences exist
819#
820proc regexp_diff { file_1 file_2 } {
821
822 set eof -1
823 set end_1 0
824 set end_2 0
825 set differences 0
826 set diff_pass 0
827
828 if [file exists $file_1] then {
829 set file_a [open $file_1 r]
830 } else {
04248055 831 perror "$file_1 doesn't exist"
252b5132
RH
832 return 1
833 }
834
835 if [file exists $file_2] then {
836 set file_b [open $file_2 r]
837 } else {
04248055 838 perror "$file_2 doesn't exist"
252b5132
RH
839 close $file_a
840 return 1
841 }
842
843 verbose " Regexp-diff'ing: $file_1 $file_2" 2
844
845 while { 1 } {
846 set line_a ""
847 set line_b ""
848 while { [string length $line_a] == 0 } {
849 if { [gets $file_a line_a] == $eof } {
850 set end_1 1
851 break
852 }
853 }
854 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
855 if [ string match "#pass" $line_b ] {
856 set end_2 1
857 set diff_pass 1
858 break
a6ea59ce
GK
859 } elseif [ string match "#..." $line_b ] {
860 if { [gets $file_b line_b] == $eof } {
861 set end_2 1
5cfd5a0c 862 set diff_pass 1
a6ea59ce
GK
863 break
864 }
865 verbose "looking for \"^$line_b$\"" 3
866 while { ![regexp "^$line_b$" "$line_a"] } {
867 verbose "skipping \"$line_a\"" 3
868 if { [gets $file_a line_a] == $eof } {
869 set end_1 1
870 break
871 }
872 }
873 break
252b5132
RH
874 }
875 if { [gets $file_b line_b] == $eof } {
876 set end_2 1
877 break
878 }
879 }
880
139e4a70
AM
881 if { $diff_pass } {
882 break
883 } elseif { $end_1 && $end_2 } {
252b5132
RH
884 break
885 } elseif { $end_1 } {
886 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
887 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
888 set differences 1
889 break
890 } elseif { $end_2 } {
891 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
892 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
893 set differences 1
894 break
895 } else {
896 verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
897 if ![regexp "^$line_b$" "$line_a"] {
898 send_log "regexp_diff match failure\n"
899 send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
3ad62fc4 900 verbose "regexp_diff match failure\n" 3
252b5132 901 set differences 1
252b5132
RH
902 }
903 }
904 }
905
906 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
907 send_log "$file_1 and $file_2 are different lengths\n"
908 verbose "$file_1 and $file_2 are different lengths" 3
909 set differences 1
910 }
911
912 close $file_a
913 close $file_b
914
915 return $differences
916}
917
918proc file_contents { filename } {
919 set file [open $filename r]
920 set contents [read $file]
921 close $file
922 return $contents
923}
924
ff970196
CD
925proc write_file { filename contents } {
926 set file [open $filename w]
927 puts $file "$contents"
928 close $file
929}
930
252b5132
RH
931proc verbose_eval { expr { level 1 } } {
932 global verbose
933 if $verbose>$level then { eval verbose "$expr" $level }
934}
935
936# This definition is taken from an unreleased version of DejaGnu. Once
937# that version gets released, and has been out in the world for a few
938# months at least, it may be safe to delete this copy.
939if ![string length [info proc prune_warnings]] {
940 #
941 # prune_warnings -- delete various system verbosities from TEXT.
942 #
943 # An example is:
944 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
945 #
946 # Sites with particular verbose os's may wish to override this in site.exp.
947 #
948 proc prune_warnings { text } {
949 # This is from sun4's. Do it for all machines for now.
950 # The "\\1" is to try to preserve a "\n" but only if necessary.
951 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
952
953 # It might be tempting to get carried away and delete blank lines, etc.
954 # Just delete *exactly* what we're ask to, and that's it.
955 return $text
956 }
957}
dfeb0666 958
dc89df6a 959# run_list_test NAME (optional): OPTS TESTNAME
dfeb0666
NC
960#
961# Assemble the file "NAME.d" with command line options OPTS and
962# compare the assembler standard error output against thee regular
963# expressions given in the file "NAME.l". If TESTNAME is provided,
964# it will be used as the name of the test.
965
dc89df6a 966proc run_list_test { name {opts {}} {testname {}} } {
dfeb0666
NC
967 global srcdir subdir
968 if { [string length $testname] == 0 } then {
969 set testname "[file tail $subdir] $name"
970 }
971 set file $srcdir/$subdir/$name
972 gas_run ${name}.s $opts ">&dump.out"
973 if { [regexp_diff "dump.out" "${file}.l"] } then {
974 fail $testname
975 verbose "output is [file_contents "dump.out"]" 2
976 return
977 }
978 pass $testname
979}
This page took 0.552164 seconds and 4 git commands to generate.