1 # Copyright
(C
) 1993, 1994, 1997, 1998, 1999, 2000 Free Software
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.
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.
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
16 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
18 # Please email
any bugs
, comments
, and
/or additions to this file to
:
21 # This file was written by Ken Raeburn
(raeburn@cygnus.com
).
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"
32 clone_output "[which $AS] $number\n"
36 proc gas_run { prog as_opts redir } {
44 verbose "Executing $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir"
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"
48 return [list $comp_output ""];
51 proc all_ones { args } {
52 foreach x $args { if [expr $x!=1] { return 0 } }
56 proc gas_start { prog as_opts } {
63 verbose "Starting $AS $ASFLAGS $as_opts $prog" 2
65 spawn -noecho -nottycopy $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog
67 if ![regexp {^[0-9]+} $foo] then {
68 perror "Can't run $subdir
/$prog
: $foo
"
79 proc want_no_output
{ testname
} {
82 if ![string match
"" $comp_output] then {
83 send_log
"$comp_output\n"
84 verbose
"$comp_output" 3
86 if [string match
"" $comp_output] then {
95 proc gas_test_old
{ file as_opts testname
} {
96 gas_run $file $as_opts
""
97 return [want_no_output $testname
]
100 proc gas_test
{ file as_opts var_opts testname
} {
104 foreach word $var_opts
{
105 set ignore_stdout
($i
) [string match
"*>" $word]
106 set opt
($i
) [string trim $word
{>}]
110 for {set i
0} {[expr $i
<$
max]} {incr i
} {
111 set maybe_ignore_stdout
""
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"
122 set extra_opts
[string trim $extra_opts
]
123 gas_run $file
"$as_opts $extra_opts" $maybe_ignore_stdout
125 # Should I be able to use a conditional expression here?
126 if [string match
"" $extra_opts] then {
127 want_no_output $testname
129 want_no_output
"$testname ($extra_opts)"
132 if [info exists errorInfo
] then {
137 proc gas_test_ignore_stdout
{ file as_opts testname
} {
140 gas_run $file $as_opts
">/dev/null"
141 want_no_output $testname
144 proc gas_test_error
{ file as_opts testname
} {
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
152 if [string match
"" $comp_output] then {
161 proc gas_init
{ args } {
163 global target_cpu_family
169 case
"$target_cpu" in {
170 "m68???" { set target_cpu_family m68k }
171 "i[34]86" { set target_cpu_family i386 }
172 default
{ set target_cpu_family $target_cpu
}
175 set target_family
"$target_cpu_family-$target_vendor-$target_os"
178 if ![istarget
"*-*-*"] {
179 perror
"Target name [istarget] is not a triple."
181 # Need to
return an empty string.
188 # Assemble a .s file
, then run some utility
on it and check the output.
190 # There should be an assembly language file named FILE.s in the test
191 # suite directory
, and a pattern file called FILE.d. `run_dump_test
'
192 # will assemble FILE.s, run some tool like `objdump', `objcopy
', or
193 # `nm' on the .o file to produce textual output
, and
then analyze that
194 # with regexps. The FILE.d file specifies what
program to run
, and
195 # what to expect in its output.
197 # The FILE.d file begins with zero or more option lines
, which specify
198 # flags to pass to the assembler
, the
program to run to dump the
199 # assembler
's output, and the options it wants. The option lines have
204 # OPTION is the name of some option, like "name" or "objdump", and
205 # VALUE is OPTION's value. The valid options are described below.
206 # Whitespace is ignored everywhere
, except within VALUE. The option
207 # list ends with the first line that doesn
't match the above syntax
208 # (hmm, not great for error detection).
210 # The interesting options are:
213 # The name of this test, passed to DejaGNU's `pass
' and `fail'
214 # commands.
If omitted
, this defaults to FILE
, the root of the
215 # .s and .d files
' names.
218 # When assembling FILE.s, pass FLAGS to the assembler.
221 # The name of the program to run to analyze the .o file produced
222 # by the assembler. This can be omitted; run_dump_test will guess
223 # which program to run by seeing which of the flags options below
229 # Use the specified program to analyze the .o file, and pass it
230 # FLAGS, in addition to the .o file name.
233 # Assemble the file SOURCE.s. If omitted, this defaults to FILE.s.
234 # This is useful if several .d files want to share a .s file.
236 # Each option may occur at most once.
238 # After the option lines come regexp lines. `run_dump_test' calls
239 # `regexp_diff
' to compare the output of the dumping tool against the
240 # regexps in FILE.d. `regexp_diff' is defined later in this file
; see
241 # further comments there.
243 proc run_dump_test
{ name } {
245 global OBJDUMP NM AS OBJCOPY
246 global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS
249 if [string match
"*/*" $name] {
251 set name [file tail $
name]
253 set file
"$srcdir/$subdir/$name"
255 set opt_array
[slurp_options
"${file}.d"]
256 if { $opt_array
== -1 } {
257 perror
"error reading options from $file.d"
258 unresolved $subdir
/$
name
269 foreach i $opt_array
{
270 set opt_name
[lindex $i
0]
271 set opt_val
[lindex $i
1]
272 if ![info exists opts
($opt_name
)] {
273 perror
"unknown option $opt_name in file $file.d"
274 unresolved $subdir
/$
name
277 if [string length $opts
($opt_name
)] {
278 perror
"option $opt_name multiply set in $file.d"
279 unresolved $subdir
/$
name
282 set opts
($opt_name
) $opt_val
285 if {$opts
(PROG
) != ""} {
286 switch -- $opts
(PROG
) {
288 { set program objdump
}
292 { set program objcopy
}
294 { perror
"unrecognized program option $opts(PROG) in $file.d"
295 unresolved $subdir
/$
name
299 # Guess which
program to run
, by seeing which option was specified.
301 foreach p
{objdump objcopy nm
} {
302 if {$opts
($p
) != ""} {
303 if {$
program != ""} {
304 perror
"ambiguous dump program in $file.d"
305 unresolved $subdir
/$
name
312 if {$
program == ""} {
313 perror
"dump program unspecified in $file.d"
314 unresolved $subdir
/$
name
319 set progopts1 $opts
($
program)
320 eval
set progopts \$
[string toupper $
program]FLAGS
321 eval
set binary \$
[string toupper $
program]
322 if { $opts
(name) == "" } {
323 set testname
"$subdir/$name"
325 set testname $opts
(name)
328 if { $opts
(source
) == "" } {
329 set sourcefile $
{file
}.s
331 set sourcefile $srcdir
/$subdir
/$opts
(source
)
334 send_log
"$AS $ASFLAGS $opts(as) -o dump.o $sourcefile\n"
335 catch
"exec $srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile" comp_output
336 set comp_output
[prune_warnings $comp_output
]
338 if ![string match
"" $comp_output] then {
339 send_log
"$comp_output\n"
340 verbose
"$comp_output" 3
345 if { [which $binary
] == 0 } {
350 if { $progopts1
== "" } { set $progopts1 "-r" }
351 verbose
"running $binary $progopts $progopts1" 3
353 # Objcopy
, unlike the other two
, won
't send its output to stdout,
354 # so we have to run it specially.
355 if { $program == "objcopy" } {
356 send_log "$binary $progopts $progopts1 dump.o dump.out\n"
357 catch "exec $binary $progopts $progopts1 dump.o dump.out" comp_output
358 set comp_output [prune_warnings $comp_output]
359 if ![string match "" $comp_output] then {
360 send_log "$comp_output\n"
365 send_log "$binary $progopts $progopts1 dump.o > dump.out\n"
366 catch "exec $binary $progopts $progopts1 dump.o > dump.out" comp_output
367 set comp_output [prune_warnings $comp_output]
368 if ![string match "" $comp_output] then {
369 send_log "$comp_output\n"
375 verbose_eval {[file_contents "dump.out"]} 3
376 if { [regexp_diff "dump.out" "${file}.d"] } then {
378 verbose "output is [file_contents "dump.out"]" 2
385 proc slurp_options { file } {
386 if [catch { set f [open $file r] } x] {
387 #perror "couldn't open `$file
': $x"
392 # whitespace expression
395 # whitespace is ignored anywhere except within the options list;
396 # option names are alphabetic only
397 set pat "^#${ws}(\[a-zA-Z\]*)$ws:${ws}(.*)$ws\$"
398 while { [gets $f line] != -1 } {
399 set line [string trim $line]
400 # Whitespace here is space-tab.
401 if [regexp $pat $line xxx opt_name opt_val] {
403 lappend opt_array [list $opt_name $opt_val]
412 proc objdump { opts } {
417 catch "exec $OBJDUMP $opts" comp_output
418 set comp_output [prune_warnings $comp_output]
419 verbose "objdump output=$comp_output\n" 3
422 proc objdump_start_no_subdir { prog opts } {
427 verbose "Starting $OBJDUMP $opts $prog" 2
429 spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog
431 if ![regexp {^[0-9]+} $foo] then {
432 perror "Can't run $prog
: $foo
"
436 proc objdump_finish
{ } {
443 # Default timeout is
10 seconds, loses
on a slow machine. But some
444 # configurations of dejagnu may override it.
445 if {$timeout
<120} then { set timeout
120 }
448 timeout
{ perror
"timeout" }
449 "virtual memory exhausted" { perror "virtual memory exhausted" }
450 buffer_full
{ perror
"buffer full" }
454 # regexp_diff
, based
on simple_diff taken from
ld test suite
455 # compares two files line
-by
-line
456 # file1 contains strings
, file2 contains regexps and #
-comments
457 #
blank lines are ignored in either file
458 # returns non
-zero
if differences exist
460 proc regexp_diff
{ file_1 file_2
} {
468 if [file
exists $file_1
] then {
469 set file_a
[open $file_1 r
]
471 warning
"$file_1 doesn't exist"
475 if [file
exists $file_2
] then {
476 set file_b
[open $file_2 r
]
478 fail
"$file_2 doesn't exist"
483 verbose
" Regexp-diff'ing: $file_1 $file_2" 2
488 while { [string length $line_a
] == 0 } {
489 if { [gets $file_a line_a
] == $eof
} {
494 while { [string length $line_b
] == 0 ||
[string match
"#*" $line_b] } {
495 if [ string match
"#pass" $line_b ] {
499 } elseif
[ string match
"#..." $line_b ] {
500 if { [gets $file_b line_b
] == $eof
} {
504 verbose
"looking for \"^$line_b$\"" 3
505 while { ![regexp
"^$line_b$" "$line_a"] } {
506 verbose
"skipping \"$line_a\"" 3
507 if { [gets $file_a line_a
] == $eof
} {
514 if { [gets $file_b line_b
] == $eof
} {
522 } elseif
{ $end_1
&& $end_2
} {
524 } elseif
{ $end_1
} {
525 send_log
"extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
526 verbose
"extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
529 } elseif
{ $end_2
} {
530 send_log
"extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
531 verbose
"extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
535 verbose
"regexp \"^$line_b$\"\nline \"$line_a\"" 3
536 if ![regexp
"^$line_b$" "$line_a"] {
537 send_log
"regexp_diff match failure\n"
538 send_log
"regexp \"^$line_b$\"\nline \"$line_a\"\n"
544 if { $differences
== 0 && !$diff_pass
&& [eof $file_a
] != [eof $file_b
] } {
545 send_log
"$file_1 and $file_2 are different lengths\n"
546 verbose
"$file_1 and $file_2 are different lengths" 3
556 proc file_contents
{ filename
} {
557 set file
[open $filename r
]
558 set contents
[read $file
]
563 proc verbose_eval
{ expr
{ level
1 } } {
565 if $verbose
>$level
then { eval verbose
"$expr" $level }
568 # This definition is taken from an unreleased version of DejaGnu. Once
569 # that version gets released
, and has been out in the world
for a few
570 # months at least
, it may be safe to
delete this copy.
571 if ![string length
[info proc prune_warnings
]] {
573 # prune_warnings
-- delete various
system verbosities from
TEXT.
576 #
ld.so
: warning
: /usr
/lib
/libc.so
.1.8.1 has older revision than expected
9
578 # Sites with particular verbose os
's may wish to override this in site.exp.
580 proc prune_warnings { text } {
581 # This is from sun4's.
Do it
for all machines
for now.
582 # The
"\\1" is to try to preserve a "\n" but only if necessary.
583 regsub
-all
"(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
585 # It might be tempting to
get carried away and
delete blank lines
, etc.
586 # Just
delete *exactly
* what we
're ask to, and that's it.