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