summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/threading/GetCurrentThread
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/threading/GetCurrentThread')
-rw-r--r--src/pal/tests/palsuite/threading/GetCurrentThread/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/threading/GetCurrentThread/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/threading/GetCurrentThread/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.c93
-rw-r--r--src/pal/tests/palsuite/threading/GetCurrentThread/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.c144
-rw-r--r--src/pal/tests/palsuite/threading/GetCurrentThread/test2/testinfo.dat18
7 files changed, 310 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentThread/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/GetCurrentThread/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/CMakeLists.txt
new file mode 100644
index 0000000000..84cbccbca0
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ thread.c
+)
+
+add_executable(paltest_getcurrentthread_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getcurrentthread_test1 coreclrpal)
+
+target_link_libraries(paltest_getcurrentthread_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test1/testinfo.dat b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/testinfo.dat
new file mode 100644
index 0000000000..29c9767ed0
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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 = GetCurrentThread
+Name = Positive Test for GetCurrentThread
+TYPE = DEFAULT
+EXE1 = thread
+Description
+= Test to ensure GetCurrentThread returns a handle to the current thread.
diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.c b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.c
new file mode 100644
index 0000000000..b2bb97fd67
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test1/thread.c
@@ -0,0 +1,93 @@
+// 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: GetCurrentThread/test1/thread.c
+**
+** Purpose: Test to ensure GetCurrentThread returns a handle to
+** the current thread.
+**
+** Dependencies: GetThreadPriority
+** SetThreadPriority
+** Fail
+** Trace
+**
+
+**
+**=========================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main( int argc, char **argv )
+{
+
+ HANDLE hThread;
+ int nPriority;
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return ( FAIL );
+ }
+
+#if !HAVE_SCHED_OTHER_ASSIGNABLE
+ /* Defining thread priority for SCHED_OTHER is implementation defined.
+ Some platforms like NetBSD cannot reassign it as they are dynamic.
+ */
+ printf("paltest_getcurrentthread_test1 has been disabled on this platform\n");
+#else
+ hThread = GetCurrentThread();
+
+ nPriority = GetThreadPriority(hThread);
+
+ if ( THREAD_PRIORITY_NORMAL != nPriority )
+ {
+ if ( THREAD_PRIORITY_ERROR_RETURN == nPriority )
+ {
+ Fail ("GetThreadPriority function call failed for %s\n"
+ "GetLastError returned %d\n", argv[0], GetLastError());
+ }
+ else
+ {
+ Fail ("GetThreadPriority function call failed for %s\n"
+ "The priority returned was %d\n", argv[0], nPriority);
+ }
+ }
+ else
+ {
+ nPriority = 0;
+
+ if (0 == SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST))
+ {
+ Fail ("Unable to set thread priority. Either handle doesn't"
+ " point to current thread \nor SetThreadPriority "
+ "function failed. Failing test.\n");
+ }
+
+ nPriority = GetThreadPriority(hThread);
+
+ if ( THREAD_PRIORITY_ERROR_RETURN == nPriority )
+ {
+ Fail ("GetThreadPriority function call failed for %s\n"
+ "GetLastError returned %d\n", argv[0], GetLastError());
+ }
+ else if ( THREAD_PRIORITY_HIGHEST == nPriority )
+ {
+ Trace ("GetCurrentThread returns handle to the current "
+ "thread.\n");
+ exit ( PASS );
+ }
+ else
+ {
+ Fail ("Unable to set thread priority. Either handle doesn't"
+ " point to current thread \nor SetThreadPriority "
+ "function failed. Failing test.\n");
+ }
+ }
+#endif
+
+ PAL_Terminate();
+ return ( PASS );
+
+}
diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/CMakeLists.txt
new file mode 100644
index 0000000000..3fc3c3e7c6
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test2.c
+)
+
+add_executable(paltest_getcurrentthread_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getcurrentthread_test2 coreclrpal)
+
+target_link_libraries(paltest_getcurrentthread_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.c b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.c
new file mode 100644
index 0000000000..beeb5ec241
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/test2.c
@@ -0,0 +1,144 @@
+// 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: test2.c
+**
+** Dependencies: PAL_Initialize
+** PAL_Terminate
+** Fail
+** CreateThread
+** SetThreadPriority
+** GetThreadPriority
+** ResumeThread
+** WaitForSingleObject
+** GetLastError
+**
+** Purpose:
+**
+** Test to ensure proper operation of the GetCurrentThread()
+** API. The test launches a thread in suspended mode, and sets
+** its priority to a non-default value using the handle returned
+** by CreateThread(). The new thread calls GetCurrentThred() to
+** retrieve a handle to itself, and calls GetThreadPriority()
+** to verify that its priority matches what it was set to on
+** the main execution thread.
+**
+
+**
+**===========================================================================*/
+#include <palsuite.h>
+
+
+/* we store the return code from the child thread here because */
+/* we're missing the GetExitCodeThread() API */
+
+static int g_priority = 0;
+
+/**
+ * ThreadFunc
+ *
+ * Thread function that calls GetCurrentThread() to get a pseudo-handle
+ * to itself, then checks its priority and exits with that value.
+ */
+DWORD PALAPI ThreadFunc( LPVOID param )
+{
+ int priority;
+ HANDLE hThread;
+
+ /* call GetCurrentThread() to get a pseudo-handle to */
+ /* the current thread */
+ hThread = GetCurrentThread();
+ if( hThread == NULL )
+ {
+ Fail( "GetCurrentThread() call failed\n" );
+ }
+
+
+ /* get the current thread priority */
+ priority = GetThreadPriority( hThread );
+ if( priority == THREAD_PRIORITY_ERROR_RETURN )
+ {
+ /* GetThreadPriority call failed */
+ Fail( "ERROR:%lu:GetThreadPriority() call failed\n", GetLastError() );
+ }
+
+ /* store this globally because we don't have GetExitCodeThread() */
+ g_priority = priority;
+ return (DWORD)priority;
+}
+
+
+/**
+ * main
+ *
+ * executable entry point
+ */
+INT __cdecl main( INT argc, CHAR **argv )
+{
+ HANDLE hThread = NULL;
+ DWORD IDThread;
+ DWORD dwRet;
+
+ SIZE_T i = 0;
+
+ /* PAL initialization */
+ if( (PAL_Initialize(argc, argv)) != 0 )
+ {
+ return( FAIL );
+ }
+
+#if !HAVE_SCHED_OTHER_ASSIGNABLE
+ /* Defining thread priority for SCHED_OTHER is implementation defined.
+ Some platforms like NetBSD cannot reassign it as they are dynamic.
+ */
+ printf("paltest_getcurrentthread_test2 has been disabled on this platform\n");
+#else
+ /* Create multiple threads. */
+ hThread = CreateThread( NULL, /* no security attributes */
+ 0, /* use default stack size */
+ (LPTHREAD_START_ROUTINE) ThreadFunc, /* thread function */
+ (LPVOID) i, /* pass thread index as */
+ /* function argument */
+ CREATE_SUSPENDED, /* create suspended */
+ &IDThread ); /* returns thread identifier */
+
+ /* Check the return value for success. */
+ if( hThread == NULL )
+ {
+ /* ERROR */
+ Fail( "ERROR:%lu:CreateThread failed\n", GetLastError() );
+ }
+
+ /* set the thread priority of the new thread to the highest value */
+ if( ! SetThreadPriority( hThread, THREAD_PRIORITY_TIME_CRITICAL) )
+ {
+ Fail( "ERROR:%lu:SetThreadPriority() call failed\n", GetLastError() );
+ }
+
+ /* let the child thread run now */
+ ResumeThread( hThread );
+
+
+ /* wait for the thread to finish */
+ dwRet = WaitForSingleObject( hThread, INFINITE );
+ if( dwRet == WAIT_FAILED )
+ {
+ /* ERROR */
+ Fail( "ERROR:%lu:WaitForSingleObject call failed\n", GetLastError() );
+ }
+
+ /* validate the thread's exit code */
+ if( g_priority != THREAD_PRIORITY_TIME_CRITICAL )
+ {
+ /* ERROR */
+ Fail( "FAIL:Unexpected thread priority %d returned, expected %d\n",
+ g_priority, THREAD_PRIORITY_TIME_CRITICAL );
+ }
+#endif
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/threading/GetCurrentThread/test2/testinfo.dat b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/testinfo.dat
new file mode 100644
index 0000000000..96a6d403bb
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/GetCurrentThread/test2/testinfo.dat
@@ -0,0 +1,18 @@
+# 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 = GetCurrentThread
+Name = Test for GetCurrentThread
+TYPE = DEFAULT
+EXE1 = test2
+Description
+= Test to ensure proper operation of the GetCurrentThread()
+= API. The test launches a thread in suspended mode, and sets
+= its priority to a non-default value using the handle returned
+= by CreateThread(). The new thread calls GetCurrentThred() to
+= retrieve a handle to itself, and calls GetThreadPriority()
+= to verify that its priority matches what it was set to on
+= the main execution thread.