| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*===================================================================== |
| 6 | ** |
| 7 | ** Source: GetSystemTimeAsFileTime.c |
| 8 | ** |
| 9 | ** Purpose: Tests the PAL implementation of GetSystemTimeAsFileTime |
| 10 | ** Take two times, three seconds apart, and ensure that the time is |
| 11 | ** increasing, and that it has increased at least 3 seconds. |
| 12 | ** |
| 13 | ** |
| 14 | ** |
| 15 | **===================================================================*/ |
| 16 | |
| 17 | #include <palsuite.h> |
| 18 | |
| 19 | |
| 20 | int __cdecl main(int argc, char **argv) |
| 21 | { |
| 22 | |
| 23 | FILETIME TheFirstTime, TheSecondTime; |
| 24 | ULONG64 FullFirstTime, FullSecondTime; |
| 25 | |
| 26 | if (0 != PAL_Initialize(argc,argv)) |
| 27 | { |
| 28 | return FAIL; |
| 29 | } |
| 30 | |
| 31 | /* Get two times, 3 seconds apart */ |
| 32 | |
| 33 | GetSystemTimeAsFileTime( &TheFirstTime ); |
| 34 | |
| 35 | Sleep( 3000 ); |
| 36 | |
| 37 | GetSystemTimeAsFileTime( &TheSecondTime ); |
| 38 | |
| 39 | /* Convert them to ULONG64 to work with */ |
| 40 | |
| 41 | FullFirstTime = ((( (ULONG64)TheFirstTime.dwHighDateTime )<<32) | |
| 42 | ( (ULONG64)TheFirstTime.dwLowDateTime )); |
| 43 | |
| 44 | FullSecondTime = ((( (ULONG64)TheSecondTime.dwHighDateTime )<<32) | |
| 45 | ( (ULONG64)TheSecondTime.dwLowDateTime )); |
| 46 | |
| 47 | /* Test to ensure the second value is larger than the first */ |
| 48 | |
| 49 | if( FullSecondTime <= FullFirstTime ) |
| 50 | { |
| 51 | Fail("ERROR: The system time didn't increase in the last " |
| 52 | "three seconds. The second time tested was less than " |
| 53 | "or equal to the first." ); |
| 54 | } |
| 55 | |
| 56 | /* Note: The 30000000 magic number is 3 seconds in hundreds of nano |
| 57 | seconds. This test checks to ensure at least 3 seconds passed |
| 58 | between the readings. |
| 59 | */ |
| 60 | |
| 61 | if( ( (LONG64)( FullSecondTime - FullFirstTime ) - 30000000 ) < 0 ) |
| 62 | { |
| 63 | ULONG64 TimeError; |
| 64 | |
| 65 | /* Note: This test used to compare the difference between full times |
| 66 | in terms of hundreds of nanoseconds. But the x86 clock seems to be |
| 67 | precise only to the level of about 10000 nanoseconds, so we would |
| 68 | fail the comparison depending on when we took time slices. |
| 69 | |
| 70 | To fix this, we just check that we're within a millisecond of |
| 71 | sleeping 3000 milliseconds. We're not currently ensuring that we |
| 72 | haven't slept much more than 3000 ms. We may want to do that. |
| 73 | */ |
| 74 | TimeError = 30000000 - ( FullSecondTime - FullFirstTime ); |
| 75 | if ( TimeError > 10000) |
| 76 | { |
| 77 | Fail("ERROR: Two system times were tested, with a sleep of 3 " |
| 78 | "seconds between. The time passed should have been at least " |
| 79 | "3 seconds. But, it was less according to the function." ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | PAL_Terminate(); |
| 84 | return PASS; |
| 85 | } |
| 86 | |
| 87 | |