1 # Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003
2 # 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
21 # This file was written by Ken Raeburn (raeburn@cygnus.com).
25 catch "exec $AS -version < /dev/null" tmp
26 # Should find a way to discard constant parts, keep whatever's
27 # left, so the version string could be almost anything at all...
28 regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number
29 if ![info exists number] then {
30 return "[which $AS] (no version number)\n"
32 clone_output "[which $AS] $number\n"
36 proc gas_run { prog as_opts redir } {
44 verbose -log "Executing $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir"
45 catch "exec $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" comp_output
46 set comp_output [prune_warnings $comp_output]
47 verbose "output was $comp_output"
48 return [list $comp_output ""];
51 proc all_ones { args } {
52 foreach x $args { if [expr $x!=1] { return 0 } }
56 proc gas_start { prog as_opts } {
63 verbose -log "Starting $AS $ASFLAGS $as_opts $prog" 2
65 spawn -noecho -nottycopy $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog
67 if ![regexp {^[0-9]+} $foo] then {
68 perror "Can't run $subdir/$prog: $foo"
79 proc want_no_output { testname } {
82 if ![string match "" $comp_output] then {
83 send_log "$comp_output\n"
84 verbose "$comp_output" 3
86 if [string match "" $comp_output] then {
95 proc gas_test_old { file as_opts testname } {
96 gas_run $file $as_opts ""
97 return [want_no_output $testname]
100 proc gas_test { file as_opts var_opts testname } {
104 foreach word $var_opts {
105 set ignore_stdout($i) [string match "*>" $word]
106 set opt($i) [string trim $word {>}]
110 for {set i 0} {[expr $i<$max]} {incr i} {
111 set maybe_ignore_stdout ""
113 for {set bit 0} {(1<<$bit)<$max} {incr bit} {
114 set num [expr 1<<$bit]
115 if [expr $i&$num] then {
116 set extra_opts "$extra_opts $opt($bit)"
117 if $ignore_stdout($bit) then {
118 set maybe_ignore_stdout ">/dev/null"
122 set extra_opts [string trim $extra_opts]
123 gas_run $file "$as_opts $extra_opts" $maybe_ignore_stdout
125 # Should I be able to use a conditional expression here?
126 if [string match "" $extra_opts] then {
127 want_no_output $testname
129 want_no_output "$testname ($extra_opts)"
132 if [info exists errorInfo] then {
137 proc gas_test_ignore_stdout { file as_opts testname } {
140 gas_run $file $as_opts ">/dev/null"
141 want_no_output $testname
144 proc gas_test_error { file as_opts testname } {
147 gas_run $file $as_opts ">/dev/null"
148 if ![string match "" $comp_output] then {
149 send_log "$comp_output\n"
150 verbose "$comp_output" 3
152 if [string match "" $comp_output] then {
161 proc gas_init { args } {
163 global target_cpu_family
169 case "$target_cpu" in {
170 "m68???" { set target_cpu_family m68k }
171 "i[3-7]86" { set target_cpu_family i386 }
172 default { set target_cpu_family $target_cpu }
175 set target_family "$target_cpu_family-$target_vendor-$target_os"
178 if ![istarget "*-*-*"] {
179 perror "Target name [istarget] is not a triple."
181 # Need to return an empty string.
187 # true if the object format is known to be ELF
189 proc is_elf_format {} {
190 if { ![istarget *-*-sysv4*] \
191 && ![istarget *-*-unixware*] \
192 && ![istarget *-*-elf*] \
193 && ![istarget *-*-eabi*] \
194 && ![istarget hppa*64*-*-hpux*] \
195 && ![istarget *-*-linux*] \
196 && ![istarget frv-*-uclinux*] \
197 && ![istarget *-*-irix5*] \
198 && ![istarget *-*-irix6*] \
199 && ![istarget *-*-netbsd*] \
200 && ![istarget *-*-openbsd*] \
201 && ![istarget *-*-solaris2*] } {
205 if { [istarget *-*-linux*aout*] \
206 || [istarget *-*-linux*oldld*] } {
210 if { ![istarget *-*-netbsdelf*] \
211 && ([istarget *-*-netbsd*aout*] \
212 || [istarget *-*-netbsdpe*] \
213 || [istarget arm*-*-netbsd*] \
214 || [istarget sparc-*-netbsd*] \
215 || [istarget i*86-*-netbsd*] \
216 || [istarget m68*-*-netbsd*] \
217 || [istarget vax-*-netbsd*] \
218 || [istarget ns32k-*-netbsd*]) } {
222 if { [istarget arm-*-openbsd*] \
223 || [istarget i386-*-openbsd\[0-2\].*] \
224 || [istarget i386-*-openbsd3.\[0-3\]] \
225 || [istarget m68*-*-openbsd*] \
226 || [istarget ns32k-*-openbsd*] \
227 || [istarget sparc-*-openbsd\[0-2\].*] \
228 || [istarget sparc-*-openbsd3.\[0-1\]] \
229 || [istarget vax-*-openbsd*] } {
237 # run_dump_test FILE (optional:) EXTRA_OPTIONS
239 # Assemble a .s file, then run some utility on it and check the output.
241 # There should be an assembly language file named FILE.s in the test
242 # suite directory, and a pattern file called FILE.d. `run_dump_test'
243 # will assemble FILE.s, run some tool like `objdump', `objcopy', or
244 # `nm' on the .o file to produce textual output, and then analyze that
245 # with regexps. The FILE.d file specifies what program to run, and
246 # what to expect in its output.
248 # The FILE.d file begins with zero or more option lines, which specify
249 # flags to pass to the assembler, the program to run to dump the
250 # assembler's output, and the options it wants. The option lines have
255 # OPTION is the name of some option, like "name" or "objdump", and
256 # VALUE is OPTION's value. The valid options are described below.
257 # Whitespace is ignored everywhere, except within VALUE. The option
258 # list ends with the first line that doesn't match the above syntax
259 # (hmm, not great for error detection).
261 # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
262 # two-element lists. The first element of each is an option name, and
263 # the second additional arguments to be added on to the end of the
264 # option list as given in FILE.d. (If omitted, no additional options
267 # The interesting options are:
270 # The name of this test, passed to DejaGNU's `pass' and `fail'
271 # commands. If omitted, this defaults to FILE, the root of the
272 # .s and .d files' names.
275 # When assembling FILE.s, pass FLAGS to the assembler.
278 # The name of the program to run to analyze the .o file produced
279 # by the assembler. This can be omitted; run_dump_test will guess
280 # which program to run by seeing which of the flags options below
286 # Use the specified program to analyze the .o file, and pass it
287 # FLAGS, in addition to the .o file name. Note that they are run
288 # with LC_ALL=C in the environment to give consistent sorting
292 # Assemble the file SOURCE.s. If omitted, this defaults to FILE.s.
293 # This is useful if several .d files want to share a .s file.
296 # An error with message matching REGEX must be emitted for the test
297 # to pass. The PROG, objdump, nm and objcopy options have no
298 # meaning and need not supplied if this is present.
300 # Each option may occur at most once.
302 # After the option lines come regexp lines. `run_dump_test' calls
303 # `regexp_diff' to compare the output of the dumping tool against the
304 # regexps in FILE.d. `regexp_diff' is defined later in this file; see
305 # further comments there.
307 proc run_dump_test { name {extra_options {}} } {
309 global OBJDUMP NM AS OBJCOPY READELF
310 global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS
314 if [string match "*/*" $name] {
316 set name [file tail $name]
318 set file "$srcdir/$subdir/$name"
320 set opt_array [slurp_options "${file}.d"]
321 if { $opt_array == -1 } {
322 perror "error reading options from $file.d"
323 unresolved $subdir/$name
337 foreach i $opt_array {
338 set opt_name [lindex $i 0]
339 set opt_val [lindex $i 1]
340 if ![info exists opts($opt_name)] {
341 perror "unknown option $opt_name in file $file.d"
342 unresolved $subdir/$name
345 if [string length $opts($opt_name)] {
346 perror "option $opt_name multiply set in $file.d"
347 unresolved $subdir/$name
350 set opts($opt_name) $opt_val
353 foreach i $extra_options {
354 set opt_name [lindex $i 0]
355 set opt_val [lindex $i 1]
356 if ![info exists opts($opt_name)] {
357 perror "unknown option $opt_name given in extra_opts"
358 unresolved $subdir/$name
361 # add extra option to end of existing option, adding space
363 if [string length $opts($opt_name)] {
364 append opts($opt_name) " "
366 append opts($opt_name) $opt_val
369 if {$opts(PROG) != ""} {
370 switch -- $opts(PROG) {
372 { set program objdump }
376 { set program objcopy }
378 { set program readelf }
380 { perror "unrecognized program option $opts(PROG) in $file.d"
381 unresolved $subdir/$name
384 } elseif { $opts(error) != "" } {
385 # It's meaningless to require an output-testing method when we
386 # expect an error. For simplicity, we fake an arbitrary method.
389 # Guess which program to run, by seeing which option was specified.
391 foreach p {objdump objcopy nm readelf} {
392 if {$opts($p) != ""} {
393 if {$program != ""} {
394 perror "ambiguous dump program in $file.d"
395 unresolved $subdir/$name
402 if {$program == ""} {
403 perror "dump program unspecified in $file.d"
404 unresolved $subdir/$name
409 set progopts1 $opts($program)
410 eval set progopts \$[string toupper $program]FLAGS
411 eval set binary \$[string toupper $program]
412 if { $opts(name) == "" } {
413 set testname "$subdir/$name"
415 set testname $opts(name)
418 if { $opts(source) == "" } {
419 set sourcefile ${file}.s
421 set sourcefile $srcdir/$subdir/$opts(source)
424 send_log "$AS $ASFLAGS $opts(as) -o dump.o $sourcefile\n"
425 catch "exec $srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile" comp_output
426 set comp_output [prune_warnings $comp_output]
428 if { ![string match "" $comp_output] || $opts(stderr) != "" } then {
429 if { $opts(stderr) == "" } then {
430 send_log "$comp_output\n"
431 verbose "$comp_output" 3
433 if { $opts(error) != "" } {
434 verbose -log "failed with: <$comp_output>, expected: <$opts(error)>"
435 if [regexp $opts(error) $comp_output] {
443 catch {write_file dump.stderr "$comp_output"} write_output
444 if ![string match "" $write_output] then {
445 send_log "error writing dump.stderr: $write_output\n"
446 verbose "error writing dump.stderr: $write_output" 3
447 send_log "$comp_output\n"
448 verbose "$comp_output" 3
452 set stderrfile $srcdir/$subdir/$opts(stderr)
453 send_log "wrote pruned stderr to dump.stderr\n"
454 verbose "wrote pruned stderr to dump.stderr" 3
455 if { [regexp_diff "dump.stderr" "$stderrfile"] } then {
456 if { $opts(error) != "" } {
457 verbose -log "failed with: <$comp_output>, expected: <$opts(error)>"
458 if [regexp $opts(error) $comp_output] {
464 verbose "pruned stderr is [file_contents "dump.stderr"]" 2
470 if { [which $binary] == 0 } {
475 if { $progopts1 == "" } { set $progopts1 "-r" }
476 verbose "running $binary $progopts $progopts1" 3
478 # Objcopy, unlike the other two, won't send its output to stdout,
479 # so we have to run it specially.
480 set cmd "$binary $progopts $progopts1 dump.o > dump.out"
481 if { $program == "objcopy" } {
482 set cmd "$binary $progopts $progopts1 dump.o dump.out"
485 # Ensure consistent sorting of symbols
486 if {[info exists env(LC_ALL)]} {
487 set old_lc_all $env(LC_ALL)
491 catch "exec $cmd" comp_output
492 if {[info exists old_lc_all]} {
493 set env(LC_ALL) $old_lc_all
497 set comp_output [prune_warnings $comp_output]
498 if ![string match "" $comp_output] then {
499 send_log "$comp_output\n"
504 verbose_eval {[file_contents "dump.out"]} 3
505 if { [regexp_diff "dump.out" "${file}.d"] } then {
507 verbose "output is [file_contents "dump.out"]" 2
514 proc slurp_options { file } {
515 if [catch { set f [open $file r] } x] {
516 #perror "couldn't open `$file': $x"
521 # whitespace expression
524 # whitespace is ignored anywhere except within the options list;
525 # option names are alphabetic only
526 set pat "^#${ws}(\[a-zA-Z\]*)$ws:${ws}(.*)$ws\$"
527 while { [gets $f line] != -1 } {
528 set line [string trim $line]
529 # Whitespace here is space-tab.
530 if [regexp $pat $line xxx opt_name opt_val] {
532 lappend opt_array [list $opt_name $opt_val]
541 proc objdump { opts } {
546 catch "exec $OBJDUMP $opts" comp_output
547 set comp_output [prune_warnings $comp_output]
548 verbose "objdump output=$comp_output\n" 3
551 proc objdump_start_no_subdir { prog opts } {
556 verbose "Starting $OBJDUMP $opts $prog" 2
558 spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog
560 if ![regexp {^[0-9]+} $foo] then {
561 perror "Can't run $prog: $foo"
565 proc objdump_finish { } {
572 # Default timeout is 10 seconds, loses on a slow machine. But some
573 # configurations of dejagnu may override it.
574 if {$timeout<120} then { set timeout 120 }
577 timeout { perror "timeout" }
578 "virtual memory exhausted" { perror "virtual memory exhausted" }
579 buffer_full { perror "buffer full" }
583 # regexp_diff, based on simple_diff taken from ld test suite
584 # compares two files line-by-line
585 # file1 contains strings, file2 contains regexps and #-comments
586 # blank lines are ignored in either file
587 # returns non-zero if differences exist
589 proc regexp_diff { file_1 file_2 } {
597 if [file exists $file_1] then {
598 set file_a [open $file_1 r]
600 perror "$file_1 doesn't exist"
604 if [file exists $file_2] then {
605 set file_b [open $file_2 r]
607 perror "$file_2 doesn't exist"
612 verbose " Regexp-diff'ing: $file_1 $file_2" 2
617 while { [string length $line_a] == 0 } {
618 if { [gets $file_a line_a] == $eof } {
623 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
624 if [ string match "#pass" $line_b ] {
628 } elseif [ string match "#..." $line_b ] {
629 if { [gets $file_b line_b] == $eof } {
633 verbose "looking for \"^$line_b$\"" 3
634 while { ![regexp "^$line_b$" "$line_a"] } {
635 verbose "skipping \"$line_a\"" 3
636 if { [gets $file_a line_a] == $eof } {
643 if { [gets $file_b line_b] == $eof } {
651 } elseif { $end_1 && $end_2 } {
653 } elseif { $end_1 } {
654 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
655 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
658 } elseif { $end_2 } {
659 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
660 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
664 verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
665 if ![regexp "^$line_b$" "$line_a"] {
666 send_log "regexp_diff match failure\n"
667 send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
668 verbose "regexp_diff match failure\n" 3
674 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
675 send_log "$file_1 and $file_2 are different lengths\n"
676 verbose "$file_1 and $file_2 are different lengths" 3
686 proc file_contents { filename } {
687 set file [open $filename r]
688 set contents [read $file]
693 proc write_file { filename contents } {
694 set file [open $filename w]
695 puts $file "$contents"
699 proc verbose_eval { expr { level 1 } } {
701 if $verbose>$level then { eval verbose "$expr" $level }
704 # This definition is taken from an unreleased version of DejaGnu. Once
705 # that version gets released, and has been out in the world for a few
706 # months at least, it may be safe to delete this copy.
707 if ![string length [info proc prune_warnings]] {
709 # prune_warnings -- delete various system verbosities from TEXT.
712 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
714 # Sites with particular verbose os's may wish to override this in site.exp.
716 proc prune_warnings { text } {
717 # This is from sun4's. Do it for all machines for now.
718 # The "\\1" is to try to preserve a "\n" but only if necessary.
719 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
721 # It might be tempting to get carried away and delete blank lines, etc.
722 # Just delete *exactly* what we're ask to, and that's it.