Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

416 lines
19KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Directives (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Directives (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Directives (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Test-Directives.html#Test-Directives" rel="up" title="Test Directives">
  30. <link href="Selectors.html#Selectors" rel="next" title="Selectors">
  31. <link href="Test-Directives.html#Test-Directives" rel="prev" title="Test Directives">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Directives"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Selectors.html#Selectors" accesskey="n" rel="next">Selectors</a>, Up: <a href="Test-Directives.html#Test-Directives" accesskey="u" rel="up">Test Directives</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Syntax-and-Descriptions-of-test-directives"></a>
  68. <h4 class="subsection">7.2.1 Syntax and Descriptions of test directives</h4>
  69. <p>Test directives appear within comments in a test source file and begin
  70. with <code>dg-</code>. Some of these are defined within DejaGnu and others
  71. are local to the GCC testsuite.
  72. </p>
  73. <p>The order in which test directives appear in a test can be important:
  74. directives local to GCC sometimes override information used by the
  75. DejaGnu directives, which know nothing about the GCC directives, so the
  76. DejaGnu directives must precede GCC directives.
  77. </p>
  78. <p>Several test directives include selectors (see <a href="Selectors.html#Selectors">Selectors</a>)
  79. which are usually preceded by the keyword <code>target</code> or <code>xfail</code>.
  80. </p>
  81. <a name="Specify-how-to-build-the-test"></a>
  82. <h4 class="subsubsection">7.2.1.1 Specify how to build the test</h4>
  83. <dl compact="compact">
  84. <dt><code>{ dg-do <var>do-what-keyword</var> [{ target/xfail <var>selector</var> }] }</code></dt>
  85. <dd><p><var>do-what-keyword</var> specifies how the test is compiled and whether
  86. it is executed. It is one of:
  87. </p>
  88. <dl compact="compact">
  89. <dt><code>preprocess</code></dt>
  90. <dd><p>Compile with <samp>-E</samp> to run only the preprocessor.
  91. </p></dd>
  92. <dt><code>compile</code></dt>
  93. <dd><p>Compile with <samp>-S</samp> to produce an assembly code file.
  94. </p></dd>
  95. <dt><code>assemble</code></dt>
  96. <dd><p>Compile with <samp>-c</samp> to produce a relocatable object file.
  97. </p></dd>
  98. <dt><code>link</code></dt>
  99. <dd><p>Compile, assemble, and link to produce an executable file.
  100. </p></dd>
  101. <dt><code>run</code></dt>
  102. <dd><p>Produce and run an executable file, which is expected to return
  103. an exit code of 0.
  104. </p></dd>
  105. </dl>
  106. <p>The default is <code>compile</code>. That can be overridden for a set of
  107. tests by redefining <code>dg-do-what-default</code> within the <code>.exp</code>
  108. file for those tests.
  109. </p>
  110. <p>If the directive includes the optional &lsquo;<samp>{ target <var>selector</var> }</samp>&rsquo;
  111. then the test is skipped unless the target system matches the
  112. <var>selector</var>.
  113. </p>
  114. <p>If <var>do-what-keyword</var> is <code>run</code> and the directive includes
  115. the optional &lsquo;<samp>{ xfail <var>selector</var> }</samp>&rsquo; and the selector is met
  116. then the test is expected to fail. The <code>xfail</code> clause is ignored
  117. for other values of <var>do-what-keyword</var>; those tests can use
  118. directive <code>dg-xfail-if</code>.
  119. </p></dd>
  120. </dl>
  121. <a name="Specify-additional-compiler-options"></a>
  122. <h4 class="subsubsection">7.2.1.2 Specify additional compiler options</h4>
  123. <dl compact="compact">
  124. <dt><code>{ dg-options <var>options</var> [{ target <var>selector</var> }] }</code></dt>
  125. <dd><p>This DejaGnu directive provides a list of compiler options, to be used
  126. if the target system matches <var>selector</var>, that replace the default
  127. options used for this set of tests.
  128. </p>
  129. </dd>
  130. <dt><code>{ dg-add-options <var>feature</var> &hellip; }</code></dt>
  131. <dd><p>Add any compiler options that are needed to access certain features.
  132. This directive does nothing on targets that enable the features by
  133. default, or that don&rsquo;t provide them at all. It must come after
  134. all <code>dg-options</code> directives.
  135. For supported values of <var>feature</var> see <a href="Add-Options.html#Add-Options">Add Options</a>.
  136. </p>
  137. </dd>
  138. <dt><code>{ dg-additional-options <var>options</var> [{ target <var>selector</var> }] }</code></dt>
  139. <dd><p>This directive provides a list of compiler options, to be used
  140. if the target system matches <var>selector</var>, that are added to the default
  141. options used for this set of tests.
  142. </p></dd>
  143. </dl>
  144. <a name="Modify-the-test-timeout-value"></a>
  145. <h4 class="subsubsection">7.2.1.3 Modify the test timeout value</h4>
  146. <p>The normal timeout limit, in seconds, is found by searching the
  147. following in order:
  148. </p>
  149. <ul>
  150. <li> the value defined by an earlier <code>dg-timeout</code> directive in
  151. the test
  152. </li><li> variable <var>tool_timeout</var> defined by the set of tests
  153. </li><li> <var>gcc</var>,<var>timeout</var> set in the target board
  154. </li><li> 300
  155. </li></ul>
  156. <dl compact="compact">
  157. <dt><code>{ dg-timeout <var>n</var> [{target <var>selector</var> }] }</code></dt>
  158. <dd><p>Set the time limit for the compilation and for the execution of the test
  159. to the specified number of seconds.
  160. </p>
  161. </dd>
  162. <dt><code>{ dg-timeout-factor <var>x</var> [{ target <var>selector</var> }] }</code></dt>
  163. <dd><p>Multiply the normal time limit for compilation and execution of the test
  164. by the specified floating-point factor.
  165. </p></dd>
  166. </dl>
  167. <a name="Skip-a-test-for-some-targets"></a>
  168. <h4 class="subsubsection">7.2.1.4 Skip a test for some targets</h4>
  169. <dl compact="compact">
  170. <dt><code>{ dg-skip-if <var>comment</var> { <var>selector</var> } [{ <var>include-opts</var> } [{ <var>exclude-opts</var> }]] }</code></dt>
  171. <dd><p>Arguments <var>include-opts</var> and <var>exclude-opts</var> are lists in which
  172. each element is a string of zero or more GCC options.
  173. Skip the test if all of the following conditions are met:
  174. </p><ul>
  175. <li> the test system is included in <var>selector</var>
  176. </li><li> for at least one of the option strings in <var>include-opts</var>,
  177. every option from that string is in the set of options with which
  178. the test would be compiled; use &lsquo;<samp>&quot;*&quot;</samp>&rsquo; for an <var>include-opts</var> list
  179. that matches any options; that is the default if <var>include-opts</var> is
  180. not specified
  181. </li><li> for each of the option strings in <var>exclude-opts</var>, at least one
  182. option from that string is not in the set of options with which the test
  183. would be compiled; use &lsquo;<samp>&quot;&quot;</samp>&rsquo; for an empty <var>exclude-opts</var> list;
  184. that is the default if <var>exclude-opts</var> is not specified
  185. </li></ul>
  186. <p>For example, to skip a test if option <code>-Os</code> is present:
  187. </p>
  188. <div class="smallexample">
  189. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;-Os&quot; } { &quot;&quot; } } */
  190. </pre></div>
  191. <p>To skip a test if both options <code>-O2</code> and <code>-g</code> are present:
  192. </p>
  193. <div class="smallexample">
  194. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;-O2 -g&quot; } { &quot;&quot; } } */
  195. </pre></div>
  196. <p>To skip a test if either <code>-O2</code> or <code>-O3</code> is present:
  197. </p>
  198. <div class="smallexample">
  199. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;-O2&quot; &quot;-O3&quot; } { &quot;&quot; } } */
  200. </pre></div>
  201. <p>To skip a test unless option <code>-Os</code> is present:
  202. </p>
  203. <div class="smallexample">
  204. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;*&quot; } { &quot;-Os&quot; } } */
  205. </pre></div>
  206. <p>To skip a test if either <code>-O2</code> or <code>-O3</code> is used with <code>-g</code>
  207. but not if <code>-fpic</code> is also present:
  208. </p>
  209. <div class="smallexample">
  210. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;-O2 -g&quot; &quot;-O3 -g&quot; } { &quot;-fpic&quot; } } */
  211. </pre></div>
  212. </dd>
  213. <dt><code>{ dg-require-effective-target <var>keyword</var> [{ <var>selector</var> }] }</code></dt>
  214. <dd><p>Skip the test if the test target, including current multilib flags,
  215. is not covered by the effective-target keyword.
  216. If the directive includes the optional &lsquo;<samp>{ <var>selector</var> }</samp>&rsquo;
  217. then the effective-target test is only performed if the target system
  218. matches the <var>selector</var>.
  219. This directive must appear after any <code>dg-do</code> directive in the test
  220. and before any <code>dg-additional-sources</code> directive.
  221. See <a href="Effective_002dTarget-Keywords.html#Effective_002dTarget-Keywords">Effective-Target Keywords</a>.
  222. </p>
  223. </dd>
  224. <dt><code>{ dg-require-<var>support</var> args }</code></dt>
  225. <dd><p>Skip the test if the target does not provide the required support.
  226. These directives must appear after any <code>dg-do</code> directive in the test
  227. and before any <code>dg-additional-sources</code> directive.
  228. They require at least one argument, which can be an empty string if the
  229. specific procedure does not examine the argument.
  230. See <a href="Require-Support.html#Require-Support">Require Support</a>, for a complete list of these directives.
  231. </p></dd>
  232. </dl>
  233. <a name="Expect-a-test-to-fail-for-some-targets"></a>
  234. <h4 class="subsubsection">7.2.1.5 Expect a test to fail for some targets</h4>
  235. <dl compact="compact">
  236. <dt><code>{ dg-xfail-if <var>comment</var> { <var>selector</var> } [{ <var>include-opts</var> } [{ <var>exclude-opts</var> }]] }</code></dt>
  237. <dd><p>Expect the test to fail if the conditions (which are the same as for
  238. <code>dg-skip-if</code>) are met. This does not affect the execute step.
  239. </p>
  240. </dd>
  241. <dt><code>{ dg-xfail-run-if <var>comment</var> { <var>selector</var> } [{ <var>include-opts</var> } [{ <var>exclude-opts</var> }]] }</code></dt>
  242. <dd><p>Expect the execute step of a test to fail if the conditions (which are
  243. the same as for <code>dg-skip-if</code>) are met.
  244. </p></dd>
  245. </dl>
  246. <a name="Expect-the-test-executable-to-fail"></a>
  247. <h4 class="subsubsection">7.2.1.6 Expect the test executable to fail</h4>
  248. <dl compact="compact">
  249. <dt><code>{ dg-shouldfail <var>comment</var> [{ <var>selector</var> } [{ <var>include-opts</var> } [{ <var>exclude-opts</var> }]]] }</code></dt>
  250. <dd><p>Expect the test executable to return a nonzero exit status if the
  251. conditions (which are the same as for <code>dg-skip-if</code>) are met.
  252. </p></dd>
  253. </dl>
  254. <a name="Verify-compiler-messages"></a>
  255. <h4 class="subsubsection">7.2.1.7 Verify compiler messages</h4>
  256. <p>Where <var>line</var> is an accepted argument for these commands, a value of &lsquo;<samp>0</samp>&rsquo;
  257. can be used if there is no line associated with the message.
  258. </p>
  259. <dl compact="compact">
  260. <dt><code>{ dg-error <var>regexp</var> [<var>comment</var> [{ target/xfail <var>selector</var> } [<var>line</var>] ]] }</code></dt>
  261. <dd><p>This DejaGnu directive appears on a source line that is expected to get
  262. an error message, or else specifies the source line associated with the
  263. message. If there is no message for that line or if the text of that
  264. message is not matched by <var>regexp</var> then the check fails and
  265. <var>comment</var> is included in the <code>FAIL</code> message. The check does
  266. not look for the string &lsquo;<samp>error</samp>&rsquo; unless it is part of <var>regexp</var>.
  267. </p>
  268. </dd>
  269. <dt><code>{ dg-warning <var>regexp</var> [<var>comment</var> [{ target/xfail <var>selector</var> } [<var>line</var>] ]] }</code></dt>
  270. <dd><p>This DejaGnu directive appears on a source line that is expected to get
  271. a warning message, or else specifies the source line associated with the
  272. message. If there is no message for that line or if the text of that
  273. message is not matched by <var>regexp</var> then the check fails and
  274. <var>comment</var> is included in the <code>FAIL</code> message. The check does
  275. not look for the string &lsquo;<samp>warning</samp>&rsquo; unless it is part of <var>regexp</var>.
  276. </p>
  277. </dd>
  278. <dt><code>{ dg-message <var>regexp</var> [<var>comment</var> [{ target/xfail <var>selector</var> } [<var>line</var>] ]] }</code></dt>
  279. <dd><p>The line is expected to get a message other than an error or warning.
  280. If there is no message for that line or if the text of that message is
  281. not matched by <var>regexp</var> then the check fails and <var>comment</var> is
  282. included in the <code>FAIL</code> message.
  283. </p>
  284. </dd>
  285. <dt><code>{ dg-bogus <var>regexp</var> [<var>comment</var> [{ target/xfail <var>selector</var> } [<var>line</var>] ]] }</code></dt>
  286. <dd><p>This DejaGnu directive appears on a source line that should not get a
  287. message matching <var>regexp</var>, or else specifies the source line
  288. associated with the bogus message. It is usually used with &lsquo;<samp>xfail</samp>&rsquo;
  289. to indicate that the message is a known problem for a particular set of
  290. targets.
  291. </p>
  292. </dd>
  293. <dt><code>{ dg-line <var>linenumvar</var> }</code></dt>
  294. <dd><p>This DejaGnu directive sets the variable <var>linenumvar</var> to the line number of
  295. the source line. The variable <var>linenumvar</var> can then be used in subsequent
  296. <code>dg-error</code>, <code>dg-warning</code>, <code>dg-message</code> and <code>dg-bogus</code>
  297. directives. For example:
  298. </p>
  299. <div class="smallexample">
  300. <pre class="smallexample">int a; /* { dg-line first_def_a } */
  301. float a; /* { dg-error &quot;conflicting types of&quot; } */
  302. /* { dg-message &quot;previous declaration of&quot; &quot;&quot; { target *-*-* } first_def_a } */
  303. </pre></div>
  304. </dd>
  305. <dt><code>{ dg-excess-errors <var>comment</var> [{ target/xfail <var>selector</var> }] }</code></dt>
  306. <dd><p>This DejaGnu directive indicates that the test is expected to fail due
  307. to compiler messages that are not handled by &lsquo;<samp>dg-error</samp>&rsquo;,
  308. &lsquo;<samp>dg-warning</samp>&rsquo; or &lsquo;<samp>dg-bogus</samp>&rsquo;. For this directive &lsquo;<samp>xfail</samp>&rsquo;
  309. has the same effect as &lsquo;<samp>target</samp>&rsquo;.
  310. </p>
  311. </dd>
  312. <dt><code>{ dg-prune-output <var>regexp</var> }</code></dt>
  313. <dd><p>Prune messages matching <var>regexp</var> from the test output.
  314. </p></dd>
  315. </dl>
  316. <a name="Verify-output-of-the-test-executable"></a>
  317. <h4 class="subsubsection">7.2.1.8 Verify output of the test executable</h4>
  318. <dl compact="compact">
  319. <dt><code>{ dg-output <var>regexp</var> [{ target/xfail <var>selector</var> }] }</code></dt>
  320. <dd><p>This DejaGnu directive compares <var>regexp</var> to the combined output
  321. that the test executable writes to <samp>stdout</samp> and <samp>stderr</samp>.
  322. </p></dd>
  323. </dl>
  324. <a name="Specify-environment-variables-for-a-test"></a>
  325. <h4 class="subsubsection">7.2.1.9 Specify environment variables for a test</h4>
  326. <dl compact="compact">
  327. <dt><code>{ dg-set-compiler-env-var <var>var_name</var> &quot;<var>var_value</var>&quot; }</code></dt>
  328. <dd><p>Specify that the environment variable <var>var_name</var> needs to be set
  329. to <var>var_value</var> before invoking the compiler on the test file.
  330. </p>
  331. </dd>
  332. <dt><code>{ dg-set-target-env-var <var>var_name</var> &quot;<var>var_value</var>&quot; }</code></dt>
  333. <dd><p>Specify that the environment variable <var>var_name</var> needs to be set
  334. to <var>var_value</var> before execution of the program created by the test.
  335. </p></dd>
  336. </dl>
  337. <a name="Specify-additional-files-for-a-test"></a>
  338. <h4 class="subsubsection">7.2.1.10 Specify additional files for a test</h4>
  339. <dl compact="compact">
  340. <dt><code>{ dg-additional-files &quot;<var>filelist</var>&quot; }</code></dt>
  341. <dd><p>Specify additional files, other than source files, that must be copied
  342. to the system where the compiler runs.
  343. </p>
  344. </dd>
  345. <dt><code>{ dg-additional-sources &quot;<var>filelist</var>&quot; }</code></dt>
  346. <dd><p>Specify additional source files to appear in the compile line
  347. following the main test file.
  348. </p></dd>
  349. </dl>
  350. <a name="Add-checks-at-the-end-of-a-test"></a>
  351. <h4 class="subsubsection">7.2.1.11 Add checks at the end of a test</h4>
  352. <dl compact="compact">
  353. <dt><code>{ dg-final { <var>local-directive</var> } }</code></dt>
  354. <dd><p>This DejaGnu directive is placed within a comment anywhere in the
  355. source file and is processed after the test has been compiled and run.
  356. Multiple &lsquo;<samp>dg-final</samp>&rsquo; commands are processed in the order in which
  357. they appear in the source file. See <a href="Final-Actions.html#Final-Actions">Final Actions</a>, for a list
  358. of directives that can be used within <code>dg-final</code>.
  359. </p></dd>
  360. </dl>
  361. <hr>
  362. <div class="header">
  363. <p>
  364. Next: <a href="Selectors.html#Selectors" accesskey="n" rel="next">Selectors</a>, Up: <a href="Test-Directives.html#Test-Directives" accesskey="u" rel="up">Test Directives</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  365. </div>
  366. </body>
  367. </html>