Ticket #7397: boost_test_new_timer.diff

File boost_test_new_timer.diff, 20.3 KB (added by Jamie Allsop <ja11sop@…>, 10 years ago)

boost_test_new_timer.diff

  • boost/test/progress_monitor.hpp

     
    1818// Boost.Test
    1919#include <boost/test/tree/observer.hpp>
    2020#include <boost/test/utils/trivial_singleton.hpp>
     21#include <boost/test/utils/timer.hpp>
    2122
    2223// STL
    2324#include <iosfwd>   // for std::ostream&
     
    4142    void    test_aborted();
    4243
    4344    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 );
    4546    void    test_unit_skipped( test_unit const& );
    4647    void    test_unit_aborted( test_unit const& ) {}
    4748
  • boost/test/impl/framework.ipp

     
    4040#include <boost/test/detail/global_typedef.hpp>
    4141
    4242#include <boost/test/utils/foreach.hpp>
     43#include <boost/test/utils/timer.hpp>
    4344
    4445// Boost
    45 #include <boost/timer.hpp>
    4646#include <boost/bind.hpp>
    4747
    4848// STL
     
    372372        return true;
    373373    }
    374374
    375     void            test_unit_finish( test_unit const& tu, unit_test_monitor_t::error_level run_result, unsigned long elapsed )
     375    void            test_unit_finish( test_unit const& tu, unit_test_monitor_t::error_level run_result, elapsed_t elapsed )
    376376    {
    377377        // if run error is critical skip teardown, who knows what the state of the program at this point
    378378        if( !unit_test_monitor.is_critical_error( run_result ) ) {
     
    412412        m_curr_test_case = tc.p_id;
    413413
    414414        // execute the test case body
    415         boost::timer tc_timer;
     415        timer_t tc_timer;
    416416        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();
    418420
    419421        // cleanup leftover context
    420422        m_context.clear();
     
    433435
    434436    void            test_suite_finish( test_suite const& ts )
    435437    {
    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() );
    437439    }
    438440
    439441    //////////////////////////////////////////////////////////////////
  • boost/test/impl/test_tree.ipp

     
    3131#include <boost/test/utils/foreach.hpp>
    3232
    3333#include <boost/test/unit_test_parameters.hpp>
     34#include <boost/test/utils/timer.hpp>
    3435
    3536// Boost
    36 #include <boost/timer.hpp>
     37// none
    3738
    3839// STL
    3940#include <algorithm>
  • boost/test/impl/compiler_log_formatter.ipp

     
    2424#include <boost/test/utils/setcolor.hpp>
    2525#include <boost/test/output/compiler_log_formatter.hpp>
    2626#include <boost/test/unit_test_parameters.hpp>
     27#include <boost/test/utils/timer.hpp>
    2728
    2829// Boost
    2930#include <boost/version.hpp>
     
    99100//____________________________________________________________________________//
    100101
    101102void
    102 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed )
     103compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, elapsed_t elapsed )
    103104{
    104105    BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE );
    105106
    106107    output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\"";
    107108
    108     if( elapsed > 0 ) {
     109    if( has_time( elapsed ) ) {
    109110        output << "; testing time: ";
    110         if( elapsed % 1000 == 0 )
    111             output << elapsed/1000 << "ms";
    112         else
    113             output << elapsed << "mks";
     111        output << to_string( elapsed );
    114112    }
    115113
    116114    output << std::endl;
  • boost/test/impl/unit_test_log.ipp

     
    2828#include <boost/test/output/compiler_log_formatter.hpp>
    2929#include <boost/test/output/xml_log_formatter.hpp>
    3030
     31#include <boost/test/utils/timer.hpp>
     32
    3133// Boost
    3234#include <boost/scoped_ptr.hpp>
    3335#include <boost/io/ios_state.hpp>
     
    177179//____________________________________________________________________________//
    178180
    179181void
    180 unit_test_log_t::test_unit_finish( test_unit const& tu, unsigned long elapsed )
     182unit_test_log_t::test_unit_finish( test_unit const& tu, elapsed_t elapsed )
    181183{
    182184    if( s_log_impl().m_threshold_level > log_test_units )
    183185        return;
  • boost/test/impl/results_collector.ipp

     
    2424#include <boost/test/tree/visitor.hpp>
    2525#include <boost/test/tree/test_case_counter.hpp>
    2626#include <boost/test/tree/traverse.hpp>
     27#include <boost/test/utils/timer.hpp>
    2728
    2829// Boost
    2930#include <boost/cstdlib.hpp>
     
    204205//____________________________________________________________________________//
    205206
    206207void
    207 results_collector_t::test_unit_finish( test_unit const& tu, unsigned long )
     208results_collector_t::test_unit_finish( test_unit const& tu, elapsed_t )
    208209{
    209210    if( tu.p_type == tut_suite ) {
    210211        results_collect_helper ch( s_rc_impl().m_results_store[tu.p_id], tu );
  • boost/test/impl/progress_monitor.ipp

     
    2424#include <boost/test/tree/test_unit.hpp>
    2525#include <boost/test/tree/test_case_counter.hpp>
    2626#include <boost/test/tree/traverse.hpp>
     27#include <boost/test/utils/timer.hpp>
     28#include <boost/test/utils/progress.hpp>
    2729
    2830// Boost
    29 #include <boost/progress.hpp>
    3031#include <boost/scoped_ptr.hpp>
    3132
    3233#include <boost/test/detail/suppress_warnings.hpp>
     
    7980//____________________________________________________________________________//
    8081
    8182void
    82 progress_monitor_t::test_unit_finish( test_unit const& tu, unsigned long )
     83progress_monitor_t::test_unit_finish( test_unit const& tu, elapsed_t )
    8384{
    8485    BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA );
    8586
  • boost/test/impl/xml_log_formatter.ipp

     
    2323#include <boost/test/utils/basic_cstring/io.hpp>
    2424#include <boost/test/utils/xml_printer.hpp>
    2525
     26#include <boost/test/utils/timer.hpp>
     27
    2628// Boost
    2729#include <boost/version.hpp>
    2830
     
    8688//____________________________________________________________________________//
    8789
    8890void
    89 xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed )
     91xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, elapsed_t elapsed )
    9092{
    9193    if( tu.p_type == tut_case )
    92         ostr << "<TestingTime>" << elapsed << "</TestingTime>";
    93        
     94        ostr << to_xml( elapsed );
     95
    9496    ostr << "</" << tu_type_name( tu ) << ">";
    9597}
    9698
  • boost/test/unit_test_log.hpp

     
    2828#include <boost/test/utils/trivial_singleton.hpp>
    2929#include <boost/test/utils/lazy_ostream.hpp>
    3030
     31#include <boost/test/utils/timer.hpp>
     32
    3133// Boost
    3234
    3335// STL
     
    9698    void                test_aborted();
    9799
    98100    void                test_unit_start( test_unit const& );
    99     void                test_unit_finish( test_unit const&, unsigned long elapsed );
     101    void                test_unit_finish( test_unit const&, elapsed_t elapsed );
    100102    void                test_unit_skipped( test_unit const& );
    101103    void                test_unit_aborted( test_unit const& );
    102104
  • boost/test/results_collector.hpp

     
    8383    void                test_aborted();
    8484
    8585    void                test_unit_start( test_unit const& );
    86     void                test_unit_finish( test_unit const&, unsigned long elapsed );
     86    void                test_unit_finish( test_unit const&, elapsed_t elapsed );
    8787    void                test_unit_skipped( test_unit const& );
    8888    void                test_unit_aborted( test_unit const& );
    8989
  • boost/test/output/xml_log_formatter.hpp

     
    1919#include <boost/test/detail/global_typedef.hpp>
    2020#include <boost/test/unit_test_log_formatter.hpp>
    2121
     22#include <boost/test/utils/timer.hpp>
     23
    2224// STL
    2325#include <cstddef> // std::size_t
    2426
     
    4244    void    log_build_info( std::ostream& );
    4345
    4446    void    test_unit_start( std::ostream&, test_unit const& tu );
    45     void    test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed );
     47    void    test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed );
    4648    void    test_unit_skipped( std::ostream&, test_unit const& tu );
    4749
    4850    void    log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex );
  • boost/test/output/compiler_log_formatter.hpp

     
    2121
    2222#include <boost/test/detail/suppress_warnings.hpp>
    2323
     24#include <boost/test/utils/timer.hpp>
     25
    2426//____________________________________________________________________________//
    2527
    2628namespace boost {
     
    3941    void    log_build_info( std::ostream& );
    4042
    4143    void    test_unit_start( std::ostream&, test_unit const& tu );
    42     void    test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed );
     44    void    test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed );
    4345    void    test_unit_skipped( std::ostream&, test_unit const& tu );
    4446
    4547    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
     26namespace boost {
     27namespace 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
     38class 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
     22namespace boost {
     23namespace unit_test {
     24
     25// ************************************************************************** //
     26// **************          opaque timer and elapsed types      ************** //
     27// ************************************************************************** //
     28
     29#ifdef BOOST_TEST_USE_DEPRECATED_TIMER
     30
     31typedef boost::timer timer_t;
     32typedef unsigned long elapsed_t;
     33
     34inline 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
     48inline std::string to_xml( elapsed_t elapsed )
     49{
     50    std::ostringstream output;
     51    output << "<TestingTime>" << elapsed << "</TestingTime>";
     52    return output.str();
     53}
     54
     55inline bool has_time( const elapsed_t& elapsed )
     56{
     57    return elapsed;
     58}
     59
     60#else
     61
     62typedef boost::timer::cpu_timer timer_t;
     63typedef boost::timer::cpu_times elapsed_t;
     64
     65inline 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
     70inline 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
     80inline 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

     
    2020#include <boost/test/detail/log_level.hpp>
    2121#include <boost/test/detail/fwd_decl.hpp>
    2222
     23#include <boost/test/utils/timer.hpp>
     24
    2325// STL
    2426#include <iosfwd>
    2527#include <string> // for std::string
     
    9294    virtual void        log_build_info( std::ostream& ) = 0;
    9395
    9496    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 long elapsed ) = 0;
     97    virtual void        test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed ) = 0;
    9698    virtual void        test_unit_skipped( std::ostream&, test_unit const& ) = 0;
    9799
    98100    virtual void        log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex ) = 0;
  • boost/test/tree/observer.hpp

     
    2222
    2323#include <boost/test/detail/suppress_warnings.hpp>
    2424
     25#include <boost/test/utils/timer.hpp>
     26
    2527//____________________________________________________________________________//
    2628
    2729namespace boost {
     
    3941    virtual void    test_aborted() {}
    4042
    4143    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 */ ) {}
    4345    virtual void    test_unit_skipped( test_unit const& ) {}
    4446    virtual void    test_unit_aborted( test_unit const& ) {}
    4547
  • libs/test/test/Jamfile.v2

     
    66#  See http://www.boost.org/libs/test for the library home page.
    77
    88
     9project
     10    : requirements
     11      <library>/boost/system//boost_system
     12      <library>/boost/timer//boost_timer
     13    ;
     14
     15
    916rule test-btl-lib ( test-rule : test-name : lib-name ? : pattern_file * : source_files * : extra-libs ? )
    1017{
    1118   source_files ?= $(test-name).cpp ;