summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/threading/ResetEvent
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
commit4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch)
tree98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/threading/ResetEvent
parentfa45f57ed55137c75ac870356a1b8f76c84b229c (diff)
downloadcoreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/tests/palsuite/threading/ResetEvent')
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/CMakeLists.txt7
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test1/test1.c99
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test1/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test2/test2.c89
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test2/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test3/test3.c86
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test3/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test4/test4.c161
-rw-r--r--src/pal/tests/palsuite/threading/ResetEvent/test4/testinfo.dat15
13 files changed, 576 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/ResetEvent/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/CMakeLists.txt
new file mode 100644
index 0000000000..a3847f8ca9
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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/ResetEvent/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/test1/CMakeLists.txt
new file mode 100644
index 0000000000..78e84da2b9
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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_resetevent_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_resetevent_test1 coreclrpal)
+
+target_link_libraries(paltest_resetevent_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.c b/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.c
new file mode 100644
index 0000000000..20a0d5dffa
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/test1/test1.c
@@ -0,0 +1,99 @@
+// 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 ResetEvent. Create an event with an intial
+** state signaled. Then reset that signal, and check to see that
+** the event is now not signaled.
+**
+**
+**=========================================================*/
+
+#include <palsuite.h>
+
+BOOL ResetEventTest()
+{
+ BOOL bRet = FALSE;
+ DWORD dwRet = 0;
+
+ LPSECURITY_ATTRIBUTES lpEventAttributes = 0;
+ BOOL bManualReset = TRUE;
+ BOOL bInitialState = TRUE;
+
+ /* Create an Event, ensure it is valid */
+ HANDLE hEvent = CreateEvent( lpEventAttributes,
+ bManualReset, bInitialState, NULL);
+
+ if (hEvent != INVALID_HANDLE_VALUE)
+ {
+ /* Check that WaitFor returns WAIT_OBJECT_0, indicating that
+ the event is signaled.
+ */
+
+ dwRet = WaitForSingleObject(hEvent,0);
+
+ if (dwRet != WAIT_OBJECT_0)
+ {
+ Fail("ResetEventTest:WaitForSingleObject failed (%x)\n", GetLastError());
+ }
+ else
+ {
+ /* Call ResetEvent, which will reset the signal */
+ bRet = ResetEvent(hEvent);
+
+ if (!bRet)
+ {
+ Fail("ResetEventTest:ResetEvent failed (%x)\n", GetLastError());
+ }
+ else
+ {
+ /* Call WaitFor again, and since it has been reset,
+ the return value should now be WAIT_TIMEOUT
+ */
+ dwRet = WaitForSingleObject(hEvent,0);
+
+ if (dwRet != WAIT_TIMEOUT)
+ {
+ Fail("ResetEventTest:WaitForSingleObject %s failed (%x)\n", GetLastError());
+ }
+ else
+ {
+ bRet = CloseHandle(hEvent);
+
+ if (!bRet)
+ {
+ Fail("ResetEventTest:CloseHandle failed (%x)\n", GetLastError());
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ Fail("ResetEventTest:CreateEvent failed (%x)\n", GetLastError());
+ }
+
+ return bRet;
+}
+
+int __cdecl main(int argc, char **argv)
+{
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return ( FAIL );
+ }
+
+ if(!ResetEventTest())
+ {
+ Fail ("Test failed\n");
+ }
+
+ PAL_Terminate();
+ return ( PASS );
+
+}
diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test1/testinfo.dat b/src/pal/tests/palsuite/threading/ResetEvent/test1/testinfo.dat
new file mode 100644
index 0000000000..ed27f13dba
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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 = ResetEvent
+Name = Positive Test for ResetEvent
+TYPE = DEFAULT
+EXE1 = test1
+Description
+= Test for ResetEvent. Create an event with an intial
+= state signaled. Then reset that signal, and check to see that
+= the event is now not signaled.
diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/test2/CMakeLists.txt
new file mode 100644
index 0000000000..ad0fe9b4a1
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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_resetevent_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_resetevent_test2 coreclrpal)
+
+target_link_libraries(paltest_resetevent_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.c b/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.c
new file mode 100644
index 0000000000..8117f44353
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/test2/test2.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: test2.c
+**
+** Dependencies: PAL_Initialize
+** PAL_Terminate
+** CreateEvent
+** CloseHandle
+** WaitForSingleObject
+**
+** Purpose: Test to ensure proper operation of the ResetEvent()
+** API by calling it on an event handle that's already
+** unsignalled.
+**
+
+**
+**===========================================================================*/
+#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 unsignalled event which we can use with ResetEvent */
+ 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" );
+ }
+
+ /* try to reset the event */
+ if( ! ResetEvent( hEvent ) )
+ {
+ /* ERROR */
+ Trace( "FAIL:%lu:ResetEvent() call failed\n", GetLastError() );
+ 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/ResetEvent/test2/testinfo.dat b/src/pal/tests/palsuite/threading/ResetEvent/test2/testinfo.dat
new file mode 100644
index 0000000000..4af1769cd4
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/test2/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 = ResetEvent
+Name = Positive test for ResetEvent
+TYPE = DEFAULT
+EXE1 = test2
+Description
+= Test to ensure proper operation of the ResetEvent()
+= API by calling it on an event handle that's already
+= unsignalled.
diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/test3/CMakeLists.txt
new file mode 100644
index 0000000000..3c4ea1f249
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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_resetevent_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_resetevent_test3 coreclrpal)
+
+target_link_libraries(paltest_resetevent_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.c b/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.c
new file mode 100644
index 0000000000..9bc068ea72
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/test3/test3.c
@@ -0,0 +1,86 @@
+// 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 ResetEvent()
+** 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 ResetEvent */
+ 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 reset the event */
+ if( ResetEvent( hEvent ) )
+ {
+ /* ERROR */
+ Fail( "FAIL:ResetEvent() call succeeded on a closed event handle\n" );
+ }
+
+ /* verify the result of GetLastError() */
+ if( GetLastError() != ERROR_INVALID_HANDLE )
+ {
+ /* ERROR */
+ Fail( "FAIL:ResetEvent() 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/ResetEvent/test3/testinfo.dat b/src/pal/tests/palsuite/threading/ResetEvent/test3/testinfo.dat
new file mode 100644
index 0000000000..4abeeded00
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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 = ResetEvent
+Name = Negative test for ResetEvent
+TYPE = DEFAULT
+EXE1 = test3
+Description
+= Test to ensure proper operation of the ResetEvent()
+= 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/ResetEvent/test4/CMakeLists.txt b/src/pal/tests/palsuite/threading/ResetEvent/test4/CMakeLists.txt
new file mode 100644
index 0000000000..68ee20bc95
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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_resetevent_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_resetevent_test4 coreclrpal)
+
+target_link_libraries(paltest_resetevent_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/threading/ResetEvent/test4/test4.c b/src/pal/tests/palsuite/threading/ResetEvent/test4/test4.c
new file mode 100644
index 0000000000..0cc68fd9aa
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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 ResetEvent()
+** 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 = TRUE;
+
+
+ /* PAL initialization */
+ if( (PAL_Initialize(argc, argv)) != 0 )
+ {
+ return( FAIL );
+ }
+
+
+ /* create an event which we can use with ResetEvent */
+ hEvent = CreateEvent( lpEventAttributes,
+ bManualReset,
+ bInitialState,
+ NULL );
+
+ if( hEvent == INVALID_HANDLE_VALUE )
+ {
+ /* ERROR */
+ Fail( "ERROR:%lu:CreateEvent() call failed\n", GetLastError() );
+ }
+
+ /* verify that the event is signalled already */
+ 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" );
+ }
+
+
+ /* 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 is signalled with 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 );
+ CloseHandle( hDupEvent );
+ Fail( "Test failed\n" );
+ }
+
+
+ /* reset the event using the duplicate handle */
+ if( ! ResetEvent( hDupEvent ) )
+ {
+ /* ERROR */
+ Trace( "ERROR:%lu:ResetEvent() call failed\n", GetLastError() );
+ CloseHandle( hEvent );
+ CloseHandle( hDupEvent );
+ Fail( "Test failed\n" );
+ }
+
+ /* verify that the event isn't signalled using 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 );
+ Fail( "Test failed\n" );
+ }
+
+ /* check that the event isn't signalled using the original event handle */
+ 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" );
+ }
+
+
+ /* 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/ResetEvent/test4/testinfo.dat b/src/pal/tests/palsuite/threading/ResetEvent/test4/testinfo.dat
new file mode 100644
index 0000000000..0223246c6f
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ResetEvent/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 = ResetEvent
+Name = Positive test for ResetEvent
+TYPE = DEFAULT
+EXE1 = test4
+Description
+= Test to ensure proper operation of the ResetEvent()
+= API by calling it on an event handle that's the
+= result of a DuplicateHandle() call on another event
+= handle.