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