Test-Idioms.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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: Test Idioms</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Test Idioms">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Test Idioms">
  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="Testsuites.html#Testsuites" rel="up" title="Testsuites">
  30. <link href="Test-Directives.html#Test-Directives" rel="next" title="Test Directives">
  31. <link href="Testsuites.html#Testsuites" rel="prev" title="Testsuites">
  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="Test-Idioms"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Test-Directives.html#Test-Directives" accesskey="n" rel="next">Test Directives</a>, Up: <a href="Testsuites.html#Testsuites" accesskey="u" rel="up">Testsuites</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="Idioms-Used-in-Testsuite-Code"></a>
  69. <h3 class="section">7.1 Idioms Used in Testsuite Code</h3>
  70. <p>In general, C testcases have a trailing <samp>-<var>n</var>.c</samp>, starting
  71. with <samp>-1.c</samp>, in case other testcases with similar names are added
  72. later. If the test is a test of some well-defined feature, it should
  73. have a name referring to that feature such as
  74. <samp><var>feature</var>-1.c</samp>. If it does not test a well-defined feature
  75. but just happens to exercise a bug somewhere in the compiler, and a
  76. bug report has been filed for this bug in the GCC bug database,
  77. <samp>pr<var>bug-number</var>-1.c</samp> is the appropriate form of name.
  78. Otherwise (for miscellaneous bugs not filed in the GCC bug database),
  79. and previously more generally, test cases are named after the date on
  80. which they were added. This allows people to tell at a glance whether
  81. a test failure is because of a recently found bug that has not yet
  82. been fixed, or whether it may be a regression, but does not give any
  83. other information about the bug or where discussion of it may be
  84. found. Some other language testsuites follow similar conventions.
  85. </p>
  86. <p>In the <samp>gcc.dg</samp> testsuite, it is often necessary to test that an
  87. error is indeed a hard error and not just a warning&mdash;for example,
  88. where it is a constraint violation in the C standard, which must
  89. become an error with <samp>-pedantic-errors</samp>. The following idiom,
  90. where the first line shown is line <var>line</var> of the file and the line
  91. that generates the error, is used for this:
  92. </p>
  93. <div class="smallexample">
  94. <pre class="smallexample">/* { dg-bogus &quot;warning&quot; &quot;warning in place of error&quot; } */
  95. /* { dg-error &quot;<var>regexp</var>&quot; &quot;<var>message</var>&quot; { target *-*-* } <var>line</var> } */
  96. </pre></div>
  97. <p>It may be necessary to check that an expression is an integer constant
  98. expression and has a certain value. To check that <code><var>E</var></code> has
  99. value <code><var>V</var></code>, an idiom similar to the following is used:
  100. </p>
  101. <div class="smallexample">
  102. <pre class="smallexample">char x[((E) == (V) ? 1 : -1)];
  103. </pre></div>
  104. <p>In <samp>gcc.dg</samp> tests, <code>__typeof__</code> is sometimes used to make
  105. assertions about the types of expressions. See, for example,
  106. <samp>gcc.dg/c99-condexpr-1.c</samp>. The more subtle uses depend on the
  107. exact rules for the types of conditional expressions in the C
  108. standard; see, for example, <samp>gcc.dg/c99-intconst-1.c</samp>.
  109. </p>
  110. <p>It is useful to be able to test that optimizations are being made
  111. properly. This cannot be done in all cases, but it can be done where
  112. the optimization will lead to code being optimized away (for example,
  113. where flow analysis or alias analysis should show that certain code
  114. cannot be called) or to functions not being called because they have
  115. been expanded as built-in functions. Such tests go in
  116. <samp>gcc.c-torture/execute</samp>. Where code should be optimized away, a
  117. call to a nonexistent function such as <code>link_failure ()</code> may be
  118. inserted; a definition
  119. </p>
  120. <div class="smallexample">
  121. <pre class="smallexample">#ifndef __OPTIMIZE__
  122. void
  123. link_failure (void)
  124. {
  125. abort ();
  126. }
  127. #endif
  128. </pre></div>
  129. <p>will also be needed so that linking still succeeds when the test is
  130. run without optimization. When all calls to a built-in function
  131. should have been optimized and no calls to the non-built-in version of
  132. the function should remain, that function may be defined as
  133. <code>static</code> to call <code>abort ()</code> (although redeclaring a function
  134. as static may not work on all targets).
  135. </p>
  136. <p>All testcases must be portable. Target-specific testcases must have
  137. appropriate code to avoid causing failures on unsupported systems;
  138. unfortunately, the mechanisms for this differ by directory.
  139. </p>
  140. <p>FIXME: discuss non-C testsuites here.
  141. </p>
  142. <hr>
  143. <div class="header">
  144. <p>
  145. Next: <a href="Test-Directives.html#Test-Directives" accesskey="n" rel="next">Test Directives</a>, Up: <a href="Testsuites.html#Testsuites" accesskey="u" rel="up">Testsuites</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>
  146. </div>
  147. </body>
  148. </html>