diff options
Diffstat (limited to 'src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4')
3 files changed, 134 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/CMakeLists.txt new file mode 100644 index 0000000000..3cd7f72b98 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test4.c +) + +add_executable(paltest_waitformultipleobjectsex_test4 + ${SOURCES} +) + +add_dependencies(paltest_waitformultipleobjectsex_test4 coreclrpal) + +target_link_libraries(paltest_waitformultipleobjectsex_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c new file mode 100644 index 0000000000..15d0a386d1 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c @@ -0,0 +1,101 @@ +// 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: test4.c +** +** Purpose: Tests that waiting on an abandonded mutex will a return +** WAIT_ABANDONED_0. Does this by creating a child thread that +** acquires the mutex and exits. +** +** +**===================================================================*/ + +#include <palsuite.h> + + +const int ChildThreadWaitTime = 1000; +const int ParentDelayTime = 2000; + +DWORD PALAPI AbandoningProc(LPVOID lpParameter); + +int __cdecl main( int argc, char **argv ) +{ + HANDLE Mutex; + HANDLE hThread = 0; + DWORD dwThreadId = 0; + int ret; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + Mutex = CreateMutexW(NULL, FALSE, NULL); + if (Mutex == NULL) + { + Fail("Unable to create the mutex. GetLastError returned %d\n", + GetLastError()); + } + + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)AbandoningProc, + (LPVOID) Mutex, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test!\n" + "GetLastError returned %d\n", GetLastError()); + } + + Sleep(ParentDelayTime); + + ret = WaitForMultipleObjectsEx(1, &Mutex, FALSE, INFINITE, FALSE); + if (ret != WAIT_ABANDONED_0) + { + Fail("Expected WaitForMultipleObjectsEx to return WAIT_ABANDONED_0\n" + "Got %d\n", ret); + } + + ReleaseMutex(Mutex); + if (!CloseHandle(Mutex)) + { + Fail("CloseHandle on the mutex failed!\n"); + } + + if (!CloseHandle(hThread)) + { + Fail("CloseHandle on the thread failed!\n"); + } + + PAL_Terminate(); + return PASS; +} + +/* + * Entry Point for child thread. Acquries a mutex and exit's without + * releasing it. + */ +DWORD PALAPI AbandoningProc(LPVOID lpParameter) +{ + HANDLE Mutex; + DWORD ret; + + Mutex = (HANDLE) lpParameter; + + Sleep(ChildThreadWaitTime); + + ret = WaitForSingleObject(Mutex, 0); + if (ret != WAIT_OBJECT_0) + { + Fail("Expected the WaitForSingleObject call on the mutex to succeed\n" + "Expected return of WAIT_OBJECT_0, got %d\n", ret); + } + + return 0; +} diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/testinfo.dat b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/testinfo.dat new file mode 100644 index 0000000000..16f3468ac2 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/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 = threading +Function = WaitForMultipleObjectsEx +Name = Test #4 for WaitForMultipleObjectsEx +TYPE = DEFAULT +EXE1 = test4 +Description +=Tests that waiting on an abandonded mutex will a return +=WAIT_ABANDONED_0. Does this by creating a child thread that +=acquires the mutex and exits. |