1 | /* $Id: tstTime-2.cpp 5456 2007-10-24 01:04:51Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime Testcase - Simple RTTime test.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #include <iprt/time.h>
|
---|
22 | #include <iprt/stream.h>
|
---|
23 | #include <iprt/runtime.h>
|
---|
24 | #include <iprt/thread.h>
|
---|
25 | #include <VBox/sup.h>
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | int main()
|
---|
30 | {
|
---|
31 | unsigned cErrors = 0;
|
---|
32 | int i;
|
---|
33 | RTR3Init();
|
---|
34 | RTPrintf("tstTime-2: TESTING...\n");
|
---|
35 |
|
---|
36 | /*
|
---|
37 | * RTNanoTimeTS() shall never return something which
|
---|
38 | * is less or equal to the return of the previous call.
|
---|
39 | */
|
---|
40 |
|
---|
41 | RTTimeSystemNanoTS(); RTTimeNanoTS(); RTThreadYield();
|
---|
42 | uint64_t u64RTStartTS = RTTimeNanoTS();
|
---|
43 | uint64_t u64OSStartTS = RTTimeSystemNanoTS();
|
---|
44 | #define NUMBER_OF_CALLS (100*_1M)
|
---|
45 |
|
---|
46 | for (i = 0; i < NUMBER_OF_CALLS; i++)
|
---|
47 | RTTimeNanoTS();
|
---|
48 |
|
---|
49 | uint64_t u64RTElapsedTS = RTTimeNanoTS();
|
---|
50 | uint64_t u64OSElapsedTS = RTTimeSystemNanoTS();
|
---|
51 | u64RTElapsedTS -= u64RTStartTS;
|
---|
52 | u64OSElapsedTS -= u64OSStartTS;
|
---|
53 | int64_t i64Diff = u64OSElapsedTS >= u64RTElapsedTS ? u64OSElapsedTS - u64RTElapsedTS : u64RTElapsedTS - u64OSElapsedTS;
|
---|
54 | if (i64Diff > (int64_t)(u64OSElapsedTS / 1000))
|
---|
55 | {
|
---|
56 | RTPrintf("tstTime-2: error: total time differs too much! u64OSElapsedTS=%#llx u64RTElapsedTS=%#llx delta=%lld\n",
|
---|
57 | u64OSElapsedTS, u64RTElapsedTS, u64OSElapsedTS - u64RTElapsedTS);
|
---|
58 | cErrors++;
|
---|
59 | }
|
---|
60 | else
|
---|
61 | RTPrintf("tstTime-2: total time difference: u64OSElapsedTS=%#llx u64RTElapsedTS=%#llx delta=%lld\n",
|
---|
62 | u64OSElapsedTS, u64RTElapsedTS, u64OSElapsedTS - u64RTElapsedTS);
|
---|
63 |
|
---|
64 | RTPrintf("tstTime-2: %u calls to RTTimeNanoTS\n", NUMBER_OF_CALLS);
|
---|
65 | RTPrintf("tstTime-2: RTTimeDbgSteps -> %u (%d ppt)\n", RTTimeDbgSteps(), ((uint64_t)RTTimeDbgSteps() * 1000) / NUMBER_OF_CALLS);
|
---|
66 | RTPrintf("tstTime-2: RTTimeDbgExpired -> %u (%d ppt)\n", RTTimeDbgExpired(), ((uint64_t)RTTimeDbgExpired() * 1000) / NUMBER_OF_CALLS);
|
---|
67 | RTPrintf("tstTime-2: RTTimeDbgBad -> %u (%d ppt)\n", RTTimeDbgBad(), ((uint64_t)RTTimeDbgBad() * 1000) / NUMBER_OF_CALLS);
|
---|
68 | RTPrintf("tstTime-2: RTTimeDbgRaces -> %u (%d ppt)\n", RTTimeDbgRaces(), ((uint64_t)RTTimeDbgRaces() * 1000) / NUMBER_OF_CALLS);
|
---|
69 |
|
---|
70 | if (!cErrors)
|
---|
71 | RTPrintf("tstTime-2: SUCCESS\n");
|
---|
72 | else
|
---|
73 | RTPrintf("tstTime-2: FAILURE - %d errors\n", cErrors);
|
---|
74 | return !!cErrors;
|
---|
75 | }
|
---|