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