timeout.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Time-out for test cases</title>
  5. <link rel="stylesheet" href="../../boostbook.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  7. <link rel="home" href="../../index.html" title="Boost.Test">
  8. <link rel="up" href="../testing_tools.html" title="Writing unit tests">
  9. <link rel="prev" href="exception_correctness.html" title="Exception correctness">
  10. <link rel="next" href="expected_failures.html" title="Expected failures specification">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%"><tr>
  14. <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
  15. <td align="center"><a href="../../../../../../index.html">Home</a></td>
  16. <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  18. <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  19. <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
  20. </tr></table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="exception_correctness.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../testing_tools.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="expected_failures.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h3 class="title">
  27. <a name="boost_test.testing_tools.timeout"></a><a class="link" href="timeout.html" title="Time-out for test cases">Time-out for test cases</a>
  28. </h3></div></div></div>
  29. <p>
  30. The <span class="emphasis"><em>Unit Test Framework</em></span> provides the decorator <a class="link" href="../utf_reference/testing_tool_ref/decorator_timeout.html" title="timeout (decorator)"><code class="computeroutput"><span class="identifier">timeout</span></code></a> that specifies a time-out
  31. for a specific <span class="bold"><strong>test unit</strong></span>. The argument time
  32. is always expressed in <span class="bold"><strong>seconds ans wall-clock</strong></span>
  33. time.
  34. </p>
  35. <p>
  36. For test-cases, the time-out value sets the maximum allowed duration for
  37. the test. If this time is exceeded, the test case is reported as failed.
  38. On some systems, the <span class="emphasis"><em>Unit Test Framework</em></span> is able to
  39. force the test-case to stop through a <code class="computeroutput"><span class="identifier">SIGALRM</span></code>
  40. signal (see below).
  41. </p>
  42. <p>
  43. For test-suites, the time-out value sets the maximum allowed duration for
  44. the entire suite to complete. This duration is the accumulated time of all
  45. the test-cases contained in the sub-tree rooted on the test-suite, plus some
  46. extra execution time needed by the <span class="emphasis"><em>Unit Test Framework</em></span>.
  47. For each test-units under a test-suite with time-out, the maximum allowed
  48. duration is set as being the test-suite time out minus the accumulated execution
  49. time before the execution of the test-unit. If this test-unit is a test-case,
  50. it is equivalent to setting the decorator <a class="link" href="../utf_reference/testing_tool_ref/decorator_timeout.html" title="timeout (decorator)"><code class="computeroutput"><span class="identifier">timeout</span></code></a> to the test-case with a
  51. time-out value expressed as before.
  52. </p>
  53. <p>
  54. In case the test-suite times out, the suite is flagged as <code class="computeroutput"><span class="identifier">timed</span><span class="special">-</span><span class="identifier">out</span></code> and
  55. <code class="computeroutput"><span class="identifier">failed</span></code>, and all the test
  56. units (suites and cases) that have not been executed up to the time-out point
  57. are all skipped.
  58. </p>
  59. <h6>
  60. <a name="boost_test.testing_tools.timeout.h0"></a>
  61. <span class="phrase"><a name="boost_test.testing_tools.timeout.example_descr"></a></span><a class="link" href="timeout.html#boost_test.testing_tools.timeout.example_descr">Example:
  62. decorator timeout</a>
  63. </h6>
  64. <div class="informaltable"><table class="table">
  65. <colgroup><col></colgroup>
  66. <thead><tr><th>
  67. <p>
  68. Code
  69. </p>
  70. </th></tr></thead>
  71. <tbody><tr><td>
  72. <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">decorator_11</span>
  73. <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  74. <span class="keyword">namespace</span> <span class="identifier">utf</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span>
  75. <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test1</span><span class="special">,</span> <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">timeout</span><span class="special">(</span><span class="number">2</span><span class="special">))</span>
  76. <span class="special">{</span>
  77. <span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_SIGACTION_BASED_SIGNAL_HANDLING</span>
  78. <span class="keyword">for</span><span class="special">(;;)</span> <span class="special">{}</span>
  79. <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span>
  80. <span class="preprocessor">#else</span>
  81. <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span>
  82. <span class="preprocessor">#endif</span>
  83. <span class="special">}</span>
  84. </pre>
  85. </td></tr></tbody>
  86. </table></div>
  87. <div class="informaltable"><table class="table">
  88. <colgroup><col></colgroup>
  89. <thead><tr><th>
  90. <p>
  91. Output
  92. </p>
  93. </th></tr></thead>
  94. <tbody><tr><td>
  95. <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">decorator_11</span>
  96. <span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
  97. <span class="identifier">unknown</span> <span class="identifier">location</span><span class="special">(</span><span class="number">0</span><span class="special">):</span> <span class="identifier">fatal</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test1"</span><span class="special">:</span> <span class="identifier">signal</span><span class="special">:</span> <span class="identifier">SIGALRM</span> <span class="special">(</span><span class="identifier">timeout</span> <span class="keyword">while</span> <span class="identifier">executing</span> <span class="identifier">function</span><span class="special">)</span>
  98. <span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">5</span><span class="special">):</span> <span class="identifier">last</span> <span class="identifier">checkpoint</span><span class="special">:</span> <span class="string">"test1"</span> <span class="identifier">entry</span><span class="special">.</span>
  99. <span class="special">***</span> <span class="number">1</span> <span class="identifier">failures</span> <span class="identifier">is</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_11"</span>
  100. </pre>
  101. </td></tr></tbody>
  102. </table></div>
  103. <div class="note"><table border="0" summary="Note">
  104. <tr>
  105. <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
  106. <th align="left">Note</th>
  107. </tr>
  108. <tr><td align="left" valign="top"><p>
  109. The macro <code class="computeroutput"><span class="identifier">BOOST_SIGACTION_BASED_SIGNAL_HANDLING</span></code>
  110. is defined if Boost.Test is able to force the test-case to stop. This feature
  111. is for instance not supported on Windows. The <span class="emphasis"><em>Unit Test Framework</em></span>
  112. will still be able to report the test-case as failed (once the test-case
  113. finishes).
  114. </p></td></tr>
  115. </table></div>
  116. <div class="note"><table border="0" summary="Note">
  117. <tr>
  118. <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
  119. <th align="left">Note</th>
  120. </tr>
  121. <tr><td align="left" valign="top"><p>
  122. The support of test suite level time-out has been added in <a class="link" href="../change_log.html#ref_CHANGE_LOG_3_10">Boost
  123. 1.70 / <span class="emphasis"><em>Unit Test Framework</em></span> v3.10</a>
  124. </p></td></tr>
  125. </table></div>
  126. </div>
  127. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  128. <td align="left"></td>
  129. <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2019 Boost.Test
  130. contributors<p>
  131. Distributed under the Boost Software License, Version 1.0. (See accompanying
  132. file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
  133. </p>
  134. </div></td>
  135. </tr></table>
  136. <hr>
  137. <div class="spirit-nav">
  138. <a accesskey="p" href="exception_correctness.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../testing_tools.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="expected_failures.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
  139. </div>
  140. </body>
  141. </html>