Ticket #7397: boost_test_new_timer.diff
File boost_test_new_timer.diff, 20.3 KB (added by , 10 years ago) |
---|
-
boost/test/progress_monitor.hpp
18 18 // Boost.Test 19 19 #include <boost/test/tree/observer.hpp> 20 20 #include <boost/test/utils/trivial_singleton.hpp> 21 #include <boost/test/utils/timer.hpp> 21 22 22 23 // STL 23 24 #include <iosfwd> // for std::ostream& … … 41 42 void test_aborted(); 42 43 43 44 void test_unit_start( test_unit const& ) {} 44 void test_unit_finish( test_unit const&, unsigned long);45 void test_unit_finish( test_unit const&, elapsed_t ); 45 46 void test_unit_skipped( test_unit const& ); 46 47 void test_unit_aborted( test_unit const& ) {} 47 48 -
boost/test/impl/framework.ipp
40 40 #include <boost/test/detail/global_typedef.hpp> 41 41 42 42 #include <boost/test/utils/foreach.hpp> 43 #include <boost/test/utils/timer.hpp> 43 44 44 45 // Boost 45 #include <boost/timer.hpp>46 46 #include <boost/bind.hpp> 47 47 48 48 // STL … … 372 372 return true; 373 373 } 374 374 375 void test_unit_finish( test_unit const& tu, unit_test_monitor_t::error_level run_result, unsigned longelapsed )375 void test_unit_finish( test_unit const& tu, unit_test_monitor_t::error_level run_result, elapsed_t elapsed ) 376 376 { 377 377 // if run error is critical skip teardown, who knows what the state of the program at this point 378 378 if( !unit_test_monitor.is_critical_error( run_result ) ) { … … 412 412 m_curr_test_case = tc.p_id; 413 413 414 414 // execute the test case body 415 boost::timertc_timer;415 timer_t tc_timer; 416 416 unit_test_monitor_t::error_level run_result = unit_test_monitor.execute_and_translate( tc.p_test_func, tc.p_timeout ); 417 unsigned long elapsed = static_cast<unsigned long>( tc_timer.elapsed() * 1e6 ); 417 418 tc_timer.stop(); 419 elapsed_t elapsed = tc_timer.elapsed(); 418 420 419 421 // cleanup leftover context 420 422 m_context.clear(); … … 433 435 434 436 void test_suite_finish( test_suite const& ts ) 435 437 { 436 test_unit_finish( ts, unit_test_monitor_t::test_ok, 0);438 test_unit_finish( ts, unit_test_monitor_t::test_ok, elapsed_t() ); 437 439 } 438 440 439 441 ////////////////////////////////////////////////////////////////// -
boost/test/impl/test_tree.ipp
31 31 #include <boost/test/utils/foreach.hpp> 32 32 33 33 #include <boost/test/unit_test_parameters.hpp> 34 #include <boost/test/utils/timer.hpp> 34 35 35 36 // Boost 36 #include <boost/timer.hpp> 37 // none 37 38 38 39 // STL 39 40 #include <algorithm> -
boost/test/impl/compiler_log_formatter.ipp
24 24 #include <boost/test/utils/setcolor.hpp> 25 25 #include <boost/test/output/compiler_log_formatter.hpp> 26 26 #include <boost/test/unit_test_parameters.hpp> 27 #include <boost/test/utils/timer.hpp> 27 28 28 29 // Boost 29 30 #include <boost/version.hpp> … … 99 100 //____________________________________________________________________________// 100 101 101 102 void 102 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned longelapsed )103 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, elapsed_t elapsed ) 103 104 { 104 105 BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE ); 105 106 106 107 output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\""; 107 108 108 if( elapsed > 0) {109 if( has_time( elapsed ) ) { 109 110 output << "; testing time: "; 110 if( elapsed % 1000 == 0 ) 111 output << elapsed/1000 << "ms"; 112 else 113 output << elapsed << "mks"; 111 output << to_string( elapsed ); 114 112 } 115 113 116 114 output << std::endl; -
boost/test/impl/unit_test_log.ipp
28 28 #include <boost/test/output/compiler_log_formatter.hpp> 29 29 #include <boost/test/output/xml_log_formatter.hpp> 30 30 31 #include <boost/test/utils/timer.hpp> 32 31 33 // Boost 32 34 #include <boost/scoped_ptr.hpp> 33 35 #include <boost/io/ios_state.hpp> … … 177 179 //____________________________________________________________________________// 178 180 179 181 void 180 unit_test_log_t::test_unit_finish( test_unit const& tu, unsigned longelapsed )182 unit_test_log_t::test_unit_finish( test_unit const& tu, elapsed_t elapsed ) 181 183 { 182 184 if( s_log_impl().m_threshold_level > log_test_units ) 183 185 return; -
boost/test/impl/results_collector.ipp
24 24 #include <boost/test/tree/visitor.hpp> 25 25 #include <boost/test/tree/test_case_counter.hpp> 26 26 #include <boost/test/tree/traverse.hpp> 27 #include <boost/test/utils/timer.hpp> 27 28 28 29 // Boost 29 30 #include <boost/cstdlib.hpp> … … 204 205 //____________________________________________________________________________// 205 206 206 207 void 207 results_collector_t::test_unit_finish( test_unit const& tu, unsigned long)208 results_collector_t::test_unit_finish( test_unit const& tu, elapsed_t ) 208 209 { 209 210 if( tu.p_type == tut_suite ) { 210 211 results_collect_helper ch( s_rc_impl().m_results_store[tu.p_id], tu ); -
boost/test/impl/progress_monitor.ipp
24 24 #include <boost/test/tree/test_unit.hpp> 25 25 #include <boost/test/tree/test_case_counter.hpp> 26 26 #include <boost/test/tree/traverse.hpp> 27 #include <boost/test/utils/timer.hpp> 28 #include <boost/test/utils/progress.hpp> 27 29 28 30 // Boost 29 #include <boost/progress.hpp>30 31 #include <boost/scoped_ptr.hpp> 31 32 32 33 #include <boost/test/detail/suppress_warnings.hpp> … … 79 80 //____________________________________________________________________________// 80 81 81 82 void 82 progress_monitor_t::test_unit_finish( test_unit const& tu, unsigned long)83 progress_monitor_t::test_unit_finish( test_unit const& tu, elapsed_t ) 83 84 { 84 85 BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA ); 85 86 -
boost/test/impl/xml_log_formatter.ipp
23 23 #include <boost/test/utils/basic_cstring/io.hpp> 24 24 #include <boost/test/utils/xml_printer.hpp> 25 25 26 #include <boost/test/utils/timer.hpp> 27 26 28 // Boost 27 29 #include <boost/version.hpp> 28 30 … … 86 88 //____________________________________________________________________________// 87 89 88 90 void 89 xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned longelapsed )91 xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, elapsed_t elapsed ) 90 92 { 91 93 if( tu.p_type == tut_case ) 92 ostr << "<TestingTime>" << elapsed << "</TestingTime>";93 94 ostr << to_xml( elapsed ); 95 94 96 ostr << "</" << tu_type_name( tu ) << ">"; 95 97 } 96 98 -
boost/test/unit_test_log.hpp
28 28 #include <boost/test/utils/trivial_singleton.hpp> 29 29 #include <boost/test/utils/lazy_ostream.hpp> 30 30 31 #include <boost/test/utils/timer.hpp> 32 31 33 // Boost 32 34 33 35 // STL … … 96 98 void test_aborted(); 97 99 98 100 void test_unit_start( test_unit const& ); 99 void test_unit_finish( test_unit const&, unsigned longelapsed );101 void test_unit_finish( test_unit const&, elapsed_t elapsed ); 100 102 void test_unit_skipped( test_unit const& ); 101 103 void test_unit_aborted( test_unit const& ); 102 104 -
boost/test/results_collector.hpp
83 83 void test_aborted(); 84 84 85 85 void test_unit_start( test_unit const& ); 86 void test_unit_finish( test_unit const&, unsigned longelapsed );86 void test_unit_finish( test_unit const&, elapsed_t elapsed ); 87 87 void test_unit_skipped( test_unit const& ); 88 88 void test_unit_aborted( test_unit const& ); 89 89 -
boost/test/output/xml_log_formatter.hpp
19 19 #include <boost/test/detail/global_typedef.hpp> 20 20 #include <boost/test/unit_test_log_formatter.hpp> 21 21 22 #include <boost/test/utils/timer.hpp> 23 22 24 // STL 23 25 #include <cstddef> // std::size_t 24 26 … … 42 44 void log_build_info( std::ostream& ); 43 45 44 46 void test_unit_start( std::ostream&, test_unit const& tu ); 45 void test_unit_finish( std::ostream&, test_unit const& tu, unsigned longelapsed );47 void test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed ); 46 48 void test_unit_skipped( std::ostream&, test_unit const& tu ); 47 49 48 50 void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex ); -
boost/test/output/compiler_log_formatter.hpp
21 21 22 22 #include <boost/test/detail/suppress_warnings.hpp> 23 23 24 #include <boost/test/utils/timer.hpp> 25 24 26 //____________________________________________________________________________// 25 27 26 28 namespace boost { … … 39 41 void log_build_info( std::ostream& ); 40 42 41 43 void test_unit_start( std::ostream&, test_unit const& tu ); 42 void test_unit_finish( std::ostream&, test_unit const& tu, unsigned longelapsed );44 void test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed ); 43 45 void test_unit_skipped( std::ostream&, test_unit const& tu ); 44 46 45 47 void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex ); -
boost/test/utils/progress.hpp
1 // boost progress.hpp header file ------------------------------------------// 2 3 // Copyright Beman Dawes 1994-99. Distributed under the Boost 4 // Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 // See http://www.boost.org/libs/timer for documentation. 8 9 // Revision History 10 // 1 Dec 01 Add leading progress display strings (suggested by Toon Knapen) 11 // 20 May 01 Introduce several static_casts<> to eliminate warning messages 12 // (Fixed by Beman, reported by Herve Bronnimann) 13 // 12 Jan 01 Change to inline implementation to allow use without library 14 // builds. See docs for more rationale. (Beman Dawes) 15 // 22 Jul 99 Name changed to .hpp 16 // 16 Jul 99 Second beta 17 // 6 Jul 99 Initial boost version 18 19 #ifndef BOOST_TEST_UTILS_PROGRESS_DISPLAY_HPP 20 #define BOOST_TEST_UTILS_PROGRESS_DISPLAY_HPP 21 22 #include <boost/noncopyable.hpp> 23 #include <iostream> // for ostream, cout, etc 24 #include <string> // for string 25 26 namespace boost { 27 namespace unit_test { 28 29 // progress_display --------------------------------------------------------// 30 31 // progress_display displays an appropriate indication of 32 // progress at an appropriate place in an appropriate form. 33 34 // NOTE: (Jan 12, 2001) Tried to change unsigned long to boost::uintmax_t, but 35 // found some compilers couldn't handle the required conversion to double. 36 // Reverted to unsigned long until the compilers catch up. 37 38 class progress_display : private noncopyable 39 { 40 public: 41 explicit progress_display( unsigned long expected_count, 42 std::ostream & os = std::cout, 43 const std::string & s1 = "\n", //leading strings 44 const std::string & s2 = "", 45 const std::string & s3 = "" ) 46 // os is hint; implementation may ignore, particularly in embedded systems 47 : m_os(os), m_s1(s1), m_s2(s2), m_s3(s3) { restart(expected_count); } 48 49 void restart( unsigned long expected_count ) 50 // Effects: display appropriate scale 51 // Postconditions: count()==0, expected_count()==expected_count 52 { 53 _count = _next_tic_count = _tic = 0; 54 _expected_count = expected_count; 55 56 m_os << m_s1 << "0% 10 20 30 40 50 60 70 80 90 100%\n" 57 << m_s2 << "|----|----|----|----|----|----|----|----|----|----|" 58 << std::endl // endl implies flush, which ensures display 59 << m_s3; 60 if ( !_expected_count ) _expected_count = 1; // prevent divide by zero 61 } // restart 62 63 unsigned long operator+=( unsigned long increment ) 64 // Effects: Display appropriate progress tic if needed. 65 // Postconditions: count()== original count() + increment 66 // Returns: count(). 67 { 68 if ( (_count += increment) >= _next_tic_count ) { display_tic(); } 69 return _count; 70 } 71 72 unsigned long operator++() { return operator+=( 1 ); } 73 unsigned long count() const { return _count; } 74 unsigned long expected_count() const { return _expected_count; } 75 76 private: 77 std::ostream & m_os; // may not be present in all imps 78 const std::string m_s1; // string is more general, safer than 79 const std::string m_s2; // const char *, and efficiency or size are 80 const std::string m_s3; // not issues 81 82 unsigned long _count, _expected_count, _next_tic_count; 83 unsigned int _tic; 84 void display_tic() 85 { 86 // use of floating point ensures that both large and small counts 87 // work correctly. static_cast<>() is also used several places 88 // to suppress spurious compiler warnings. 89 unsigned int tics_needed = 90 static_cast<unsigned int>( 91 (static_cast<double>(_count)/_expected_count)*50.0 ); 92 do { m_os << '*' << std::flush; } while ( ++_tic < tics_needed ); 93 _next_tic_count = 94 static_cast<unsigned long>((_tic/50.0)*_expected_count); 95 if ( _count == _expected_count ) { 96 if ( _tic < 51 ) m_os << '*'; 97 m_os << std::endl; 98 } 99 } // display_tic 100 }; 101 102 } // namespace unit_test 103 } // namespace boost 104 105 #endif // BOOST_TEST_UTILS_PROGRESS_DISPLAY_HPP -
boost/test/utils/timer.hpp
1 // (C) Copyright Jamie Allsop 2012. 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 // See http://www.boost.org/libs/test for the library home page. 7 // 8 // Description : timer and elapsed types 9 // *************************************************************************** 10 11 #ifndef BOOST_TEST_UTILS_TIMER_HPP 12 #define BOOST_TEST_UTILS_TIMER_HPP 13 14 #ifdef BOOST_TEST_USE_DEPRECATED_TIMER 15 #include <boost/timer.hpp> 16 #else 17 #include <boost/timer/timer.hpp> 18 #endif 19 20 #include <sstream> 21 22 namespace boost { 23 namespace unit_test { 24 25 // ************************************************************************** // 26 // ************** opaque timer and elapsed types ************** // 27 // ************************************************************************** // 28 29 #ifdef BOOST_TEST_USE_DEPRECATED_TIMER 30 31 typedef boost::timer timer_t; 32 typedef unsigned long elapsed_t; 33 34 inline std::string to_string( elapsed_t elapsed ) 35 { 36 std::ostringstream output; 37 if( elapsed % 1000 == 0 ) 38 { 39 output << elapsed/1000 << "ms"; 40 } 41 else 42 { 43 output << elapsed << "mks"; 44 } 45 return output.str(); 46 } 47 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 65 inline std::string to_string( elapsed_t elapsed ) 66 { 67 return boost::timer::format( elapsed, 9, "%ws wall, %us user + %ss system = %ts CPU (%p%)" ); 68 } 69 70 inline std::string to_xml( elapsed_t elapsed ) 71 { 72 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>"; 77 return output.str(); 78 } 79 80 inline bool has_time( const elapsed_t& elapsed ) 81 { 82 return elapsed.wall != 0 || elapsed.user != 0 || elapsed.system != 0; 83 } 84 85 #endif 86 87 //____________________________________________________________________________// 88 89 } // namespace unit_test 90 } // namespace boost 91 92 #endif // BOOST_TEST_UTILS_TIMER_HPP 93 -
boost/test/unit_test_log_formatter.hpp
20 20 #include <boost/test/detail/log_level.hpp> 21 21 #include <boost/test/detail/fwd_decl.hpp> 22 22 23 #include <boost/test/utils/timer.hpp> 24 23 25 // STL 24 26 #include <iosfwd> 25 27 #include <string> // for std::string … … 92 94 virtual void log_build_info( std::ostream& ) = 0; 93 95 94 96 virtual void test_unit_start( std::ostream&, test_unit const& tu ) = 0; 95 virtual void test_unit_finish( std::ostream&, test_unit const& tu, unsigned longelapsed ) = 0;97 virtual void test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed ) = 0; 96 98 virtual void test_unit_skipped( std::ostream&, test_unit const& ) = 0; 97 99 98 100 virtual void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex ) = 0; -
boost/test/tree/observer.hpp
22 22 23 23 #include <boost/test/detail/suppress_warnings.hpp> 24 24 25 #include <boost/test/utils/timer.hpp> 26 25 27 //____________________________________________________________________________// 26 28 27 29 namespace boost { … … 39 41 virtual void test_aborted() {} 40 42 41 43 virtual void test_unit_start( test_unit const& ) {} 42 virtual void test_unit_finish( test_unit const&, unsigned long/* elapsed */ ) {}44 virtual void test_unit_finish( test_unit const&, elapsed_t /* elapsed */ ) {} 43 45 virtual void test_unit_skipped( test_unit const& ) {} 44 46 virtual void test_unit_aborted( test_unit const& ) {} 45 47 -
libs/test/test/Jamfile.v2
6 6 # See http://www.boost.org/libs/test for the library home page. 7 7 8 8 9 project 10 : requirements 11 <library>/boost/system//boost_system 12 <library>/boost/timer//boost_timer 13 ; 14 15 9 16 rule test-btl-lib ( test-rule : test-name : lib-name ? : pattern_file * : source_files * : extra-libs ? ) 10 17 { 11 18 source_files ?= $(test-name).cpp ;