Next: , Up: Test Directives


7.2.1 Syntax and Descriptions of test directives

Test directives appear within comments in a test source file and begin with dg-. Some of these are defined within DejaGnu and others are local to the GCC testsuite. 测试指令出现在测试源文件的注释中,并且起始于dg-。 其中一些是在DejaGnu中定义的,其它的是局限于GCC测试包自己的。

The order in which test directives appear in a test can be important: directives local to GCC sometimes override information used by the DejaGnu directives, which know nothing about the GCC directives, so the DejaGnu directives must precede GCC directives. 测试中测试指令出现的顺序很重要: 局限于GCC的指令有时会覆盖DejaGnu的指令使用的信息, 并且其对GCC指令一无所知,所以DejaGnu指令必须在GCC指令之前。

Several test directives include selectors (参见Selectors) which are usually preceded by the keyword target or xfail. 个别测试指令包含了选择器, 其通常由关键字targetxfail打头。 一个选择器为:一个或多个目标三元组,可能包含通配符; 单个的有效目标关键字;或者一个逻辑表达式。 取决于上下文,选择器指定了是否测试被跳过并报告为不支持, 或者预期为失败。使用‘*-*-*’来匹配任何目标。 有效目标关键字在GCC测试包的target-supports.exp中定义。

选择器表达式出现在大括号中, 并且使用单个的逻辑操作符:‘!’,‘&&’, 或‘||’。 操作数为另一个选择器表达式,一个有效目标关键字, 单个的目标三元组,或者一个双引号或大括号包裹的目标三元组列表。 例如:

7.2.1.1 Specify how to build the test
{ dg-do do-what-keyword [{ target/xfail selector }] }
do-what-keyword指定了测试如何被编译,以及是否被执行。其为:
preprocess
使用-E编译,从而只运行预处理器。
compile
使用-S编译,从而生成汇编代码文件。
assemble
使用-c编译,从而生成可重定位的目标文件。
link
编译,汇编,并连接,从而生成一个可执行文件。
run
生成并运行一个可执行文件,并期望其返回的退出代码为0。

缺省情况为compile。 可以通过在那些测试的.exp文件中重定义 dg-do-what-default来覆盖这个值。

如果指令包含了可选的‘{ target selector } ’, 则除非目标系统被包含在目标三元组列表中,或者匹配有效目标关键字, 否则测试将被跳过。

如果运行了‘do-what-keyword’并且指令包含了可选的 ‘{ xfail selector }’并且选择器匹配,则测试期望为失败。 对于‘do-what-keyword’的其它值,xfail子句会被忽略; 那些测试可以使用指令dg-xfail-if

7.2.1.2 Specify additional compiler options
{ dg-options options [{ target selector }] }
该DejaGnu指令提供了一个编译器选项列表, 用来在目标系统匹配selector的时候被使用, 以替换这个测试集的缺省选项。
{ dg-add-options feature ... }
增加任何访问特定特征所需要的编译器选项。 该指令对使用缺省方式启用特征或者根本不提供特征的目标不做任何事情。 其必须在所有dg-options指令之后。

支持的feature为:

7.2.1.3 Modify the test timeout value

通常的时间限制,以秒为单位,按照下列顺序来查找:

{ dg-timeout n [{target selector }] }
Set the time limit for the compilation and for the execution of the test to the specified number of seconds.
{ dg-timeout-factor x [{ target selector }] }
Multiply the normal time limit for compilation and execution of the test by the specified floating-point factor.
7.2.1.4 Skip a test for some targets
{ dg-skip-if comment { selector } [{ include-opts } [{ exclude-opts }]] }
Arguments include-opts and exclude-opts are lists in which each 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 -g but not if -fpic is also present:

          /* { dg-skip-if "" { *-*-* }  { "-O2 -g" "-O3 -g" } { "-fpic" } } */

{ dg-require-effective-target keyword [{ selector }] }
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 system matches the selector. This directive must appear after any dg-do directive in the test and before any dg-additional-sources directive. 参见Effective-Target Keywords.
{ dg-require-support args }
Skip the test if the target does not provide the required support. These directives must appear after any dg-do directive in the test and before any dg-additional-sources directive. They require at least one argument, which can be an empty string if the specific procedure does not examine the argument. 参见Require Support, for a complete list of these directives.
7.2.1.5 Expect a test to fail for some targets
{ dg-xfail-if comment { selector } [{ include-opts } [{ exclude-opts }]] }
Expect the test to fail if the conditions (which are the same as for dg-skip-if) are met. This does not affect the execute step.
{ dg-xfail-run-if comment { selector } [{ include-opts } [{ exclude-opts }]] }
Expect the execute step of a test to fail if the conditions (which are the same as for dg-skip-if) are met.
7.2.1.6 Expect the test executable to fail
{ dg-shouldfail comment [{ selector } [{ include-opts } [{ exclude-opts }]]] }
Expect the test executable to return a nonzero exit status if the conditions (which are the same as for dg-skip-if) are met.
7.2.1.7 Verify compiler messages
{ dg-error regexp [comment [{ target/xfail selector } [line] }]] }
This DejaGnu directive appears on a source line that is expected to get an error message, or else specifies the source line associated with the message. If there is no message for that line or if the text of that message is not matched by regexp then the check fails and comment is included in the FAIL message. The check does not look for the string ‘error’ unless it is part of regexp.
{ dg-warning regexp [comment [{ target/xfail selector } [line] }]] }
This DejaGnu directive appears on a source line that is expected to get a warning message, or else specifies the source line associated with the message. If there is no message for that line or if the text of that message is not matched by regexp then the check fails and comment is included in the FAIL message. The check does not look for the string ‘warning’ unless it is part of regexp.
{ dg-message regexp [comment [{ target/xfail selector } [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 is not matched by regexp then the check fails and comment is included in the FAIL message.
{ dg-bogus regexp [comment [{ target/xfail selector } [line] }]] }
This DejaGnu directive appears on a source line that should not get a message matching regexp, or else specifies the source line associated with the bogus message. It is usually used with ‘xfail’ to indicate that the message is a known problem for a particular set of targets.
{ dg-excess-errors comment [{ target/xfail selector }] }
This DejaGnu directive indicates that the test is expected to fail due to compiler messages that are not handled by ‘dg-error’, ‘dg-warning’ or ‘dg-bogus’. For this directive ‘xfail’ has the same effect as ‘target’.
{ dg-prune-output regexp }
Prune messages matching regexp from the test output.
7.2.1.8 Verify output of the test executable
{ dg-output regexp [{ target/xfail selector }] }
This DejaGnu directive compares regexp to the combined output that the test executable writes to stdout and stderr.
7.2.1.9 Specify additional files for a test
{ dg-additional-files "filelist" }
Specify additional files, other than source files, that must be copied to the system where the compiler runs.
{ dg-additional-sources "filelist" }
Specify additional source files to appear in the compile line following the main test file.
7.2.1.10 Add checks at the end of a test
{ dg-final { local-directive } }
This DejaGnu directive is placed within a comment anywhere in the source file and is processed after the test has been compiled and run. Multiple ‘dg-final’ commands are processed in the order in which they appear in the source file. 参见Final Actions, for a list of directives that can be used within dg-final.