]>
Commit | Line | Data |
---|---|---|
d193d762 | 1 | # Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
f70a4714 KR |
2 | |
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. | |
7 | # | |
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. | |
12 | # | |
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 | |
a0cc993c | 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
f70a4714 KR |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # DejaGnu@cygnus.com | |
19 | ||
20 | # This file was written by Ken Raeburn (raeburn@cygnus.com). | |
21 | ||
22 | proc gas_version {} { | |
23 | global AS | |
fd9b8885 | 24 | catch "exec $AS -version < /dev/null" tmp |
f70a4714 KR |
25 | # Should find a way to discard constant parts, keep whatever's |
26 | # left, so the version string could be almost anything at all... | |
787f6220 BM |
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" | |
30 | } | |
31 | clone_output "[which $AS] $number\n" | |
f70a4714 KR |
32 | unset version |
33 | } | |
34 | ||
fd9b8885 | 35 | proc gas_run { prog as_opts redir } { |
f70a4714 KR |
36 | global AS |
37 | global ASFLAGS | |
38 | global comp_output | |
fd9b8885 RS |
39 | global srcdir |
40 | global subdir | |
787f6220 | 41 | global host_triplet |
f70a4714 | 42 | |
787f6220 | 43 | verbose "Executing $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" |
fd9b8885 | 44 | catch "exec $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" comp_output |
787f6220 BM |
45 | set comp_output [prune_system_crud $host_triplet $comp_output] |
46 | verbose "output was $comp_output" | |
47 | return [list $comp_output ""]; | |
fd9b8885 RS |
48 | } |
49 | ||
50 | proc all_ones { args } { | |
51 | foreach x $args { if [expr $x!=1] { return 0 } } | |
52 | return 1 | |
53 | } | |
54 | ||
55 | proc gas_start { prog as_opts } { | |
56 | global AS | |
57 | global ASFLAGS | |
58 | global srcdir | |
59 | global subdir | |
60 | global spawn_id | |
61 | ||
62 | verbose "Starting $AS $ASFLAGS $as_opts $prog" 2 | |
63 | catch { | |
384b93b1 | 64 | spawn -noecho -nottycopy $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog |
fd9b8885 RS |
65 | } foo |
66 | if ![regexp {^[0-9]+} $foo] then { | |
d9ac0258 | 67 | perror "Can't run $subdir/$prog: $foo" |
f70a4714 | 68 | } |
fd9b8885 RS |
69 | } |
70 | ||
71 | proc gas_finish { } { | |
72 | global spawn_id | |
73 | ||
8cbd903e KR |
74 | catch "close" |
75 | catch "wait" | |
fd9b8885 RS |
76 | } |
77 | ||
78 | proc want_no_output { testname } { | |
79 | global comp_output | |
80 | ||
f70a4714 KR |
81 | if ![string match "" $comp_output] then { |
82 | send_log "$comp_output\n" | |
fd9b8885 RS |
83 | verbose "$comp_output" 3 |
84 | } | |
85 | if [string match "" $comp_output] then { | |
86 | pass "$testname" | |
87 | return 1 | |
88 | } else { | |
89 | fail "$testname" | |
90 | return 0 | |
91 | } | |
92 | } | |
93 | ||
94 | proc gas_test_old { file as_opts testname } { | |
95 | gas_run $file $as_opts "" | |
96 | return [want_no_output $testname] | |
97 | } | |
98 | ||
99 | proc gas_test { file as_opts var_opts testname } { | |
100 | global comp_output | |
101 | ||
102 | set i 0 | |
103 | foreach word $var_opts { | |
104 | set ignore_stdout($i) [string match "*>" $word] | |
105 | set opt($i) [string trim $word {>}] | |
106 | incr i | |
107 | } | |
108 | set max [expr 1<<$i] | |
109 | for {set i 0} {[expr $i<$max]} {incr i} { | |
110 | set maybe_ignore_stdout "" | |
111 | set extra_opts "" | |
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 { | |
09a1cedb | 117 | set maybe_ignore_stdout ">/dev/null" |
fd9b8885 RS |
118 | } |
119 | } | |
120 | } | |
121 | set extra_opts [string trim $extra_opts] | |
122 | gas_run $file "$as_opts $extra_opts" $maybe_ignore_stdout | |
123 | ||
124 | # Should I be able to use a conditional expression here? | |
125 | if [string match "" $extra_opts] then { | |
126 | want_no_output $testname | |
127 | } else { | |
128 | want_no_output "$testname ($extra_opts)" | |
f70a4714 KR |
129 | } |
130 | } | |
23c6150b RS |
131 | if [info exists errorInfo] then { |
132 | unset errorInfo | |
133 | } | |
f70a4714 KR |
134 | } |
135 | ||
fd9b8885 | 136 | proc gas_test_ignore_stdout { file as_opts testname } { |
f70a4714 KR |
137 | global comp_output |
138 | ||
09a1cedb | 139 | gas_run $file $as_opts ">/dev/null" |
fd9b8885 RS |
140 | want_no_output $testname |
141 | } | |
142 | ||
143 | proc gas_test_error { file as_opts testname } { | |
144 | global comp_output | |
145 | ||
09a1cedb | 146 | gas_run $file $as_opts ">/dev/null" |
f70a4714 KR |
147 | if ![string match "" $comp_output] then { |
148 | send_log "$comp_output\n" | |
fd9b8885 | 149 | verbose "$comp_output" 3 |
f70a4714 KR |
150 | } |
151 | if [string match "" $comp_output] then { | |
f70a4714 | 152 | fail "$testname" |
fd9b8885 RS |
153 | } else { |
154 | pass "$testname" | |
155 | } | |
156 | } | |
157 | ||
158 | proc gas_exit {} {} | |
159 | ||
160 | proc gas_init {} { | |
161 | global target_cpu | |
162 | global target_cpu_family | |
163 | global target_family | |
164 | global target_vendor | |
165 | global target_os | |
166 | global stdoptlist | |
167 | ||
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 } | |
f70a4714 | 172 | } |
fd9b8885 RS |
173 | |
174 | set target_family "$target_cpu_family-$target_vendor-$target_os" | |
175 | set stdoptlist "-a>" | |
176 | # Need to return an empty string. | |
177 | return | |
178 | } | |
179 | ||
8cbd903e KR |
180 | # This proc requires two input files -- the .s file containing the |
181 | # assembly source, and a .d file containing the expected output from | |
182 | # objdump or nm or whatever, and leading comments indicating any options | |
183 | # to be passed to the assembler or dump program. | |
91e3b582 | 184 | |
8cbd903e KR |
185 | proc run_dump_test { name } { |
186 | global subdir srcdir | |
a0cc993c ILT |
187 | global OBJDUMP NM AS OBJCOPY |
188 | global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS | |
787f6220 | 189 | global host_triplet |
8cbd903e | 190 | |
91e3b582 DE |
191 | if [string match "*/*" $name] { |
192 | set file $name | |
193 | set name [file tail $name] | |
194 | } else { | |
195 | set file "$srcdir/$subdir/$name" | |
196 | } | |
8cbd903e | 197 | set opt_array [slurp_options "${file}.d"] |
91e3b582 DE |
198 | if { $opt_array == -1 } { |
199 | unresolved $subdir/$name | |
200 | return | |
201 | } | |
8cbd903e KR |
202 | set opts(as) {} |
203 | set opts(objdump) {} | |
204 | set opts(nm) {} | |
a0cc993c | 205 | set opts(objcopy) {} |
8cbd903e KR |
206 | set opts(name) {} |
207 | set opts(PROG) {} | |
09a1cedb | 208 | set opts(source) {} |
8cbd903e KR |
209 | |
210 | foreach i $opt_array { | |
211 | set opt_name [lindex $i 0] | |
212 | set opt_val [lindex $i 1] | |
213 | if ![info exists opts($opt_name)] { | |
214 | perror "unknown option $opt_name in file $file.d" | |
91e3b582 | 215 | unresolved $subdir/$name |
8cbd903e KR |
216 | return |
217 | } | |
218 | if [string length $opts($opt_name)] { | |
219 | perror "option $opt_name multiply set in $file.d" | |
91e3b582 | 220 | unresolved $subdir/$name |
8cbd903e KR |
221 | return |
222 | } | |
223 | set opts($opt_name) $opt_val | |
224 | } | |
225 | ||
226 | if {$opts(PROG) != ""} { | |
227 | switch -- $opts(PROG) { | |
228 | objdump | |
229 | { set program objdump } | |
230 | nm | |
231 | { set program nm } | |
a0cc993c ILT |
232 | objcopy |
233 | { set program objcopy } | |
8cbd903e KR |
234 | default |
235 | { perror "unrecognized program option $opts(PROG) in $file.d" | |
91e3b582 | 236 | unresolved $subdir/$name |
8cbd903e KR |
237 | return } |
238 | } | |
239 | } elseif {$opts(objdump) == "" && $opts(nm) != ""} { | |
240 | set program nm | |
241 | } elseif {$opts(objdump) != "" && $opts(nm) == ""} { | |
242 | set program objdump | |
a0cc993c ILT |
243 | } elseif {$opts(objcopy) != ""} { |
244 | set program objcopy | |
8cbd903e KR |
245 | } else { |
246 | perror "dump program unspecified in $file.d" | |
91e3b582 | 247 | unresolved $subdir/$name |
8cbd903e KR |
248 | return |
249 | } | |
250 | set progopts1 $opts($program) | |
251 | eval set progopts \$[string toupper $program]FLAGS | |
a0cc993c | 252 | eval set binary \$[string toupper $program] |
91e3b582 DE |
253 | if { $opts(name) == "" } { |
254 | set testname "$subdir/$name" | |
255 | } else { | |
256 | set testname $opts(name) | |
257 | } | |
8cbd903e | 258 | |
09a1cedb KR |
259 | if { $opts(source) == "" } { |
260 | set sourcefile ${file}.s | |
261 | } else { | |
262 | set sourcefile $srcdir/$subdir/$opts(source) | |
263 | } | |
264 | ||
a0cc993c ILT |
265 | send_log "$AS $ASFLAGS $opts(as) -o dump.o $sourcefile\n" |
266 | catch "exec $srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile" comp_output | |
787f6220 | 267 | set comp_output [prune_system_crud $host_triplet $comp_output] |
8cbd903e KR |
268 | |
269 | if ![string match "" $comp_output] then { | |
270 | send_log "$comp_output\n" | |
271 | verbose "$comp_output" 3 | |
a0cc993c | 272 | fail $testname |
8cbd903e KR |
273 | return |
274 | } | |
275 | ||
a46c0ed8 ILT |
276 | if { [which $binary] == 0 } { |
277 | untested $testname | |
278 | return | |
279 | } | |
280 | ||
09a1cedb | 281 | if { $progopts1 == "" } { set $progopts1 "-r" } |
a0cc993c ILT |
282 | verbose "running $binary $progopts $progopts1" 3 |
283 | if { $program == "objcopy" } { | |
284 | send_log "$binary $progopts $progopts1 dump.o dump.out\n" | |
787f6220 BM |
285 | catch "exec $binary $progopts $progopts1 dump.o dump.out" comp_output |
286 | set comp_output [prune_system_crud $host_triplet $comp_output] | |
287 | if ![string match "" $comp_output] then { | |
a0cc993c ILT |
288 | send_log "$comp_output\n" |
289 | fail $testname | |
290 | return | |
291 | } | |
292 | } else { | |
293 | send_log "$binary $progopts $progopts1 dump.o > dump.out\n" | |
787f6220 BM |
294 | catch "exec $binary $progopts $progopts1 dump.o > dump.out" comp_output |
295 | set comp_output [prune_system_crud $host_triplet $comp_output] | |
296 | if ![string match "" $comp_output] then { | |
a0cc993c ILT |
297 | send_log "$comp_output\n" |
298 | fail $testname | |
299 | return | |
300 | } | |
8cbd903e KR |
301 | } |
302 | ||
91e3b582 | 303 | verbose_eval {[file_contents "dump.out"]} 3 |
8cbd903e | 304 | if { [regexp_diff "dump.out" "${file}.d"] } then { |
a0cc993c | 305 | fail $testname |
787f6220 | 306 | verbose "output is [file_contents "dump.out"]" 2 |
8cbd903e KR |
307 | return |
308 | } | |
309 | ||
310 | pass $testname | |
311 | } | |
312 | ||
313 | proc slurp_options { file } { | |
314 | if [catch { set f [open $file r] } x] { | |
91e3b582 DE |
315 | #perror "couldn't open `$file': $x" |
316 | perror "$x" | |
317 | return -1 | |
8cbd903e KR |
318 | } |
319 | set opt_array {} | |
320 | # whitespace expression | |
321 | set ws {[ ]*} | |
322 | set nws {[^ ]*} | |
323 | # whitespace is ignored anywhere except within the options list; | |
324 | # option names are alphabetic only | |
09a1cedb | 325 | set pat "^#${ws}(\[a-zA-Z\]*)$ws:${ws}(.*)$ws\$" |
8cbd903e KR |
326 | while { [gets $f line] != -1 } { |
327 | set line [string trim $line] | |
328 | # Whitespace here is space-tab. | |
329 | if [regexp $pat $line xxx opt_name opt_val] { | |
330 | # match! | |
331 | lappend opt_array [list $opt_name $opt_val] | |
332 | } else { | |
333 | break | |
334 | } | |
335 | } | |
336 | close $f | |
337 | return $opt_array | |
338 | } | |
339 | ||
d193d762 KR |
340 | proc objdump { opts } { |
341 | global OBJDUMP | |
342 | global comp_output | |
787f6220 | 343 | global host_triplet |
d193d762 KR |
344 | |
345 | catch "exec $OBJDUMP $opts" comp_output | |
787f6220 | 346 | set comp_output [prune_system_crud $host_triplet $comp_output] |
d193d762 KR |
347 | verbose "objdump output=$comp_output\n" 3 |
348 | } | |
349 | ||
350 | proc objdump_start_no_subdir { prog opts } { | |
fd9b8885 RS |
351 | global OBJDUMP |
352 | global srcdir | |
353 | global spawn_id | |
354 | ||
d193d762 | 355 | verbose "Starting $OBJDUMP $opts $prog" 2 |
fd9b8885 | 356 | catch { |
d193d762 | 357 | spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog |
fd9b8885 RS |
358 | } foo |
359 | if ![regexp {^[0-9]+} $foo] then { | |
d9ac0258 | 360 | perror "Can't run $prog: $foo" |
fd9b8885 RS |
361 | } |
362 | } | |
363 | ||
fd9b8885 RS |
364 | proc objdump_finish { } { |
365 | global spawn_id | |
366 | ||
8cbd903e KR |
367 | catch "close" |
368 | catch "wait" | |
fd9b8885 RS |
369 | } |
370 | ||
09a1cedb KR |
371 | # Default timeout is 10 seconds, loses on a slow machine. But some |
372 | # configurations of dejagnu may override it. | |
373 | if {$timeout<120} then { set timeout 120 } | |
374 | ||
3c6dc75b | 375 | expect_after -i { |
858665b7 BC |
376 | timeout { perror "timeout" } |
377 | "virtual memory exhausted" { perror "virtual memory exhausted" } | |
378 | buffer_full { perror "buffer full" } | |
379 | eof { perror "eof" } | |
f70a4714 | 380 | } |
d193d762 KR |
381 | |
382 | # regexp_diff, based on simple_diff taken from ld test suite | |
383 | # compares two files line-by-line | |
384 | # file1 contains strings, file2 contains regexps and #-comments | |
385 | # blank lines are ignored in either file | |
386 | # returns non-zero if differences exist | |
387 | # | |
388 | proc regexp_diff { file_1 file_2 } { | |
389 | ||
390 | set eof -1 | |
391 | set end 0 | |
392 | set differences 0 | |
a0cc993c | 393 | set diff_pass 0 |
8cbd903e | 394 | |
d193d762 KR |
395 | if [file exists $file_1] then { |
396 | set file_a [open $file_1 r] | |
397 | } else { | |
398 | warning "$file_1 doesn't exist" | |
8cbd903e | 399 | return 1 |
d193d762 | 400 | } |
8cbd903e | 401 | |
d193d762 KR |
402 | if [file exists $file_2] then { |
403 | set file_b [open $file_2 r] | |
404 | } else { | |
405 | fail "$file_2 doesn't exist" | |
406 | close $file_a | |
8cbd903e | 407 | return 1 |
d193d762 | 408 | } |
8cbd903e | 409 | |
d193d762 | 410 | verbose " Regexp-diff'ing: $file_1 $file_2" 2 |
8cbd903e | 411 | |
d193d762 KR |
412 | while { $differences == 0 && $end == 0 } { |
413 | set line_a "" | |
414 | set line_b "" | |
415 | while { [string length $line_a] == 0 } { | |
416 | if { [gets $file_a line_a] == $eof } { | |
417 | set end 1 | |
418 | break | |
419 | } | |
420 | } | |
421 | while { [string length $line_b] == 0 || [string match "#*" $line_b] } { | |
a0cc993c ILT |
422 | if [ string match "#pass" $line_b ] { |
423 | set end 1 | |
424 | set diff_pass 1 | |
425 | break | |
426 | } | |
d193d762 KR |
427 | if { [gets $file_b line_b] == $eof } { |
428 | set end 1 | |
429 | break | |
430 | } | |
431 | } | |
432 | if { $end } { break } | |
433 | verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3 | |
8cbd903e | 434 | if ![regexp "^$line_b$" "$line_a"] { |
09a1cedb KR |
435 | send_log "regexp_diff match failure\n" |
436 | send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n" | |
d193d762 KR |
437 | set differences 1 |
438 | } | |
439 | } | |
440 | ||
a0cc993c | 441 | if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { |
09a1cedb | 442 | send_log "different lengths\n" |
d193d762 KR |
443 | verbose "different lengths" 3 |
444 | set differences 1 | |
445 | } | |
446 | ||
447 | close $file_a | |
448 | close $file_b | |
449 | ||
450 | return $differences | |
451 | } | |
91e3b582 DE |
452 | |
453 | proc file_contents { filename } { | |
454 | set file [open $filename r] | |
455 | set contents [read $file] | |
456 | close $file | |
457 | return $contents | |
458 | } | |
459 | ||
460 | proc verbose_eval { expr { level 1 } } { | |
461 | global verbose | |
462 | if $verbose>$level then { eval verbose "$expr" $level } | |
463 | } | |
787f6220 BM |
464 | |
465 | # This definition is taken from an unreleased version of DejaGnu. Once | |
466 | # that version gets released, and has been out in the world for a few | |
467 | # months at least, it may be safe to delete this copy. | |
468 | if ![string length [info proc prune_system_crud]] { | |
469 | # | |
470 | # prune_system_crud -- delete various system verbosities from TEXT on SYSTEM | |
471 | # | |
472 | # An example is: | |
473 | # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9 | |
474 | # | |
475 | # SYSTEM is typical $target_triplet or $host_triplet. | |
476 | # | |
477 | # This is useful when trying to do pattern matches on program output. | |
478 | # Sites with particular verbose os's may wish to override this in site.exp. | |
479 | # | |
480 | proc prune_system_crud { system text } { | |
481 | # This is from sun4's. Do it for all machines for now. | |
482 | # The "\\1" is to try to preserve a "\n" but only if necessary. | |
483 | regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text | |
484 | ||
485 | # It might be tempting to get carried away and delete blank lines, etc. | |
486 | # Just delete *exactly* what we're ask to, and that's it. | |
487 | return $text | |
488 | } | |
489 | } |