VirtualBox

Changeset 6266 in vbox


Ignore:
Timestamp:
Jan 7, 2008 9:58:54 PM (17 years ago)
Author:
vboxsync
Message:

tstTime-4: Check that RTTimeNanoTS and RTTimeSystemNanoTS are using the same source so that we don't mess up should GIP be enabled late or disabled early.

Location:
trunk/src/VBox/Runtime/testcase
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r5999 r6266  
    5858        tstTime-2 \
    5959        tstTime-3 \
     60        tstTime-4 \
    6061        tstTimer \
    6162        tstTimeSpec \
     
    8889TEMPLATE = VBOXR3TSTEXE
    8990
     91tstTime_SOURCES = tstTime.cpp
     92
     93tstTime-2_SOURCES = tstTime-2.cpp
     94
     95tstTime-3_SOURCES = tstTime-3.cpp
     96
     97tstTime-4_SOURCES = tstTime-4.cpp
     98
     99tstTimeSpec_SOURCES = tstTimeSpec.cpp
    90100
    91101tstTimer_SOURCES = tstTimer.cpp
     
    93103tstTSC_SOURCES = tstTSC.cpp
    94104tstTSC_CXXFLAGS.linux += -O3
    95 
    96 tstTime_SOURCES = tstTime.cpp
    97 
    98 tstTime-2_SOURCES = tstTime-2.cpp
    99 
    100 tstTime-3_SOURCES = tstTime-3.cpp
    101 
    102 tstTimeSpec_SOURCES = tstTimeSpec.cpp
    103105
    104106tstStrFormat_SOURCES = tstStrFormat.cpp
  • trunk/src/VBox/Runtime/testcase/tstTime-4.cpp

    r6257 r6266  
    11/* $Id$ */
    22/** @file
    3  * innotek Portable Runtime Testcase - Simple RTTime test.
     3 * innotek Portable Runtime Testcase - Simple RTTime vs. RTTimeSystem test.
    44 */
    55
     
    3030#include <iprt/time.h>
    3131#include <iprt/stream.h>
    32 #include <iprt/runtime.h>
     32#include <iprt/initterm.h>
    3333#include <iprt/thread.h>
    3434#include <VBox/sup.h>
     
    3939{
    4040    unsigned cErrors = 0;
    41     int i;
     41
    4242    RTR3Init();
    43     RTPrintf("tstTime-2: TESTING...\n");
     43    RTPrintf("tstTime-4: TESTING...\n");
    4444
    4545    /*
    46      * RTNanoTimeTS() shall never return something which
    47      * is less or equal to the return of the previous call.
     46     * Check that RTTimeSystemNanoTS doesn't go backwards and
     47     * isn't too far from RTTimeNanoTS().
    4848     */
     49    RTTimeSystemNanoTS(); RTTimeNanoTS(); RTThreadYield(); /* warmup */
     50    const uint64_t SysStartTS = RTTimeSystemNanoTS();
     51    const uint64_t GipStartTS = RTTimeNanoTS();
     52    uint64_t SysPrevTS, GipPrevTS;
     53    do
     54    {
     55        SysPrevTS = RTTimeSystemNanoTS();
     56        GipPrevTS = RTTimeNanoTS();
     57        if (SysPrevTS < SysStartTS)
     58        {
     59            cErrors++;
     60            RTPrintf("tstTime-4: Bad Sys time!\n");
     61        }
     62        if (GipPrevTS < GipStartTS)
     63        {
     64            cErrors++;
     65            RTPrintf("tstTime-4: Bad Gip time!\n");
     66        }
     67        int64_t Delta = GipPrevTS - SysPrevTS;
     68        if (Delta > 0 ? Delta > 100000000 /* 100 ms */ : Delta < -100000000 /* -100 ms */)
     69        {
     70            cErrors++;
     71            RTPrintf("tstTime-4: Delta=%lld!\n", Delta);
     72        }
    4973
    50     RTTimeSystemNanoTS(); RTTimeNanoTS(); RTThreadYield();
    51     uint64_t u64RTStartTS = RTTimeNanoTS();
    52     uint64_t u64OSStartTS = RTTimeSystemNanoTS();
    53 #define NUMBER_OF_CALLS (100*_1M)
     74    } while (SysPrevTS - SysStartTS < 2000000000 /* 2s */);
    5475
    55     for (i = 0; i < NUMBER_OF_CALLS; i++)
    56         RTTimeNanoTS();
    57 
    58     uint64_t u64RTElapsedTS = RTTimeNanoTS();
    59     uint64_t u64OSElapsedTS = RTTimeSystemNanoTS();
    60     u64RTElapsedTS -= u64RTStartTS;
    61     u64OSElapsedTS -= u64OSStartTS;
    62     int64_t i64Diff = u64OSElapsedTS >= u64RTElapsedTS ? u64OSElapsedTS - u64RTElapsedTS : u64RTElapsedTS - u64OSElapsedTS;
    63     if (i64Diff > (int64_t)(u64OSElapsedTS / 1000))
    64     {
    65         RTPrintf("tstTime-2: error: total time differs too much! u64OSElapsedTS=%#llx u64RTElapsedTS=%#llx delta=%lld\n",
    66                  u64OSElapsedTS, u64RTElapsedTS, u64OSElapsedTS - u64RTElapsedTS);
    67         cErrors++;
    68     }
    69     else
    70         RTPrintf("tstTime-2: total time difference: u64OSElapsedTS=%#llx u64RTElapsedTS=%#llx delta=%lld\n",
    71                  u64OSElapsedTS, u64RTElapsedTS, u64OSElapsedTS - u64RTElapsedTS);
    72 
    73     RTPrintf("tstTime-2: %u calls to RTTimeNanoTS\n", NUMBER_OF_CALLS);
    74     RTPrintf("tstTime-2: RTTimeDbgSteps   -> %u (%d ppt)\n", RTTimeDbgSteps(),   ((uint64_t)RTTimeDbgSteps() * 1000) / NUMBER_OF_CALLS);
    75     RTPrintf("tstTime-2: RTTimeDbgExpired -> %u (%d ppt)\n", RTTimeDbgExpired(), ((uint64_t)RTTimeDbgExpired() * 1000) / NUMBER_OF_CALLS);
    76     RTPrintf("tstTime-2: RTTimeDbgBad     -> %u (%d ppt)\n", RTTimeDbgBad(),     ((uint64_t)RTTimeDbgBad() * 1000) / NUMBER_OF_CALLS);
    77     RTPrintf("tstTime-2: RTTimeDbgRaces   -> %u (%d ppt)\n", RTTimeDbgRaces(),   ((uint64_t)RTTimeDbgRaces() * 1000) / NUMBER_OF_CALLS);
    7876
    7977    if (!cErrors)
    80         RTPrintf("tstTime-2: SUCCESS\n");
     78        RTPrintf("tstTime-4: SUCCESS\n");
    8179    else
    82         RTPrintf("tstTime-2: FAILURE - %d errors\n", cErrors);
     80        RTPrintf("tstTime-4: FAILURE - %d errors\n", cErrors);
    8381    return !!cErrors;
    8482}
     83
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette