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