1 # Copyright
(C
) 1993, 1994, 1997 Free Software Foundation
, Inc.
3 # This
program is free software
; you can redistribute it and
/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation
; either version
2 of the License
, or
6 #
(at your option
) any later version.
8 # This
program is distributed in the hope that it will be useful
,
9 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License
for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program; if not
, write to the Free Software
15 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
17 # Please email
any bugs
, comments
, and
/or additions to this file to
:
20 # This file was written by Ken Raeburn
(raeburn@cygnus.com
).
24 catch
"exec $AS -version < /dev/null" tmp
25 # Should find a way to discard constant parts
, keep whatever
's
26 # left, so the version string could be almost anything at all...
27 regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number
28 if ![info exists number] then {
29 return "[which $AS] (no version number)\n"
31 clone_output "[which $AS] $number\n"
35 proc gas_run { prog as_opts redir } {
43 verbose "Executing $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir"
44 catch "exec $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" comp_output
45 set comp_output [prune_warnings $comp_output]
46 verbose "output was $comp_output"
47 return [list $comp_output ""];
50 proc all_ones { args } {
51 foreach x $args { if [expr $x!=1] { return 0 } }
55 proc gas_start { prog as_opts } {
62 verbose "Starting $AS $ASFLAGS $as_opts $prog" 2
64 spawn -noecho -nottycopy $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog
66 if ![regexp {^[0-9]+} $foo] then {
67 perror "Can't run $subdir
/$prog
: $foo
"
78 proc want_no_output
{ testname
} {
81 if ![string match
"" $comp_output] then {
82 send_log
"$comp_output\n"
83 verbose
"$comp_output" 3
85 if [string match
"" $comp_output] then {
94 proc gas_test_old
{ file as_opts testname
} {
95 gas_run $file $as_opts
""
96 return [want_no_output $testname
]
99 proc gas_test
{ file as_opts var_opts testname
} {
103 foreach word $var_opts
{
104 set ignore_stdout
($i
) [string match
"*>" $word]
105 set opt
($i
) [string trim $word
{>}]
109 for {set i
0} {[expr $i
<$
max]} {incr i
} {
110 set maybe_ignore_stdout
""
112 for {set bit
0} {(1<<$bit
)<$
max} {incr bit
} {
113 set num
[expr
1<<$bit
]
114 if [expr $i
&$num
] then {
115 set extra_opts
"$extra_opts $opt($bit)"
116 if $ignore_stdout
($bit
) then {
117 set maybe_ignore_stdout
">/dev/null"
121 set extra_opts
[string trim $extra_opts
]
122 gas_run $file
"$as_opts $extra_opts" $maybe_ignore_stdout
124 # Should I be able to use a conditional expression here?
125 if [string match
"" $extra_opts] then {
126 want_no_output $testname
128 want_no_output
"$testname ($extra_opts)"
131 if [info exists errorInfo
] then {
136 proc gas_test_ignore_stdout
{ file as_opts testname
} {
139 gas_run $file $as_opts
">/dev/null"
140 want_no_output $testname
143 proc gas_test_error
{ file as_opts testname
} {
146 gas_run $file $as_opts
">/dev/null"
147 if ![string match
"" $comp_output] then {
148 send_log
"$comp_output\n"
149 verbose
"$comp_output" 3
151 if [string match
"" $comp_output] then {
160 proc gas_init
{ args } {
162 global target_cpu_family
168 case
"$target_cpu" in {
169 "m68???" { set target_cpu_family m68k }
170 "i[34]86" { set target_cpu_family i386 }
171 default
{ set target_cpu_family $target_cpu
}
174 set target_family
"$target_cpu_family-$target_vendor-$target_os"
177 if ![istarget
"*-*-*"] {
178 perror
"Target name [istarget] is not a triple."
180 # Need to
return an empty string.
187 # Assemble a .s file
, then run some utility
on it and check the output.
189 # There should be an assembly language file named FILE.s in the test
190 # suite directory
, and a pattern file called FILE.d. `run_dump_test
'
191 # will assemble FILE.s, run some tool like `objdump', `objcopy
', or
192 # `nm' on the .o file to produce textual output
, and
then analyze that
193 # with regexps. The FILE.d file specifies what
program to run
, and
194 # what to expect in its output.
196 # The FILE.d file begins with zero or more option lines
, which specify
197 # flags to pass to the assembler
, the
program to run to dump the
198 # assembler
's output, and the options it wants. The option lines have
203 # OPTION is the name of some option, like "name" or "objdump", and
204 # VALUE is OPTION's value. The valid options are described below.
205 # Whitespace is ignored everywhere
, except within VALUE. The option
206 # list ends with the first line that doesn
't match the above syntax
207 # (hmm, not great for error detection).
209 # The interesting options are:
212 # The name of this test, passed to DejaGNU's `pass
' and `fail'
213 # commands.
If omitted
, this defaults to FILE
, the root of the
214 # .s and .d files
' names.
217 # When assembling FILE.s, pass FLAGS to the assembler.
220 # The name of the program to run to analyze the .o file produced
221 # by the assembler. This can be omitted; run_dump_test will guess
222 # which program to run by seeing which of the flags options below
228 # Use the specified program to analyze the .o file, and pass it
229 # FLAGS, in addition to the .o file name.
232 # Assemble the file SOURCE.s. If omitted, this defaults to FILE.s.
233 # This is useful if several .d files want to share a .s file.
235 # Each option may occur at most once.
237 # After the option lines come regexp lines. `run_dump_test' calls
238 # `regexp_diff
' to compare the output of the dumping tool against the
239 # regexps in FILE.d. `regexp_diff' is defined later in this file
; see
240 # further comments there.
242 proc run_dump_test
{ name } {
244 global OBJDUMP NM AS OBJCOPY
245 global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS
248 if [string match
"*/*" $name] {
250 set name [file tail $
name]
252 set file
"$srcdir/$subdir/$name"
254 set opt_array
[slurp_options
"${file}.d"]
255 if { $opt_array
== -1 } {
256 perror
"error reading options from $file.d"
257 unresolved $subdir
/$
name
268 foreach i $opt_array
{
269 set opt_name
[lindex $i
0]
270 set opt_val
[lindex $i
1]
271 if ![info exists opts
($opt_name
)] {
272 perror
"unknown option $opt_name in file $file.d"
273 unresolved $subdir
/$
name
276 if [string length $opts
($opt_name
)] {
277 perror
"option $opt_name multiply set in $file.d"
278 unresolved $subdir
/$
name
281 set opts
($opt_name
) $opt_val
284 if {$opts
(PROG
) != ""} {
285 switch -- $opts
(PROG
) {
287 { set program objdump
}
291 { set program objcopy
}
293 { perror
"unrecognized program option $opts(PROG) in $file.d"
294 unresolved $subdir
/$
name
298 # Guess which
program to run
, by seeing which option was specified.
300 foreach p
{objdump objcopy nm
} {
301 if {$opts
($p
) != ""} {
302 if {$
program != ""} {
303 perror
"ambiguous dump program in $file.d"
304 unresolved $subdir
/$
name
311 if {$
program == ""} {
312 perror
"dump program unspecified in $file.d"
313 unresolved $subdir
/$
name
318 set progopts1 $opts
($
program)
319 eval
set progopts \$
[string toupper $
program]FLAGS
320 eval
set binary \$
[string toupper $
program]
321 if { $opts
(name) == "" } {
322 set testname
"$subdir/$name"
324 set testname $opts
(name)
327 if { $opts
(source
) == "" } {
328 set sourcefile $
{file
}.s
330 set sourcefile $srcdir
/$subdir
/$opts
(source
)
333 send_log
"$AS $ASFLAGS $opts(as) -o dump.o $sourcefile\n"
334 catch
"exec $srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile" comp_output
335 set comp_output
[prune_warnings $comp_output
]
337 if ![string match
"" $comp_output] then {
338 send_log
"$comp_output\n"
339 verbose
"$comp_output" 3
344 if { [which $binary
] == 0 } {
349 if { $progopts1
== "" } { set $progopts1 "-r" }
350 verbose
"running $binary $progopts $progopts1" 3
352 # Objcopy
, unlike the other two
, won
't send its output to stdout,
353 # so we have to run it specially.
354 if { $program == "objcopy" } {
355 send_log "$binary $progopts $progopts1 dump.o dump.out\n"
356 catch "exec $binary $progopts $progopts1 dump.o dump.out" comp_output
357 set comp_output [prune_warnings $comp_output]
358 if ![string match "" $comp_output] then {
359 send_log "$comp_output\n"
364 send_log "$binary $progopts $progopts1 dump.o > dump.out\n"
365 catch "exec $binary $progopts $progopts1 dump.o > dump.out" comp_output
366 set comp_output [prune_warnings $comp_output]
367 if ![string match "" $comp_output] then {
368 send_log "$comp_output\n"
374 verbose_eval {[file_contents "dump.out"]} 3
375 if { [regexp_diff "dump.out" "${file}.d"] } then {
377 verbose "output is [file_contents "dump.out"]" 2
384 proc slurp_options { file } {
385 if [catch { set f [open $file r] } x] {
386 #perror "couldn't open `$file
': $x"
391 # whitespace expression
394 # whitespace is ignored anywhere except within the options list;
395 # option names are alphabetic only
396 set pat "^#${ws}(\[a-zA-Z\]*)$ws:${ws}(.*)$ws\$"
397 while { [gets $f line] != -1 } {
398 set line [string trim $line]
399 # Whitespace here is space-tab.
400 if [regexp $pat $line xxx opt_name opt_val] {
402 lappend opt_array [list $opt_name $opt_val]
411 proc objdump { opts } {
416 catch "exec $OBJDUMP $opts" comp_output
417 set comp_output [prune_warnings $comp_output]
418 verbose "objdump output=$comp_output\n" 3
421 proc objdump_start_no_subdir { prog opts } {
426 verbose "Starting $OBJDUMP $opts $prog" 2
428 spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog
430 if ![regexp {^[0-9]+} $foo] then {
431 perror "Can't run $prog
: $foo
"
435 proc objdump_finish
{ } {
442 # Default timeout is
10 seconds, loses
on a slow machine. But some
443 # configurations of dejagnu may override it.
444 if {$timeout
<120} then { set timeout
120 }
447 timeout
{ perror
"timeout" }
448 "virtual memory exhausted" { perror "virtual memory exhausted" }
449 buffer_full
{ perror
"buffer full" }
453 # regexp_diff
, based
on simple_diff taken from
ld test suite
454 # compares two files line
-by
-line
455 # file1 contains strings
, file2 contains regexps and #
-comments
456 #
blank lines are ignored in either file
457 # returns non
-zero
if differences exist
459 proc regexp_diff
{ file_1 file_2
} {
467 if [file
exists $file_1
] then {
468 set file_a
[open $file_1 r
]
470 warning
"$file_1 doesn't exist"
474 if [file
exists $file_2
] then {
475 set file_b
[open $file_2 r
]
477 fail
"$file_2 doesn't exist"
482 verbose
" Regexp-diff'ing: $file_1 $file_2" 2
487 while { [string length $line_a
] == 0 } {
488 if { [gets $file_a line_a
] == $eof
} {
493 while { [string length $line_b
] == 0 ||
[string match
"#*" $line_b] } {
494 if [ string match
"#pass" $line_b ] {
498 } elseif
[ string match
"#..." $line_b ] {
499 if { [gets $file_b line_b
] == $eof
} {
503 verbose
"looking for \"^$line_b$\"" 3
504 while { ![regexp
"^$line_b$" "$line_a"] } {
505 verbose
"skipping \"$line_a\"" 3
506 if { [gets $file_a line_a
] == $eof
} {
513 if { [gets $file_b line_b
] == $eof
} {
521 } elseif
{ $end_1
&& $end_2
} {
523 } elseif
{ $end_1
} {
524 send_log
"extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
525 verbose
"extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
528 } elseif
{ $end_2
} {
529 send_log
"extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
530 verbose
"extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
534 verbose
"regexp \"^$line_b$\"\nline \"$line_a\"" 3
535 if ![regexp
"^$line_b$" "$line_a"] {
536 send_log
"regexp_diff match failure\n"
537 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.