• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
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
76<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>
77<span class="special">{</span>
78<span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_SIGACTION_BASED_SIGNAL_HANDLING</span>
79  <span class="keyword">for</span><span class="special">(;;)</span> <span class="special">{}</span>
80  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span>
81<span class="preprocessor">#else</span>
82  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span>
83<span class="preprocessor">#endif</span>
84<span class="special">}</span>
85</pre>
86              </td></tr></tbody>
87</table></div>
88<div class="informaltable"><table class="table">
89<colgroup><col></colgroup>
90<thead><tr><th>
91                <p>
92                  Output
93                </p>
94              </th></tr></thead>
95<tbody><tr><td>
96<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>
97<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
98<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>
99<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>
100
101<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>
102</pre>
103              </td></tr></tbody>
104</table></div>
105<div class="note"><table border="0" summary="Note">
106<tr>
107<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
108<th align="left">Note</th>
109</tr>
110<tr><td align="left" valign="top"><p>
111          The macro <code class="computeroutput"><span class="identifier">BOOST_SIGACTION_BASED_SIGNAL_HANDLING</span></code>
112          is defined if Boost.Test is able to force the test-case to stop. This feature
113          is for instance not supported on Windows. The <span class="emphasis"><em>Unit Test Framework</em></span>
114          will still be able to report the test-case as failed (once the test-case
115          finishes).
116        </p></td></tr>
117</table></div>
118<div class="note"><table border="0" summary="Note">
119<tr>
120<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
121<th align="left">Note</th>
122</tr>
123<tr><td align="left" valign="top"><p>
124          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
125          1.70 / <span class="emphasis"><em>Unit Test Framework</em></span> v3.10</a>
126        </p></td></tr>
127</table></div>
128</div>
129<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
130<td align="left"></td>
131<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p>
132        Distributed under the Boost Software License, Version 1.0. (See accompanying
133        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>)
134      </p>
135</div></td>
136</tr></table>
137<hr>
138<div class="spirit-nav">
139<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>
140</div>
141</body>
142</html>
143