gas/
[deliverable/binutils-gdb.git] / gas / testsuite / lib / gas-defs.exp
CommitLineData
fee5fcc5 1# Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003
139e4a70 2# 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
139e4a70 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
252b5132 236
e8119602 237# run_dump_test FILE (optional:) EXTRA_OPTIONS
252b5132
RH
238#
239# Assemble a .s file, then run some utility on it and check the output.
139e4a70 240#
252b5132
RH
241# There should be an assembly language file named FILE.s in the test
242# suite directory, and a pattern file called FILE.d. `run_dump_test'
243# will assemble FILE.s, run some tool like `objdump', `objcopy', or
244# `nm' on the .o file to produce textual output, and then analyze that
245# with regexps. The FILE.d file specifies what program to run, and
246# what to expect in its output.
247#
248# The FILE.d file begins with zero or more option lines, which specify
249# flags to pass to the assembler, the program to run to dump the
250# assembler's output, and the options it wants. The option lines have
251# the syntax:
139e4a70 252#
252b5132 253# # OPTION: VALUE
139e4a70 254#
252b5132
RH
255# OPTION is the name of some option, like "name" or "objdump", and
256# VALUE is OPTION's value. The valid options are described below.
257# Whitespace is ignored everywhere, except within VALUE. The option
258# list ends with the first line that doesn't match the above syntax
259# (hmm, not great for error detection).
260#
e8119602
CD
261# The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
262# two-element lists. The first element of each is an option name, and
263# the second additional arguments to be added on to the end of the
264# option list as given in FILE.d. (If omitted, no additional options
265# are added.)
266#
252b5132 267# The interesting options are:
139e4a70 268#
252b5132
RH
269# name: TEST-NAME
270# The name of this test, passed to DejaGNU's `pass' and `fail'
271# commands. If omitted, this defaults to FILE, the root of the
272# .s and .d files' names.
139e4a70 273#
252b5132
RH
274# as: FLAGS
275# When assembling FILE.s, pass FLAGS to the assembler.
139e4a70 276#
252b5132
RH
277# PROG: PROGRAM-NAME
278# The name of the program to run to analyze the .o file produced
279# by the assembler. This can be omitted; run_dump_test will guess
280# which program to run by seeing which of the flags options below
281# is present.
139e4a70 282#
252b5132
RH
283# objdump: FLAGS
284# nm: FLAGS
285# objcopy: FLAGS
286# Use the specified program to analyze the .o file, and pass it
139e4a70
AM
287# FLAGS, in addition to the .o file name. Note that they are run
288# with LC_ALL=C in the environment to give consistent sorting
289# of symbols.
252b5132
RH
290#
291# source: SOURCE
292# Assemble the file SOURCE.s. If omitted, this defaults to FILE.s.
293# This is useful if several .d files want to share a .s file.
294#
8c2784a5
TR
295# error: REGEX
296# An error with message matching REGEX must be emitted for the test
297# to pass. The PROG, objdump, nm and objcopy options have no
298# meaning and need not supplied if this is present.
299#
cfdf4aaa
HPN
300# warning: REGEX
301# Expect a gas warning matching REGEX. It is an error to issue
302# both "error" and "warning".
303#
252b5132
RH
304# Each option may occur at most once.
305#
306# After the option lines come regexp lines. `run_dump_test' calls
307# `regexp_diff' to compare the output of the dumping tool against the
308# regexps in FILE.d. `regexp_diff' is defined later in this file; see
309# further comments there.
310
e8119602 311proc run_dump_test { name {extra_options {}} } {
252b5132 312 global subdir srcdir
4b0d96c2
HPN
313 global OBJDUMP NM AS OBJCOPY READELF
314 global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS
252b5132 315 global host_triplet
139e4a70 316 global env
252b5132
RH
317
318 if [string match "*/*" $name] {
319 set file $name
320 set name [file tail $name]
321 } else {
322 set file "$srcdir/$subdir/$name"
323 }
324 set opt_array [slurp_options "${file}.d"]
325 if { $opt_array == -1 } {
61feeec2 326 perror "error reading options from $file.d"
252b5132
RH
327 unresolved $subdir/$name
328 return
329 }
330 set opts(as) {}
331 set opts(objdump) {}
332 set opts(nm) {}
333 set opts(objcopy) {}
4b0d96c2 334 set opts(readelf) {}
252b5132
RH
335 set opts(name) {}
336 set opts(PROG) {}
337 set opts(source) {}
ff970196 338 set opts(stderr) {}
8c2784a5 339 set opts(error) {}
cfdf4aaa 340 set opts(warning) {}
252b5132
RH
341
342 foreach i $opt_array {
343 set opt_name [lindex $i 0]
344 set opt_val [lindex $i 1]
345 if ![info exists opts($opt_name)] {
346 perror "unknown option $opt_name in file $file.d"
347 unresolved $subdir/$name
348 return
349 }
350 if [string length $opts($opt_name)] {
351 perror "option $opt_name multiply set in $file.d"
352 unresolved $subdir/$name
353 return
354 }
355 set opts($opt_name) $opt_val
356 }
357
e8119602
CD
358 foreach i $extra_options {
359 set opt_name [lindex $i 0]
360 set opt_val [lindex $i 1]
361 if ![info exists opts($opt_name)] {
362 perror "unknown option $opt_name given in extra_opts"
363 unresolved $subdir/$name
364 return
365 }
366 # add extra option to end of existing option, adding space
367 # if necessary.
368 if [string length $opts($opt_name)] {
369 append opts($opt_name) " "
370 }
371 append opts($opt_name) $opt_val
372 }
373
252b5132
RH
374 if {$opts(PROG) != ""} {
375 switch -- $opts(PROG) {
376 objdump
377 { set program objdump }
378 nm
379 { set program nm }
380 objcopy
381 { set program objcopy }
4b0d96c2
HPN
382 readelf
383 { set program readelf }
252b5132
RH
384 default
385 { perror "unrecognized program option $opts(PROG) in $file.d"
386 unresolved $subdir/$name
387 return }
388 }
8c2784a5
TR
389 } elseif { $opts(error) != "" } {
390 # It's meaningless to require an output-testing method when we
391 # expect an error. For simplicity, we fake an arbitrary method.
392 set program "nm"
252b5132
RH
393 } else {
394 # Guess which program to run, by seeing which option was specified.
395 set program ""
4b0d96c2 396 foreach p {objdump objcopy nm readelf} {
252b5132
RH
397 if {$opts($p) != ""} {
398 if {$program != ""} {
399 perror "ambiguous dump program in $file.d"
400 unresolved $subdir/$name
401 return
402 } else {
403 set program $p
404 }
405 }
406 }
407 if {$program == ""} {
408 perror "dump program unspecified in $file.d"
409 unresolved $subdir/$name
410 return
411 }
412 }
413
cfdf4aaa
HPN
414 set expmsg $opts(error)
415 if { $opts(warning) != "" } {
416 set expmsg $opts(warning)
417 }
418 if { (($opts(warning) != "") && ($opts(error) != "")) \
419 || (($opts(warning) != "") && ($opts(stderr) != "")) } {
420 perror "$testname: bad mix of stderr, error and warning test-directives"
421 return
422 }
423
252b5132
RH
424 set progopts1 $opts($program)
425 eval set progopts \$[string toupper $program]FLAGS
426 eval set binary \$[string toupper $program]
427 if { $opts(name) == "" } {
428 set testname "$subdir/$name"
429 } else {
430 set testname $opts(name)
431 }
432
433 if { $opts(source) == "" } {
434 set sourcefile ${file}.s
435 } else {
436 set sourcefile $srcdir/$subdir/$opts(source)
437 }
438
cfdf4aaa
HPN
439 set cmd "$srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile"
440 send_log "$cmd\n"
441 set cmdret [catch "exec $cmd" comp_output]
252b5132
RH
442 set comp_output [prune_warnings $comp_output]
443
cfdf4aaa
HPN
444 if { $cmdret != 0 || $comp_output != "" || $opts(stderr) != "" } then {
445 # If the executed program writes to stderr and stderr is not
446 # redirected, exec *always* returns failure, regardless of the
447 # program exit code. Thankfully, we can retrieve the true
448 # return status from a special variable. Redirection would
449 # cause a tcl-specific message to be appended, and we'd rather
450 # not deal with that if we can help it.
451 global errorCode
452 if { $cmdret != 0 && [lindex $errorCode 0] == "NONE" } {
453 set cmdret 0
454 }
455
456 set exitstat "succeeded"
457 if { $cmdret != 0 } { set exitstat "failed" }
458
ff970196
CD
459 if { $opts(stderr) == "" } then {
460 send_log "$comp_output\n"
461 verbose "$comp_output" 3
8c2784a5 462
cfdf4aaa
HPN
463 if { $expmsg != "" \
464 && [regexp $expmsg $comp_output] \
465 && (($cmdret == 0) == ($opts(warning) != "")) } {
466 verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
467
468 # Only "pass" and return here if we expected (and got)
469 # an error.
470 if { $opts(error) != "" } {
8c2784a5
TR
471 pass $testname
472 return
473 }
cfdf4aaa
HPN
474 } {
475 fail $testname
476 return
8c2784a5 477 }
ff970196
CD
478 } else {
479 catch {write_file dump.stderr "$comp_output"} write_output
480 if ![string match "" $write_output] then {
481 send_log "error writing dump.stderr: $write_output\n"
482 verbose "error writing dump.stderr: $write_output" 3
483 send_log "$comp_output\n"
484 verbose "$comp_output" 3
485 fail $testname
486 return
487 }
488 set stderrfile $srcdir/$subdir/$opts(stderr)
489 send_log "wrote pruned stderr to dump.stderr\n"
490 verbose "wrote pruned stderr to dump.stderr" 3
491 if { [regexp_diff "dump.stderr" "$stderrfile"] } then {
8c2784a5 492 if { $opts(error) != "" } {
cfdf4aaa 493 verbose -log "$exitstat with: <$comp_output>, expected: <$opts(error)>"
8c2784a5
TR
494 if [regexp $opts(error) $comp_output] {
495 pass $testname
496 return
497 }
498 }
ff970196
CD
499 fail $testname
500 verbose "pruned stderr is [file_contents "dump.stderr"]" 2
501 return
502 }
503 }
252b5132
RH
504 }
505
506 if { [which $binary] == 0 } {
507 untested $testname
508 return
509 }
510
511 if { $progopts1 == "" } { set $progopts1 "-r" }
512 verbose "running $binary $progopts $progopts1" 3
513
514 # Objcopy, unlike the other two, won't send its output to stdout,
515 # so we have to run it specially.
139e4a70 516 set cmd "$binary $progopts $progopts1 dump.o > dump.out"
252b5132 517 if { $program == "objcopy" } {
139e4a70
AM
518 set cmd "$binary $progopts $progopts1 dump.o dump.out"
519 }
520
521 # Ensure consistent sorting of symbols
522 if {[info exists env(LC_ALL)]} {
523 set old_lc_all $env(LC_ALL)
524 }
525 set env(LC_ALL) "C"
526 send_log "$cmd\n"
527 catch "exec $cmd" comp_output
528 if {[info exists old_lc_all]} {
529 set env(LC_ALL) $old_lc_all
252b5132 530 } else {
139e4a70
AM
531 unset env(LC_ALL)
532 }
533 set comp_output [prune_warnings $comp_output]
534 if ![string match "" $comp_output] then {
535 send_log "$comp_output\n"
536 fail $testname
537 return
252b5132
RH
538 }
539
540 verbose_eval {[file_contents "dump.out"]} 3
541 if { [regexp_diff "dump.out" "${file}.d"] } then {
542 fail $testname
543 verbose "output is [file_contents "dump.out"]" 2
544 return
545 }
546
547 pass $testname
548}
549
550proc slurp_options { file } {
551 if [catch { set f [open $file r] } x] {
552 #perror "couldn't open `$file': $x"
553 perror "$x"
554 return -1
555 }
556 set opt_array {}
557 # whitespace expression
558 set ws {[ ]*}
559 set nws {[^ ]*}
560 # whitespace is ignored anywhere except within the options list;
561 # option names are alphabetic only
562 set pat "^#${ws}(\[a-zA-Z\]*)$ws:${ws}(.*)$ws\$"
563 while { [gets $f line] != -1 } {
564 set line [string trim $line]
565 # Whitespace here is space-tab.
566 if [regexp $pat $line xxx opt_name opt_val] {
567 # match!
568 lappend opt_array [list $opt_name $opt_val]
569 } else {
570 break
571 }
572 }
573 close $f
574 return $opt_array
575}
576
577proc objdump { opts } {
578 global OBJDUMP
579 global comp_output
580 global host_triplet
581
582 catch "exec $OBJDUMP $opts" comp_output
583 set comp_output [prune_warnings $comp_output]
584 verbose "objdump output=$comp_output\n" 3
585}
586
587proc objdump_start_no_subdir { prog opts } {
588 global OBJDUMP
589 global srcdir
590 global spawn_id
591
592 verbose "Starting $OBJDUMP $opts $prog" 2
593 catch {
594 spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog
595 } foo
596 if ![regexp {^[0-9]+} $foo] then {
597 perror "Can't run $prog: $foo"
598 }
599}
600
601proc objdump_finish { } {
602 global spawn_id
603
604 catch "close"
605 catch "wait"
606}
607
608# Default timeout is 10 seconds, loses on a slow machine. But some
609# configurations of dejagnu may override it.
610if {$timeout<120} then { set timeout 120 }
611
612expect_after -i {
613 timeout { perror "timeout" }
614 "virtual memory exhausted" { perror "virtual memory exhausted" }
615 buffer_full { perror "buffer full" }
616 eof { perror "eof" }
617}
618
619# regexp_diff, based on simple_diff taken from ld test suite
620# compares two files line-by-line
621# file1 contains strings, file2 contains regexps and #-comments
622# blank lines are ignored in either file
623# returns non-zero if differences exist
624#
625proc regexp_diff { file_1 file_2 } {
626
627 set eof -1
628 set end_1 0
629 set end_2 0
630 set differences 0
631 set diff_pass 0
632
633 if [file exists $file_1] then {
634 set file_a [open $file_1 r]
635 } else {
04248055 636 perror "$file_1 doesn't exist"
252b5132
RH
637 return 1
638 }
639
640 if [file exists $file_2] then {
641 set file_b [open $file_2 r]
642 } else {
04248055 643 perror "$file_2 doesn't exist"
252b5132
RH
644 close $file_a
645 return 1
646 }
647
648 verbose " Regexp-diff'ing: $file_1 $file_2" 2
649
650 while { 1 } {
651 set line_a ""
652 set line_b ""
653 while { [string length $line_a] == 0 } {
654 if { [gets $file_a line_a] == $eof } {
655 set end_1 1
656 break
657 }
658 }
659 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
660 if [ string match "#pass" $line_b ] {
661 set end_2 1
662 set diff_pass 1
663 break
a6ea59ce
GK
664 } elseif [ string match "#..." $line_b ] {
665 if { [gets $file_b line_b] == $eof } {
666 set end_2 1
667 break
668 }
669 verbose "looking for \"^$line_b$\"" 3
670 while { ![regexp "^$line_b$" "$line_a"] } {
671 verbose "skipping \"$line_a\"" 3
672 if { [gets $file_a line_a] == $eof } {
673 set end_1 1
674 break
675 }
676 }
677 break
252b5132
RH
678 }
679 if { [gets $file_b line_b] == $eof } {
680 set end_2 1
681 break
682 }
683 }
684
139e4a70
AM
685 if { $diff_pass } {
686 break
687 } elseif { $end_1 && $end_2 } {
252b5132
RH
688 break
689 } elseif { $end_1 } {
690 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
691 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
692 set differences 1
693 break
694 } elseif { $end_2 } {
695 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
696 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
697 set differences 1
698 break
699 } else {
700 verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
701 if ![regexp "^$line_b$" "$line_a"] {
702 send_log "regexp_diff match failure\n"
703 send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
3ad62fc4 704 verbose "regexp_diff match failure\n" 3
252b5132 705 set differences 1
252b5132
RH
706 }
707 }
708 }
709
710 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
711 send_log "$file_1 and $file_2 are different lengths\n"
712 verbose "$file_1 and $file_2 are different lengths" 3
713 set differences 1
714 }
715
716 close $file_a
717 close $file_b
718
719 return $differences
720}
721
722proc file_contents { filename } {
723 set file [open $filename r]
724 set contents [read $file]
725 close $file
726 return $contents
727}
728
ff970196
CD
729proc write_file { filename contents } {
730 set file [open $filename w]
731 puts $file "$contents"
732 close $file
733}
734
252b5132
RH
735proc verbose_eval { expr { level 1 } } {
736 global verbose
737 if $verbose>$level then { eval verbose "$expr" $level }
738}
739
740# This definition is taken from an unreleased version of DejaGnu. Once
741# that version gets released, and has been out in the world for a few
742# months at least, it may be safe to delete this copy.
743if ![string length [info proc prune_warnings]] {
744 #
745 # prune_warnings -- delete various system verbosities from TEXT.
746 #
747 # An example is:
748 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
749 #
750 # Sites with particular verbose os's may wish to override this in site.exp.
751 #
752 proc prune_warnings { text } {
753 # This is from sun4's. Do it for all machines for now.
754 # The "\\1" is to try to preserve a "\n" but only if necessary.
755 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
756
757 # It might be tempting to get carried away and delete blank lines, etc.
758 # Just delete *exactly* what we're ask to, and that's it.
759 return $text
760 }
761}
This page took 0.28062 seconds and 4 git commands to generate.