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">
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>
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>
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>
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>
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>
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.
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
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:
64 <div class="informaltable"><table class="table">
65 <colgroup><col></colgroup>
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"><</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">></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>
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>
88 <div class="informaltable"><table class="table">
89 <colgroup><col></colgroup>
96 <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></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>
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>
105 <div class="note"><table border="0" summary="Note">
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>
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
118 <div class="note"><table border="0" summary="Note">
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>
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>
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-2019 Boost.Test
133 Distributed under the Boost Software License, Version 1.0. (See accompanying
134 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>)
139 <div class="spirit-nav">
140 <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>