diff options
Diffstat (limited to 'src/pal/tests/palsuite/threading/SetEvent')
13 files changed, 605 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/SetEvent/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/CMakeLists.txt new file mode 100644 index 0000000000..a3847f8ca9 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) + diff --git a/src/pal/tests/palsuite/threading/SetEvent/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/test1/CMakeLists.txt new file mode 100644 index 0000000000..9be8d5a421 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/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_setevent_test1 + ${SOURCES} +) + +add_dependencies(paltest_setevent_test1 coreclrpal) + +target_link_libraries(paltest_setevent_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/threading/SetEvent/test1/test1.c b/src/pal/tests/palsuite/threading/SetEvent/test1/test1.c new file mode 100644 index 0000000000..d5a29ce3f3 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test1/test1.c @@ -0,0 +1,94 @@ +// 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: Test for SetEvent. Create an Event and then set +** this event, checking the return value. Ensure that it returns +** positive. +** +** +**=========================================================*/ + +#include <palsuite.h> + +BOOL SetEventTest() +{ + int bRet = 0; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = 0; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + /* Create an event which we can use with SetEvent */ + HANDLE hEvent = CreateEvent( lpEventAttributes, + bManualReset, bInitialState, NULL); + + if (hEvent != INVALID_HANDLE_VALUE) + { + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("SetEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + /* Set the event to the previously created event and check + the return value. + */ + bRet = SetEvent(hEvent); + + if (!bRet) + { + Trace("SetEventTest:SetEvent failed (%x)\n", GetLastError()); + } + else + { + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("SetEventTest:WaitForSingleObject failed (%x)\n", GetLastError()); + } + else + { + dwRet = CloseHandle(hEvent); + + if (!dwRet) + { + Trace("SetEventTest:CloseHandle failed (%x)\n", GetLastError()); + } + } + } + } + } + else + { + Trace("SetEventTest:CreateEvent failed (%x)\n", GetLastError()); + } + + return bRet; +} + + +int __cdecl main(int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(SetEventTest() == 0) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test1/testinfo.dat b/src/pal/tests/palsuite/threading/SetEvent/test1/testinfo.dat new file mode 100644 index 0000000000..9bfd80829c --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/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 = threading +Function = SetEvent +Name = Positive Test for SetEvent +TYPE = DEFAULT +EXE1 = test1 +Description +=Test for SetEvent. Create an Event and then set +=this event, checking the return value. Ensure that it returns +=positive. diff --git a/src/pal/tests/palsuite/threading/SetEvent/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/test2/CMakeLists.txt new file mode 100644 index 0000000000..87522b3ffc --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/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_setevent_test2 + ${SOURCES} +) + +add_dependencies(paltest_setevent_test2 coreclrpal) + +target_link_libraries(paltest_setevent_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/threading/SetEvent/test2/test2.c b/src/pal/tests/palsuite/threading/SetEvent/test2/test2.c new file mode 100644 index 0000000000..5fd2833957 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test2/test2.c @@ -0,0 +1,125 @@ +// 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 +** CreateEvent +** CloseHandle +** WaitForSingleObject +** +** Purpose: +** +** Test to ensure proper operation of the SetEvent() +** API by calling it on an event handle that's already set. +** + +** +**===========================================================================*/ +#include <palsuite.h> + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + DWORD dwRet = 0; + HANDLE hEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with SetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* verify that the event isn't signalled yet */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* set the event */ + if( ! SetEvent( hEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event is signalled */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* try to set the event again */ + if( ! SetEvent( hEvent ) ) + { + /* ERROR */ + Trace( "FAIL:%lu:SetEvent() call failed on signalled event\n", + GetLastError() ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event is still signalled */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test2/testinfo.dat b/src/pal/tests/palsuite/threading/SetEvent/test2/testinfo.dat new file mode 100644 index 0000000000..f2153052bb --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test2/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 = SetEvent +Name = Positive test for SetEvent +TYPE = DEFAULT +EXE1 = test2 +Description += Test to ensure proper operation of the SetEvent() += API by calling it on an event handle that's already set. diff --git a/src/pal/tests/palsuite/threading/SetEvent/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/test3/CMakeLists.txt new file mode 100644 index 0000000000..d09239b3e4 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.c +) + +add_executable(paltest_setevent_test3 + ${SOURCES} +) + +add_dependencies(paltest_setevent_test3 coreclrpal) + +target_link_libraries(paltest_setevent_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/threading/SetEvent/test3/test3.c b/src/pal/tests/palsuite/threading/SetEvent/test3/test3.c new file mode 100644 index 0000000000..21601f00b8 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test3/test3.c @@ -0,0 +1,85 @@ +// 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: test3.c +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** +** Purpose: +** +** Test to ensure proper operation of the SetEvent() +** API by calling it on an event handle that's been +** closed. We expect it to return an appropriate error +** result. +** + +** +**===========================================================================*/ +#include <palsuite.h> + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + HANDLE hEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with SetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() ); + } + + /* try to set the event */ + if( SetEvent( hEvent ) ) + { + /* ERROR */ + Fail( "FAIL:SetEvent() call succeeded on a closed event handle\n" ); + } + + /* verify the result of GetLastError() */ + if( GetLastError() != ERROR_INVALID_HANDLE ) + { + /* ERROR */ + Fail( "FAIL:SetEvent() call failed on a closed event handle" + "but returned an unexpected error result %lu\n" ); + } + + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test3/testinfo.dat b/src/pal/tests/palsuite/threading/SetEvent/test3/testinfo.dat new file mode 100644 index 0000000000..7b8f43013a --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test3/testinfo.dat @@ -0,0 +1,15 @@ +# 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 = SetEvent +Name = Negative test for SetEvent +TYPE = DEFAULT +EXE1 = test3 +Description += Test to ensure proper operation of the SetEvent() += API by calling it on an event handle that's been += closed. We expect it to return an appropriate error += result. diff --git a/src/pal/tests/palsuite/threading/SetEvent/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/SetEvent/test4/CMakeLists.txt new file mode 100644 index 0000000000..3f1d344292 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/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_setevent_test4 + ${SOURCES} +) + +add_dependencies(paltest_setevent_test4 coreclrpal) + +target_link_libraries(paltest_setevent_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/threading/SetEvent/test4/test4.c b/src/pal/tests/palsuite/threading/SetEvent/test4/test4.c new file mode 100644 index 0000000000..7a79a9d708 --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test4/test4.c @@ -0,0 +1,161 @@ +// 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 +** +** Dependencies: PAL_Initialize +** PAL_Terminate +** CreateEvent +** CloseHandle +** WaitForSingleObject +** DuplicateHandle +** GetCurrentProcess +** +** Purpose: +** +** Test to ensure proper operation of the SetEvent() +** API by calling it on an event handle that's the +** result of a DuplicateHandle() call on another event +** handle. +** + +** +**===========================================================================*/ +#include <palsuite.h> + + + +int __cdecl main( int argc, char **argv ) + +{ + /* local variables */ + DWORD dwRet = 0; + HANDLE hEvent = NULL; + HANDLE hDupEvent = NULL; + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + + + /* PAL initialization */ + if( (PAL_Initialize(argc, argv)) != 0 ) + { + return( FAIL ); + } + + + /* create an event which we can use with SetEvent */ + hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + NULL ); + + if( hEvent == INVALID_HANDLE_VALUE ) + { + /* ERROR */ + Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() ); + } + + /* verify that the event isn't signalled yet */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + + /* duplicate the event handle */ + if( ! (DuplicateHandle( + GetCurrentProcess(), + hEvent, + GetCurrentProcess(), + &hDupEvent, + GENERIC_READ|GENERIC_WRITE, /* ignored in PAL */ + FALSE, + DUPLICATE_SAME_ACCESS ) ) ) + { + Trace("ERROR:%u:DuplicateHandle() call failed\n", + GetLastError() ); + CloseHandle( hEvent ); + Fail("Test failed\n"); + } + + /* verify that the event isn't signalled yet with the duplicate handle */ + dwRet = WaitForSingleObject( hDupEvent, 0 ); + if( dwRet != WAIT_TIMEOUT ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_TIMEOUT\n", + dwRet ); + CloseHandle( hEvent ); + CloseHandle( hDupEvent ); + Fail( "Test failed\n" ); + } + + + /* set the event using the duplicate handle */ + if( ! SetEvent( hDupEvent ) ) + { + /* ERROR */ + Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); + CloseHandle( hEvent ); + CloseHandle( hDupEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event is signalled using the duplicate handle*/ + dwRet = WaitForSingleObject( hDupEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + /* verify that the event is signalled using the original event handle */ + dwRet = WaitForSingleObject( hEvent, 0 ); + if( dwRet != WAIT_OBJECT_0 ) + { + /* ERROR */ + Trace( "ERROR:WaitForSingleObject() call returned %lu, " + "expected WAIT_OBJECT_0\n", + dwRet ); + CloseHandle( hEvent ); + Fail( "Test failed\n" ); + } + + + /* close the duplicate event handle */ + if( ! CloseHandle( hDupEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed for duplicate handle\n", + GetLastError() ); + } + + + /* close the event handle */ + if( ! CloseHandle( hEvent ) ) + { + Fail( "ERROR:%lu:CloseHandle() call failed for original handle\n", + GetLastError() ); + } + + + /* PAL termination */ + PAL_Terminate(); + + /* return success */ + return PASS; +} diff --git a/src/pal/tests/palsuite/threading/SetEvent/test4/testinfo.dat b/src/pal/tests/palsuite/threading/SetEvent/test4/testinfo.dat new file mode 100644 index 0000000000..9a7f7ddb3b --- /dev/null +++ b/src/pal/tests/palsuite/threading/SetEvent/test4/testinfo.dat @@ -0,0 +1,15 @@ +# 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 = SetEvent +Name = Positive test for SetEvent +TYPE = DEFAULT +EXE1 = test4 +Description += Test to ensure proper operation of the SetEvent() += API by calling it on an event handle that's the += result of a DuplicateHandle() call on another event += handle. |