Directives.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>GNU Compiler Collection (GCC) Internals: Directives</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Directives">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Directives">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Directives"></a>
  63. <div class="header">
  64. <p>
  65. 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>
  66. </div>
  67. <hr>
  68. <a name="Syntax-and-Descriptions-of-test-directives"></a>
  69. <h4 class="subsection">7.2.1 Syntax and Descriptions of test directives</h4>
  70. <p>Test directives appear within comments in a test source file and begin
  71. with <code>dg-</code>. Some of these are defined within DejaGnu and others
  72. are local to the GCC testsuite.
  73. </p>
  74. <p>The order in which test directives appear in a test can be important:
  75. directives local to GCC sometimes override information used by the
  76. DejaGnu directives, which know nothing about the GCC directives, so the
  77. DejaGnu directives must precede GCC directives.
  78. </p>
  79. <p>Several test directives include selectors (see <a href="Selectors.html#Selectors">Selectors</a>)
  80. which are usually preceded by the keyword <code>target</code> or <code>xfail</code>.
  81. </p>
  82. <a name="Specify-how-to-build-the-test"></a>
  83. <h4 class="subsubsection">7.2.1.1 Specify how to build the test</h4>
  84. <dl compact="compact">
  85. <dt><code>{ dg-do <var>do-what-keyword</var> [{ target/xfail <var>selector</var> }] }</code></dt>
  86. <dd><p><var>do-what-keyword</var> specifies how the test is compiled and whether
  87. it is executed. It is one of:
  88. </p>
  89. <dl compact="compact">
  90. <dt><code>preprocess</code></dt>
  91. <dd><p>Compile with <samp>-E</samp> to run only the preprocessor.
  92. </p></dd>
  93. <dt><code>compile</code></dt>
  94. <dd><p>Compile with <samp>-S</samp> to produce an assembly code file.
  95. </p></dd>
  96. <dt><code>assemble</code></dt>
  97. <dd><p>Compile with <samp>-c</samp> to produce a relocatable object file.
  98. </p></dd>
  99. <dt><code>link</code></dt>
  100. <dd><p>Compile, assemble, and link to produce an executable file.
  101. </p></dd>
  102. <dt><code>run</code></dt>
  103. <dd><p>Produce and run an executable file, which is expected to return
  104. an exit code of 0.
  105. </p></dd>
  106. </dl>
  107. <p>The default is <code>compile</code>. That can be overridden for a set of
  108. tests by redefining <code>dg-do-what-default</code> within the <code>.exp</code>
  109. file for those tests.
  110. </p>
  111. <p>If the directive includes the optional &lsquo;<samp>{ target <var>selector</var> }</samp>&rsquo;
  112. then the test is skipped unless the target system matches the
  113. <var>selector</var>.
  114. </p>
  115. <p>If <var>do-what-keyword</var> is <code>run</code> and the directive includes
  116. the optional &lsquo;<samp>{ xfail <var>selector</var> }</samp>&rsquo; and the selector is met
  117. then the test is expected to fail. The <code>xfail</code> clause is ignored
  118. for other values of <var>do-what-keyword</var>; those tests can use
  119. directive <code>dg-xfail-if</code>.
  120. </p></dd>
  121. </dl>
  122. <a name="Specify-additional-compiler-options"></a>
  123. <h4 class="subsubsection">7.2.1.2 Specify additional compiler options</h4>
  124. <dl compact="compact">
  125. <dt><code>{ dg-options <var>options</var> [{ target <var>selector</var> }] }</code></dt>
  126. <dd><p>This DejaGnu directive provides a list of compiler options, to be used
  127. if the target system matches <var>selector</var>, that replace the default
  128. options used for this set of tests.
  129. </p>
  130. </dd>
  131. <dt><code>{ dg-add-options <var>feature</var> &hellip; }</code></dt>
  132. <dd><p>Add any compiler options that are needed to access certain features.
  133. This directive does nothing on targets that enable the features by
  134. default, or that don&rsquo;t provide them at all. It must come after
  135. all <code>dg-options</code> directives.
  136. For supported values of <var>feature</var> see <a href="Add-Options.html#Add-Options">Add Options</a>.
  137. </p>
  138. </dd>
  139. <dt><code>{ dg-additional-options <var>options</var> [{ target <var>selector</var> }] }</code></dt>
  140. <dd><p>This directive provides a list of compiler options, to be used
  141. if the target system matches <var>selector</var>, that are added to the default
  142. options used for this set of tests.
  143. </p></dd>
  144. </dl>
  145. <a name="Modify-the-test-timeout-value"></a>
  146. <h4 class="subsubsection">7.2.1.3 Modify the test timeout value</h4>
  147. <p>The normal timeout limit, in seconds, is found by searching the
  148. following in order:
  149. </p>
  150. <ul>
  151. <li> the value defined by an earlier <code>dg-timeout</code> directive in
  152. the test
  153. </li><li> variable <var>tool_timeout</var> defined by the set of tests
  154. </li><li> <var>gcc</var>,<var>timeout</var> set in the target board
  155. </li><li> 300
  156. </li></ul>
  157. <dl compact="compact">
  158. <dt><code>{ dg-timeout <var>n</var> [{target <var>selector</var> }] }</code></dt>
  159. <dd><p>Set the time limit for the compilation and for the execution of the test
  160. to the specified number of seconds.
  161. </p>
  162. </dd>
  163. <dt><code>{ dg-timeout-factor <var>x</var> [{ target <var>selector</var> }] }</code></dt>
  164. <dd><p>Multiply the normal time limit for compilation and execution of the test
  165. by the specified floating-point factor.
  166. </p></dd>
  167. </dl>
  168. <a name="Skip-a-test-for-some-targets"></a>
  169. <h4 class="subsubsection">7.2.1.4 Skip a test for some targets</h4>
  170. <dl compact="compact">
  171. <dt><code>{ dg-skip-if <var>comment</var> { <var>selector</var> } [{ <var>include-opts</var> } [{ <var>exclude-opts</var> }]] }</code></dt>
  172. <dd><p>Arguments <var>include-opts</var> and <var>exclude-opts</var> are lists in which
  173. each element is a string of zero or more GCC options.
  174. Skip the test if all of the following conditions are met:
  175. </p><ul>
  176. <li> the test system is included in <var>selector</var>
  177. </li><li> for at least one of the option strings in <var>include-opts</var>,
  178. every option from that string is in the set of options with which
  179. the test would be compiled; use &lsquo;<samp>&quot;*&quot;</samp>&rsquo; for an <var>include-opts</var> list
  180. that matches any options; that is the default if <var>include-opts</var> is
  181. not specified
  182. </li><li> for each of the option strings in <var>exclude-opts</var>, at least one
  183. option from that string is not in the set of options with which the test
  184. would be compiled; use &lsquo;<samp>&quot;&quot;</samp>&rsquo; for an empty <var>exclude-opts</var> list;
  185. that is the default if <var>exclude-opts</var> is not specified
  186. </li></ul>
  187. <p>For example, to skip a test if option <code>-Os</code> is present:
  188. </p>
  189. <div class="smallexample">
  190. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;-Os&quot; } { &quot;&quot; } } */
  191. </pre></div>
  192. <p>To skip a test if both options <code>-O2</code> and <code>-g</code> are present:
  193. </p>
  194. <div class="smallexample">
  195. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;-O2 -g&quot; } { &quot;&quot; } } */
  196. </pre></div>
  197. <p>To skip a test if either <code>-O2</code> or <code>-O3</code> is present:
  198. </p>
  199. <div class="smallexample">
  200. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;-O2&quot; &quot;-O3&quot; } { &quot;&quot; } } */
  201. </pre></div>
  202. <p>To skip a test unless option <code>-Os</code> is present:
  203. </p>
  204. <div class="smallexample">
  205. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;*&quot; } { &quot;-Os&quot; } } */
  206. </pre></div>
  207. <p>To skip a test if either <code>-O2</code> or <code>-O3</code> is used with <code>-g</code>
  208. but not if <code>-fpic</code> is also present:
  209. </p>
  210. <div class="smallexample">
  211. <pre class="smallexample">/* { dg-skip-if &quot;&quot; { *-*-* } { &quot;-O2 -g&quot; &quot;-O3 -g&quot; } { &quot;-fpic&quot; } } */
  212. </pre></div>
  213. </dd>
  214. <dt><code>{ dg-require-effective-target <var>keyword</var> [{ <var>selector</var> }] }</code></dt>
  215. <dd><p>Skip the test if the test target, including current multilib flags,
  216. is not covered by the effective-target keyword.
  217. If the directive includes the optional &lsquo;<samp>{ <var>selector</var> }</samp>&rsquo;
  218. then the effective-target test is only performed if the target system
  219. matches the <var>selector</var>.
  220. This directive must appear after any <code>dg-do</code> directive in the test
  221. and before any <code>dg-additional-sources</code> directive.
  222. See <a href="Effective_002dTarget-Keywords.html#Effective_002dTarget-Keywords">Effective-Target Keywords</a>.
  223. </p>
  224. </dd>
  225. <dt><code>{ dg-require-<var>support</var> args }</code></dt>
  226. <dd><p>Skip the test if the target does not provide the required support.
  227. These directives must appear after any <code>dg-do</code> directive in the test
  228. and before any <code>dg-additional-sources</code> directive.
  229. They require at least one argument, which can be an empty string if the
  230. specific procedure does not examine the argument.
  231. See <a href="Require-Support.html#Require-Support">Require Support</a>, for a complete list of these directives.
  232. </p></dd>
  233. </dl>
  234. <a name="Expect-a-test-to-fail-for-some-targets"></a>
  235. <h4 class="subsubsection">7.2.1.5 Expect a test to fail for some targets</h4>
  236. <dl compact="compact">
  237. <dt><code>{ dg-xfail-if <var>comment</var> { <var>selector</var> } [{ <var>include-opts</var> } [{ <var>exclude-opts</var> }]] }</code></dt>
  238. <dd><p>Expect the test to fail if the conditions (which are the same as for
  239. <code>dg-skip-if</code>) are met. This does not affect the execute step.
  240. </p>
  241. </dd>
  242. <dt><code>{ dg-xfail-run-if <var>comment</var> { <var>selector</var> } [{ <var>include-opts</var> } [{ <var>exclude-opts</var> }]] }</code></dt>
  243. <dd><p>Expect the execute step of a test to fail if the conditions (which are
  244. the same as for <code>dg-skip-if</code>) are met.
  245. </p></dd>
  246. </dl>
  247. <a name="Expect-the-test-executable-to-fail"></a>
  248. <h4 class="subsubsection">7.2.1.6 Expect the test executable to fail</h4>
  249. <dl compact="compact">
  250. <dt><code>{ dg-shouldfail <var>comment</var> [{ <var>selector</var> } [{ <var>include-opts</var> } [{ <var>exclude-opts</var> }]]] }</code></dt>
  251. <dd><p>Expect the test executable to return a nonzero exit status if the
  252. conditions (which are the same as for <code>dg-skip-if</code>) are met.
  253. </p></dd>
  254. </dl>
  255. <a name="Verify-compiler-messages"></a>
  256. <h4 class="subsubsection">7.2.1.7 Verify compiler messages</h4>
  257. <dl compact="compact">
  258. <dt><code>{ dg-error <var>regexp</var> [<var>comment</var> [{ target/xfail <var>selector</var> } [<var>line</var>] ]] }</code></dt>
  259. <dd><p>This DejaGnu directive appears on a source line that is expected to get
  260. an error message, or else specifies the source line associated with the
  261. message. If there is no message for that line or if the text of that
  262. message is not matched by <var>regexp</var> then the check fails and
  263. <var>comment</var> is included in the <code>FAIL</code> message. The check does
  264. not look for the string &lsquo;<samp>error</samp>&rsquo; unless it is part of <var>regexp</var>.
  265. </p>
  266. </dd>
  267. <dt><code>{ dg-warning <var>regexp</var> [<var>comment</var> [{ target/xfail <var>selector</var> } [<var>line</var>] ]] }</code></dt>
  268. <dd><p>This DejaGnu directive appears on a source line that is expected to get
  269. a warning message, or else specifies the source line associated with the
  270. message. If there is no message for that line or if the text of that
  271. message is not matched by <var>regexp</var> then the check fails and
  272. <var>comment</var> is included in the <code>FAIL</code> message. The check does
  273. not look for the string &lsquo;<samp>warning</samp>&rsquo; unless it is part of <var>regexp</var>.
  274. </p>
  275. </dd>
  276. <dt><code>{ dg-message <var>regexp</var> [<var>comment</var> [{ target/xfail <var>selector</var> } [<var>line</var>] ]] }</code></dt>
  277. <dd><p>The line is expected to get a message other than an error or warning.
  278. If there is no message for that line or if the text of that message is
  279. not matched by <var>regexp</var> then the check fails and <var>comment</var> is
  280. included in the <code>FAIL</code> message.
  281. </p>
  282. </dd>
  283. <dt><code>{ dg-bogus <var>regexp</var> [<var>comment</var> [{ target/xfail <var>selector</var> } [<var>line</var>] ]] }</code></dt>
  284. <dd><p>This DejaGnu directive appears on a source line that should not get a
  285. message matching <var>regexp</var>, or else specifies the source line
  286. associated with the bogus message. It is usually used with &lsquo;<samp>xfail</samp>&rsquo;
  287. to indicate that the message is a known problem for a particular set of
  288. targets.
  289. </p>
  290. </dd>
  291. <dt><code>{ dg-excess-errors <var>comment</var> [{ target/xfail <var>selector</var> }] }</code></dt>
  292. <dd><p>This DejaGnu directive indicates that the test is expected to fail due
  293. to compiler messages that are not handled by &lsquo;<samp>dg-error</samp>&rsquo;,
  294. &lsquo;<samp>dg-warning</samp>&rsquo; or &lsquo;<samp>dg-bogus</samp>&rsquo;. For this directive &lsquo;<samp>xfail</samp>&rsquo;
  295. has the same effect as &lsquo;<samp>target</samp>&rsquo;.
  296. </p>
  297. </dd>
  298. <dt><code>{ dg-prune-output <var>regexp</var> }</code></dt>
  299. <dd><p>Prune messages matching <var>regexp</var> from the test output.
  300. </p></dd>
  301. </dl>
  302. <a name="Verify-output-of-the-test-executable"></a>
  303. <h4 class="subsubsection">7.2.1.8 Verify output of the test executable</h4>
  304. <dl compact="compact">
  305. <dt><code>{ dg-output <var>regexp</var> [{ target/xfail <var>selector</var> }] }</code></dt>
  306. <dd><p>This DejaGnu directive compares <var>regexp</var> to the combined output
  307. that the test executable writes to <samp>stdout</samp> and <samp>stderr</samp>.
  308. </p></dd>
  309. </dl>
  310. <a name="Specify-additional-files-for-a-test"></a>
  311. <h4 class="subsubsection">7.2.1.9 Specify additional files for a test</h4>
  312. <dl compact="compact">
  313. <dt><code>{ dg-additional-files &quot;<var>filelist</var>&quot; }</code></dt>
  314. <dd><p>Specify additional files, other than source files, that must be copied
  315. to the system where the compiler runs.
  316. </p>
  317. </dd>
  318. <dt><code>{ dg-additional-sources &quot;<var>filelist</var>&quot; }</code></dt>
  319. <dd><p>Specify additional source files to appear in the compile line
  320. following the main test file.
  321. </p></dd>
  322. </dl>
  323. <a name="Add-checks-at-the-end-of-a-test"></a>
  324. <h4 class="subsubsection">7.2.1.10 Add checks at the end of a test</h4>
  325. <dl compact="compact">
  326. <dt><code>{ dg-final { <var>local-directive</var> } }</code></dt>
  327. <dd><p>This DejaGnu directive is placed within a comment anywhere in the
  328. source file and is processed after the test has been compiled and run.
  329. Multiple &lsquo;<samp>dg-final</samp>&rsquo; commands are processed in the order in which
  330. they appear in the source file. See <a href="Final-Actions.html#Final-Actions">Final Actions</a>, for a list
  331. of directives that can be used within <code>dg-final</code>.
  332. </p></dd>
  333. </dl>
  334. <hr>
  335. <div class="header">
  336. <p>
  337. 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>
  338. </div>
  339. </body>
  340. </html>