diff options
Diffstat (limited to 'src/pal/tests/palsuite/threading/GetCurrentThreadId')
4 files changed, 118 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/GetCurrentThreadId/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentThreadId/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentThreadId/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/CMakeLists.txt new file mode 100644 index 0000000000..490bff8f5f --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + threadId.c +) + +add_executable(paltest_getcurrentthreadid_test1 + ${SOURCES} +) + +add_dependencies(paltest_getcurrentthreadid_test1 coreclrpal) + +target_link_libraries(paltest_getcurrentthreadid_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/testinfo.dat b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/testinfo.dat new file mode 100644 index 0000000000..4d1e056b71 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentThreadId/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 = GetCurrentThreadId +Name = Positive Test for GetCurrentThreadId +TYPE = DEFAULT +EXE1 = threadid +Description += Test to ensure GetCurrentThreadId returns the threadId of the current += thread. diff --git a/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.c b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.c new file mode 100644 index 0000000000..acbb1ff373 --- /dev/null +++ b/src/pal/tests/palsuite/threading/GetCurrentThreadId/test1/threadId.c @@ -0,0 +1,82 @@ +// 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: getcurrentthreadid/test1/threadid.c +** +** Purpose: Test to ensure GetCurrentThreadId returns the threadId of the +** current thread. +** +** Dependencies: CloseHandle +** WaitForSingleObject +** CreateThread +** + +** +**=========================================================*/ + + +#include <palsuite.h> + +DWORD dwThreadIdTF; + +DWORD PALAPI ThreadFunction ( LPVOID lpParam ) +{ + Trace ("thread code executed\n"); + dwThreadIdTF = GetCurrentThreadId(); + return 0; +} + +int __cdecl main( int argc, char **argv ) +{ + extern DWORD dwThreadIdTF; + DWORD dwThreadIdCT; + HANDLE hThread; + DWORD dwThreadParam = 1; + DWORD dwThreadWait; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + hThread = CreateThread( + NULL, + 0, + ThreadFunction, + &dwThreadParam, + 0, + &dwThreadIdCT); + + if ( NULL == hThread ) + { + Fail ( "CreateThread() call failed - returned NULL"); + } + else + { + dwThreadWait = WaitForSingleObject( hThread, INFINITE ); + + Trace ("dwThreadWait returned %d\n", dwThreadWait ); + + if ( dwThreadIdCT == dwThreadIdTF ) + { + Trace ( "ThreadId numbers match - GetCurrentThreadId" + " works. dwThreadIdCT == dwThreadIdTF == %d\n", + dwThreadIdTF ); + PAL_Terminate(); + return ( PASS ); + } + else + { + Fail ( "ThreadId numbers don't match - " + "GetCurrentThreadId fails dwThreadIdCT = %d " + "and dwThreadIdTF = %d\n", dwThreadIdCT, dwThreadIdTF); + } + } + + PAL_TerminateEx(FAIL); + return (FAIL); + +} |