|
|
@@ -1690,6 +1690,7 @@ int TestDateTime()
|
|
|
// implementations of the tv_usec value are grainy and so this is the
|
|
|
// best we can validate against.
|
|
|
const uint64_t kMaxErrorNs = (EA::StdC::GetTimePrecision() < UINT64_C(100000000)) ? UINT64_C(200000000) : UINT64_C(2000000000);
|
|
|
+ const uint64_t kMaxErrorMs = (EA::StdC::GetTimePrecision() < UINT64_C(100000000)) ? UINT64_C(200) : UINT64_C(2000);
|
|
|
|
|
|
// Converts GetTimeOfDay output to an uint64_t representation.
|
|
|
auto GetTimeOfDayAsUInt64 = []
|
|
|
@@ -1705,16 +1706,21 @@ int TestDateTime()
|
|
|
// our tests are running.
|
|
|
uint64_t testStartTimeNs = GetTimeOfDayAsUInt64();
|
|
|
uint64_t dateChangedDiffNs = 0;
|
|
|
+ uint64_t dateChangedDiffMs = 0;
|
|
|
int failCount = 0;
|
|
|
|
|
|
for (int i = 0; i < kTestCount; i++)
|
|
|
{
|
|
|
uint64_t t1 = GetTime(); // nanoseconds
|
|
|
uint64_t t2 = GetTimeOfDayAsUInt64();
|
|
|
+ uint64_t t3 = GetTimeMilliseconds(); // milliseconds
|
|
|
+ uint64_t t1ms = t1 / 1000000;
|
|
|
const uint64_t diffNs = (t1 > t2) ? (t1 - t2) : (t2 - t1);
|
|
|
+ const uint64_t diffMs = (t1ms > t3) ? (t1ms - t3) : (t3 - t1ms);
|
|
|
|
|
|
// Adjust the clock if the date has been changed
|
|
|
t2 += dateChangedDiffNs;
|
|
|
+ t3 += dateChangedDiffMs;
|
|
|
|
|
|
// If a thread context switch happened right between the two calls above, resample t1.
|
|
|
// We encounter this problem fairly regularly.
|
|
|
@@ -1725,6 +1731,7 @@ int TestDateTime()
|
|
|
if (diffNs > kSecondsPerMinute)
|
|
|
{
|
|
|
dateChangedDiffNs = t2 > testStartTimeNs ? (~diffNs) + 1 : diffNs; // take diff or two's complement of diff
|
|
|
+ dateChangedDiffMs = dateChangedDiffNs / 1000000;
|
|
|
}
|
|
|
|
|
|
// It's very unlikely we could get another context switch so soon.
|
|
|
@@ -1741,6 +1748,12 @@ int TestDateTime()
|
|
|
"%I64u ns (%I64u s)\nGetTimeOfDay: %I64u ns (%I64u s)\n",
|
|
|
i, kTestCount, diffNs, kMaxErrorNs, t1, t1 / 1000000000, t2,
|
|
|
t2 / 1000000000); // Verify that the difference is within N nanoseconds.
|
|
|
+
|
|
|
+ EATEST_VERIFY_F(diffMs <= kMaxErrorMs,
|
|
|
+ "GetTimeOfDay failure on run %d of %d: diffMs: %I64u ns, kMaxErrorMs: %I64u ms. GetTime: "
|
|
|
+ "%I64u ms (%I64u s)\nGetTimeOfDay: %I64u ms (%I64u s)\n",
|
|
|
+ i, kTestCount, diffMs, kMaxErrorMs, t1ms, t1ms / 1000, t3,
|
|
|
+ t3 / 1000); // Verify that the difference is within N nanoseconds.
|
|
|
#endif
|
|
|
|
|
|
EA::Thread::ThreadSleep(EA::Thread::ThreadTime(500)); // Sleep for N milliseconds, and test again.
|