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