Commit | Line | Data |
---|---|---|
ba7f26d2 | 1 | # Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
dfeb0666 | 2 | # 2004, 2005, 2007 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 | |
ec2655a6 | 6 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 | 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 | |
ec2655a6 NC |
16 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
17 | # MA 02110-1301, USA. | |
252b5132 RH |
18 | |
19 | # Please email any bugs, comments, and/or additions to this file to: | |
fc697c14 | 20 | # dejagnu@gnu.org |
252b5132 RH |
21 | |
22 | # This file was written by Ken Raeburn (raeburn@cygnus.com). | |
23 | ||
24 | proc gas_version {} { | |
25 | global AS | |
26 | catch "exec $AS -version < /dev/null" tmp | |
27 | # Should find a way to discard constant parts, keep whatever's | |
28 | # left, so the version string could be almost anything at all... | |
29 | regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number | |
30 | if ![info exists number] then { | |
31 | return "[which $AS] (no version number)\n" | |
32 | } | |
33 | clone_output "[which $AS] $number\n" | |
34 | unset version | |
35 | } | |
36 | ||
37 | proc gas_run { prog as_opts redir } { | |
38 | global AS | |
39 | global ASFLAGS | |
40 | global comp_output | |
41 | global srcdir | |
42 | global subdir | |
43 | global host_triplet | |
44 | ||
04248055 | 45 | verbose -log "Executing $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" |
252b5132 RH |
46 | catch "exec $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" comp_output |
47 | set comp_output [prune_warnings $comp_output] | |
48 | verbose "output was $comp_output" | |
c0b22597 | 49 | return [list $comp_output ""] |
252b5132 RH |
50 | } |
51 | ||
52 | proc all_ones { args } { | |
53 | foreach x $args { if [expr $x!=1] { return 0 } } | |
54 | return 1 | |
55 | } | |
56 | ||
412cc54e L |
57 | # ${tool}_finish (gas_finish) will be called by runtest.exp. But |
58 | # gas_finish should only be used with gas_start. We use gas_started | |
59 | # to tell gas_finish if gas_start has been called so that runtest.exp | |
60 | # can call gas_finish without closing the wrong fd. | |
61 | set gas_started 0 | |
62 | ||
252b5132 RH |
63 | proc gas_start { prog as_opts } { |
64 | global AS | |
65 | global ASFLAGS | |
66 | global srcdir | |
67 | global subdir | |
68 | global spawn_id | |
412cc54e L |
69 | global gas_started |
70 | ||
71 | set gas_started 1 | |
252b5132 | 72 | |
04248055 | 73 | verbose -log "Starting $AS $ASFLAGS $as_opts $prog" 2 |
252b5132 RH |
74 | catch { |
75 | spawn -noecho -nottycopy $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog | |
76 | } foo | |
77 | if ![regexp {^[0-9]+} $foo] then { | |
78 | perror "Can't run $subdir/$prog: $foo" | |
79 | } | |
80 | } | |
81 | ||
82 | proc gas_finish { } { | |
83 | global spawn_id | |
412cc54e | 84 | global gas_started |
252b5132 | 85 | |
412cc54e L |
86 | if { $gas_started == 1 } { |
87 | catch "close" | |
88 | catch "wait" | |
89 | set gas_started 0 | |
90 | } | |
252b5132 RH |
91 | } |
92 | ||
93 | proc want_no_output { testname } { | |
94 | global comp_output | |
95 | ||
96 | if ![string match "" $comp_output] then { | |
97 | send_log "$comp_output\n" | |
98 | verbose "$comp_output" 3 | |
99 | } | |
100 | if [string match "" $comp_output] then { | |
101 | pass "$testname" | |
102 | return 1 | |
103 | } else { | |
104 | fail "$testname" | |
105 | return 0 | |
106 | } | |
107 | } | |
108 | ||
109 | proc gas_test_old { file as_opts testname } { | |
110 | gas_run $file $as_opts "" | |
111 | return [want_no_output $testname] | |
112 | } | |
113 | ||
114 | proc gas_test { file as_opts var_opts testname } { | |
115 | global comp_output | |
116 | ||
117 | set i 0 | |
118 | foreach word $var_opts { | |
119 | set ignore_stdout($i) [string match "*>" $word] | |
120 | set opt($i) [string trim $word {>}] | |
121 | incr i | |
122 | } | |
123 | set max [expr 1<<$i] | |
124 | for {set i 0} {[expr $i<$max]} {incr i} { | |
125 | set maybe_ignore_stdout "" | |
126 | set extra_opts "" | |
127 | for {set bit 0} {(1<<$bit)<$max} {incr bit} { | |
128 | set num [expr 1<<$bit] | |
129 | if [expr $i&$num] then { | |
130 | set extra_opts "$extra_opts $opt($bit)" | |
131 | if $ignore_stdout($bit) then { | |
132 | set maybe_ignore_stdout ">/dev/null" | |
133 | } | |
134 | } | |
135 | } | |
136 | set extra_opts [string trim $extra_opts] | |
137 | gas_run $file "$as_opts $extra_opts" $maybe_ignore_stdout | |
138 | ||
139 | # Should I be able to use a conditional expression here? | |
140 | if [string match "" $extra_opts] then { | |
141 | want_no_output $testname | |
142 | } else { | |
143 | want_no_output "$testname ($extra_opts)" | |
144 | } | |
145 | } | |
146 | if [info exists errorInfo] then { | |
147 | unset errorInfo | |
148 | } | |
149 | } | |
150 | ||
151 | proc gas_test_ignore_stdout { file as_opts testname } { | |
152 | global comp_output | |
153 | ||
154 | gas_run $file $as_opts ">/dev/null" | |
155 | want_no_output $testname | |
156 | } | |
157 | ||
158 | proc gas_test_error { file as_opts testname } { | |
159 | global comp_output | |
160 | ||
161 | gas_run $file $as_opts ">/dev/null" | |
162 | if ![string match "" $comp_output] then { | |
163 | send_log "$comp_output\n" | |
164 | verbose "$comp_output" 3 | |
165 | } | |
166 | if [string match "" $comp_output] then { | |
167 | fail "$testname" | |
168 | } else { | |
169 | pass "$testname" | |
170 | } | |
171 | } | |
172 | ||
173 | proc gas_exit {} {} | |
174 | ||
175 | proc gas_init { args } { | |
176 | global target_cpu | |
177 | global target_cpu_family | |
178 | global target_family | |
179 | global target_vendor | |
180 | global target_os | |
181 | global stdoptlist | |
182 | ||
183 | case "$target_cpu" in { | |
184 | "m68???" { set target_cpu_family m68k } | |
80c7c40a | 185 | "i[3-7]86" { set target_cpu_family i386 } |
252b5132 RH |
186 | default { set target_cpu_family $target_cpu } |
187 | } | |
188 | ||
189 | set target_family "$target_cpu_family-$target_vendor-$target_os" | |
190 | set stdoptlist "-a>" | |
191 | ||
192 | if ![istarget "*-*-*"] { | |
193 | perror "Target name [istarget] is not a triple." | |
194 | } | |
195 | # Need to return an empty string. | |
196 | return | |
197 | } | |
198 | ||
d04428bd AM |
199 | # |
200 | # is_elf_format | |
201 | # true if the object format is known to be ELF | |
202 | # | |
203 | proc is_elf_format {} { | |
204 | if { ![istarget *-*-sysv4*] \ | |
205 | && ![istarget *-*-unixware*] \ | |
206 | && ![istarget *-*-elf*] \ | |
207 | && ![istarget *-*-eabi*] \ | |
208 | && ![istarget hppa*64*-*-hpux*] \ | |
209 | && ![istarget *-*-linux*] \ | |
fee5fcc5 | 210 | && ![istarget frv-*-uclinux*] \ |
d04428bd AM |
211 | && ![istarget *-*-irix5*] \ |
212 | && ![istarget *-*-irix6*] \ | |
213 | && ![istarget *-*-netbsd*] \ | |
d9943e50 | 214 | && ![istarget *-*-openbsd*] \ |
d04428bd AM |
215 | && ![istarget *-*-solaris2*] } { |
216 | return 0 | |
217 | } | |
218 | ||
219 | if { [istarget *-*-linux*aout*] \ | |
220 | || [istarget *-*-linux*oldld*] } { | |
221 | return 0 | |
222 | } | |
223 | ||
224 | if { ![istarget *-*-netbsdelf*] \ | |
225 | && ([istarget *-*-netbsd*aout*] \ | |
226 | || [istarget *-*-netbsdpe*] \ | |
227 | || [istarget arm*-*-netbsd*] \ | |
228 | || [istarget sparc-*-netbsd*] \ | |
229 | || [istarget i*86-*-netbsd*] \ | |
230 | || [istarget m68*-*-netbsd*] \ | |
231 | || [istarget vax-*-netbsd*] \ | |
232 | || [istarget ns32k-*-netbsd*]) } { | |
233 | return 0 | |
234 | } | |
d9943e50 MK |
235 | |
236 | if { [istarget arm-*-openbsd*] \ | |
237 | || [istarget i386-*-openbsd\[0-2\].*] \ | |
238 | || [istarget i386-*-openbsd3.\[0-3\]] \ | |
239 | || [istarget m68*-*-openbsd*] \ | |
240 | || [istarget ns32k-*-openbsd*] \ | |
241 | || [istarget sparc-*-openbsd\[0-2\].*] \ | |
242 | || [istarget sparc-*-openbsd3.\[0-1\]] \ | |
243 | || [istarget vax-*-openbsd*] } { | |
244 | return 0 | |
245 | } | |
246 | ||
d04428bd AM |
247 | return 1 |
248 | } | |
249 | ||
9a5c4b9e PB |
250 | # run_dump_tests TESTCASES EXTRA_OPTIONS |
251 | # Wrapper for run_dump_test, which is suitable for invoking as | |
252 | # run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]] | |
253 | # EXTRA_OPTIONS are passed down to run_dump_test. Honors runtest_file_p. | |
254 | # Body cribbed from dg-runtest. | |
255 | ||
256 | proc run_dump_tests { testcases {extra_options {}} } { | |
257 | global runtests | |
258 | ||
259 | foreach testcase $testcases { | |
260 | # If testing specific files and this isn't one of them, skip it. | |
261 | if ![runtest_file_p $runtests $testcase] { | |
262 | continue | |
263 | } | |
264 | run_dump_test [file rootname [file tail $testcase]] $extra_options | |
265 | } | |
266 | } | |
267 | ||
252b5132 | 268 | |
e8119602 | 269 | # run_dump_test FILE (optional:) EXTRA_OPTIONS |
252b5132 RH |
270 | # |
271 | # Assemble a .s file, then run some utility on it and check the output. | |
139e4a70 | 272 | # |
252b5132 RH |
273 | # There should be an assembly language file named FILE.s in the test |
274 | # suite directory, and a pattern file called FILE.d. `run_dump_test' | |
275 | # will assemble FILE.s, run some tool like `objdump', `objcopy', or | |
276 | # `nm' on the .o file to produce textual output, and then analyze that | |
277 | # with regexps. The FILE.d file specifies what program to run, and | |
278 | # what to expect in its output. | |
279 | # | |
280 | # The FILE.d file begins with zero or more option lines, which specify | |
281 | # flags to pass to the assembler, the program to run to dump the | |
282 | # assembler's output, and the options it wants. The option lines have | |
283 | # the syntax: | |
139e4a70 | 284 | # |
252b5132 | 285 | # # OPTION: VALUE |
139e4a70 | 286 | # |
252b5132 RH |
287 | # OPTION is the name of some option, like "name" or "objdump", and |
288 | # VALUE is OPTION's value. The valid options are described below. | |
289 | # Whitespace is ignored everywhere, except within VALUE. The option | |
9a5c4b9e PB |
290 | # list ends with the first line that doesn't match the above syntax. |
291 | # However, a line within the options that begins with a #, but doesn't | |
292 | # have a recognizable option name followed by a colon, is considered a | |
293 | # comment and entirely ignored. | |
252b5132 | 294 | # |
e8119602 CD |
295 | # The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of |
296 | # two-element lists. The first element of each is an option name, and | |
297 | # the second additional arguments to be added on to the end of the | |
298 | # option list as given in FILE.d. (If omitted, no additional options | |
299 | # are added.) | |
300 | # | |
252b5132 | 301 | # The interesting options are: |
139e4a70 | 302 | # |
252b5132 RH |
303 | # name: TEST-NAME |
304 | # The name of this test, passed to DejaGNU's `pass' and `fail' | |
305 | # commands. If omitted, this defaults to FILE, the root of the | |
306 | # .s and .d files' names. | |
139e4a70 | 307 | # |
252b5132 RH |
308 | # as: FLAGS |
309 | # When assembling FILE.s, pass FLAGS to the assembler. | |
139e4a70 | 310 | # |
252b5132 RH |
311 | # PROG: PROGRAM-NAME |
312 | # The name of the program to run to analyze the .o file produced | |
313 | # by the assembler. This can be omitted; run_dump_test will guess | |
314 | # which program to run by seeing which of the flags options below | |
315 | # is present. | |
139e4a70 | 316 | # |
252b5132 RH |
317 | # objdump: FLAGS |
318 | # nm: FLAGS | |
319 | # objcopy: FLAGS | |
320 | # Use the specified program to analyze the .o file, and pass it | |
139e4a70 AM |
321 | # FLAGS, in addition to the .o file name. Note that they are run |
322 | # with LC_ALL=C in the environment to give consistent sorting | |
323 | # of symbols. | |
252b5132 RH |
324 | # |
325 | # source: SOURCE | |
326 | # Assemble the file SOURCE.s. If omitted, this defaults to FILE.s. | |
327 | # This is useful if several .d files want to share a .s file. | |
328 | # | |
9a5c4b9e PB |
329 | # target: GLOBS... |
330 | # Run this test only on a specified list of targets. More precisely, | |
331 | # each glob in the space-separated list is passed to "istarget"; if | |
332 | # it evaluates true for any of them, the test will be run, otherwise | |
333 | # it will be marked unsupported. | |
334 | # | |
335 | # not-target: GLOBS... | |
336 | # Do not run this test on a specified list of targets. Again, | |
337 | # the each glob in the space-separated list is passed to | |
338 | # "istarget", and the test is run if it evaluates *false* for | |
339 | # *all* of them. Otherwise it will be marked unsupported. | |
340 | # | |
341 | # skip: GLOBS... | |
342 | # not-skip: GLOBS... | |
343 | # These are exactly the same as "not-target" and "target", | |
344 | # respectively, except that they do nothing at all if the check | |
345 | # fails. They should only be used in groups, to construct a single | |
346 | # test which is run on all targets but with variant options or | |
347 | # expected output on some targets. (For example, see | |
348 | # gas/arm/inst.d and gas/arm/wince_inst.d.) | |
349 | # | |
8c2784a5 TR |
350 | # error: REGEX |
351 | # An error with message matching REGEX must be emitted for the test | |
352 | # to pass. The PROG, objdump, nm and objcopy options have no | |
353 | # meaning and need not supplied if this is present. | |
354 | # | |
cfdf4aaa HPN |
355 | # warning: REGEX |
356 | # Expect a gas warning matching REGEX. It is an error to issue | |
357 | # both "error" and "warning". | |
358 | # | |
9a5c4b9e PB |
359 | # stderr: FILE |
360 | # FILE contains regexp lines to be matched against the diagnostic | |
361 | # output of the assembler. This does not preclude the use of | |
362 | # PROG, nm, objdump, or objcopy. | |
363 | # | |
364 | # error-output: FILE | |
365 | # Means the same as 'stderr', but also indicates that the assembler | |
366 | # is expected to exit unsuccessfully (therefore PROG, objdump, nm, | |
367 | # and objcopy have no meaning and should not be supplied). | |
368 | # | |
252b5132 RH |
369 | # Each option may occur at most once. |
370 | # | |
371 | # After the option lines come regexp lines. `run_dump_test' calls | |
372 | # `regexp_diff' to compare the output of the dumping tool against the | |
373 | # regexps in FILE.d. `regexp_diff' is defined later in this file; see | |
374 | # further comments there. | |
375 | ||
e8119602 | 376 | proc run_dump_test { name {extra_options {}} } { |
252b5132 | 377 | global subdir srcdir |
4b0d96c2 HPN |
378 | global OBJDUMP NM AS OBJCOPY READELF |
379 | global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS | |
252b5132 | 380 | global host_triplet |
139e4a70 | 381 | global env |
252b5132 RH |
382 | |
383 | if [string match "*/*" $name] { | |
384 | set file $name | |
385 | set name [file tail $name] | |
386 | } else { | |
387 | set file "$srcdir/$subdir/$name" | |
388 | } | |
389 | set opt_array [slurp_options "${file}.d"] | |
390 | if { $opt_array == -1 } { | |
61feeec2 | 391 | perror "error reading options from $file.d" |
252b5132 RH |
392 | unresolved $subdir/$name |
393 | return | |
394 | } | |
395 | set opts(as) {} | |
396 | set opts(objdump) {} | |
397 | set opts(nm) {} | |
398 | set opts(objcopy) {} | |
4b0d96c2 | 399 | set opts(readelf) {} |
252b5132 RH |
400 | set opts(name) {} |
401 | set opts(PROG) {} | |
402 | set opts(source) {} | |
ff970196 | 403 | set opts(stderr) {} |
8c2784a5 | 404 | set opts(error) {} |
9a5c4b9e | 405 | set opts(error-output) {} |
cfdf4aaa | 406 | set opts(warning) {} |
9a5c4b9e PB |
407 | set opts(target) {} |
408 | set opts(not-target) {} | |
409 | set opts(skip) {} | |
410 | set opts(not-skip) {} | |
252b5132 RH |
411 | |
412 | foreach i $opt_array { | |
413 | set opt_name [lindex $i 0] | |
414 | set opt_val [lindex $i 1] | |
415 | if ![info exists opts($opt_name)] { | |
416 | perror "unknown option $opt_name in file $file.d" | |
417 | unresolved $subdir/$name | |
418 | return | |
419 | } | |
420 | if [string length $opts($opt_name)] { | |
421 | perror "option $opt_name multiply set in $file.d" | |
422 | unresolved $subdir/$name | |
423 | return | |
424 | } | |
425 | set opts($opt_name) $opt_val | |
426 | } | |
427 | ||
e8119602 CD |
428 | foreach i $extra_options { |
429 | set opt_name [lindex $i 0] | |
430 | set opt_val [lindex $i 1] | |
431 | if ![info exists opts($opt_name)] { | |
432 | perror "unknown option $opt_name given in extra_opts" | |
433 | unresolved $subdir/$name | |
434 | return | |
435 | } | |
436 | # add extra option to end of existing option, adding space | |
437 | # if necessary. | |
438 | if [string length $opts($opt_name)] { | |
439 | append opts($opt_name) " " | |
440 | } | |
441 | append opts($opt_name) $opt_val | |
442 | } | |
443 | ||
9a5c4b9e PB |
444 | if { $opts(name) == "" } { |
445 | set testname "$subdir/$name" | |
446 | } else { | |
447 | set testname $opts(name) | |
448 | } | |
449 | verbose "Testing $testname" | |
450 | ||
ba7f26d2 | 451 | if { (($opts(warning) != "") && ($opts(error) != "")) \ |
9a5c4b9e PB |
452 | || (($opts(warning) != "") && ($opts(stderr) != "")) \ |
453 | || (($opts(error-output) != "") && ($opts(stderr) != "")) \ | |
454 | || (($opts(error-output) != "") && ($opts(error) != "")) \ | |
455 | || (($opts(error-output) != "") && ($opts(warning) != "")) } { | |
456 | perror "$testname: bad mix of stderr, error-output, error, and warning test-directives" | |
457 | unresolved $testname | |
ba7f26d2 AM |
458 | return |
459 | } | |
9a5c4b9e PB |
460 | if { $opts(error-output) != "" } then { |
461 | set opts(stderr) $opts(error-output) | |
462 | } | |
ba7f26d2 AM |
463 | |
464 | set program "" | |
465 | # It's meaningless to require an output-testing method when we | |
466 | # expect an error. | |
9a5c4b9e | 467 | if { $opts(error) == "" && $opts(error-output) == "" } { |
ba7f26d2 AM |
468 | if {$opts(PROG) != ""} { |
469 | switch -- $opts(PROG) { | |
470 | objdump { set program objdump } | |
471 | nm { set program nm } | |
472 | objcopy { set program objcopy } | |
473 | readelf { set program readelf } | |
474 | default { | |
475 | perror "unrecognized program option $opts(PROG) in $file.d" | |
9a5c4b9e | 476 | unresolved $testname |
ba7f26d2 AM |
477 | return } |
478 | } | |
479 | } else { | |
480 | # Guess which program to run, by seeing which option was specified. | |
481 | foreach p {objdump objcopy nm readelf} { | |
482 | if {$opts($p) != ""} { | |
483 | if {$program != ""} { | |
484 | perror "ambiguous dump program in $file.d" | |
9a5c4b9e | 485 | unresolved $testname |
ba7f26d2 AM |
486 | return |
487 | } else { | |
488 | set program $p | |
489 | } | |
252b5132 RH |
490 | } |
491 | } | |
492 | } | |
ba7f26d2 | 493 | if { $program == "" && $opts(warning) == "" } { |
252b5132 | 494 | perror "dump program unspecified in $file.d" |
9a5c4b9e | 495 | unresolved $testname |
252b5132 RH |
496 | return |
497 | } | |
498 | } | |
499 | ||
9a5c4b9e PB |
500 | # Handle skipping the test on specified targets. |
501 | # You can have both skip/not-skip and target/not-target, but you can't | |
502 | # have both skip and not-skip, or target and not-target, in the same file. | |
503 | if { $opts(skip) != "" } then { | |
504 | if { $opts(not-skip) != "" } then { | |
505 | perror "$testname: mixing skip and not-skip directives is invalid" | |
506 | unresolved $testname | |
507 | return | |
508 | } | |
509 | foreach glob $opts(skip) { | |
510 | if {[istarget $glob]} { return } | |
511 | } | |
512 | } | |
513 | if { $opts(not-skip) != "" } then { | |
514 | set skip 1 | |
515 | foreach glob $opts(not-skip) { | |
516 | if {[istarget $glob]} { | |
517 | set skip 0 | |
518 | break | |
519 | } | |
520 | } | |
521 | if {$skip} { return } | |
522 | } | |
523 | if { $opts(target) != "" } then { | |
524 | if { $opts(not-target) != "" } then { | |
525 | perror "$testname: mixing target and not-target directives is invalid" | |
526 | unresolved $testname | |
527 | return | |
528 | } | |
529 | set skip 1 | |
530 | foreach glob $opts(target) { | |
531 | if {[istarget $glob]} { | |
532 | set skip 0 | |
533 | break | |
534 | } | |
535 | } | |
536 | if {$skip} { | |
537 | unsupported $testname | |
538 | return | |
539 | } | |
252b5132 | 540 | } |
9a5c4b9e PB |
541 | if { $opts(not-target) != "" } then { |
542 | foreach glob $opts(not-target) { | |
543 | if {[istarget $glob]} { | |
544 | unsupported $testname | |
545 | return | |
546 | } | |
547 | } | |
548 | } | |
549 | ||
252b5132 RH |
550 | |
551 | if { $opts(source) == "" } { | |
552 | set sourcefile ${file}.s | |
553 | } else { | |
554 | set sourcefile $srcdir/$subdir/$opts(source) | |
555 | } | |
556 | ||
cfdf4aaa HPN |
557 | set cmd "$srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile" |
558 | send_log "$cmd\n" | |
559 | set cmdret [catch "exec $cmd" comp_output] | |
252b5132 RH |
560 | set comp_output [prune_warnings $comp_output] |
561 | ||
ba7f26d2 AM |
562 | set expmsg $opts(error) |
563 | if { $opts(warning) != "" } { | |
564 | set expmsg $opts(warning) | |
565 | } | |
566 | if { $cmdret != 0 || $comp_output != "" || $expmsg != "" } then { | |
cfdf4aaa HPN |
567 | # If the executed program writes to stderr and stderr is not |
568 | # redirected, exec *always* returns failure, regardless of the | |
569 | # program exit code. Thankfully, we can retrieve the true | |
570 | # return status from a special variable. Redirection would | |
571 | # cause a tcl-specific message to be appended, and we'd rather | |
572 | # not deal with that if we can help it. | |
573 | global errorCode | |
574 | if { $cmdret != 0 && [lindex $errorCode 0] == "NONE" } { | |
575 | set cmdret 0 | |
576 | } | |
577 | ||
578 | set exitstat "succeeded" | |
579 | if { $cmdret != 0 } { set exitstat "failed" } | |
580 | ||
9a5c4b9e PB |
581 | send_log "$comp_output\n" |
582 | verbose "$comp_output" 3 | |
ff970196 | 583 | if { $opts(stderr) == "" } then { |
ba7f26d2 | 584 | if { [regexp $expmsg $comp_output] \ |
cfdf4aaa | 585 | && (($cmdret == 0) == ($opts(warning) != "")) } { |
ba7f26d2 AM |
586 | # We have the expected output from gas. |
587 | # Return if there's nothing more to do. | |
588 | if { $opts(error) != "" || $program == "" } { | |
8c2784a5 TR |
589 | pass $testname |
590 | return | |
591 | } | |
ba7f26d2 AM |
592 | } else { |
593 | verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>" | |
594 | ||
cfdf4aaa HPN |
595 | fail $testname |
596 | return | |
8c2784a5 | 597 | } |
ff970196 CD |
598 | } else { |
599 | catch {write_file dump.stderr "$comp_output"} write_output | |
600 | if ![string match "" $write_output] then { | |
601 | send_log "error writing dump.stderr: $write_output\n" | |
602 | verbose "error writing dump.stderr: $write_output" 3 | |
603 | send_log "$comp_output\n" | |
604 | verbose "$comp_output" 3 | |
605 | fail $testname | |
606 | return | |
607 | } | |
608 | set stderrfile $srcdir/$subdir/$opts(stderr) | |
ff970196 CD |
609 | verbose "wrote pruned stderr to dump.stderr" 3 |
610 | if { [regexp_diff "dump.stderr" "$stderrfile"] } then { | |
8c2784a5 | 611 | if { $opts(error) != "" } { |
cfdf4aaa | 612 | verbose -log "$exitstat with: <$comp_output>, expected: <$opts(error)>" |
8c2784a5 TR |
613 | if [regexp $opts(error) $comp_output] { |
614 | pass $testname | |
615 | return | |
616 | } | |
617 | } | |
ff970196 CD |
618 | fail $testname |
619 | verbose "pruned stderr is [file_contents "dump.stderr"]" 2 | |
620 | return | |
9a5c4b9e PB |
621 | } elseif { $opts(error-output) != "" } then { |
622 | pass $testname | |
623 | return | |
ff970196 CD |
624 | } |
625 | } | |
252b5132 RH |
626 | } |
627 | ||
ba7f26d2 AM |
628 | if { $program == "" } { |
629 | return | |
630 | } | |
631 | set progopts1 $opts($program) | |
632 | eval set progopts \$[string toupper $program]FLAGS | |
633 | eval set binary \$[string toupper $program] | |
634 | ||
252b5132 RH |
635 | if { [which $binary] == 0 } { |
636 | untested $testname | |
637 | return | |
638 | } | |
639 | ||
640 | if { $progopts1 == "" } { set $progopts1 "-r" } | |
641 | verbose "running $binary $progopts $progopts1" 3 | |
642 | ||
643 | # Objcopy, unlike the other two, won't send its output to stdout, | |
644 | # so we have to run it specially. | |
139e4a70 | 645 | set cmd "$binary $progopts $progopts1 dump.o > dump.out" |
252b5132 | 646 | if { $program == "objcopy" } { |
139e4a70 AM |
647 | set cmd "$binary $progopts $progopts1 dump.o dump.out" |
648 | } | |
649 | ||
650 | # Ensure consistent sorting of symbols | |
651 | if {[info exists env(LC_ALL)]} { | |
652 | set old_lc_all $env(LC_ALL) | |
653 | } | |
654 | set env(LC_ALL) "C" | |
655 | send_log "$cmd\n" | |
656 | catch "exec $cmd" comp_output | |
657 | if {[info exists old_lc_all]} { | |
658 | set env(LC_ALL) $old_lc_all | |
252b5132 | 659 | } else { |
139e4a70 AM |
660 | unset env(LC_ALL) |
661 | } | |
662 | set comp_output [prune_warnings $comp_output] | |
663 | if ![string match "" $comp_output] then { | |
664 | send_log "$comp_output\n" | |
665 | fail $testname | |
666 | return | |
252b5132 RH |
667 | } |
668 | ||
669 | verbose_eval {[file_contents "dump.out"]} 3 | |
670 | if { [regexp_diff "dump.out" "${file}.d"] } then { | |
671 | fail $testname | |
672 | verbose "output is [file_contents "dump.out"]" 2 | |
673 | return | |
674 | } | |
675 | ||
676 | pass $testname | |
677 | } | |
678 | ||
679 | proc slurp_options { file } { | |
680 | if [catch { set f [open $file r] } x] { | |
681 | #perror "couldn't open `$file': $x" | |
682 | perror "$x" | |
683 | return -1 | |
684 | } | |
685 | set opt_array {} | |
686 | # whitespace expression | |
687 | set ws {[ ]*} | |
688 | set nws {[^ ]*} | |
689 | # whitespace is ignored anywhere except within the options list; | |
9a5c4b9e PB |
690 | # option names are alphabetic plus dash |
691 | set pat "^#${ws}(\[a-zA-Z-\]*)$ws:${ws}(.*)$ws\$" | |
252b5132 RH |
692 | while { [gets $f line] != -1 } { |
693 | set line [string trim $line] | |
694 | # Whitespace here is space-tab. | |
695 | if [regexp $pat $line xxx opt_name opt_val] { | |
696 | # match! | |
697 | lappend opt_array [list $opt_name $opt_val] | |
9a5c4b9e | 698 | } elseif {![regexp "^#" $line ]} { |
252b5132 RH |
699 | break |
700 | } | |
701 | } | |
702 | close $f | |
703 | return $opt_array | |
704 | } | |
705 | ||
706 | proc objdump { opts } { | |
707 | global OBJDUMP | |
708 | global comp_output | |
709 | global host_triplet | |
710 | ||
711 | catch "exec $OBJDUMP $opts" comp_output | |
712 | set comp_output [prune_warnings $comp_output] | |
713 | verbose "objdump output=$comp_output\n" 3 | |
714 | } | |
715 | ||
716 | proc objdump_start_no_subdir { prog opts } { | |
717 | global OBJDUMP | |
718 | global srcdir | |
719 | global spawn_id | |
720 | ||
721 | verbose "Starting $OBJDUMP $opts $prog" 2 | |
722 | catch { | |
723 | spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog | |
724 | } foo | |
725 | if ![regexp {^[0-9]+} $foo] then { | |
726 | perror "Can't run $prog: $foo" | |
727 | } | |
728 | } | |
729 | ||
730 | proc objdump_finish { } { | |
731 | global spawn_id | |
732 | ||
733 | catch "close" | |
734 | catch "wait" | |
735 | } | |
736 | ||
737 | # Default timeout is 10 seconds, loses on a slow machine. But some | |
738 | # configurations of dejagnu may override it. | |
739 | if {$timeout<120} then { set timeout 120 } | |
740 | ||
741 | expect_after -i { | |
742 | timeout { perror "timeout" } | |
743 | "virtual memory exhausted" { perror "virtual memory exhausted" } | |
744 | buffer_full { perror "buffer full" } | |
745 | eof { perror "eof" } | |
746 | } | |
747 | ||
748 | # regexp_diff, based on simple_diff taken from ld test suite | |
749 | # compares two files line-by-line | |
750 | # file1 contains strings, file2 contains regexps and #-comments | |
751 | # blank lines are ignored in either file | |
752 | # returns non-zero if differences exist | |
753 | # | |
754 | proc regexp_diff { file_1 file_2 } { | |
755 | ||
756 | set eof -1 | |
757 | set end_1 0 | |
758 | set end_2 0 | |
759 | set differences 0 | |
760 | set diff_pass 0 | |
761 | ||
762 | if [file exists $file_1] then { | |
763 | set file_a [open $file_1 r] | |
764 | } else { | |
04248055 | 765 | perror "$file_1 doesn't exist" |
252b5132 RH |
766 | return 1 |
767 | } | |
768 | ||
769 | if [file exists $file_2] then { | |
770 | set file_b [open $file_2 r] | |
771 | } else { | |
04248055 | 772 | perror "$file_2 doesn't exist" |
252b5132 RH |
773 | close $file_a |
774 | return 1 | |
775 | } | |
776 | ||
777 | verbose " Regexp-diff'ing: $file_1 $file_2" 2 | |
778 | ||
779 | while { 1 } { | |
780 | set line_a "" | |
781 | set line_b "" | |
782 | while { [string length $line_a] == 0 } { | |
783 | if { [gets $file_a line_a] == $eof } { | |
784 | set end_1 1 | |
785 | break | |
786 | } | |
787 | } | |
788 | while { [string length $line_b] == 0 || [string match "#*" $line_b] } { | |
789 | if [ string match "#pass" $line_b ] { | |
790 | set end_2 1 | |
791 | set diff_pass 1 | |
792 | break | |
a6ea59ce GK |
793 | } elseif [ string match "#..." $line_b ] { |
794 | if { [gets $file_b line_b] == $eof } { | |
795 | set end_2 1 | |
5cfd5a0c | 796 | set diff_pass 1 |
a6ea59ce GK |
797 | break |
798 | } | |
799 | verbose "looking for \"^$line_b$\"" 3 | |
800 | while { ![regexp "^$line_b$" "$line_a"] } { | |
801 | verbose "skipping \"$line_a\"" 3 | |
802 | if { [gets $file_a line_a] == $eof } { | |
803 | set end_1 1 | |
804 | break | |
805 | } | |
806 | } | |
807 | break | |
252b5132 RH |
808 | } |
809 | if { [gets $file_b line_b] == $eof } { | |
810 | set end_2 1 | |
811 | break | |
812 | } | |
813 | } | |
814 | ||
139e4a70 AM |
815 | if { $diff_pass } { |
816 | break | |
817 | } elseif { $end_1 && $end_2 } { | |
252b5132 RH |
818 | break |
819 | } elseif { $end_1 } { | |
820 | send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n" | |
821 | verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3 | |
822 | set differences 1 | |
823 | break | |
824 | } elseif { $end_2 } { | |
825 | send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" | |
826 | verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3 | |
827 | set differences 1 | |
828 | break | |
829 | } else { | |
830 | verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3 | |
831 | if ![regexp "^$line_b$" "$line_a"] { | |
832 | send_log "regexp_diff match failure\n" | |
833 | send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n" | |
3ad62fc4 | 834 | verbose "regexp_diff match failure\n" 3 |
252b5132 | 835 | set differences 1 |
252b5132 RH |
836 | } |
837 | } | |
838 | } | |
839 | ||
840 | if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { | |
841 | send_log "$file_1 and $file_2 are different lengths\n" | |
842 | verbose "$file_1 and $file_2 are different lengths" 3 | |
843 | set differences 1 | |
844 | } | |
845 | ||
846 | close $file_a | |
847 | close $file_b | |
848 | ||
849 | return $differences | |
850 | } | |
851 | ||
852 | proc file_contents { filename } { | |
853 | set file [open $filename r] | |
854 | set contents [read $file] | |
855 | close $file | |
856 | return $contents | |
857 | } | |
858 | ||
ff970196 CD |
859 | proc write_file { filename contents } { |
860 | set file [open $filename w] | |
861 | puts $file "$contents" | |
862 | close $file | |
863 | } | |
864 | ||
252b5132 RH |
865 | proc verbose_eval { expr { level 1 } } { |
866 | global verbose | |
867 | if $verbose>$level then { eval verbose "$expr" $level } | |
868 | } | |
869 | ||
870 | # This definition is taken from an unreleased version of DejaGnu. Once | |
871 | # that version gets released, and has been out in the world for a few | |
872 | # months at least, it may be safe to delete this copy. | |
873 | if ![string length [info proc prune_warnings]] { | |
874 | # | |
875 | # prune_warnings -- delete various system verbosities from TEXT. | |
876 | # | |
877 | # An example is: | |
878 | # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9 | |
879 | # | |
880 | # Sites with particular verbose os's may wish to override this in site.exp. | |
881 | # | |
882 | proc prune_warnings { text } { | |
883 | # This is from sun4's. Do it for all machines for now. | |
884 | # The "\\1" is to try to preserve a "\n" but only if necessary. | |
885 | regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text | |
886 | ||
887 | # It might be tempting to get carried away and delete blank lines, etc. | |
888 | # Just delete *exactly* what we're ask to, and that's it. | |
889 | return $text | |
890 | } | |
891 | } | |
dfeb0666 NC |
892 | |
893 | # run_list_test NAME OPTS (optional): TESTNAME | |
894 | # | |
895 | # Assemble the file "NAME.d" with command line options OPTS and | |
896 | # compare the assembler standard error output against thee regular | |
897 | # expressions given in the file "NAME.l". If TESTNAME is provided, | |
898 | # it will be used as the name of the test. | |
899 | ||
900 | proc run_list_test { name opts {testname {}} } { | |
901 | global srcdir subdir | |
902 | if { [string length $testname] == 0 } then { | |
903 | set testname "[file tail $subdir] $name" | |
904 | } | |
905 | set file $srcdir/$subdir/$name | |
906 | gas_run ${name}.s $opts ">&dump.out" | |
907 | if { [regexp_diff "dump.out" "${file}.l"] } then { | |
908 | fail $testname | |
909 | verbose "output is [file_contents "dump.out"]" 2 | |
910 | return | |
911 | } | |
912 | pass $testname | |
913 | } |