Skip to content

Commit 3961aec

Browse files
author
jamie
committed
Replace BOOST_TEST_USE_DEPRECATED_TIMER macro with --deprecated_timer_format
Remove the macro BOOST_TEST_USE_DEPRECATED_TIMER and replace it with a runtime cla --deprecated_timer_format. Additionally change <TestingTime> to write the testing time in microseconds and add <CpuTime> giving the time in nanoseconds. Existing scripts and parsers that handle the XML output should not be affected by this change.
1 parent 2cb8441 commit 3961aec

5 files changed

Lines changed: 138 additions & 79 deletions

File tree

doc/html/utf/user-guide/runtime-config/reference.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<li><a href="#" onclick="id339462 = select_form_page( 'utf.user-guide.runtime-config.parameters.color_output', id339462 ); return false;">color_output</a></li>
4646
<li><a href="#" onclick="id339462 = select_form_page( 'utf.user-guide.runtime-config.parameters.detect_fp_exceptions', id339462 ); return false;">detect_fp_exceptions</a></li>
4747
<li><a href="#" onclick="id339462 = select_form_page( 'utf.user-guide.runtime-config.parameters.detect_memory_leaks', id339462 ); return false;">detect_memory_leaks</a></li>
48+
<li><a href="#" onclick="id339462 = select_form_page( 'utf.user-guide.runtime-config.parameters.deprecated_timer_format', id339462 ); return false;">deprecated_timer_format</a></li>
4849
<li><a href="#" onclick="id339462 = select_form_page( 'utf.user-guide.runtime-config.parameters.log_format', id339462 ); return false;">log_format</a></li>
4950
<li><a href="#" onclick="id339462 = select_form_page( 'utf.user-guide.runtime-config.parameters.log_level', id339462 ); return false;">log_level</a></li>
5051
<li><a href="#" onclick="id339462 = select_form_page( 'utf.user-guide.runtime-config.parameters.log_sink', id339462 ); return false;">log_sink</a></li>
@@ -317,6 +318,44 @@
317318
</table>
318319
<br>
319320
</div></div>
321+
<div class="entry" id="utf.user-guide.runtime-config.parameters.deprecated_timer_format"><div class="segmentedlist">
322+
<table class="seglistitem">
323+
<tr class="seg">
324+
<td><strong><nobr><span class="segtitle">Parameter Name</span></nobr></strong></td>
325+
<td>: </td>
326+
<td><span class="emphasis"><em>Force the timer output format to match the deprecated Boost.Timer</em></span></td>
327+
</tr>
328+
<tr class="seg">
329+
<td><strong><nobr><span class="segtitle">Environment variable name</span></nobr></strong></td>
330+
<td>: </td>
331+
<td><code class="varname">BOOST_TEST_DEPRECATED_TIMER_FORMAT</code></td>
332+
</tr>
333+
<tr class="seg">
334+
<td><strong><nobr><span class="segtitle">Command line argument name</span></nobr></strong></td>
335+
<td>: </td>
336+
<td><em class="parameter"><code>deprecated_timer_format</code></em></td>
337+
</tr>
338+
<tr class="seg">
339+
<td><strong><nobr><span class="segtitle">Acceptable Values</span></nobr></strong></td>
340+
<td>: </td>
341+
<td><table border="0" summary="Simple list" class="simplelist">
342+
<tr><td><span class="bold"><strong>no</strong></span></td></tr>
343+
<tr><td>yes</td></tr>
344+
</table></td>
345+
</tr>
346+
<tr class="seg">
347+
<td><strong><nobr><span class="segtitle">Description</span></nobr></strong></td>
348+
<td>: </td>
349+
<td><p>
350+
Specifying this option forces any timer output to match that provided by the deprecated Boost.Timer
351+
class. If you use scripts that parse either the HRF or XML output for Boost.Test and find you are no
352+
longer able to parse the output correctly then enabling this feature should allow your scripts to
353+
work as before. Disabled by default.
354+
</p></td>
355+
</tr>
356+
</table>
357+
<br>
358+
</div></div>
320359
<div class="entry" id="utf.user-guide.runtime-config.parameters.log_format"><div class="segmentedlist">
321360
<table class="seglistitem">
322361
<tr class="seg">

