1 # `dg
' general purpose testcase driver.
3 # Copyright (C) 1992-2019, 2020 Free Software Foundation, Inc.
5 # This file is part of DejaGnu.
7 # DejaGnu is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # DejaGnu is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with DejaGnu; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21 # This file was written by Doug Evans (dje@cygnus.com).
23 # This file is based on old-dejagnu.exp. It is intended to be more extensible
24 # without incurring the overhead that old-dejagnu.exp can. All test framework
25 # commands appear in the testcase as "{ dg-xxx args ... }". We pull them out
26 # with one grep, and then run the function(s) named by "dg-xxx". When running
27 # dg-xxx, the line number that it occurs on is always passed as the first
28 # argument. We also support different kinds of tools via callbacks.
30 # The currently supported options are:
35 # dg-options "options ..." [{ target selector }]
36 # specify special options to pass to the tool (eg: compiler)
38 # dg-do do-what-keyword [{ target/xfail selector }]
39 # `do-what-keyword' is tool specific and is passed unchanged to
40 # $
{tool
}-dg
-test. An example is gcc where `keyword
' can be any of:
41 # preprocess | compile | assemble | link | run
42 # and will do one of: produce a .i, produce a .s, produce a .o,
43 # produce an a.out, or produce an a.out and run it (the default is
46 # dg-error regexp comment [{ target/xfail selector } [{.|0|linenum}]]
47 # indicate an error message <regexp> is expected on this line
48 # (the test fails if it doesn't occur
)
49 #
linenum=0 for general tool messages
(eg
: -V
arg missing
).
50 #
"." means the current line.
52 # dg
-warning regexp comment
[{ target
/xfail selector
} [{.|
0|
linenum}]]
53 # indicate a warning message
<regexp
> is expected
on this line
54 #
(the test fails
if it doesn
't occur)
56 # dg-bogus regexp comment [{ target/xfail selector } [{.|0|linenum}]]
57 # indicate a bogus error message <regexp> used to occur here
58 # (the test fails if it does occur)
60 # dg-build regexp comment [{ target/xfail selector }]
61 # indicate the build use to fail for some reason
62 # (errors covered here include bad assembler generated, tool crashes,
64 # (the test fails if it does occur)
66 # dg-excess-errors comment [{ target/xfail selector }]
67 # indicate excess errors are expected (any line)
68 # (this should only be used sparingly and temporarily)
70 # dg-output regexp [{ target selector }]
71 # indicate the expected output of the program is <regexp>
72 # (there may be multiple occurrences of this, they are concatenated)
74 # dg-final { tcl script }
75 # add some Tcl script to be run at the end
76 # (there may be multiple occurrences of this, they are concatenated)
77 # (unbalanced braces must be \-escaped)
79 # "{ target selector }" is a list of expressions that determine whether the
80 # test succeeds or fails for a particular target, or in some cases whether the
81 # option applies for a particular target. If the case of `dg-do' it specifies
82 # whether the testcase is even attempted
on the specified target.
84 # The target selector is always optional. The format is one of
:
86 #
{ xfail
*-*-* ...
} - the test is expected to fail
for the given targets
87 #
{ target
*-*-* ...
} - the option only applies to the given targets
89 # At least one target must be specified
, use
*-*-* for "all targets".
90 # At present it is not possible to specify both `xfail
' and `target'.
91 #
"native" may be used in place of "*-*-*".
95 #
[ ... some complicated code ...
]
96 #
return a
; /* { dg
-build
"fatal" "ran out of spill regs" { xfail i386-*-* } } */
98 # In this contrived example
, the compiler used to crash
on the
"return
99 # a
;" for some target and it still does crash on i386-*-*.
101 # ??? It might be possible to add additional optional arguments by having
102 # something like
: { dg
-error
".*syntax.*" "syntax error" { { foo 1 } ... } }
106 # $
{tool
}-dg
-test testfile
do-what
-keyword extra
-flags
108 # Run the test
, be it compiler
, assembler
, or whatever.
110 # $
{tool
}-dg
-prune target_triplet
text
112 # Optional callback to
delete output from the tool that can occur
113 # even in successful
("pass") situations and interfere with output
114 # pattern matching. This also gives the tool an opportunity to review
115 # the output and check
for any conditions which indicate an
"untested"
116 # or
"unresolved" state. An example is if a testcase is too big and
117 # fills all available ram
(which can happen
for 16 bit CPUs
). The
118 # result is either the pruned
text or
119 #
"::untested|unresolved|unsupported::message"
120 #
(eg
: "::unsupported::memory full").
123 #
1) All runnable testcases must
return 0 from main
() for success.
124 # You can
't rely on getting any return code from target boards, and the
125 # `exec' command says a
program fails
if it returns non
-zero.
127 # Language independence is
(theoretically
) achieved by
:
129 #
1) Using global $tool to indicate the language
(eg
: gcc
, g
++, gas
, etc.
).
130 # This should only be used to look up other objects. We don
't want to
131 # have to add code for each new language that is supported. If this is
132 # done right, no code needs to be added here for each new language.
134 # 2) Passing tool options in as arguments.
136 # Earlier versions of ${tool}_start (eg: gcc_start) would only take the name
137 # of the file to compile as an argument. Newer versions accept a list of
138 # one or two elements, the second being a string of *all* options to pass
139 # to the tool. We require this facility.
143 # Try not to do anything else that makes life difficult.
145 # The normal way to write a testsuite is to have a .exp file containing:
147 # load_lib ${tool}-dg.exp
149 # dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/foo*]] ...
152 # Global state variables.
153 # The defaults are for GCC.
155 # The default do-what keyword.
156 set dg-do-what-default compile
158 # When dg-interpreter-batch-mode is 1, no execution test or excess error
159 # tests are performed.
160 set dg-interpreter-batch-mode 0
162 # Line number format. This is how line numbers appear in program output.
163 set dg-linenum-format ":%d:"
164 proc dg-format-linenum { linenum } {
165 global dg-linenum-format
166 return [format ${dg-linenum-format} $linenum]
169 # Useful subroutines.
171 # dg-get-options -- pick out the dg-xxx options in a testcase
173 # PROG is the file name of the testcase.
174 # The result is a list of options found.
176 # Example: For the following testcase:
178 # /* { dg-prms-id 1234 } */
179 # int foo { return 0; } /* { dg-build fatal "some comment" } */
183 # { dg-prms-id 1 1234 } { dg-build 2 fatal "some comment" }
185 proc dg-get-options { prog } {
188 set tmp [grep $prog "{\[ \t\]\+dg-\[-a-z\]\+\[ \t\]\+.*\[ \t\]\+}" line]
191 regexp "(\[0-9\]+)\[ \t\]+{\[ \t\]+(dg-\[-a-z\]+)\[ \t\]+(.*)\[ \t\]+}\[^\}\]*(\n|$)" $i i line cmd args
192 append result " { $cmd $line $args }"
199 # Process optional xfail/target arguments
201 # SELECTOR is "xfail target-triplet-1 ..." or "target target-triplet-1 ..."
202 # `target-triplet' may be
"native".
203 #
For xfail
, the result is
"F" (expected to Fail) if the current target is
204 # affected
, otherwise
"P" (expected to Pass).
205 #
For target
, the result is
"S" (target is Selected) if the target is selected,
206 # otherwise
"N" (target is Not selected).
208 proc dg
-process
-target
{ selector
} {
209 global target_triplet
211 set isnative
[isnative
]
214 set selector
[string trim $selector
]
215 if {[regexp
"^xfail " $selector]} {
217 } elseif
{[regexp
"^target " $selector]} {
220 # The use of error here and in other dg
-xxx utilities is intentional.
221 # dg
-test will catch them and
do the right thing.
222 error
"syntax error in target selector \"$selector\""
225 if {[regexp
"^${what}( \[^ \]+-\[^ \]+-\[^ \]+| native)+$" $selector]} {
226 regsub
"^${what} " $selector "" selector
227 foreach triplet $selector
{
228 if {[string match $triplet $target_triplet
]} {
230 } elseif
{ $isnative
&& $triplet eq
"native" } {
235 error
"syntax error in target selector \"$selector\""
238 if { $triplet_match
} {
239 return [expr
{ $what eq
"xfail" ? "F" : "S" }]
241 return [expr
{ $what eq
"xfail" ? "P" : "N" }]
245 # Predefined user option handlers.
246 # The line number is always the first element.
247 # Note that each of these are varargs procs
(they have an `
args' argument).
248 # Tests for optional arguments are coded with ">=" to simplify adding new ones.
250 proc dg-prms-id { args } {
253 if { [llength $args] > 2 } {
254 error "[lindex $args 0]: too many arguments"
257 set prms_id [lindex $args 1]
262 # Different options can be used for different targets by having multiple
263 # instances, selecting a different target each time. Since options are
264 # processed in order, put the default value first. Subsequent occurrences
265 # will override previous ones.
267 proc dg-options { args } {
268 upvar dg-extra-tool-flags extra-tool-flags
270 if { [llength $args] > 3 } {
271 error "[lindex $args 0]: too many arguments"
274 if { [llength $args] >= 3 } {
275 switch -- [dg-process-target [lindex $args 2]] {
276 "S" { set extra-tool-flags [lindex $args 1] }
278 "F" { error "[lindex $args 0]: `xfail' not allowed here
" }
279 "P" { error "[lindex $args 0]: `xfail' not allowed here" }
282 set extra
-tool
-flags
[lindex $
args 1]
286 # Record what to
do (compile/run
/etc.
)
288 # Multiple instances are supported
(since we don
't support target and xfail
289 # selectors on one line), though it doesn't make much sense to change the
290 #
compile/assemble
/link
/run field. Nor does it make
any sense to have
291 # multiple lines of target selectors
(use one line
).
293 proc dg
-do { args } {
294 upvar dg
-do-what
do-what
296 if { [llength $
args] > 3 } {
297 error
"[lindex $args 0]: too many arguments"
300 set doaction
[lindex $
args 1]
301 set selected
[lindex $
{do-what
} 1] ;# selected?
(""/S/N)
302 set expected
[lindex $
{do-what
} 2] ;# expected to pass
/fail
(P
/F
)
304 if { [llength $
args] >= 3 } {
305 switch -- [dg
-process
-target
[lindex $
args 2]] {
310 # Don
't deselect a target if it's been explicitly selected
,
311 # but indicate a specific target has been selected
(so don
't
312 # do this testcase if it's not appropriate
for this target
).
313 # The user really shouldn
't have multiple lines of target
314 # selectors, but try to do the intuitive thing (multiple lines
315 # are OR'd together
).
316 if { $selected ne
"S" } {
319 set doaction
[lindex $
{do-what
} 0]
322 "F" { set expected "F" }
324 # There
's nothing to do for "P". We don't want to clobber a
325 # previous xfail
for this target.
329 # Note
: A previous occurrence of `dg
-do' with target/xfail selectors
330 # is a user mistake. We clobber previous values here.
335 switch -- [lindex $args 1] {
342 error "[lindex $args 0]: syntax error"
345 set do-what [list $doaction $selected $expected]
348 proc dg-error { args } {
349 upvar dg-messages messages
351 if { [llength $args] > 5 } {
352 error "[lindex $args 0]: too many arguments"
356 if { [llength $args] >= 4 } {
357 switch -- [dg-process-target [lindex $args 3]] {
358 "F" { set xfail "X" }
361 # If we get "N", this error doesn't apply to us so ignore it.
367 if { [llength $
args] >= 5 } {
368 switch -- [lindex $
args 4] {
369 "." { set line [dg-format-linenum [lindex $args 0]] }
371 "default" { set line [dg-format-linenum [lindex $args 4]] }
374 set line
[dg
-format
-linenum [lindex $
args 0]]
377 lappend messages
[list $line $
{xfail
}ERROR
[lindex $
args 1] [lindex $
args 2]]
380 proc dg
-warning
{ args } {
381 upvar dg
-messages messages
383 if { [llength $
args] > 5 } {
384 error
"[lindex $args 0]: too many arguments"
388 if { [llength $
args] >= 4 } {
389 switch -- [dg
-process
-target
[lindex $
args 3]] {
390 "F" { set xfail "X" }
393 #
If we
get "N", this warning doesn't apply to us so ignore it.
399 if { [llength $
args] >= 5 } {
400 switch -- [lindex $
args 4] {
401 "." { set line [dg-format-linenum [lindex $args 0]] }
403 "default" { set line [dg-format-linenum [lindex $args 4]] }
406 set line
[dg
-format
-linenum [lindex $
args 0]]
409 lappend messages
[list $line $
{xfail
}WARNING
[lindex $
args 1] [lindex $
args 2]]
412 proc dg
-bogus
{ args } {
413 upvar dg
-messages messages
415 if { [llength $
args] > 5 } {
416 error
"[lindex $args 0]: too many arguments"
420 if { [llength $
args] >= 4 } {
421 switch -- [dg
-process
-target
[lindex $
args 3]] {
422 "F" { set xfail "X" }
425 #
If we
get "N", this message doesn't apply to us so ignore it.
431 if { [llength $
args] >= 5 } {
432 switch -- [lindex $
args 4] {
433 "." { set line [dg-format-linenum [lindex $args 0]] }
435 "default" { set line [dg-format-linenum [lindex $args 4]] }
438 set line
[dg
-format
-linenum [lindex $
args 0]]
441 lappend messages
[list $line $
{xfail
}BOGUS
[lindex $
args 1] [lindex $
args 2]]
444 proc dg
-build
{ args } {
445 upvar dg
-messages messages
447 if { [llength $
args] > 4 } {
448 error
"[lindex $args 0]: too many arguments"
452 if { [ llength $
args] >= 4 } {
453 switch -- [dg
-process
-target
[lindex $
args 3]] {
454 "F" { set xfail "X" }
457 #
If we
get "N", this lossage doesn't apply to us so ignore it.
463 lappend messages
[list
[lindex $
args 0] $
{xfail
}BUILD
[lindex $
args 1] [lindex $
args 2]]
466 proc dg
-excess
-errors
{ args } {
467 upvar dg
-excess
-errors
-flag excess
-errors
-flag
469 if { [llength $
args] > 3 } {
470 error
"[lindex $args 0]: too many arguments"
473 if { [llength $
args] >= 3 } {
474 switch -- [dg
-process
-target
[lindex $
args 2]] {
475 "F" { set excess-errors-flag 1 }
476 "S" { set excess-errors-flag 1 }
479 set excess
-errors
-flag
1
483 # Indicate expected
program output.
485 # We support multiple occurrences
, but we
do not implicitly insert newlines
488 # Note that target boards don
't all support this kind of thing so it's a good
489 # idea to specify the target all the time.
If one or more targets are
490 # explicitly selected
, the test won
't be performed if we're not one of them
491 #
(as long as we were never mentioned
).
493 #
If you have target dependent output and want to
set an xfail
for one or more
494 # of them
, use
{ dg
-output
"" { xfail a-b-c ... } }. The "" won't contribute
495 # to the expected output.
497 proc dg
-output
{ args } {
498 upvar dg
-output
-text output
-text
500 if { [llength $
args] > 3 } {
501 error
"[lindex $args 0]: too many arguments"
504 # Allow target dependent output.
506 set expected
[lindex $
{output
-text} 0]
507 if { [llength $
args] >= 3 } {
508 switch -- [dg
-process
-target
[lindex $
args 2]] {
511 "F" { set expected "F" }
512 # Don
't override a previous xfail.
517 if { [llength ${output-text}] == 1 } {
519 set output-text [list $expected [lindex $args 1]]
521 set output-text [list $expected "[lindex ${output-text} 1][lindex $args 1]"]
525 proc dg-final { args } {
526 upvar dg-final-code final-code
528 if { [llength $args] > 2 } {
529 error "[lindex $args 0]: too many arguments"
532 append final-code "[lindex $args 1]\n"
535 # Set up our environment
537 # There currently isn't much to
do, but always calling it allows us to add
538 # enhancements without having to
update our callers.
539 # It must be run before calling `dg
-test
'.
544 # dg-runtest -- simple main loop useful to most testsuites
546 # OPTIONS is a set of options to always pass.
547 # DEFAULT_EXTRA_OPTIONS is a set of options to pass if the testcase
548 # doesn't specify
any (with dg
-option
).
550 proc dg
-runtest
{ testcases options default
-extra
-options
} {
553 foreach testcase $testcases
{
554 #
If we
're only testing specific files and this isn't one of them
, skip it.
555 if {![runtest_file_p $runtests $testcase
]} {
558 verbose
"Testing [file tail [file dirname $testcase]]/[file tail $testcase]"
559 dg
-test $testcase $options $
{default
-extra
-options
}
563 # dg
-trim
-dirname
-- rip DIR_NAME out of FILE_NAME
565 # Syntax
: dg
-trim
-dirname dir_name file_name
566 # We need to go through this contortion in order to properly support
567 # directory
-names which might have embedded regexp special characters.
569 proc dg
-trim
-dirname
{ dir_name file_name
} {
570 set special_character
"\[\?\+\-\.\(\)\$\|\]"
571 regsub
-all
-- $special_character $dir_name
{\\&} dir_name
572 regsub
"^$dir_name/?" $file_name "" file_name
576 # dg
-test
-- runs a new style DejaGnu test
578 # Syntax
: dg
-test
[-keep
-output
] prog tool_flags default_extra_tool_flags
580 # PROG is the full path
name of the file to pass to the tool
(eg
: compiler
).
581 # TOOL_FLAGS is a
set of options to always pass.
582 # DEFAULT_EXTRA_TOOL_FLAGS are additional options
if the testcase has
none.
584 #proc dg
-test
{ prog tool_flags default_extra_tool_flags
} {
585 proc dg
-test
{ args } {
586 global dg
-do-what
-default dg
-interpreter
-batch
-mode dg
-linenum-format
587 global errorCode errorInfo
590 global host_triplet target_triplet
595 if { [string index
[lindex $
args 0] 0] eq
"-" } {
596 for { set i
0 } { $i
< [llength $
args] } { incr i
} {
597 if { [lindex $
args $i
] eq
"--" } {
600 } elseif
{ [lindex $
args $i
] eq
"-keep-output" } {
602 } elseif
{ [string index
[lindex $
args $i
] 0] eq
"-" } {
603 clone_output
"ERROR: dg-test: illegal argument: [lindex $args $i]"
611 if { $i
+ 3 != [llength $
args] } {
612 clone_output
"ERROR: dg-test: missing arguments in call"
615 set prog
[lindex $
args $i
]
616 set tool_flags
[lindex $
args [expr
{$i
+ 1}]]
617 set default_extra_tool_flags
[lindex $
args [expr
{$i
+ 2}]]
619 set text "\[- A-Za-z0-9\.\;\"\_\:\'\`\(\)\!\#\=\+\?\&\*]*"
621 set name [dg
-trim
-dirname $srcdir $prog
]
622 #
If we couldn
't rip $srcdir out of `prog' then just
do the best we can.
623 # The point is to reduce the unnecessary noise in the logs. Don
't strip
624 # out too much because different testcases with the same name can confuse
626 if {[string match
"/*" $name]} {
627 set name "[file tail [file dirname $prog]]/[file tail $prog]"
630 # We append the compilation flags
, if any, to ensure that the test case
632 if { $tool_flags ne
"" } {
633 set name "$name $tool_flags"
636 # Process
any embedded dg options in the testcase.
638 # Use
"" for the second element of dg-do-what so we can tell if it's been
639 # explicitly
set to
"S".
640 set dg
-do-what
[list $
{dg
-do-what
-default
} "" P]
641 set dg
-excess
-errors
-flag
0
643 set dg
-extra
-tool
-flags $default_extra_tool_flags
646 # `dg
-output
-text' is a list of two elements: pass/fail and text.
647 # Leave second element off for now (indicates "don't perform test
")
648 set dg
-output
-text "P"
650 #
Define our own
"special function" `unknown' so we catch spelling errors.
651 # But first
rename the existing one so we can restore it afterwards.
652 if { [info procs dg
-save
-unknown
] == [list
] } {
653 rename unknown dg
-save
-unknown
654 proc unknown
{ args } {
655 return -code error
"unknown dg option: $args"
659 set tmp
[dg
-get-options $prog
]
661 verbose
"Processing option: $op" 3
662 set status [catch $op errmsg
]
663 if { $
status != 0 } {
664 if { 0 && [info exists errorInfo
] } {
665 # This also prints a backtrace which will just confuse
666 # testcase writers
, so it
's disabled.
667 perror "$name: $errorInfo\n"
669 perror "$name: $errmsg for \"$op\"\n"
671 perror "$name: $errmsg for \"$op\"" 0
676 # Restore normal error handling.
677 if { [info procs dg-save-unknown] != [list] } {
679 rename dg-save-unknown unknown
682 # If we're not supposed to try this test
on this target
, we
're done.
683 if { [lindex ${dg-do-what} 1] eq "N" } {
685 verbose "$name not supported on this target, skipping it" 3
689 # Run the tool and analyze the results.
690 # The result of ${tool}-dg-test is in a bit of flux.
691 # Currently it is the name of the output file (or "" if none).
692 # If we need more than this it will grow into a list of things.
693 # No intention is made (at this point) to preserve upward compatibility
694 # (though at some point we'll have to
).
696 set results
[$
{tool
}-dg
-test $prog
[lindex $
{dg
-do-what
} 0] "$tool_flags ${dg-extra-tool-flags}"]
698 set comp_output
[lindex $results
0]
699 set output_file
[lindex $results
1]
701 # Store an analysis of the messages produced.
702 foreach i $
{dg
-messages
} {
703 verbose
"Scanning for message: $i" 4
705 # Remove all error messages
for the line
[lindex $i
0]
706 # in the source file.
If we find
any, success
!
707 set line
[lindex $i
0]
708 set pattern
[lindex $i
2]
709 set comment
[lindex $i
3]
710 if {[regsub
-all
"(^|\n)(\[^\n\]+$line\[^\n\]*($pattern)\[^\n\]*\n?)+" $comp_output "\n" comp_output]} {
711 set comp_output
[string trimleft $comp_output
]
719 # $line will either be a formatted line number or a number all by
720 # itself.
Delete the formatting.
721 scan $line $
{dg
-linenum-format
} line
722 switch -- [lindex $i
1] {
724 lappend scan_results $ok \
725 "$name $comment (test for errors, line $line)"
728 lappend scan_results x$ok \
729 "$name $comment (test for errors, line $line)"
732 lappend scan_results $ok \
733 "$name $comment (test for warnings, line $line)"
736 lappend scan_results x$ok \
737 "$name $comment (test for warnings, line $line)"
740 lappend scan_results $uhoh \
741 "$name $comment (test for bogus messages, line $line)"
744 lappend scan_results x$uhoh \
745 "$name $comment (test for bogus messages, line $line)"
748 lappend scan_results $uhoh \
749 "$name $comment (test for build failure, line $line)"
752 lappend scan_results x$uhoh \
753 "$name $comment (test for build failure, line $line)"
760 # Remove messages from the tool that we can ignore.
761 set comp_output
[prune_warnings $comp_output
]
763 if { [info procs $
{tool
}-dg
-prune
] ne
"" } {
764 set comp_output
[$
{tool
}-dg
-prune $target_triplet $comp_output
]
765 switch -glob
-- $comp_output
{
767 regsub
"::untested::" $comp_output "" message
768 untested
"$name: $message"
772 regsub
"::unresolved::" $comp_output "" message
773 unresolved
"$name: $message"
777 regsub
"::unsupported::" $comp_output "" message
778 unsupported
"$name: $message"
784 #
Report the results of the message analysis.
785 if { [info exists scan_results
] } {
786 foreach
{ result message
} $scan_results
{ $result $message
}
790 # See
if someone forgot to
delete the extra lines.
791 regsub
-all
"\n+" $comp_output "\n" comp_output
792 regsub
"^\n+" $comp_output "" comp_output
794 # Don
't do this if we're testing an interpreter.
796 if { $
{dg
-interpreter
-batch
-mode} == 0 } {
797 # Catch excess errors
(new bugs or incomplete testcases
).
798 if {$
{dg
-excess
-errors
-flag
}} {
801 if {$comp_output ne
""} {
802 fail
"$name (test for excess errors)"
803 send_log
"Excess errors:\n$comp_output\n"
805 pass
"$name (test for excess errors)"
809 # Run the executable image
if asked to
do so.
810 # FIXME
: This is the only place where we assume a standard meaning to
811 # the `keyword
' argument of dg-do. This could be cleaned up.
812 if { [lindex ${dg-do-what} 0] eq "run" } {
813 if {![file exists $output_file]} {
814 unresolved "$name compilation failed to produce executable"
817 set result [${tool}_load $output_file]
818 set status [lindex $result 0]
819 set output [lindex $result 1]
820 if { [lindex ${dg-do-what} 2] eq "F" } {
823 if { $status eq "pass" } {
824 pass "$name execution test"
825 verbose "Exec succeeded." 3
826 if { [llength ${dg-output-text}] > 1 } {
827 if { [lindex ${dg-output-text} 0] eq "F" } {
830 set texttmp [lindex ${dg-output-text} 1]
831 if { ![regexp -- $texttmp $output] } {
832 fail "$name output pattern test"
833 send_log "Output was:\n${output}\nShould match:\n$texttmp\n"
834 verbose "Failed test for output pattern $texttmp" 3
836 pass "$name output pattern test"
837 verbose "Passed test for output pattern $texttmp" 3
841 } elseif { $status eq "fail" } {
842 # It would be nice to get some info out of errorCode.
843 if {[info exists errorCode]} {
844 verbose "Exec failed, errorCode: $errorCode" 3
846 verbose "Exec failed, errorCode not defined!" 3
848 fail "$name execution test"
850 $status "$name execution test"
855 # Are there any further tests to perform?
856 # Note that if the program has special run-time requirements, running
857 # of the program can be delayed until here. Ditto for other situations.
858 # It would be a bit cumbersome though.
860 if {${dg-final-code} ne ""} {
861 regsub -all {\\([{}])} ${dg-final-code} {\1} dg-final-code
862 # Note that the use of `args' here makes this a varargs proc.
863 proc dg
-final
-proc
{ args } $
{dg
-final
-code
}
864 verbose
"Running dg-final tests." 3
865 verbose
"dg-final-proc:\n[info body dg-final-proc]" 4
866 if {[catch
"dg-final-proc $prog" errmsg]} {
867 perror
"$name: error executing dg-final: $errmsg" 0
871 #
Do some final clean up.
872 # When testing an interpreter
, we don
't compile something and leave an
874 if { ! ${keep} && ${dg-interpreter-batch-mode} == 0 } {
875 catch "file delete -force -- $output_file"
879 # Do any necessary cleanups.
880 # This is called at the end to undo anything dg-init did (that needs undoing).
883 # Reset this in case caller wonders whether s/he should.
887 # The framework doesn't like to see
any error remnants
, so remove them.
889 if {[info exists errorInfo
]} {
893 #
If the tool has a
"finish" routine, call it.
894 # There may be a bit of duplication
(eg
: resetting prms_id
), leave it.
895 # Let
's keep these procs robust.
897 if {[info procs ${tool}_finish] ne ""} {