Changeset 98637 in vbox for trunk/src/VBox/Runtime/testcase/tstRTTime.cpp
- Timestamp:
- Feb 20, 2023 8:58:45 AM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTTime.cpp
r98103 r98637 63 63 */ 64 64 65 /* Take down the start time of both sources, try get them w/o being rescheduled. */ 65 66 RTTimeSystemNanoTS(); RTTimeNanoTS(); RTThreadYield(); 66 67 uint64_t u64RTStartTS = RTTimeNanoTS(); 67 68 uint64_t u64OSStartTS = RTTimeSystemNanoTS(); 69 uint64_t const cNsMaxTolerance = 256 * RT_NS_1US; 70 for (unsigned cTries = 0; cTries < 32 && RTTimeNanoTS() - u64RTStartTS > cNsMaxTolerance; cTries++) 71 { 72 RTThreadYield(); 73 u64RTStartTS = RTTimeNanoTS(); 74 u64OSStartTS = RTTimeSystemNanoTS(); 75 } 68 76 77 /* Test loop. */ 69 78 uint32_t i; 70 79 uint64_t u64Prev = RTTimeNanoTS(); … … 98 107 } 99 108 109 /* Take down the stop time of both sources, again try get them w/o being rescheduled. */ 100 110 RTTimeSystemNanoTS(); RTTimeNanoTS(); RTThreadYield(); 101 111 uint64_t u64RTElapsedTS = RTTimeNanoTS(); 102 112 uint64_t u64OSElapsedTS = RTTimeSystemNanoTS(); 113 for (unsigned cTries = 0; cTries < 32 && RTTimeNanoTS() - u64RTElapsedTS > cNsMaxTolerance; cTries++) 114 { 115 RTThreadYield(); 116 u64RTElapsedTS = RTTimeNanoTS(); 117 u64OSElapsedTS = RTTimeSystemNanoTS(); 118 } 103 119 u64RTElapsedTS -= u64RTStartTS; 104 120 u64OSElapsedTS -= u64OSStartTS; 121 122 /* Check the runtime difference between the two sources. */ 105 123 int64_t i64Diff = u64OSElapsedTS >= u64RTElapsedTS ? u64OSElapsedTS - u64RTElapsedTS : u64RTElapsedTS - u64OSElapsedTS; 106 if (i64Diff > (int64_t)( u64OSElapsedTS / 1000))124 if (i64Diff > (int64_t)(RT_MAX(u64OSElapsedTS / 1000, cNsMaxTolerance))) 107 125 RTTestFailed(hTest, "total time differs too much! u64OSElapsedTS=%#llx u64RTElapsedTS=%#llx delta=%lld\n", 108 126 u64OSElapsedTS, u64RTElapsedTS, u64OSElapsedTS - u64RTElapsedTS); … … 117 135 } 118 136 137 /* Report debug details: */ 119 138 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) /** @todo This isn't really x86 or AMD64 specific... */ 120 139 RTTestValue(hTest, "RTTimeDbgSteps", RTTimeDbgSteps(), RTTESTUNIT_OCCURRENCES);
Note:
See TracChangeset
for help on using the changeset viewer.