doc/src/utf.user-guide.runtime-config.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,24 @@ Leaving test suite "example"
377377
</descr>
378378
</refentry>
379379

380+
<refentry name="deprecated_timer_format">
381+
<name>Use the deprecated timer format for output</name>
382+
<env>BOOST_TEST_DEPRECATED_TIMER_FORMAT</env>
383+
<cla>deprecated_timer_format</cla>
384+
<vals>
385+
<simplelist>
386+
<member><emphasis role="bold">no</emphasis></member>
387+
<member>yes</member>
388+
</simplelist>
389+
</vals>
390+
<descr>
391+
<simpara>
392+
This ensures timer test output matches the format produced for the deprecated Boost.Timer class. Otherwise
393+
updated output will be displayed that provides Wall, User and System times.
394+
</simpara>
395+
</descr>
396+
</refentry>
397+
380398
<refentry name="log_format">
381399
<name>The log format</name>
382400
<env>BOOST_TEST_LOG_FORMAT</env>

include/boost/test/impl/unit_test_parameters.ipp

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,29 @@ namespace runtime_config {
152152
namespace {
153153

154154
// framework parameters and corresponding command-line arguments
155-
std::string AUTO_START_DBG = "auto_start_dbg";
156-
std::string BREAK_EXEC_PATH = "break_exec_path";
157-
std::string BUILD_INFO = "build_info";
158-
std::string CATCH_SYS_ERRORS = "catch_system_errors";
159-
std::string COLOR_OUTPUT = "color_output";
160-
std::string DETECT_FP_EXCEPT = "detect_fp_exceptions";
161-
std::string DETECT_MEM_LEAKS = "detect_memory_leaks";
162-
std::string LIST_CONTENT = "list_content";
163-
std::string LOG_FORMAT = "log_format";
164-
std::string LOG_LEVEL = "log_level";
165-
std::string LOG_SINK = "log_sink";
166-
std::string OUTPUT_FORMAT = "output_format";
167-
std::string RANDOM_SEED = "random";
168-
std::string REPORT_FORMAT = "report_format";
169-
std::string REPORT_LEVEL = "report_level";
170-
std::string REPORT_SINK = "report_sink";
171-
std::string RESULT_CODE = "result_code";
172-
std::string TESTS_TO_RUN = "run_test";
173-
std::string SAVE_TEST_PATTERN = "save_pattern";
174-
std::string SHOW_PROGRESS = "show_progress";
175-
std::string USE_ALT_STACK = "use_alt_stack";
176-
std::string WAIT_FOR_DEBUGGER = "wait_for_debugger";
155+
std::string AUTO_START_DBG = "auto_start_dbg";
156+
std::string BREAK_EXEC_PATH = "break_exec_path";
157+
std::string BUILD_INFO = "build_info";
158+
std::string CATCH_SYS_ERRORS = "catch_system_errors";
159+
std::string COLOR_OUTPUT = "color_output";
160+
std::string DETECT_FP_EXCEPT = "detect_fp_exceptions";
161+
std::string DETECT_MEM_LEAKS = "detect_memory_leaks";
162+
std::string DEPRECATED_TIMER_FORMAT = "deprecated_timer_format";
163+
std::string LIST_CONTENT = "list_content";
164+
std::string LOG_FORMAT = "log_format";
165+
std::string LOG_LEVEL = "log_level";
166+
std::string LOG_SINK = "log_sink";
167+
std::string OUTPUT_FORMAT = "output_format";
168+
std::string RANDOM_SEED = "random";
169+
std::string REPORT_FORMAT = "report_format";
170+
std::string REPORT_LEVEL = "report_level";
171+
std::string REPORT_SINK = "report_sink";
172+
std::string RESULT_CODE = "result_code";
173+
std::string TESTS_TO_RUN = "run_test";
174+
std::string SAVE_TEST_PATTERN = "save_pattern";
175+
std::string SHOW_PROGRESS = "show_progress";
176+
std::string USE_ALT_STACK = "use_alt_stack";
177+
std::string WAIT_FOR_DEBUGGER = "wait_for_debugger";
177178

178179
static const_string
179180
parameter_2_env_var( const_string param_name )
@@ -182,28 +183,29 @@ parameter_2_env_var( const_string param_name )
182183
static mtype s_mapping;
183184

184185
if( s_mapping.empty() ) {
185-
s_mapping[AUTO_START_DBG] = "BOOST_TEST_AUTO_START_DBG";
186-
s_mapping[BREAK_EXEC_PATH] = "BOOST_TEST_BREAK_EXEC_PATH";
187-
s_mapping[BUILD_INFO] = "BOOST_TEST_BUILD_INFO";
188-
s_mapping[CATCH_SYS_ERRORS] = "BOOST_TEST_CATCH_SYSTEM_ERRORS";
189-
s_mapping[COLOR_OUTPUT] = "BOOST_TEST_COLOR_OUTPUT";
190-
s_mapping[DETECT_FP_EXCEPT] = "BOOST_TEST_DETECT_FP_EXCEPTIONS";
191-
s_mapping[DETECT_MEM_LEAKS] = "BOOST_TEST_DETECT_MEMORY_LEAK";
192-
s_mapping[LIST_CONTENT] = "BOOST_TEST_LIST_CONTENT";
193-
s_mapping[LOG_FORMAT] = "BOOST_TEST_LOG_FORMAT";
194-
s_mapping[LOG_LEVEL] = "BOOST_TEST_LOG_LEVEL";
195-
s_mapping[LOG_SINK] = "BOOST_TEST_LOG_SINK";
196-
s_mapping[OUTPUT_FORMAT] = "BOOST_TEST_OUTPUT_FORMAT";
197-
s_mapping[RANDOM_SEED] = "BOOST_TEST_RANDOM";
198-
s_mapping[REPORT_FORMAT] = "BOOST_TEST_REPORT_FORMAT";
199-
s_mapping[REPORT_LEVEL] = "BOOST_TEST_REPORT_LEVEL";
200-
s_mapping[REPORT_SINK] = "BOOST_TEST_REPORT_SINK";
201-
s_mapping[RESULT_CODE] = "BOOST_TEST_RESULT_CODE";
202-
s_mapping[TESTS_TO_RUN] = "BOOST_TESTS_TO_RUN";
203-
s_mapping[SAVE_TEST_PATTERN] = "BOOST_TEST_SAVE_PATTERN";
204-
s_mapping[SHOW_PROGRESS] = "BOOST_TEST_SHOW_PROGRESS";
205-
s_mapping[USE_ALT_STACK] = "BOOST_TEST_USE_ALT_STACK";
206-
s_mapping[WAIT_FOR_DEBUGGER] = "BOOST_TEST_WAIT_FOR_DEBUGGER";
186+
s_mapping[AUTO_START_DBG] = "BOOST_TEST_AUTO_START_DBG";
187+
s_mapping[BREAK_EXEC_PATH] = "BOOST_TEST_BREAK_EXEC_PATH";
188+
s_mapping[BUILD_INFO] = "BOOST_TEST_BUILD_INFO";
189+
s_mapping[CATCH_SYS_ERRORS] = "BOOST_TEST_CATCH_SYSTEM_ERRORS";
190+
s_mapping[COLOR_OUTPUT] = "BOOST_TEST_COLOR_OUTPUT";
191+
s_mapping[DETECT_FP_EXCEPT] = "BOOST_TEST_DETECT_FP_EXCEPTIONS";
192+
s_mapping[DETECT_MEM_LEAKS] = "BOOST_TEST_DETECT_MEMORY_LEAK";
193+
s_mapping[DEPRECATED_TIMER_FORMAT] = "BOOST_TEST_DEPRECATED_TIMER_FORMAT";
194+
s_mapping[LIST_CONTENT] = "BOOST_TEST_LIST_CONTENT";
195+
s_mapping[LOG_FORMAT] = "BOOST_TEST_LOG_FORMAT";
196+
s_mapping[LOG_LEVEL] = "BOOST_TEST_LOG_LEVEL";
197+
s_mapping[LOG_SINK] = "BOOST_TEST_LOG_SINK";
198+
s_mapping[OUTPUT_FORMAT] = "BOOST_TEST_OUTPUT_FORMAT";
199+
s_mapping[RANDOM_SEED] = "BOOST_TEST_RANDOM";
200+
s_mapping[REPORT_FORMAT] = "BOOST_TEST_REPORT_FORMAT";
201+
s_mapping[REPORT_LEVEL] = "BOOST_TEST_REPORT_LEVEL";
202+
s_mapping[REPORT_SINK] = "BOOST_TEST_REPORT_SINK";
203+
s_mapping[RESULT_CODE] = "BOOST_TEST_RESULT_CODE";
204+
s_mapping[TESTS_TO_RUN] = "BOOST_TESTS_TO_RUN";
205+
s_mapping[SAVE_TEST_PATTERN] = "BOOST_TEST_SAVE_PATTERN";
206+
s_mapping[SHOW_PROGRESS] = "BOOST_TEST_SHOW_PROGRESS";
207+
s_mapping[USE_ALT_STACK] = "BOOST_TEST_USE_ALT_STACK";
208+
s_mapping[WAIT_FOR_DEBUGGER] = "BOOST_TEST_WAIT_FOR_DEBUGGER";
207209
}
208210

209211
mtype::const_iterator it = s_mapping.find( param_name );
@@ -288,6 +290,9 @@ init( int& argc, char** argv )
288290
<< cla::named_parameter<std::string>( DETECT_MEM_LEAKS )
289291
- (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,cla::optional_value,
290292
cla::description = "Allows to switch between catching and ignoring memory leaks")
293+
<< cla::named_parameter<std::string>( DEPRECATED_TIMER_FORMAT )
294+
- (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,cla::optional_value,
295+
cla::description = "Forces HRF output for timing information to mimic the deprecated boost timer output")
291296
<< cla::dual_name_parameter<unit_test::output_format>( LOG_FORMAT + "|f" )
292297
- (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
293298
cla::description = "Specifies log format")
@@ -499,6 +504,14 @@ detect_fp_exceptions()
499504

500505
//____________________________________________________________________________//
501506

507+
bool
508+
deprecated_timer_format()
509+
{
510+
return retrieve_parameter( DEPRECATED_TIMER_FORMAT, s_cla_parser, false );
511+
}
512+
513+
//____________________________________________________________________________//
514+
502515
output_format
503516
report_format()
504517
{

include/boost/test/unit_test_parameters.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ BOOST_TEST_DECL bool catch_sys_errors();
4242
BOOST_TEST_DECL bool color_output();
4343
BOOST_TEST_DECL bool detect_fp_exceptions();
4444
BOOST_TEST_DECL long detect_memory_leaks();
45+
BOOST_TEST_DECL bool deprecated_timer_format();
4546
BOOST_TEST_DECL bool list_content();
4647
BOOST_TEST_DECL output_format log_format();
4748
BOOST_TEST_DECL unit_test::log_level log_level();

include/boost/test/utils/timer.hpp

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// (C) Copyright Jamie Allsop 2012.
1+
// (C) Copyright Jamie Allsop 2015.
22
// Distributed under the Boost Software License, Version 1.0.
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
@@ -11,11 +11,8 @@
1111
#ifndef BOOST_TEST_UTILS_TIMER_HPP
1212
#define BOOST_TEST_UTILS_TIMER_HPP
1313

14-
#ifdef BOOST_TEST_USE_DEPRECATED_TIMER
15-
#include <boost/timer.hpp>
16-
#else
14+
#include <boost/test/unit_test_parameters.hpp>
1715
#include <boost/timer/timer.hpp>
18-
#endif
1916
#include <sstream>
2017

2118
namespace boost {
@@ -26,54 +23,47 @@ namespace unit_test {
2623
// ************** opaque timer and elapsed types ************** //
2724
// ************************************************************************** //
2825

29-
#ifdef BOOST_TEST_USE_DEPRECATED_TIMER
26+
typedef boost::timer::cpu_timer timer_t;
27+
typedef boost::timer::cpu_times elapsed_t;
28+
typedef boost::timer::nanosecond_type nanoseconds_t;
3029

31-
typedef boost::timer timer_t;
32-
typedef unsigned long elapsed_t;
30+
inline long microsecond_cpu_time( elapsed_t elapsed )
31+
{
32+
return ( elapsed.user + elapsed.system )/1000;
33+
}
3334

34-
inline std::string to_string( elapsed_t elapsed )
35+
inline std::string deprecated_hrf_format( elapsed_t elapsed )
3536
{
3637
std::ostringstream output;
37-
if( elapsed % 1000 == 0 )
38+
long duration = microsecond_cpu_time( elapsed );
39+
if( duration % 1000 == 0 )
3840
{
39-
output << elapsed/1000 << "ms";
41+
output << duration/1000 << "ms";
4042
}
4143
else
4244
{
43-
output << elapsed << "mks";
45+
output << duration << "mks";
4446
}
4547
return output.str();
4648
}
4749

48-
inline std::string to_xml( elapsed_t elapsed )
49-
{
50-
std::ostringstream output;
51-
output << "<TestingTime>" << elapsed << "</TestingTime>";
52-
return output.str();
53-
}
54-
55-
inline bool has_time( const elapsed_t& elapsed )
56-
{
57-
return elapsed;
58-
}
59-
60-
#else
61-
62-
typedef boost::timer::cpu_timer timer_t;
63-
typedef boost::timer::cpu_times elapsed_t;
64-
6550
inline std::string to_string( elapsed_t elapsed )
6651
{
52+
if( runtime_config::deprecated_timer_format() )
53+
{
54+
return deprecated_hrf_format( elapsed );
55+
}
6756
return boost::timer::format( elapsed, 9, "%ws wall, %us user + %ss system = %ts CPU (%p%)" );
6857
}
6958

7059
inline std::string to_xml( elapsed_t elapsed )
7160
{
7261
std::ostringstream output;
73-
output << "<TestingTime>" << ( elapsed.user + elapsed.system ) << "</TestingTime>"
74-
<< "<WallTime>" << elapsed.wall << "</WallTime>"
75-
<< "<UserTime>" << elapsed.user << "</UserTime>"
76-
<< "<SystemTime>" << elapsed.system << "</SystemTime>";
62+
output << "<TestingTime>" << microsecond_cpu_time( elapsed ) << "</TestingTime>"
63+
<< "<CpuTime>" << ( elapsed.user + elapsed.system ) << "</CpuTime>"
64+
<< "<WallTime>" << elapsed.wall << "</WallTime>"
65+
<< "<UserTime>" << elapsed.user << "</UserTime>"
66+
<< "<SystemTime>" << elapsed.system << "</SystemTime>";
7767
return output.str();
7868
}
7969

@@ -82,8 +72,6 @@ inline bool has_time( const elapsed_t& elapsed )
8272
return elapsed.wall != 0 || elapsed.user != 0 || elapsed.system != 0;
8373
}
8474

85-
#endif
86-
8775
//____________________________________________________________________________//
8876

8977
} // namespace unit_test

0 commit comments

Comments
 (0)