gcov-Testing.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: gcov Testing</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: gcov Testing">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: gcov Testing">
  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="profopt-Testing.html#profopt-Testing" rel="next" title="profopt Testing">
  31. <link href="LTO-Testing.html#LTO-Testing" rel="prev" title="LTO Testing">
  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="gcov-Testing"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="profopt-Testing.html#profopt-Testing" accesskey="n" rel="next">profopt Testing</a>, Previous: <a href="LTO-Testing.html#LTO-Testing" accesskey="p" rel="prev">LTO Testing</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="Support-for-testing-gcov"></a>
  69. <h3 class="section">7.6 Support for testing <code>gcov</code></h3>
  70. <p>Language-independent support for testing <code>gcov</code>, and for checking
  71. that branch profiling produces expected values, is provided by the
  72. expect file <samp>lib/gcov.exp</samp>. <code>gcov</code> tests also rely on procedures
  73. in <samp>lib/gcc-dg.exp</samp> to compile and run the test program. A typical
  74. <code>gcov</code> test contains the following DejaGnu commands within comments:
  75. </p>
  76. <div class="smallexample">
  77. <pre class="smallexample">{ dg-options &quot;-fprofile-arcs -ftest-coverage&quot; }
  78. { dg-do run { target native } }
  79. { dg-final { run-gcov sourcefile } }
  80. </pre></div>
  81. <p>Checks of <code>gcov</code> output can include line counts, branch percentages,
  82. and call return percentages. All of these checks are requested via
  83. commands that appear in comments in the test&rsquo;s source file.
  84. Commands to check line counts are processed by default.
  85. Commands to check branch percentages and call return percentages are
  86. processed if the <code>run-gcov</code> command has arguments <code>branches</code>
  87. or <code>calls</code>, respectively. For example, the following specifies
  88. checking both, as well as passing <samp>-b</samp> to <code>gcov</code>:
  89. </p>
  90. <div class="smallexample">
  91. <pre class="smallexample">{ dg-final { run-gcov branches calls { -b sourcefile } } }
  92. </pre></div>
  93. <p>A line count command appears within a comment on the source line
  94. that is expected to get the specified count and has the form
  95. <code>count(<var>cnt</var>)</code>. A test should only check line counts for
  96. lines that will get the same count for any architecture.
  97. </p>
  98. <p>Commands to check branch percentages (<code>branch</code>) and call
  99. return percentages (<code>returns</code>) are very similar to each other.
  100. A beginning command appears on or before the first of a range of
  101. lines that will report the percentage, and the ending command
  102. follows that range of lines. The beginning command can include a
  103. list of percentages, all of which are expected to be found within
  104. the range. A range is terminated by the next command of the same
  105. kind. A command <code>branch(end)</code> or <code>returns(end)</code> marks
  106. the end of a range without starting a new one. For example:
  107. </p>
  108. <div class="smallexample">
  109. <pre class="smallexample">if (i &gt; 10 &amp;&amp; j &gt; i &amp;&amp; j &lt; 20) /* <span class="roman">branch(27 50 75)</span> */
  110. /* <span class="roman">branch(end)</span> */
  111. foo (i, j);
  112. </pre></div>
  113. <p>For a call return percentage, the value specified is the
  114. percentage of calls reported to return. For a branch percentage,
  115. the value is either the expected percentage or 100 minus that
  116. value, since the direction of a branch can differ depending on the
  117. target or the optimization level.
  118. </p>
  119. <p>Not all branches and calls need to be checked. A test should not
  120. check for branches that might be optimized away or replaced with
  121. predicated instructions. Don&rsquo;t check for calls inserted by the
  122. compiler or ones that might be inlined or optimized away.
  123. </p>
  124. <p>A single test can check for combinations of line counts, branch
  125. percentages, and call return percentages. The command to check a
  126. line count must appear on the line that will report that count, but
  127. commands to check branch percentages and call return percentages can
  128. bracket the lines that report them.
  129. </p>
  130. <hr>
  131. <div class="header">
  132. <p>
  133. Next: <a href="profopt-Testing.html#profopt-Testing" accesskey="n" rel="next">profopt Testing</a>, Previous: <a href="LTO-Testing.html#LTO-Testing" accesskey="p" rel="prev">LTO Testing</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>
  134. </div>
  135. </body>
  136. </html>