1 # Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2 # 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
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.
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
16 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # Please email any bugs, comments, and/or additions to this file to:
22 # This file was written by Ken Raeburn (raeburn@cygnus.com).
26 if [is_remote host] then {
27 remote_exec host "$AS -version < /dev/null" "" "" "gas.version"
28 remote_exec host "which $AS" "" "" "gas.which"
30 remote_upload host "gas.version"
31 remote_upload host "gas.which"
33 set which_as [file_contents "gas.which"]
34 set tmp [file_contents "gas.version"]
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"
41 set which_as [which $AS]
42 catch "exec $AS -version < /dev/null" tmp
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 {
49 return "$which_as (no version number)\n"
51 clone_output "$which_as $number\n"
55 proc gas_host_run { cmd redir } {
56 verbose "Executing $cmd $redir"
57 set return_contents_of ""
58 if [regexp ">& */dev/null" $redir] then {
60 set command "$cmd $redir"
61 } elseif [regexp "> */dev/null" $redir] then {
63 set command "$cmd 2>gas.stderr"
64 set return_contents_of "gas.stderr"
65 } elseif [regexp ">&.*" $redir] then {
66 # See PR 5322 for why the following line is used.
67 regsub ">&" $redir "" output_file
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 {
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"
82 fail "gas_host_run: unknown form of redirection string"
85 set status [remote_exec host [concat sh -c [list $command]] "" "/dev/null" "$output_file"]
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
93 if { [lindex $status 0] == 0 && "$output_file" != ""
94 && "$output_file" != "$return_contents_of" } then {
95 remote_upload host "$output_file"
98 return [list [lindex $status 0] "$to_return"]
101 proc gas_run { prog as_opts redir } {
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"
114 set comp_output [prune_warnings $comp_output]
115 verbose "output was $comp_output"
116 return [list $comp_output ""]
119 proc gas_run_stdin { prog as_opts redir } {
127 set status [gas_host_run "$AS $ASFLAGS $as_opts < $srcdir/$subdir/$prog" "$redir"]
128 set comp_output [lindex $status 1]
129 if { [lindex $status 0] != 0 && [regexp "2>.*" $redir] } then {
130 append comp_output "child process exited abnormally"
132 set comp_output [prune_warnings $comp_output]
133 verbose "output was $comp_output"
134 return [list $comp_output ""]
137 proc all_ones { args } {
138 foreach x $args { if [expr $x!=1] { return 0 } }
142 # ${tool}_finish (gas_finish) will be called by runtest.exp. But
143 # gas_finish should only be used with gas_start. We use gas_started
144 # to tell gas_finish if gas_start has been called so that runtest.exp
145 # can call gas_finish without closing the wrong fd.
148 proc gas_start { prog as_opts } {
158 verbose -log "Starting $AS $ASFLAGS $as_opts $prog" 2
159 set status [gas_host_run "$AS $ASFLAGS $as_opts $srcdir/$subdir/$prog" ">&gas.out"]
160 spawn -noecho -nottycopy cat gas.out
163 proc gas_finish { } {
167 if { $gas_started == 1 } {
174 proc want_no_output { testname } {
177 if ![string match "" $comp_output] then {
178 send_log "$comp_output\n"
179 verbose "$comp_output" 3
181 if [string match "" $comp_output] then {
190 proc gas_test_old { file as_opts testname } {
191 gas_run $file $as_opts ""
192 return [want_no_output $testname]
195 proc gas_test { file as_opts var_opts testname } {
199 foreach word $var_opts {
200 set ignore_stdout($i) [string match "*>" $word]
201 set opt($i) [string trim $word {>}]
205 for {set i 0} {[expr $i<$max]} {incr i} {
206 set maybe_ignore_stdout ""
208 for {set bit 0} {(1<<$bit)<$max} {incr bit} {
209 set num [expr 1<<$bit]
210 if [expr $i&$num] then {
211 set extra_opts "$extra_opts $opt($bit)"
212 if $ignore_stdout($bit) then {
213 set maybe_ignore_stdout ">/dev/null"
217 set extra_opts [string trim $extra_opts]
218 gas_run $file "$as_opts $extra_opts" $maybe_ignore_stdout
220 # Should I be able to use a conditional expression here?
221 if [string match "" $extra_opts] then {
222 want_no_output $testname
224 want_no_output "$testname ($extra_opts)"
227 if [info exists errorInfo] then {
232 proc gas_test_ignore_stdout { file as_opts testname } {
235 gas_run $file $as_opts ">/dev/null"
236 want_no_output $testname
239 proc gas_test_error { file as_opts testname } {
242 gas_run $file $as_opts ">/dev/null"
243 send_log "$comp_output\n"
244 verbose "$comp_output" 3
245 if { ![string match "" $comp_output]
246 && ![string match "*Assertion failure*" $comp_output]
247 && ![string match "*Internal error*" $comp_output] } then {
256 proc gas_init { args } {
258 global target_cpu_family
264 case "$target_cpu" in {
265 "m68???" { set target_cpu_family m68k }
266 "i[3-7]86" { set target_cpu_family i386 }
267 default { set target_cpu_family $target_cpu }
270 set target_family "$target_cpu_family-$target_vendor-$target_os"
273 if ![istarget "*-*-*"] {
274 perror "Target name [istarget] is not a triple."
276 # Need to return an empty string.
280 # True if the object format is known to be ELF.
282 proc is_elf_format {} {
283 if { ![istarget *-*-sysv4*]
284 && ![istarget *-*-unixware*]
285 && ![istarget *-*-elf*]
286 && ![istarget *-*-eabi*]
287 && ![istarget *-*-rtems*]
288 && ![istarget hppa*64*-*-hpux*]
289 && ![istarget ia64-*-hpux*]
290 && ![istarget *-*-linux*]
291 && ![istarget frv-*-uclinux*]
292 && ![istarget bfin-*-uclinux]
293 && ![istarget sh*-*-uclinux*]
294 && ![istarget *-*-irix5*]
295 && ![istarget *-*-irix6*]
296 && ![istarget *-*-netbsd*]
297 && ![istarget *-*-openbsd*]
298 && ![istarget *-*-solaris2*] } {
302 if { [istarget *-*-linux*aout*]
303 || [istarget *-*-linux*oldld*]
304 || [istarget h8500-*-rtems*]
305 || [istarget i960-*-rtems*]
306 || [istarget *-*-rtemscoff*] } {
310 if { ![istarget *-*-netbsdelf*]
311 && ([istarget *-*-netbsd*aout*]
312 || [istarget *-*-netbsdpe*]
313 || [istarget arm*-*-netbsd*]
314 || [istarget sparc-*-netbsd*]
315 || [istarget i*86-*-netbsd*]
316 || [istarget m68*-*-netbsd*]
317 || [istarget vax-*-netbsd*]
318 || [istarget ns32k-*-netbsd*]) } {
322 if { [istarget arm-*-openbsd*]
323 || [istarget i386-*-openbsd\[0-2\].*]
324 || [istarget i386-*-openbsd3.\[0-2\]]
325 || [istarget m68*-*-openbsd*]
326 || [istarget ns32k-*-openbsd*]
327 || [istarget sparc-*-openbsd\[0-2\].*]
328 || [istarget sparc-*-openbsd3.\[0-1\]]
329 || [istarget vax-*-openbsd*] } {
336 # True if the object format is known to be a.out.
338 proc is_aout_format {} {
339 if { [istarget *-*-netbsdelf]
340 || [istarget sparc64-*-netbsd*]
341 || [istarget sparc64-*-openbsd*] } {
344 if { [istarget *-*-*\[ab\]out*]
345 || [istarget *-*-linux*oldld*]
346 || [istarget *-*-bsd*]
347 || [istarget *-*-msdos*]
348 || [istarget arm-*-netbsd*]
349 || [istarget arm-*-openbsd*]
350 || [istarget arm-*-riscix*]
351 || [istarget i?86-*-freebsd\[12\]*]
352 || [istarget i?86-*-netbsd*]
353 || [istarget i?86-*-openbsd\[0-2\]*]
354 || [istarget i?86-*-openbsd3.\[0-2\]*]
355 || [istarget i?86-*-vsta]
356 || [istarget i?86-*-mach*]
357 || [istarget m68*-*-netbsd*]
358 || [istarget m68*-*-openbsd*]
359 || [istarget ns32k-*-*]
360 || [istarget pdp11-*-*]
361 || [istarget sparc*-*-sunos4*]
362 || [istarget sparc*-*-netbsd*]
363 || [istarget sparc*-*-openbsd\[0-2\]*]
364 || [istarget sparc*-*-openbsd3.\[0-1\]*]
365 || [istarget sparc*-fujitsu-none]
366 || [istarget vax-dec-ultrix*]
367 || [istarget vax-*-netbsd] } {
373 # True if the object format is known to be PE COFF.
375 proc is_pecoff_format {} {
376 if { ![istarget *-*-mingw*]
377 && ![istarget *-*-cygwin*]
378 && ![istarget *-*-cegcc*]
379 && ![istarget *-*-pe*] } {
386 # Internal procedure: return the names of the standard sections
388 proc get_standard_section_names {} {
389 if [istarget "rx-*-*"] {
390 return { "P" "D_1" "B_1" }
395 # run_dump_tests TESTCASES EXTRA_OPTIONS
396 # Wrapper for run_dump_test, which is suitable for invoking as
397 # run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
398 # EXTRA_OPTIONS are passed down to run_dump_test. Honors runtest_file_p.
399 # Body cribbed from dg-runtest.
401 proc run_dump_tests { testcases {extra_options {}} } {
404 foreach testcase $testcases {
405 # If testing specific files and this isn't one of them, skip it.
406 if ![runtest_file_p $runtests $testcase] {
409 run_dump_test [file rootname [file tail $testcase]] $extra_options
414 # run_dump_test FILE (optional:) EXTRA_OPTIONS
416 # Assemble a .s file, then run some utility on it and check the output.
418 # There should be an assembly language file named FILE.s in the test
419 # suite directory, and a pattern file called FILE.d. `run_dump_test'
420 # will assemble FILE.s, run some tool like `objdump', `objcopy', or
421 # `nm' on the .o file to produce textual output, and then analyze that
422 # with regexps. The FILE.d file specifies what program to run, and
423 # what to expect in its output.
425 # The FILE.d file begins with zero or more option lines, which specify
426 # flags to pass to the assembler, the program to run to dump the
427 # assembler's output, and the options it wants. The option lines have
432 # OPTION is the name of some option, like "name" or "objdump", and
433 # VALUE is OPTION's value. The valid options are described below.
434 # Whitespace is ignored everywhere, except within VALUE. The option
435 # list ends with the first line that doesn't match the above syntax.
436 # However, a line within the options that begins with a #, but doesn't
437 # have a recognizable option name followed by a colon, is considered a
438 # comment and entirely ignored.
440 # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
441 # two-element lists. The first element of each is an option name, and
442 # the second additional arguments to be added on to the end of the
443 # option list as given in FILE.d. (If omitted, no additional options
446 # The interesting options are:
449 # The name of this test, passed to DejaGNU's `pass' and `fail'
450 # commands. If omitted, this defaults to FILE, the root of the
451 # .s and .d files' names.
454 # When assembling FILE.s, pass FLAGS to the assembler.
461 # Use the specified program to analyze the .o file, and pass it
462 # FLAGS, in addition to the .o file name. Note that they are run
463 # with LC_ALL=C in the environment to give consistent sorting
464 # of symbols. If no FLAGS are needed then use:
465 # PROG: [nm objcopy objdump readelf addr2line]
467 # Note: for objdump, we automatically replaces the standard section
468 # names (.text, .data and .bss) by target ones if any (eg. rx-elf
469 # uses "P" instead of .text). The substition is done for both
470 # the objdump options (eg: "-j .text" is replaced by "-j P") and the
474 # Assemble the file SOURCE.s. If omitted, this defaults to FILE.s.
475 # This is useful if several .d files want to share a .s file.
478 # Match against DUMP.d. If omitted, this defaults to FILE.d. This
479 # is useful if several .d files differ by options only. Options are
480 # always read from FILE.d.
483 # Run this test only on a specified list of targets. More precisely,
484 # each glob in the space-separated list is passed to "istarget"; if
485 # it evaluates true for any of them, the test will be run, otherwise
486 # it will be marked unsupported.
488 # not-target: GLOBS...
489 # Do not run this test on a specified list of targets. Again,
490 # the each glob in the space-separated list is passed to
491 # "istarget", and the test is run if it evaluates *false* for
492 # *all* of them. Otherwise it will be marked unsupported.
496 # These are exactly the same as "not-target" and "target",
497 # respectively, except that they do nothing at all if the check
498 # fails. They should only be used in groups, to construct a single
499 # test which is run on all targets but with variant options or
500 # expected output on some targets. (For example, see
501 # gas/arm/inst.d and gas/arm/wince_inst.d.)
504 # An error with message matching REGEX must be emitted for the test
505 # to pass. The PROG, objdump, nm and objcopy options have no
506 # meaning and need not supplied if this is present.
509 # Expect a gas warning matching REGEX. It is an error to issue
510 # both "error" and "warning".
513 # FILE contains regexp lines to be matched against the diagnostic
514 # output of the assembler. This does not preclude the use of
515 # PROG, nm, objdump, or objcopy.
518 # Means the same as 'stderr', but also indicates that the assembler
519 # is expected to exit unsuccessfully (therefore PROG, objdump, nm,
520 # and objcopy have no meaning and should not be supplied).
523 # Means that the section substitution for objdump is disabled.
525 # Each option may occur at most once.
527 # After the option lines come regexp lines. `run_dump_test' calls
528 # `regexp_diff' to compare the output of the dumping tool against the
529 # regexps in FILE.d. `regexp_diff' is defined later in this file; see
530 # further comments there.
532 proc run_dump_test { name {extra_options {}} } {
534 global OBJDUMP NM AS OBJCOPY READELF
535 global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS
536 global ADDR2LINE ADDR2LINEFLAGS
540 if [string match "*/*" $name] {
542 set name [file tail $name]
544 set file "$srcdir/$subdir/$name"
546 set opt_array [slurp_options "${file}.d"]
547 if { $opt_array == -1 } {
548 perror "error reading options from $file.d"
549 unresolved $subdir/$name
552 set opts(addr2line) {}
564 set opts(error-output) {}
567 set opts(not-target) {}
569 set opts(not-skip) {}
570 set opts(section-subst) {}
572 foreach i $opt_array {
573 set opt_name [lindex $i 0]
574 set opt_val [lindex $i 1]
575 if ![info exists opts($opt_name)] {
576 perror "unknown option $opt_name in file $file.d"
577 unresolved $subdir/$name
580 if [string length $opts($opt_name)] {
581 perror "option $opt_name multiply set in $file.d"
582 unresolved $subdir/$name
585 if { $opt_name == "as" } {
586 set opt_val [subst $opt_val]
588 set opts($opt_name) $opt_val
591 foreach i $extra_options {
592 set opt_name [lindex $i 0]
593 set opt_val [lindex $i 1]
594 if ![info exists opts($opt_name)] {
595 perror "unknown option $opt_name given in extra_opts"
596 unresolved $subdir/$name
599 # add extra option to end of existing option, adding space
601 if [string length $opts($opt_name)] {
602 append opts($opt_name) " "
604 append opts($opt_name) $opt_val
607 if { $opts(name) == "" } {
608 set testname "$subdir/$name"
610 set testname $opts(name)
612 verbose "Testing $testname"
614 if { (($opts(warning) != "") && ($opts(error) != "")) \
615 || (($opts(warning) != "") && ($opts(stderr) != "")) \
616 || (($opts(error-output) != "") && ($opts(stderr) != "")) \
617 || (($opts(error-output) != "") && ($opts(error) != "")) \
618 || (($opts(error-output) != "") && ($opts(warning) != "")) } {
619 perror "$testname: bad mix of stderr, error-output, error, and warning test-directives"
623 if { $opts(error-output) != "" } then {
624 set opts(stderr) $opts(error-output)
628 # It's meaningless to require an output-testing method when we
630 if { $opts(error) == "" && $opts(error-output) == "" } {
631 if {$opts(PROG) != ""} {
632 switch -- $opts(PROG) {
633 addr2line { set program addr2line }
634 objdump { set program objdump }
635 nm { set program nm }
636 objcopy { set program objcopy }
637 readelf { set program readelf }
639 perror "unrecognized program option $opts(PROG) in $file.d"
644 # Guess which program to run, by seeing which option was specified.
645 foreach p {objdump objcopy nm readelf addr2line} {
646 if {$opts($p) != ""} {
647 if {$program != ""} {
648 perror "ambiguous dump program in $file.d"
657 if { $program == "" && $opts(warning) == "" } {
658 perror "dump program unspecified in $file.d"
664 # Handle skipping the test on specified targets.
665 # You can have both skip/not-skip and target/not-target, but you can't
666 # have both skip and not-skip, or target and not-target, in the same file.
667 if { $opts(skip) != "" } then {
668 if { $opts(not-skip) != "" } then {
669 perror "$testname: mixing skip and not-skip directives is invalid"
673 foreach glob $opts(skip) {
674 if {[istarget $glob]} { return }
677 if { $opts(not-skip) != "" } then {
679 foreach glob $opts(not-skip) {
680 if {[istarget $glob]} {
685 if {$skip} { return }
687 if { $opts(target) != "" } then {
688 if { $opts(not-target) != "" } then {
689 perror "$testname: mixing target and not-target directives is invalid"
694 foreach glob $opts(target) {
695 if {[istarget $glob]} {
701 unsupported $testname
705 if { $opts(not-target) != "" } then {
706 foreach glob $opts(not-target) {
707 if {[istarget $glob]} {
708 unsupported $testname
715 if { $opts(source) == "" } {
716 set sourcefile ${file}.s
718 set sourcefile $srcdir/$subdir/$opts(source)
721 if { $opts(dump) == "" } {
722 set dumpfile ${file}.d
724 set dumpfile $srcdir/$subdir/$opts(dump)
727 set cmd "$AS $ASFLAGS $opts(as) -o dump.o $sourcefile"
729 set status [gas_host_run $cmd ""]
730 set cmdret [lindex $status 0]
731 set comp_output [prune_warnings [lindex $status 1]]
733 set expmsg $opts(error)
734 if { $opts(warning) != "" } {
735 set expmsg $opts(warning)
737 if { $cmdret != 0 || $comp_output != "" || $expmsg != "" } then {
738 # If the executed program writes to stderr and stderr is not
739 # redirected, exec *always* returns failure, regardless of the
740 # program exit code. Thankfully, we can retrieve the true
741 # return status from a special variable. Redirection would
742 # cause a tcl-specific message to be appended, and we'd rather
743 # not deal with that if we can help it.
745 if { $cmdret != 0 && [lindex $errorCode 0] == "NONE" } {
749 set exitstat "succeeded"
750 if { $cmdret != 0 } { set exitstat "failed" }
752 send_log "$comp_output\n"
753 verbose "$comp_output" 3
754 if { $opts(stderr) == "" } then {
755 if { [regexp $expmsg $comp_output] \
756 && (($cmdret == 0) == ($opts(warning) != "")) } {
757 # We have the expected output from gas.
758 # Return if there's nothing more to do.
759 if { $opts(error) != "" || $program == "" } {
764 verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
770 catch {write_file dump.stderr "$comp_output"} write_output
771 if ![string match "" $write_output] then {
772 send_log "error writing dump.stderr: $write_output\n"
773 verbose "error writing dump.stderr: $write_output" 3
774 send_log "$comp_output\n"
775 verbose "$comp_output" 3
779 set stderrfile $srcdir/$subdir/$opts(stderr)
780 verbose "wrote pruned stderr to dump.stderr" 3
781 if { [regexp_diff "dump.stderr" "$stderrfile" ""] } then {
782 if { $opts(error) != "" } {
783 verbose -log "$exitstat with: <$comp_output>, expected: <$opts(error)>"
784 if [regexp $opts(error) $comp_output] {
790 verbose "pruned stderr is [file_contents "dump.stderr"]" 2
792 } elseif { $opts(error-output) != "" } then {
798 if { $opts(error) != "" || $opts(error-output) != "" } {
803 if { $program == "" } {
806 set progopts1 $opts($program)
807 eval set progopts \$[string toupper $program]FLAGS
808 eval set binary \$[string toupper $program]
810 if { ![is_remote host] && [which $binary] == 0 } {
815 # For objdump, automatically translate standard section names to the targets one,
816 # if they are different.
817 set sect_names [get_standard_section_names]
818 if { $sect_names != "" && $program == "objdump" && $opts(section-subst) == ""} {
819 regsub -- "-j \\.text" $progopts1 "-j [lindex $sect_names 0]" progopts1
820 regsub -- "-j \\.data" $progopts1 "-j [lindex $sect_names 1]" progopts1
821 regsub -- "-j \\.bss" $progopts1 "-j [lindex $sect_names 2]" progopts1
824 if { $progopts1 == "" } { set $progopts1 "-r" }
825 verbose "running $binary $progopts $progopts1" 3
827 # Objcopy, unlike the other two, won't send its output to stdout,
828 # so we have to run it specially.
829 set cmd "$binary $progopts $progopts1 dump.o"
830 set redir ">dump.out"
831 if { $program == "objcopy" } {
832 set cmd "$binary $progopts $progopts1 dump.o dump.out"
836 # Ensure consistent sorting of symbols
837 if {[info exists env(LC_ALL)]} {
838 set old_lc_all $env(LC_ALL)
842 set status [gas_host_run "$cmd" "$redir"]
843 set comp_output [prune_warnings [lindex $status 1]]
844 if {[info exists old_lc_all]} {
845 set env(LC_ALL) $old_lc_all
849 set comp_output [prune_warnings $comp_output]
850 if ![string match "" $comp_output] then {
851 send_log "$comp_output\n"
856 # Create the substition list only for objdump reference.
857 if { $sect_names != "" && $program == "objdump" } {
858 # Some testcases use ".text" while others use "\.text".
859 set regexp_subst [list "\\\\?\\.text" [lindex $sect_names 0] \
860 "\\\\?\\.data" [lindex $sect_names 1] \
861 "\\\\?\\.bss" [lindex $sect_names 2] ]
866 verbose_eval {[file_contents "dump.out"]} 3
867 if { [regexp_diff "dump.out" "${dumpfile}" $regexp_subst] } then {
869 verbose "output is [file_contents "dump.out"]" 2
876 proc slurp_options { file } {
877 if [catch { set f [open $file r] } x] {
878 #perror "couldn't open `$file': $x"
883 # whitespace expression
886 # whitespace is ignored anywhere except within the options list;
887 # option names are alphabetic plus dash
888 set pat "^#${ws}(\[a-zA-Z0-9-\]*)$ws:${ws}(.*)$ws\$"
889 while { [gets $f line] != -1 } {
890 set line [string trim $line]
891 # Whitespace here is space-tab.
892 if [regexp $pat $line xxx opt_name opt_val] {
894 lappend opt_array [list $opt_name $opt_val]
895 } elseif {![regexp "^#" $line ]} {
903 proc objdump { opts } {
908 set status [gas_host_run "$OBJDUMP $opts" ""]
909 set comp_output [prune_warnings [lindex $status 1]]
910 verbose "objdump output=$comp_output\n" 3
913 proc objdump_start_no_subdir { prog opts } {
918 verbose "Starting $OBJDUMP $opts $prog" 2
919 set status [gas_host_run "$OBJDUMP $opts $prog" ">&gas.out"]
920 spawn -noecho -nottycopy cat gas.out
923 proc objdump_finish { } {
930 # Default timeout is 10 seconds, loses on a slow machine. But some
931 # configurations of dejagnu may override it.
932 if {$timeout<120} then { set timeout 120 }
935 timeout { perror "timeout" }
936 "virtual memory exhausted" { perror "virtual memory exhausted" }
937 buffer_full { perror "buffer full" }
941 # regexp_diff, based on simple_diff taken from ld test suite.
942 # Compares two files line-by-line.
943 # FILE_1 contains strings, FILE_2 contains regexps and #-comments
944 # Blank lines are ignored in either file.
945 # Subsitutions in REF_SUBST are applied on FILE_2 lines.
946 # Returns non-zero if differences exist.
948 proc regexp_diff { file_1 file_2 ref_subst} {
956 if [file exists $file_1] then {
957 set file_a [open $file_1 r]
959 perror "$file_1 doesn't exist"
963 if [file exists $file_2] then {
964 set file_b [open $file_2 r]
966 perror "$file_2 doesn't exist"
971 verbose " Regexp-diff'ing: $file_1 $file_2" 2
976 while { [string length $line_a] == 0 } {
977 # Ignore blank line in FILE_1.
978 if { [gets $file_a line_a] == $eof } {
983 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
984 if [ string match "#pass" $line_b ] {
988 } elseif [ string match "#..." $line_b ] {
989 if { [gets $file_b line_b] == $eof } {
994 # Substitute on the reference.
995 foreach {name value} $ref_subst {
996 regsub -- $name $line_b $value line_b
998 verbose "looking for \"^$line_b$\"" 3
999 while { ![regexp "^$line_b$" "$line_a"] } {
1000 verbose "skipping \"$line_a\"" 3
1001 if { [gets $file_a line_a] == $eof } {
1008 if { [gets $file_b line_b] == $eof } {
1016 } elseif { $end_1 && $end_2 } {
1018 } elseif { $end_1 } {
1019 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
1020 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
1023 } elseif { $end_2 } {
1024 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
1025 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
1029 # Substitute on the reference.
1030 foreach {name value} $ref_subst {
1031 regsub -- $name $line_b $value line_b
1033 verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
1034 if ![regexp "^$line_b$" "$line_a"] {
1035 send_log "regexp_diff match failure\n"
1036 send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
1037 verbose "regexp_diff match failure\n" 3
1043 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
1044 send_log "$file_1 and $file_2 are different lengths\n"
1045 verbose "$file_1 and $file_2 are different lengths" 3
1055 proc file_contents { filename } {
1056 set file [open $filename r]
1057 set contents [read $file]
1062 proc write_file { filename contents } {
1063 set file [open $filename w]
1064 puts $file "$contents"
1068 proc verbose_eval { expr { level 1 } } {
1070 if $verbose>$level then { eval verbose "$expr" $level }
1073 # This definition is taken from an unreleased version of DejaGnu. Once
1074 # that version gets released, and has been out in the world for a few
1075 # months at least, it may be safe to delete this copy.
1076 if ![string length [info proc prune_warnings]] {
1078 # prune_warnings -- delete various system verbosities from TEXT.
1081 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
1083 # Sites with particular verbose os's may wish to override this in site.exp.
1085 proc prune_warnings { text } {
1086 # This is from sun4's. Do it for all machines for now.
1087 # The "\\1" is to try to preserve a "\n" but only if necessary.
1088 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
1090 # It might be tempting to get carried away and delete blank lines, etc.
1091 # Just delete *exactly* what we're ask to, and that's it.
1096 # run_list_test NAME (optional): OPTS TESTNAME
1098 # Assemble the file "NAME.s" with command line options OPTS and
1099 # compare the assembler standard error output against the regular
1100 # expressions given in the file "NAME.l". If TESTNAME is provided,
1101 # it will be used as the name of the test.
1103 proc run_list_test { name {opts {}} {testname {}} } {
1104 global srcdir subdir
1105 if { [string length $testname] == 0 } then {
1106 set testname "[file tail $subdir] $name"
1108 set file $srcdir/$subdir/$name
1109 gas_run ${name}.s $opts ">&dump.out"
1110 if { [regexp_diff "dump.out" "${file}.l" ""] } then {
1112 verbose "output is [file_contents "dump.out"]" 2
1118 # run_list_test_stdin NAME (optional): OPTS TESTNAME
1120 # Similar to run_list_test, but use stdin as input.
1122 proc run_list_test_stdin { name {opts {}} {testname {}} } {
1123 global srcdir subdir
1124 if { [string length $testname] == 0 } then {
1125 set testname "[file tail $subdir] $name"
1127 set file $srcdir/$subdir/$name
1128 gas_run_stdin ${name}.s $opts ">&dump.out"
1129 if { [regexp_diff "dump.out" "${file}.l" ""] } then {
1131 verbose "output is [file_contents "dump.out"]" 2