diff options
Diffstat (limited to 'src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime')
4 files changed, 123 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/CMakeLists.txt new file mode 100644 index 0000000000..977a826e7a --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + GetSystemTimeAsFileTime.c +) + +add_executable(paltest_getsystemtimeasfiletime_test1 + ${SOURCES} +) + +add_dependencies(paltest_getsystemtimeasfiletime_test1 coreclrpal) + +target_link_libraries(paltest_getsystemtimeasfiletime_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.c b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.c new file mode 100644 index 0000000000..bd7e856abd --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/GetSystemTimeAsFileTime.c @@ -0,0 +1,86 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: GetSystemTimeAsFileTime.c +** +** Purpose: Tests the PAL implementation of GetSystemTimeAsFileTime +** Take two times, three seconds apart, and ensure that the time is +** increasing, and that it has increased at least 3 seconds. +** +** +** +**===================================================================*/ + +#include <palsuite.h> + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME TheFirstTime, TheSecondTime; + ULONG64 FullFirstTime, FullSecondTime; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Get two times, 3 seconds apart */ + + GetSystemTimeAsFileTime( &TheFirstTime ); + + Sleep( 3000 ); + + GetSystemTimeAsFileTime( &TheSecondTime ); + + /* Convert them to ULONG64 to work with */ + + FullFirstTime = ((( (ULONG64)TheFirstTime.dwHighDateTime )<<32) | + ( (ULONG64)TheFirstTime.dwLowDateTime )); + + FullSecondTime = ((( (ULONG64)TheSecondTime.dwHighDateTime )<<32) | + ( (ULONG64)TheSecondTime.dwLowDateTime )); + + /* Test to ensure the second value is larger than the first */ + + if( FullSecondTime <= FullFirstTime ) + { + Fail("ERROR: The system time didn't increase in the last " + "three seconds. The second time tested was less than " + "or equal to the first."); + } + + /* Note: The 30000000 magic number is 3 seconds in hundreds of nano + seconds. This test checks to ensure at least 3 seconds passed + between the readings. + */ + + if( ( (LONG64)( FullSecondTime - FullFirstTime ) - 30000000 ) < 0 ) + { + ULONG64 TimeError; + + /* Note: This test used to compare the difference between full times + in terms of hundreds of nanoseconds. But the x86 clock seems to be + precise only to the level of about 10000 nanoseconds, so we would + fail the comparison depending on when we took time slices. + + To fix this, we just check that we're within a millisecond of + sleeping 3000 milliseconds. We're not currently ensuring that we + haven't slept much more than 3000 ms. We may want to do that. + */ + TimeError = 30000000 - ( FullSecondTime - FullFirstTime ); + if ( TimeError > 10000) + { + Fail("ERROR: Two system times were tested, with a sleep of 3 " + "seconds between. The time passed should have been at least " + "3 seconds. But, it was less according to the function."); + } + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/testinfo.dat new file mode 100644 index 0000000000..3318d1386a --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetSystemTimeAsFileTime/test1/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = file_io +Function = GetSystemTimeAsFileTime +Name = Positive Test for GetSystemTimeAsFileTime +TYPE = DEFAULT +EXE1 = getsystemtimeasfiletime +Description += Test the GetSystemTimeAsFileTime function. += Take two times, three seconds apart, and ensure that the time is += increasing, and that it has increased at least 3 seconds. |