| 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: Sleep.c |
| 8 | ** |
| 9 | ** Purpose: Test to establish whether the Sleep function stops the thread from |
| 10 | ** executing for the specified times. |
| 11 | ** |
| 12 | ** Dependencies: GetTickCount |
| 13 | ** |
| 14 | |
| 15 | ** |
| 16 | **=========================================================*/ |
| 17 | |
| 18 | #include <palsuite.h> |
| 19 | |
| 20 | /* |
| 21 | * times in 10^(-3) seconds |
| 22 | */ |
| 23 | |
| 24 | DWORD SleepTimes[] = |
| 25 | { |
| 26 | 60000, |
| 27 | 300000, |
| 28 | 1800000, |
| 29 | 3200000 |
| 30 | }; |
| 31 | |
| 32 | /* Milliseconds of error which are acceptable Function execution time, etc. */ |
| 33 | DWORD AcceptableTimeError = 150; |
| 34 | |
| 35 | int __cdecl main( int argc, char **argv ) |
| 36 | { |
| 37 | UINT64 OldTimeStamp; |
| 38 | UINT64 NewTimeStamp; |
| 39 | DWORD MaxDelta; |
| 40 | DWORD TimeDelta; |
| 41 | DWORD i; |
| 42 | |
| 43 | if(0 != (PAL_Initialize(argc, argv))) |
| 44 | { |
| 45 | return ( FAIL ); |
| 46 | } |
| 47 | |
| 48 | LARGE_INTEGER performanceFrequency; |
| 49 | if (!QueryPerformanceFrequency(&performanceFrequency)) |
| 50 | { |
| 51 | return FAIL; |
| 52 | } |
| 53 | |
| 54 | for( i = 0; i < sizeof(SleepTimes) / sizeof(DWORD); i++) |
| 55 | { |
| 56 | OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); |
| 57 | Sleep(SleepTimes[i]); |
| 58 | NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency); |
| 59 | |
| 60 | TimeDelta = NewTimeStamp - OldTimeStamp; |
| 61 | |
| 62 | MaxDelta = SleepTimes[i] + AcceptableTimeError; |
| 63 | |
| 64 | if ( TimeDelta<SleepTimes[i] || TimeDelta>MaxDelta ) |
| 65 | { |
| 66 | Fail("The sleep function slept for %u ms when it should have " |
| 67 | "slept for %u ms\n", TimeDelta, SleepTimes[i]); |
| 68 | } |
| 69 | } |
| 70 | PAL_Terminate(); |
| 71 | return ( PASS ); |
| 72 | |
| 73 | } |
| 74 |