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