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