| 
      1
     | 
    
      //----------------------------------------------------------------------------
 
     | 
  
  
    | 
      2
     | 
    
      ///
 
     | 
  
  
    | 
      3
     | 
    
      /// \file   tests_lrtimer.cpp
 
     | 
  
  
    | 
      4
     | 
    
      ///
 
     | 
  
  
    | 
      5
     | 
    
      /// \brief  Check time validity
 
     | 
  
  
    | 
      6
     | 
    
      ///
 
     | 
  
  
    | 
      7
     | 
    
      /// \date   20241120
 
     | 
  
  
    | 
      8
     | 
    
      /// \author Maximilian Seesslen <mes@seesslen.net>
 
     | 
  
  
    | 
      9
     | 
    
      ///
 
     | 
  
  
    | 
      10
     | 
    
      //----------------------------------------------------------------------------
 
     | 
  
  
    | 
      11
     | 
    
      
 
     | 
  
  
    | 
      12
     | 
    
      
 
     | 
  
  
    | 
      13
     | 
    
      //---Documentation------------------------------------------------------------
 
     | 
  
  
    | 
      14
     | 
    
      
 
     | 
  
  
    | 
      15
     | 
    
      
 
     | 
  
  
    | 
      16
     | 
    
      //---Includes -----------------------------------------------------------------
 
     | 
  
  
    | 
      17
     | 
    
      
 
     | 
  
  
    | 
      18
     | 
    
      
 
     | 
  
  
    | 
      19
     | 
    
      //---General--------------------------
 
     | 
  
  
    | 
      20
     | 
    
      
 
     | 
  
  
    | 
      21
     | 
    
      #if defined ( CATCH2 )
 
     | 
  
  
    | 
      22
     | 
    
         #include <catch2/catch_test_macros.hpp>
 
     | 
  
  
    | 
      23
     | 
    
      #elif defined ( CATCH )
 
     | 
  
  
    | 
      24
     | 
    
         #include <catch/catch.hpp>
 
     | 
  
  
    | 
      25
     | 
    
      #else
 
     | 
  
  
    | 
      26
     | 
    
         #error "Either 'catch' or 'catch2' has to be installed"
 
     | 
  
  
    | 
      27
     | 
    
      #endif
 
     | 
  
  
    | 
      28
     | 
    
      
 
     | 
  
  
    | 
      29
     | 
    
      #include <QDebug>
 
     | 
  
  
    | 
      30
     | 
    
      
 
     | 
  
  
    | 
      31
     | 
    
      //--- Own ----------------------------
 
     | 
  
  
    | 
      32
     | 
    
      
 
     | 
  
  
    | 
      33
     | 
    
      #include <biwak/timer.hpp>
 
     | 
  
  
    | 
      34
     | 
    
      #include <lepto/imago.hpp>
 
     | 
  
  
    | 
      35
     | 
    
      
 
     | 
  
  
    | 
      36
     | 
    
      
 
     | 
  
  
    | 
      37
     | 
    
      //---Defines-------------------------------------------------------------------
 
     | 
  
  
    | 
      38
     | 
    
      
 
     | 
  
  
    | 
      39
     | 
    
      
 
     | 
  
  
    | 
      40
     | 
    
      #define TEST_ALL
 
     | 
  
  
    | 
      41
     | 
    
      #define STOP_ON_FAIL
 
     | 
  
  
    | 
      42
     | 
    
      
 
     | 
  
  
    | 
      43
     | 
    
      
 
     | 
  
  
    | 
      44
     | 
    
      //---Implementation------------------------------------------------------------
 
     | 
  
  
    | 
      45
     | 
    
      
 
     | 
  
  
    | 
      46
     | 
    
      
 
     | 
  
  
    | 
      47
     | 
    
      TEST_CASE( "LRTimer", "[default]" ) {
     | 
  
  
    | 
      48
     | 
    
      
 
     | 
  
  
    | 
      49
     | 
    
         /* Let one exactly pass second.
 
     | 
  
  
    | 
      50
     | 
    
          * The difference in the lrtimer has to be around 1000.
 
     | 
  
  
    | 
      51
     | 
    
          */
 
     | 
  
  
    | 
      52
     | 
    
         SECTION( "Standard" )
 
     | 
  
  
    | 
      53
     | 
    
         {
     | 
  
  
    | 
      54
     | 
    
            /* The lrtimer has an resolution of 1ms
 
     | 
  
  
    | 
      55
     | 
    
             * The hrtimer has an resolution of 1ms/0x10000
 
     | 
  
  
    | 
      56
     | 
    
             */
 
     | 
  
  
    | 
      57
     | 
    
            lrtimer_t lrstart;
 
     | 
  
  
    | 
      58
     | 
    
            lrtimer_t lrstop;
 
     | 
  
  
    | 
      59
     | 
    
            lrtimer_t lrdiff;
 
     | 
  
  
    | 
      60
     | 
    
      
 
     | 
  
  
    | 
      61
     | 
    
            time_t t=time( nullptr );
 
     | 
  
  
    | 
      62
     | 
    
            struct tm start=*gmtime( &t );
 
     | 
  
  
    | 
      63
     | 
    
            struct tm stop;
 
     | 
  
  
    | 
      64
     | 
    
            do{
     | 
  
  
    | 
      65
     | 
    
               t=time( nullptr );
 
     | 
  
  
    | 
      66
     | 
    
               stop=*gmtime( &t );
 
     | 
  
  
    | 
      67
     | 
    
            }while( start.tm_sec == stop.tm_sec );
 
     | 
  
  
    | 
      68
     | 
    
      
 
     | 
  
  
    | 
      69
     | 
    
            lrstart=lrNow();
 
     | 
  
  
    | 
      70
     | 
    
            start=stop;
 
     | 
  
  
    | 
      71
     | 
    
            do{
     | 
  
  
    | 
      72
     | 
    
               t=time( nullptr );
 
     | 
  
  
    | 
      73
     | 
    
               stop=*gmtime( &t );
 
     | 
  
  
    | 
      74
     | 
    
            }while( start.tm_sec == stop.tm_sec );
 
     | 
  
  
    | 
      75
     | 
    
      
 
     | 
  
  
    | 
      76
     | 
    
            lrstop=lrNow();
 
     | 
  
  
    | 
      77
     | 
    
      
 
     | 
  
  
    | 
      78
     | 
    
            lrdiff=lrstop - lrstart;
 
     | 
  
  
    | 
      79
     | 
    
            INFO( "lrNow jitter" )
 
     | 
  
  
    | 
      80
     | 
    
            REQUIRE( matchesJittered( lrdiff, 1000, 0 ) );
 
     | 
  
  
    | 
      81
     | 
    
         }
 
     | 
  
  
    | 
      82
     | 
    
      }
 
     | 
  
  
    | 
      83
     | 
    
      
 
     | 
  
  
    | 
      84
     | 
    
      
 
     | 
  
  
    | 
      85
     | 
    
      //---fin-----------------------------------------------------------------------
 
     |