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