VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstTime-2.cpp@ 918

Last change on this file since 918 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1/* $Id: tstTime-2.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime Testcase - Simple RTTime test.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#ifdef __WIN__
26# include <Windows.h>
27
28#elif defined __L4__
29
30#else /* posix */
31# include <sys/time.h>
32#endif
33
34#include <iprt/time.h>
35#include <iprt/stream.h>
36#include <iprt/runtime.h>
37#include <iprt/thread.h>
38#include <VBox/sup.h>
39
40DECLINLINE(uint64_t) OSNanoTS(void)
41{
42#ifdef __WIN__
43 uint64_t u64; /* manual say larger integer, should be safe to assume it's the same. */
44 GetSystemTimeAsFileTime((LPFILETIME)&u64);
45 return u64 * 100;
46
47#elif defined __L4__
48 /** @todo fix a different timesource on l4. */
49 return RTTimeNanoTS();
50
51#else /* posix */
52
53 struct timeval tv;
54 gettimeofday(&tv, NULL);
55 return (uint64_t)tv.tv_sec * (uint64_t)(1000 * 1000 * 1000)
56 + (uint64_t)(tv.tv_usec * 1000);
57#endif
58}
59
60
61
62int main()
63{
64 unsigned cErrors = 0;
65 int i;
66 RTR3Init();
67SUPInit();
68 RTPrintf("tstTime-2: TESTING...\n");
69
70 /*
71 * RTNanoTimeTS() shall never return something which
72 * is less or equal to the return of the previous call.
73 */
74
75 OSNanoTS(); RTTimeNanoTS(); RTThreadYield();
76 uint64_t u64RTStartTS = RTTimeNanoTS();
77 uint64_t u64OSStartTS = OSNanoTS();
78#define NUMBER_OF_CALLS (100*_1M)
79
80 for (i = 0; i < NUMBER_OF_CALLS; i++)
81 RTTimeNanoTS();
82
83 uint64_t u64RTElapsedTS = RTTimeNanoTS();
84 uint64_t u64OSElapsedTS = OSNanoTS();
85 u64RTElapsedTS -= u64RTStartTS;
86 u64OSElapsedTS -= u64OSStartTS;
87 int64_t i64Diff = u64OSElapsedTS >= u64RTElapsedTS ? u64OSElapsedTS - u64RTElapsedTS : u64RTElapsedTS - u64OSElapsedTS;
88 if (i64Diff > (int64_t)(u64OSElapsedTS / 1000))
89 {
90 RTPrintf("tstTime-2: error: total time differs too much! u64OSElapsedTS=%#llx u64RTElapsedTS=%#llx delta=%lld\n",
91 u64OSElapsedTS, u64RTElapsedTS, u64OSElapsedTS - u64RTElapsedTS);
92 cErrors++;
93 }
94 else
95 RTPrintf("tstTime-2: total time difference: u64OSElapsedTS=%#llx u64RTElapsedTS=%#llx delta=%lld\n",
96 u64OSElapsedTS, u64RTElapsedTS, u64OSElapsedTS - u64RTElapsedTS);
97
98#if defined __WIN__ || defined __LINUX__
99 RTPrintf("tstTime-2: RTTime1nsSteps -> %u out of %u calls\n", RTTime1nsSteps(), NUMBER_OF_CALLS);
100#endif
101 if (!cErrors)
102 RTPrintf("tstTime-2: SUCCESS\n");
103 else
104 RTPrintf("tstTime-2: FAILURE - %d errors\n", cErrors);
105 return !!cErrors;
106}
Note: See TracBrowser for help on using the repository browser.

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