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