Next:Selecting targets to which a test applies, Up:Directives used within DejaGnu tests [Contents][Index]
Test directives appear within comments in a test source file and beginwithdg-. Some of these are defined within DejaGnu and othersare local to the GCC testsuite.
The order in which test directives appear in a test can be important:directives local to GCC sometimes override information used by theDejaGnu directives, which know nothing about the GCC directives, so theDejaGnu directives must precede GCC directives.
Several test directives include selectors (seeSelecting targets to which a test applies)which are usually preceded by the keywordtarget orxfail.
{ dg-dodo-what-keyword [{ target/xfailselector }] }do-what-keyword specifies how the test is compiled and whetherit is executed. It is one of:
preprocessCompile with-E to run only the preprocessor.
compileCompile with-S to produce an assembly code file.
assembleCompile with-c to produce a relocatable object file.
linkCompile, assemble, and link to produce an executable file.
runProduce and run an executable file, which is expected to returnan exit code of 0.
The default iscompile. That can be overridden for a set oftests by redefiningdg-do-what-default within the.expfile for those tests.
If the directive includes the optional ‘{ targetselector }’then the test is skipped unless the target system matches theselector.
Ifdo-what-keyword isrun and the directive includesthe optional ‘{ xfailselector }’ and the selector is metthen the test is expected to fail. Thexfail clause is ignoredfor other values ofdo-what-keyword; those tests can usedirectivedg-xfail-if.
{ dg-optionsoptions [{ targetselector }] }This DejaGnu directive provides a list of compiler options, to be usedif the target system matchesselector, that replace the defaultoptions used for this set of tests.
{ dg-add-optionsfeature … }Add any compiler options that are needed to access certain features.This directive does nothing on targets that enable the features bydefault, or that don’t provide them at all. It must come afteralldg-options directives.For supported values offeature seeFeatures fordg-add-options.
{ dg-remove-optionsfeature … }Remove any compiler options that are needed to access certain features.This directive does nothing on targets that disable the features bydefault, or that don’t provide them at all. It must come afteralldg-options anddg-add-options directives.For supported values offeature seeFeatures fordg-remove-options.
{ dg-additional-optionsoptions [{ targetselector }] }This directive provides a list of compiler options, to be usedif the target system matchesselector, that are added to the defaultoptions used for this set of tests.
The normal timeout limit, in seconds, is found by searching thefollowing in order:
dg-timeout directive inthe test{ dg-timeoutn [{targetselector }] }Set the time limit for the compilation and for the execution of the testto the specified number of seconds.
{ dg-timeout-factorx [{ targetselector }] }Multiply the normal time limit for compilation and execution of the testby the specified floating-point factor.
{ dg-do-ifaction {selector } }Same as dg-do if the selector matches and the test hasn’t already beenmarked as unsupported. Use it to override an action on a target whileleaving the default action alone for other targets.
{ dg-skip-ifcomment {selector } [{include-opts } [{exclude-opts }]] }Argumentsinclude-opts andexclude-opts are lists in whicheach element is a string of zero or more GCC options.Skip the test if all of the following conditions are met:
For example, to skip a test if option-Os is present:
/* { dg-skip-if "" { *-*-* } { "-Os" } { "" } } */To skip a test if both options-O2 and-g are present:
/* { dg-skip-if "" { *-*-* } { "-O2 -g" } { "" } } */To skip a test if either-O2 or-O3 is present:
/* { dg-skip-if "" { *-*-* } { "-O2" "-O3" } { "" } } */To skip a test unless option-Os is present:
/* { dg-skip-if "" { *-*-* } { "*" } { "-Os" } } */To skip a test if either-O2 or-O3 is used with-gbut not if-fpic is also present:
/* { dg-skip-if "" { *-*-* } { "-O2 -g" "-O3 -g" } { "-fpic" } } */{ dg-require-effective-targetkeyword [{ targetselector }] }Skip the test if the test target, including current multilib flags,is not covered by the effective-target keyword.If the directive includes the optional ‘{selector }’then the effective-target test is only performed if the target systemmatches theselector.This directive must appear after anydg-do directive in the testand before anydg-additional-sources directive.SeeKeywords describing target attributes.
{ dg-require-support args }Skip the test if the target does not provide the required support.These directives must appear after anydg-do directive in the testand before anydg-additional-sources directive.They require at least one argument, which can be an empty string if thespecific procedure does not examine the argument.SeeVariants ofdg-require-support, for a complete list of these directives.
{ dg-xfail-ifcomment {selector } [{include-opts } [{exclude-opts }]] }Expect the test to fail if the conditions (which are the same as fordg-skip-if) are met. This does not affect the execute step.
{ dg-xfail-run-ifcomment {selector } [{include-opts } [{exclude-opts }]] }Expect the execute step of a test to fail if the conditions (which arethe same as fordg-skip-if) are met.
{ dg-icecomment [{selector } [{include-opts } [{exclude-opts }]]] }Expect the compiler to crash with an internal compiler error and returna nonzero exit status if the conditions (which are the same as fordg-skip-if) are met. Used for tests that test bugs that have not beenfixed yet.
{ dg-shouldfailcomment [{selector } [{include-opts } [{exclude-opts }]]] }Expect the test executable to return a nonzero exit status if theconditions (which are the same as fordg-skip-if) are met.
Whereline is an accepted argument for these commands, a value of ‘0’can be used if there is no line associated with the message.
{ dg-errorregexp [comment [{ target/xfailselector } [line] ]] }This DejaGnu directive appears on a source line that is expected to getan error message, or else specifies the source line associated with themessage. If there is no message for that line or if the text of thatmessage is not matched byregexp then the check fails andcomment is included in theFAIL message. The check doesnot look for the string ‘error’ unless it is part ofregexp.
{ dg-warningregexp [comment [{ target/xfailselector } [line] ]] }This DejaGnu directive appears on a source line that is expected to geta warning message, or else specifies the source line associated with themessage. If there is no message for that line or if the text of thatmessage is not matched byregexp then the check fails andcomment is included in theFAIL message. The check doesnot look for the string ‘warning’ unless it is part ofregexp.
{ dg-messageregexp [comment [{ target/xfailselector } [line] ]] }The line is expected to get a message other than an error or warning.If there is no message for that line or if the text of that message isnot matched byregexp then the check fails andcomment isincluded in theFAIL message.
{ dg-noteregexp [comment [{ target/xfailselector } [line] ]] }The line is expected to get a ‘note’ message.If there is no message for that line or if the text of that message isnot matched byregexp then the check fails andcomment isincluded in theFAIL message.
By default, anyexcess ‘note’ messages are pruned, meaningtheir appearance doesn’t triggerexcess errors.However, if ‘dg-note’ is used at least once in a testcase,they’re not pruned and instead mustall be handled explicitly.Thus, if looking for just single instances of messages with‘note:’ prefixes without caring for all of them, use‘dg-message "note: […]"’ instead of ‘dg-note’, or use‘dg-note’ together with ‘dg-prune-output "note: "’.
{ dg-bogusregexp [comment [{ target/xfailselector } [line] ]] }This DejaGnu directive appears on a source line that should not get amessage matchingregexp, or else specifies the source lineassociated with the bogus message. It is usually used with ‘xfail’to indicate that the message is a known problem for a particular set oftargets.
{ dg-linelinenumvar }This DejaGnu directive sets the variablelinenumvar to the line number ofthe source line. The variablelinenumvar can then be used in subsequentdg-error,dg-warning,dg-message,dg-noteanddg-bogusdirectives. For example:
int a; /* { dg-line first_def_a } */float a; /* { dg-error "conflicting types of" } *//* { dg-message "previous declaration of" "" { target *-*-* } first_def_a } */{ dg-excess-errorscomment [{ target/xfailselector }] }This DejaGnu directive indicates that the test is expected to fail dueto compiler messages that are not handled by ‘dg-error’,‘dg-warning’,dg-message, ‘dg-note’ or‘dg-bogus’.For this directive ‘xfail’has the same effect as ‘target’.
{ dg-prune-outputregexp }Prune messages matchingregexp from the test output.
{ dg-outputregexp [{ target/xfailselector }] }This DejaGnu directive comparesregexp to the combined outputthat the test executable writes tostdout andstderr.
{ dg-output-filefile [{ target/xfailselector }] }Compares the content offile against the combined output that thetest executable writes tostdout andstderr.
{ dg-set-compiler-env-varvar_name "var_value" }Specify that the environment variablevar_name needs to be settovar_value before invoking the compiler on the test file.
{ dg-set-target-env-varvar_name "var_value" }Specify that the environment variablevar_name needs to be settovar_value before execution of the program created by the test.
{ dg-additional-files "filelist" }Specify additional files, other than source files, that must be copiedto the system where the compiler runs.
{ dg-additional-sources "filelist" [{ \[linkonly\] \[targetselector\] }] }Specify additional source files to appear in the compile linefollowing the main test file.If the directive includes the optional ‘{selector }’then the additional sources are only added if the target systemmatches theselector.If ‘linkonly’ is specified, additional sources are used only in‘link’ and ‘run’ tests; they are reported as unsupported anddiscarded in other kinds of tests that direct the compiler to output toa single file.
{ dg-final {local-directive } }This DejaGnu directive is placed within a comment anywhere in thesource file and is processed after the test has been compiled and run.Multiple ‘dg-final’ commands are processed in the order in whichthey appear in the source file. SeeCommands for use indg-final, for a listof directives that can be used withindg-final.
Next:Selecting targets to which a test applies, Up:Directives used within DejaGnu tests [Contents][Index]