1 # Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004, 2006, 2007,
2 # 2009, 2010 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, MA 02110-1301, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-dejagnu@prep.ai.mit.edu
21 # This file was written by Rob Savoye <rob@cygnus.com>
22 # and extended by Ian Lance Taylor <ian@cygnus.com>
24 proc binutil_version { prog } {
25 if ![is_remote host] {
26 set path [which $prog]
27 if {$path == 0} then {
28 perror "$prog can't be run, file not found."
34 set state [remote_exec host $prog --version]
35 set tmp "[lindex $state 1]\n"
36 # Should find a way to discard constant parts, keep whatever's
37 # left, so the version string could be almost anything at all...
38 regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" "$tmp" version cyg number
39 if ![info exists number] then {
40 return "$path (no version number)\n"
42 return "$path $number\n"
46 # default_binutils_run
47 # run a program, returning the output
48 # sets binutils_run_failed if the program does not exist
50 proc default_binutils_run { prog progargs } {
51 global binutils_run_failed
54 set binutils_run_failed 0
56 if ![is_remote host] {
57 if {[which $prog] == 0} then {
58 perror "$prog does not exist"
59 set binutils_run_failed 1
64 send_log "$prog $progargs\n"
65 verbose "$prog $progargs"
67 # Gotta quote dollar-signs because they get mangled by the
69 regsub -all "\\$" "$progargs" "\\$" progargs
71 set state [remote_exec host $prog $progargs]
72 set exec_output [prune_warnings [lindex $state 1]]
73 if {![string match "" $exec_output]} then {
74 send_log "$exec_output\n"
75 verbose "$exec_output"
77 if { [lindex $state 0] != 0 } {
78 set exec_output "$prog exited with status [lindex $state 0]"
79 send_log "$exec_output\n"
80 verbose "$exec_output"
87 # default_binutils_assemble_flags
90 proc default_binutils_assemble_flags { source object asflags } {
94 # The HPPA assembler syntax is a little different than most, to make
95 # the test source file assemble we need to run it through sed.
97 # This is a hack in that it won't scale well if other targets need
98 # similar transformations to assemble. We'll generalize the hack
99 # if/when other targets need similar handling.
100 if { [istarget "hppa*-*-*"] && ![istarget "*-*-linux*" ] } then {
101 set sed_file $srcdir/config/hppa.sed
102 send_log "sed -f $sed_file < $source > asm.s\n"
103 verbose "sed -f $sed_file < $source > asm.s"
104 catch "exec sed -f $sed_file < $source > asm.s"
108 set exec_output [target_assemble $source $object $asflags]
109 set exec_output [prune_warnings $exec_output]
111 if [string match "" $exec_output] {
114 send_log "$exec_output\n"
115 verbose "$exec_output"
116 perror "$source: assembly failed"
121 # True if the object format is known to be ELF.
123 proc is_elf_format {} {
124 if { ![istarget *-*-sysv4*]
125 && ![istarget *-*-unixware*]
126 && ![istarget *-*-elf*]
127 && ![istarget *-*-eabi*]
128 && ![istarget *-*-rtems*]
129 && ![istarget hppa*64*-*-hpux*]
130 && ![istarget ia64-*-hpux*]
131 && ![istarget *-*-linux*]
132 && ![istarget *-*-gnu*]
133 && ![istarget frv-*-uclinux*]
134 && ![istarget bfin-*-uclinux]
135 && ![istarget sh*-*-uclinux*]
136 && ![istarget *-*-irix5*]
137 && ![istarget *-*-irix6*]
138 && ![istarget *-*-netbsd*]
139 && ![istarget *-*-openbsd*]
140 && ![istarget *-*-solaris2*] } {
144 if { [istarget *-*-linux*aout*]
145 || [istarget *-*-linux*oldld*]
146 || [istarget h8500-*-rtems*]
147 || [istarget i960-*-rtems*]
148 || [istarget *-*-rtemscoff*] } {
152 if { ![istarget *-*-netbsdelf*]
153 && ([istarget *-*-netbsd*aout*]
154 || [istarget *-*-netbsdpe*]
155 || [istarget arm*-*-netbsd*]
156 || [istarget sparc-*-netbsd*]
157 || [istarget i*86-*-netbsd*]
158 || [istarget m68*-*-netbsd*]
159 || [istarget vax-*-netbsd*]
160 || [istarget ns32k-*-netbsd*]) } {
164 if { [istarget arm-*-openbsd*]
165 || [istarget i386-*-openbsd\[0-2\].*]
166 || [istarget i386-*-openbsd3.\[0-2\]]
167 || [istarget m68*-*-openbsd*]
168 || [istarget ns32k-*-openbsd*]
169 || [istarget sparc-*-openbsd\[0-2\].*]
170 || [istarget sparc-*-openbsd3.\[0-1\]]
171 || [istarget vax-*-openbsd*] } {
180 # Returns target executable extension, if any.
183 if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
190 # Copied and modified from gas.
192 # run_dump_test FILE (optional:) EXTRA_OPTIONS
194 # Assemble a .s file, then run some utility on it and check the output.
196 # There should be an assembly language file named FILE.s in the test
197 # suite directory, and a pattern file called FILE.d. `run_dump_test'
198 # will assemble FILE.s, run some tool like `objdump', `objcopy', or
199 # `nm' on the .o file to produce textual output, and then analyze that
200 # with regexps. The FILE.d file specifies what program to run, and
201 # what to expect in its output.
203 # The FILE.d file begins with zero or more option lines, which specify
204 # flags to pass to the assembler, the program to run to dump the
205 # assembler's output, and the options it wants. The option lines have
210 # OPTION is the name of some option, like "name" or "objdump", and
211 # VALUE is OPTION's value. The valid options are described below.
212 # Whitespace is ignored everywhere, except within VALUE. The option
213 # list ends with the first line that doesn't match the above syntax.
214 # However, a line within the options that begins with a #, but doesn't
215 # have a recognizable option name followed by a colon, is considered a
216 # comment and entirely ignored.
218 # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
219 # two-element lists. The first element of each is an option name, and
220 # the second additional arguments to be added on to the end of the
221 # option list as given in FILE.d. (If omitted, no additional options
224 # The interesting options are:
227 # The name of this test, passed to DejaGNU's `pass' and `fail'
228 # commands. If omitted, this defaults to FILE, the root of the
229 # .s and .d files' names.
232 # When assembling FILE.s, pass FLAGS to the assembler.
235 # The name of the program to run to analyze the .o file produced
236 # by the assembler. This can be omitted; run_dump_test will guess
237 # which program to run by seeing which of the flags options below
243 # Use the specified program to analyze the .o file, and pass it
244 # FLAGS, in addition to the .o file name. Note that they are run
245 # with LC_ALL=C in the environment to give consistent sorting
249 # Assemble the file SOURCE.s. If omitted, this defaults to FILE.s.
250 # This is useful if several .d files want to share a .s file.
253 # Run this test only on a specified list of targets. More precisely,
254 # each glob in the space-separated list is passed to "istarget"; if
255 # it evaluates true for any of them, the test will be run, otherwise
256 # it will be marked unsupported.
258 # not-target: GLOBS...
259 # Do not run this test on a specified list of targets. Again,
260 # the each glob in the space-separated list is passed to
261 # "istarget", and the test is run if it evaluates *false* for
262 # *all* of them. Otherwise it will be marked unsupported.
266 # These are exactly the same as "not-target" and "target",
267 # respectively, except that they do nothing at all if the check
268 # fails. They should only be used in groups, to construct a single
269 # test which is run on all targets but with variant options or
270 # expected output on some targets. (For example, see
271 # gas/arm/inst.d and gas/arm/wince_inst.d.)
274 # An error with message matching REGEX must be emitted for the test
275 # to pass. The PROG, objdump, nm and objcopy options have no
276 # meaning and need not supplied if this is present.
279 # Expect a gas warning matching REGEX. It is an error to issue
280 # both "error" and "warning".
283 # FILE contains regexp lines to be matched against the diagnostic
284 # output of the assembler. This does not preclude the use of
285 # PROG, nm, objdump, or objcopy.
288 # Means the same as 'stderr', but also indicates that the assembler
289 # is expected to exit unsuccessfully (therefore PROG, objdump, nm,
290 # and objcopy have no meaning and should not be supplied).
292 # Each option may occur at most once.
294 # After the option lines come regexp lines. `run_dump_test' calls
295 # `regexp_diff' to compare the output of the dumping tool against the
296 # regexps in FILE.d. `regexp_diff' is defined later in this file; see
297 # further comments there.
299 proc run_dump_test { name {extra_options {}} } {
301 global OBJDUMP NM OBJCOPY READELF STRIP
302 global OBJDUMPFLAGS NMFLAGS OBJCOPYFLAGS READELFFLAGS STRIPFLAGS
303 global ELFEDIT ELFEDITFLAGS
309 if [string match "*/*" $name] {
311 set name [file tail $name]
313 set file "$srcdir/$subdir/$name"
315 set opt_array [slurp_options "${file}.d"]
316 if { $opt_array == -1 } {
317 perror "error reading options from $file.d"
318 unresolved $subdir/$name
321 set opts(addr2line) {}
335 set opts(DUMPPROG) {}
338 set opts(not-target) {}
340 set opts(not-skip) {}
342 foreach i $opt_array {
343 set opt_name [lindex $i 0]
344 set opt_val [lindex $i 1]
345 if ![info exists opts($opt_name)] {
346 perror "unknown option $opt_name in file $file.d"
347 unresolved $subdir/$name
351 # Permit the option to use $srcdir to refer to the source
353 regsub -all "\\\$srcdir" "$opt_val" "$srcdir/$subdir" opt_val
355 if [string length $opts($opt_name)] {
356 perror "option $opt_name multiply set in $file.d"
357 unresolved $subdir/$name
360 set opts($opt_name) $opt_val
363 foreach i $extra_options {
364 set opt_name [lindex $i 0]
365 set opt_val [lindex $i 1]
366 if ![info exists opts($opt_name)] {
367 perror "unknown option $opt_name given in extra_opts"
368 unresolved $subdir/$name
372 # Permit the option to use $srcdir to refer to the source
374 regsub -all "\\\$srcdir" "$opt_val" "$srcdir/$subdir" opt_val
376 # add extra option to end of existing option, adding space
378 if [string length $opts($opt_name)] {
379 append opts($opt_name) " "
381 append opts($opt_name) $opt_val
384 if { $opts(name) == "" } {
385 set testname "$subdir/$name"
387 set testname $opts(name)
389 verbose "Testing $testname"
391 if {$opts(PROG) == ""} {
392 perror "program isn't set in $file.d"
398 switch -- $opts(PROG) {
399 ar { set program ar }
400 objcopy { set program objcopy }
401 ranlib { set program ranlib }
406 strings { set program strings }
407 elfedit { set program elfedit }
409 perror "unrecognized program option $opts(PROG) in $file.d"
415 if { $opts(DUMPPROG) != "" } {
416 switch -- $opts(DUMPPROG) {
417 addr2line { set dumpprogram addr2line }
418 nm { set dumpprogram nm }
419 objdump { set dumpprogram objdump }
420 readelf { set dumpprogram readelf }
421 size { set dumpprogram size }
423 perror "unrecognized dump program option $opts(DUMPPROG) in $file.d"
428 # Guess which program to run, by seeing which option was specified.
429 foreach p {objdump nm readelf} {
430 if {$opts($p) != ""} {
431 if {$dumpprogram != ""} {
432 perror "ambiguous dump program in $file.d"
442 # Handle skipping the test on specified targets.
443 # You can have both skip/not-skip and target/not-target, but you can't
444 # have both skip and not-skip, or target and not-target, in the same file.
445 if { $opts(skip) != "" } then {
446 if { $opts(not-skip) != "" } then {
447 perror "$testname: mixing skip and not-skip directives is invalid"
451 foreach glob $opts(skip) {
452 if {[istarget $glob]} { return }
455 if { $opts(not-skip) != "" } then {
457 foreach glob $opts(not-skip) {
458 if {[istarget $glob]} {
463 if {$skip} { return }
465 if { $opts(target) != "" } then {
466 if { $opts(not-target) != "" } then {
467 perror "$testname: mixing target and not-target directives is invalid"
472 foreach glob $opts(target) {
473 if {[istarget $glob]} {
479 unsupported $testname
483 if { $opts(not-target) != "" } then {
484 foreach glob $opts(not-target) {
485 if {[istarget $glob]} {
486 unsupported $testname
492 if { $opts(source) == "" } {
493 set srcfile ${file}.s
495 set srcfile $srcdir/$subdir/$opts(source)
498 set exec_output [binutils_assemble_flags ${srcfile} $tempfile $opts(as)]
499 if [string match "" $exec_output] then {
500 send_log "$exec_output\n"
501 verbose "$exec_output"
506 set progopts1 $opts($program)
507 eval set progopts \$[string toupper $program]FLAGS
508 eval set binary \$[string toupper $program]
510 set exec_output [binutils_run $binary "$progopts $progopts1 $tempfile $destopt ${copyfile}.o"]
511 if ![string match "" $exec_output] {
512 send_log "$exec_output\n"
513 verbose "$exec_output"
518 set progopts1 $opts($dumpprogram)
519 eval set progopts \$[string toupper $dumpprogram]FLAGS
520 eval set binary \$[string toupper $dumpprogram]
522 if { ![is_remote host] && [which $binary] == 0 } {
527 verbose "running $binary $progopts $progopts1" 3
529 set cmd "$binary $progopts $progopts1 ${copyfile}.o"
531 # Ensure consistent sorting of symbols
532 if {[info exists env(LC_ALL)]} {
533 set old_lc_all $env(LC_ALL)
537 set comp_output [remote_exec host $cmd "" "/dev/null" "tmpdir/dump.out"]
538 if {[info exists old_lc_all]} {
539 set env(LC_ALL) $old_lc_all
543 if { [lindex $comp_output 0] != 0 } then {
544 send_log "$comp_output\n"
548 set comp_output [prune_warnings [lindex $comp_output 1]]
549 if ![string match "" $comp_output] then {
550 send_log "$comp_output\n"
555 verbose_eval {[file_contents "tmpdir/dump.out"]} 3
556 if { [regexp_diff "tmpdir/dump.out" "${file}.d"] } then {
558 verbose "output is [file_contents "tmpdir/dump.out"]" 2
565 proc slurp_options { file } {
566 if [catch { set f [open $file r] } x] {
567 #perror "couldn't open `$file': $x"
572 # whitespace expression
575 # whitespace is ignored anywhere except within the options list;
576 # option names are alphabetic plus dash
577 set pat "^#${ws}(\[a-zA-Z-\]*)$ws:${ws}(.*)$ws\$"
578 while { [gets $f line] != -1 } {
579 set line [string trim $line]
580 # Whitespace here is space-tab.
581 if [regexp $pat $line xxx opt_name opt_val] {
583 lappend opt_array [list $opt_name $opt_val]
584 } elseif {![regexp "^#" $line ]} {
592 # regexp_diff, based on simple_diff taken from ld test suite
593 # compares two files line-by-line
594 # file1 contains strings, file2 contains regexps and #-comments
595 # blank lines are ignored in either file
596 # returns non-zero if differences exist
598 proc regexp_diff { file_1 file_2 } {
606 if [file exists $file_1] then {
607 set file_a [open $file_1 r]
609 perror "$file_1 doesn't exist"
613 if [file exists $file_2] then {
614 set file_b [open $file_2 r]
616 perror "$file_2 doesn't exist"
621 verbose " Regexp-diff'ing: $file_1 $file_2" 2
626 while { [string length $line_a] == 0 } {
627 if { [gets $file_a line_a] == $eof } {
632 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
633 if [ string match "#pass" $line_b ] {
637 } elseif [ string match "#..." $line_b ] {
638 if { [gets $file_b line_b] == $eof } {
643 verbose "looking for \"^$line_b$\"" 3
644 while { ![regexp "^$line_b$" "$line_a"] } {
645 verbose "skipping \"$line_a\"" 3
646 if { [gets $file_a line_a] == $eof } {
653 if { [gets $file_b line_b] == $eof } {
661 } elseif { $end_1 && $end_2 } {
663 } elseif { $end_1 } {
664 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
665 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
668 } elseif { $end_2 } {
669 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
670 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
674 verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
675 if ![regexp "^$line_b$" "$line_a"] {
676 send_log "regexp_diff match failure\n"
677 send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
678 verbose "regexp_diff match failure\n" 3
684 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
685 send_log "$file_1 and $file_2 are different lengths\n"
686 verbose "$file_1 and $file_2 are different lengths" 3
696 proc file_contents { filename } {
697 set file [open $filename r]
698 set contents [read $file]
703 proc verbose_eval { expr { level 1 } } {
705 if $verbose>$level then { eval verbose "$expr" $level }