root/examples/hp_timer.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. BOOST_AUTO_TEST_SUITE
  2. BOOST_AUTO_TEST_CASE_TEMPLATE
  3. BOOST_AUTO_TEST_CASE_TEMPLATE
  4. BOOST_AUTO_TEST_CASE_TEMPLATE
  5. BOOST_AUTO_TEST_CASE_TEMPLATE
  6. BOOST_AUTO_TEST_SUITE_END
  7. BOOST_AUTO_TEST_CASE
  8. BOOST_AUTO_TEST_CASE

   1 /******************************************************************************

   2 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/examples/hp_timer.cpp 2185 2017-10-13 10:14:17Z jmmcg $

   3 **

   4 ** Copyright (c) 2010 by J.M.McGuiness, coder@hussar.me.uk

   5 **

   6 ** This library is free software; you can redistribute it and/or

   7 ** modify it under the terms of the GNU Lesser General Public

   8 ** License as published by the Free Software Foundation; either

   9 ** version 2.1 of the License, or (at your option) any later version.

  10 **

  11 ** This library is distributed in the hope that it will be useful,

  12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of

  13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

  14 ** Lesser General Public License for more details.

  15 **

  16 ** You should have received a copy of the GNU Lesser General Public

  17 ** License along with this library; if not, write to the Free Software

  18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

  19 */
  20 
  21 #include "stdafx.h"
  22 
  23 #define BOOST_TEST_MODULE libjmmcg_tests
  24 #include <boost/test/included/unit_test.hpp>
  25 
  26 #include <boost/test/test_case_template.hpp>
  27 #include <boost/mpl/list.hpp>
  28 
  29 #include "core/thread_api_traits.hpp"
  30 
  31 typedef boost::mpl::list<jmmcg::ppd::heavyweight_threading, jmmcg::ppd::sequential_mode> thread_types;
  32 
  33 BOOST_AUTO_TEST_SUITE(hp_timer)
  34 
  35 BOOST_AUTO_TEST_CASE(check_cpu_frequency) {
  36         BOOST_CHECK_GT(jmmcg::cpu_timer::private_::start_ticks, 0);
  37         BOOST_CHECK_GT(jmmcg::cpu_timer::private_::start_UTC.time_of_day().total_milliseconds(), 0);
  38         BOOST_CHECK_GT(jmmcg::cpu_timer::private_::ticks_per_microsec.min, 0);
  39         BOOST_CHECK_GT(jmmcg::cpu_timer::private_::ticks_per_microsec.mean, jmmcg::cpu_timer::private_::ticks_per_microsec.min);
  40         BOOST_CHECK_GT(jmmcg::cpu_timer::private_::ticks_per_microsec.max, jmmcg::cpu_timer::private_::ticks_per_microsec.mean);
  41         BOOST_CHECK_GE(jmmcg::cpu_timer::private_::ticks_per_microsec.mean_average_dev, 0);
  42         BOOST_CHECK_LT(jmmcg::cpu_timer::private_::ticks_per_microsec.mean_average_dev, 1);
  43         BOOST_CHECK_GT(jmmcg::cpu_timer::out_of_order::get(), 0);
  44         BOOST_CHECK_GT(jmmcg::cpu_timer::in_order::get(), 0);
  45 }
  46 
  47 BOOST_AUTO_TEST_CASE_TEMPLATE(create_timer, Mdl, thread_types) {
  48         typedef jmmcg::hp_timer<jmmcg::ppd::platform_api,Mdl> hp_timer_t;
  49 
  50         hp_timer_t t;
  51         BOOST_CHECK_GT(t.start_up_count, 0);
  52         BOOST_CHECK_GT(t.to_usec(t.start_up_time), 0);
  53 }
  54 
  55 BOOST_AUTO_TEST_CASE_TEMPLATE(check_timer_counter_counts, Mdl, thread_types) {
  56         typedef jmmcg::hp_timer<jmmcg::ppd::platform_api,Mdl> hp_timer_t;
  57 
  58         hp_timer_t t;
  59         BOOST_CHECK_GE(t.current_count(), t.start_up_count);
  60         BOOST_CHECK_GE(t.current_count(), t.start_up_count);
  61         BOOST_CHECK_GE(t.current_count(), t.start_up_count);
  62         BOOST_CHECK_GE(t.current_count(), t.start_up_count);
  63         BOOST_CHECK_GE(t.current_count(), t.start_up_count);
  64         BOOST_CHECK_GE(t.current_count(), t.start_up_count);
  65         BOOST_CHECK_GE(t.current_count(), t.start_up_count);
  66 }
  67 
  68 BOOST_AUTO_TEST_CASE_TEMPLATE(check_timer_usec_simply_increments, Mdl, thread_types) {
  69         typedef jmmcg::hp_timer<jmmcg::ppd::platform_api,Mdl> hp_timer_t;
  70 
  71         hp_timer_t t;
  72         BOOST_CHECK_GE(t.to_usec(t.current_time()), t.start_up_count);
  73         BOOST_CHECK_GE(t.to_usec(t.current_time()), t.start_up_count);
  74         BOOST_CHECK_GE(t.to_usec(t.current_time()), t.start_up_count);
  75 }
  76 
  77 BOOST_AUTO_TEST_CASE_TEMPLATE(check_timer_usec_increments, Mdl, thread_types) {
  78         typedef jmmcg::hp_timer<jmmcg::ppd::platform_api,Mdl> hp_timer_t;
  79 
  80         hp_timer_t t;
  81         const typename hp_timer_t::value_type t1=t.to_usec(t.current_time());
  82         const typename hp_timer_t::value_type t2=t.to_usec(t.current_time());
  83         BOOST_CHECK_GE(t2, t1);
  84         const typename hp_timer_t::value_type t3=t.to_usec(t.current_time());
  85         BOOST_CHECK_GE(t3, t2);
  86         BOOST_CHECK_GT(t3, t1);
  87 }
  88 
  89 BOOST_AUTO_TEST_SUITE_END()
  90 
  91 BOOST_AUTO_TEST_SUITE(hp_interval)
  92 
  93 BOOST_AUTO_TEST_CASE_TEMPLATE(create_interval, Mdl, thread_types) {
  94         typedef jmmcg::hp_timer<jmmcg::ppd::platform_api,Mdl> hp_timer_t;
  95         typedef jmmcg::hp_interval<hp_timer_t> hp_interval_t;
  96 
  97         hp_timer_t timer;
  98         typename hp_timer_t::time_utc_t interval;
  99         hp_interval_t measure(timer,interval);
 100         BOOST_CHECK_GE(measure.timer.to_usec(measure.start), measure.timer.start_up_count);
 101 }
 102 
 103 BOOST_AUTO_TEST_CASE(measure_one_sec_thread_interval) {
 104         typedef jmmcg::ppd::api_threading_traits<jmmcg::ppd::platform_api,jmmcg::ppd::heavyweight_threading> thread_traits;
 105         typedef jmmcg::hp_timer<jmmcg::ppd::platform_api,jmmcg::ppd::heavyweight_threading> hp_timer_t;
 106         typedef jmmcg::hp_interval<hp_timer_t> hp_interval_t;
 107 
 108         const thread_traits::api_params_type::suspend_period_ms one_sec=1000;
 109         hp_timer_t timer;
 110         hp_timer_t::time_utc_t interval;
 111         {
 112                 hp_interval_t measure(timer,interval);
 113                 thread_traits::sleep(one_sec);
 114         }
 115         BOOST_CHECK_GT(timer.to_usec(interval), static_cast<hp_timer_t::value_type>(one_sec*0.9*1000));
 116         BOOST_CHECK_LT(timer.to_usec(interval), static_cast<hp_timer_t::value_type>(one_sec*2*1000));
 117 }
 118 
 119 BOOST_AUTO_TEST_CASE(measure_one_sec_seq_interval) {
 120         typedef jmmcg::ppd::api_threading_traits<jmmcg::ppd::platform_api,jmmcg::ppd::sequential_mode> thread_traits;
 121         typedef jmmcg::hp_timer<jmmcg::ppd::platform_api,jmmcg::ppd::sequential_mode> hp_timer_t;
 122         typedef jmmcg::hp_interval<hp_timer_t> hp_interval_t;
 123 
 124         const thread_traits::api_params_type::suspend_period_ms one_sec=1000;
 125         hp_timer_t timer;
 126         hp_timer_t::time_utc_t interval;
 127         {
 128                 hp_interval_t measure(timer,interval);
 129                 thread_traits::sleep(one_sec);
 130         }
 131         BOOST_CHECK_GE(timer.to_usec(interval), 0);
 132 }
 133 
 134 BOOST_AUTO_TEST_SUITE_END()

/* [<][>][^][v][top][bottom][index][help] */