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 unresolved $subdir
/$
name
267 foreach i $opt_array
{
268 set opt_name
[lindex $i
0]
269 set opt_val
[lindex $i
1]
270 if ![info exists opts
($opt_name
)] {
271 perror
"unknown option $opt_name in file $file.d"
272 unresolved $subdir
/$
name
275 if [string length $opts
($opt_name
)] {
276 perror
"option $opt_name multiply set in $file.d"
277 unresolved $subdir
/$
name
280 set opts
($opt_name
) $opt_val
283 if {$opts
(PROG
) != ""} {
284 switch -- $opts
(PROG
) {
286 { set program objdump
}
290 { set program objcopy
}
292 { perror
"unrecognized program option $opts(PROG) in $file.d"
293 unresolved $subdir
/$
name
297 # Guess which
program to run
, by seeing which option was specified.
299 foreach p
{objdump objcopy nm
} {
300 if {$opts
($p
) != ""} {
301 if {$
program != ""} {
302 perror
"ambiguous dump program in $file.d"
303 unresolved $subdir
/$
name
310 if {$
program == ""} {
311 perror
"dump program unspecified in $file.d"
312 unresolved $subdir
/$
name
317 set progopts1 $opts
($
program)
318 eval
set progopts \$
[string toupper $
program]FLAGS
319 eval
set binary \$
[string toupper $
program]
320 if { $opts
(name) == "" } {
321 set testname
"$subdir/$name"
323 set testname $opts
(name)
326 if { $opts
(source
) == "" } {
327 set sourcefile $
{file
}.s
329 set sourcefile $srcdir
/$subdir
/$opts
(source
)
332 send_log
"$AS $ASFLAGS $opts(as) -o dump.o $sourcefile\n"
333 catch
"exec $srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile" comp_output
334 set comp_output
[prune_warnings $comp_output
]
336 if ![string match
"" $comp_output] then {
337 send_log
"$comp_output\n"
338 verbose
"$comp_output" 3
343 if { [which $binary
] == 0 } {
348 if { $progopts1
== "" } { set $progopts1 "-r" }
349 verbose
"running $binary $progopts $progopts1" 3
351 # Objcopy
, unlike the other two
, won
't send its output to stdout,
352 # so we have to run it specially.
353 if { $program == "objcopy" } {
354 send_log "$binary $progopts $progopts1 dump.o dump.out\n"
355 catch "exec $binary $progopts $progopts1 dump.o dump.out" comp_output
356 set comp_output [prune_warnings $comp_output]
357 if ![string match "" $comp_output] then {
358 send_log "$comp_output\n"
363 send_log "$binary $progopts $progopts1 dump.o > dump.out\n"
364 catch "exec $binary $progopts $progopts1 dump.o > dump.out" comp_output
365 set comp_output [prune_warnings $comp_output]
366 if ![string match "" $comp_output] then {
367 send_log "$comp_output\n"
373 verbose_eval {[file_contents "dump.out"]} 3
374 if { [regexp_diff "dump.out" "${file}.d"] } then {
376 verbose "output is [file_contents "dump.out"]" 2
383 proc slurp_options { file } {
384 if [catch { set f [open $file r] } x] {
385 #perror "couldn't open `$file
': $x"
390 # whitespace expression
393 # whitespace is ignored anywhere except within the options list;
394 # option names are alphabetic only
395 set pat "^#${ws}(\[a-zA-Z\]*)$ws:${ws}(.*)$ws\$"
396 while { [gets $f line] != -1 } {
397 set line [string trim $line]
398 # Whitespace here is space-tab.
399 if [regexp $pat $line xxx opt_name opt_val] {
401 lappend opt_array [list $opt_name $opt_val]
410 proc objdump { opts } {
415 catch "exec $OBJDUMP $opts" comp_output
416 set comp_output [prune_warnings $comp_output]
417 verbose "objdump output=$comp_output\n" 3
420 proc objdump_start_no_subdir { prog opts } {
425 verbose "Starting $OBJDUMP $opts $prog" 2
427 spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog
429 if ![regexp {^[0-9]+} $foo] then {
430 perror "Can't run $prog
: $foo
"
434 proc objdump_finish
{ } {
441 # Default timeout is
10 seconds, loses
on a slow machine. But some
442 # configurations of dejagnu may override it.
443 if {$timeout
<120} then { set timeout
120 }
446 timeout
{ perror
"timeout" }
447 "virtual memory exhausted" { perror "virtual memory exhausted" }
448 buffer_full
{ perror
"buffer full" }
452 # regexp_diff
, based
on simple_diff taken from
ld test suite
453 # compares two files line
-by
-line
454 # file1 contains strings
, file2 contains regexps and #
-comments
455 #
blank lines are ignored in either file
456 # returns non
-zero
if differences exist
458 proc regexp_diff
{ file_1 file_2
} {
466 if [file
exists $file_1
] then {
467 set file_a
[open $file_1 r
]
469 warning
"$file_1 doesn't exist"
473 if [file
exists $file_2
] then {
474 set file_b
[open $file_2 r
]
476 fail
"$file_2 doesn't exist"
481 verbose
" Regexp-diff'ing: $file_1 $file_2" 2
486 while { [string length $line_a
] == 0 } {
487 if { [gets $file_a line_a
] == $eof
} {
492 while { [string length $line_b
] == 0 ||
[string match
"#*" $line_b] } {
493 if [ string match
"#pass" $line_b ] {
498 if { [gets $file_b line_b
] == $eof
} {
506 } elseif
{ $end_1
&& $end_2
} {
508 } elseif
{ $end_1
} {
509 send_log
"extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
510 verbose
"extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
513 } elseif
{ $end_2
} {
514 send_log
"extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
515 verbose
"extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
519 verbose
"regexp \"^$line_b$\"\nline \"$line_a\"" 3
520 if ![regexp
"^$line_b$" "$line_a"] {
521 send_log
"regexp_diff match failure\n"
522 send_log
"regexp \"^$line_b$\"\nline \"$line_a\"\n"
529 if { $differences
== 0 && !$diff_pass
&& [eof $file_a
] != [eof $file_b
] } {
530 send_log
"$file_1 and $file_2 are different lengths\n"
531 verbose
"$file_1 and $file_2 are different lengths" 3
541 proc file_contents
{ filename
} {
542 set file
[open $filename r
]
543 set contents
[read $file
]
548 proc verbose_eval
{ expr
{ level
1 } } {
550 if $verbose
>$level
then { eval verbose
"$expr" $level }
553 # This definition is taken from an unreleased version of DejaGnu. Once
554 # that version gets released
, and has been out in the world
for a few
555 # months at least
, it may be safe to
delete this copy.
556 if ![string length
[info proc prune_warnings
]] {
558 # prune_warnings
-- delete various
system verbosities from
TEXT.
561 #
ld.so
: warning
: /usr
/lib
/libc.so
.1.8.1 has older revision than expected
9
563 # Sites with particular verbose os
's may wish to override this in site.exp.
565 proc prune_warnings { text } {
566 # This is from sun4's.
Do it
for all machines
for now.
567 # The
"\\1" is to try to preserve a "\n" but only if necessary.
568 regsub
-all
"(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
570 # It might be tempting to
get carried away and
delete blank lines
, etc.
571 # Just
delete *exactly
* what we
're ask to, and that's it.