summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/threading/SleepEx/test1
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/threading/SleepEx/test1')
-rw-r--r--src/pal/tests/palsuite/threading/SleepEx/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/threading/SleepEx/test1/test1.c89
-rw-r--r--src/pal/tests/palsuite/threading/SleepEx/test1/testinfo.dat13
3 files changed, 121 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/SleepEx/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/SleepEx/test1/CMakeLists.txt
new file mode 100644
index 0000000000..de562755fc
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/SleepEx/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test1.c
+)
+
+add_executable(paltest_sleepex_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_sleepex_test1 coreclrpal)
+
+target_link_libraries(paltest_sleepex_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/threading/SleepEx/test1/test1.c b/src/pal/tests/palsuite/threading/SleepEx/test1/test1.c
new file mode 100644
index 0000000000..7ccfe0ce87
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/SleepEx/test1/test1.c
@@ -0,0 +1,89 @@
+// 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: test1.c
+**
+** Purpose: Tests that SleepEx correctly sleeps for a given amount of time,
+** regardless of the alertable flag.
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+typedef struct
+{
+ DWORD SleepTime;
+ BOOL Alertable;
+} testCase;
+
+testCase testCases[] =
+{
+ {0, FALSE},
+ {50, FALSE},
+ {100, FALSE},
+ {500, FALSE},
+ {2000, FALSE},
+
+ {0, TRUE},
+ {50, TRUE},
+ {100, TRUE},
+ {500, TRUE},
+ {2000, TRUE},
+};
+
+/* Milliseconds of error which are acceptable Function execution time, etc. */
+DWORD AcceptableTimeError = 150;
+
+int __cdecl main( int argc, char **argv )
+{
+ UINT64 OldTimeStamp;
+ UINT64 NewTimeStamp;
+ DWORD MaxDelta;
+ DWORD TimeDelta;
+ DWORD i;
+
+ if (0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ LARGE_INTEGER performanceFrequency;
+ if (!QueryPerformanceFrequency(&performanceFrequency))
+ {
+ return FAIL;
+ }
+
+ for (i = 0; i<sizeof(testCases) / sizeof(testCases[0]); i++)
+ {
+ OldTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency);
+
+ SleepEx(testCases[i].SleepTime, testCases[i].Alertable);
+
+ NewTimeStamp = GetHighPrecisionTimeStamp(performanceFrequency);
+
+ TimeDelta = NewTimeStamp - OldTimeStamp;
+
+ /* For longer intervals use a 10 percent tolerance */
+ if ((testCases[i].SleepTime * 0.1) > AcceptableTimeError)
+ {
+ MaxDelta = testCases[i].SleepTime + (DWORD)(testCases[i].SleepTime * 0.1);
+ }
+ else
+ {
+ MaxDelta = testCases[i].SleepTime + AcceptableTimeError;
+ }
+
+ if (TimeDelta < testCases[i].SleepTime || TimeDelta > MaxDelta)
+ {
+ Fail("The sleep function slept for %d ms when it should have "
+ "slept for %d ms\n", TimeDelta, testCases[i].SleepTime);
+ }
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/threading/SleepEx/test1/testinfo.dat b/src/pal/tests/palsuite/threading/SleepEx/test1/testinfo.dat
new file mode 100644
index 0000000000..1242768743
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/SleepEx/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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 = threading
+Function = SleepEx
+Name = Test #1 for SleepEx
+TYPE = DEFAULT
+EXE1 = test1
+Description
+=Tests that SleepEx correctly sleeps for a given amount of time,
+=regardless of the alertable flag.