diff options
Diffstat (limited to 'src/pal/tests/palsuite/threading/CreateEventA')
10 files changed, 519 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/CreateEventA/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventA/CMakeLists.txt new file mode 100644 index 0000000000..1962ade358 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) +add_subdirectory(test3) + diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventA/test1/CMakeLists.txt new file mode 100644 index 0000000000..49cbfebd0e --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test1/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_createeventa_test1 + ${SOURCES} +) + +add_dependencies(paltest_createeventa_test1 CoreClrPal) + +target_link_libraries(paltest_createeventa_test1 + pthread + rt + m + CoreClrPal +) diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.c b/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.c new file mode 100644 index 0000000000..8a90c76985 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test1/test1.c @@ -0,0 +1,100 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================ +** +** Source: test1.c +** +** Purpose: Test for CreateEvent. Create an event, ensure the +** HANDLE is valid. Then check to ensure that the object is in the +** signaled state. Close the HANDLE and done. +** +** +**=========================================================*/ + +/* + Note: From the rotor_pal documentation: + + lpEventAttributes will always be NULL, bManualReset can be either + TRUE or FALSE, bInitialState can be either TRUE or FALSE, the lpName + may be non-NULL + +*/ + + +#include <palsuite.h> + +BOOL CreateEventTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; + BOOL bManualReset = TRUE; + BOOL bInitialState = TRUE; + LPCTSTR lpName = "Event #1"; + + /* Call CreateEvent, and check to ensure the returned HANDLE is a + valid event HANDLE + */ + + HANDLE hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + lpName); + + if (hEvent != NULL) + { + /* Wait for the Object (for 0 time) and ensure that it returns + the value indicating that the event is signaled. + */ + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_OBJECT_0) + { + Trace("CreateEventTest:WaitForSingleObject %s " + "failed (%x)\n",lpName,GetLastError()); + } + else + { + /* If we make it here, and CloseHandle succeeds, then the + entire test has passed. Otherwise bRet will still show + failure + */ + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Trace("CreateEventTest:CloseHandle %s " + "failed (%x)\n",lpName,GetLastError()); + } + } + } + else + { + Trace("CreateEventTest:CreateEvent %s " + "failed (%x)\n",lpName,GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!CreateEventTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test1/testinfo.dat b/src/pal/tests/palsuite/threading/CreateEventA/test1/testinfo.dat new file mode 100644 index 0000000000..7917e61f5d --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test1/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = threading +Function = CreateEvent +Name = Positive Test for CreateEvent +TYPE = DEFAULT +EXE1 = test1 +Description += Test for CreateEvent. Create an event, ensure the += HANDLE is valid. Then check to ensure that the object is in the += signaled state. Close the HANDLE and done. diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test2/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventA/test2/CMakeLists.txt new file mode 100644 index 0000000000..a5719498f4 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test2/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.c +) + +add_executable(paltest_createeventa_test2 + ${SOURCES} +) + +add_dependencies(paltest_createeventa_test2 CoreClrPal) + +target_link_libraries(paltest_createeventa_test2 + pthread + rt + m + CoreClrPal +) diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.c b/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.c new file mode 100644 index 0000000000..1079459b8a --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test2/test2.c @@ -0,0 +1,89 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================ +** +** Source: test2.c +** +** Purpose: Test for CreateEvent. Create the event with the +** initial state being not signaled. Check to ensure that it +** times out when the event is triggered. +** +** +**=========================================================*/ + +#include <palsuite.h> + +BOOL CreateEventTest() +{ + BOOL bRet = FALSE; + DWORD dwRet = 0; + + LPSECURITY_ATTRIBUTES lpEventAttributes = 0; + BOOL bManualReset = TRUE; + BOOL bInitialState = FALSE; + LPCTSTR lpName = "Event #2"; + + /* Create an event with the Initial State set to FALSE */ + + HANDLE hEvent = CreateEvent( lpEventAttributes, + bManualReset, + bInitialState, + lpName); + + if (hEvent != NULL) + { + /* This should ensure that the object is reset, or + non-signaled. + */ + + dwRet = WaitForSingleObject(hEvent,0); + + if (dwRet != WAIT_TIMEOUT) + { + Trace("CloseEventTest:WaitForSingleObject %s " + "failed (%x)\n",lpName,GetLastError()); + } + else + { + /* At this point, we've tested the function with success. + So long as the HANDLE can be closed, this test should + pass. + */ + + bRet = CloseHandle(hEvent); + + if (!bRet) + { + Trace("CloseEventTest:CloseHandle %s failed " + " (%x)\n",lpName,GetLastError()); + } + } + } + else + { + Trace("CloseEventTest:CreateEvent %s " + "failed (%x)\n",lpName,GetLastError()); + } + + return bRet; +} + +int __cdecl main(int argc, char **argv) +{ + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + if(!CreateEventTest()) + { + Fail ("Test failed\n"); + } + + PAL_Terminate(); + return ( PASS ); + +} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test2/testinfo.dat b/src/pal/tests/palsuite/threading/CreateEventA/test2/testinfo.dat new file mode 100644 index 0000000000..c0ad88150d --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test2/testinfo.dat @@ -0,0 +1,14 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = threading +Function = CreateEvent +Name = Positive Test for CreateEvent +TYPE = DEFAULT +EXE1 = test2 +Description += Test for CreateEvent. Create the event with the += initial state being not signaled. Check to ensure that it += times out when the event is triggered. diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test3/CMakeLists.txt b/src/pal/tests/palsuite/threading/CreateEventA/test3/CMakeLists.txt new file mode 100644 index 0000000000..4437a9d4ba --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test3/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.c +) + +add_executable(paltest_createeventa_test3 + ${SOURCES} +) + +add_dependencies(paltest_createeventa_test3 CoreClrPal) + +target_link_libraries(paltest_createeventa_test3 + pthread + rt + m + CoreClrPal +) diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.c b/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.c new file mode 100644 index 0000000000..69854e5292 --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test3/test3.c @@ -0,0 +1,220 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*============================================================ +** +** Source: test3.c +** +** Purpose: Tests for CreateEventA. Create an event with an empty name, +** create an event with the same name as an already created event +** object. +** +** +**=========================================================*/ + +#include <palsuite.h> + +#define SWAPPTR ((VOID *)(-1)) + +struct testCase +{ + LPSECURITY_ATTRIBUTES lpEventAttributes; + BOOL bManualReset; + BOOL bInitialState; + char lpName[MAX_PATH + 2]; + DWORD dwNameLen; + DWORD lastError; + BOOL bResult; +}; + +struct testCase testCases[]= +{ + {0, TRUE, FALSE, "", 0, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, "", 5, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, "", 5, ERROR_ALREADY_EXISTS, PASS}, + {0, TRUE, FALSE, "", 6, ERROR_INVALID_HANDLE, PASS}, + {0, TRUE, FALSE, "", MAX_PATH - 1 - 60, ERROR_SUCCESS, PASS}, + {0, TRUE, FALSE, "", MAX_PATH + 1, ERROR_FILENAME_EXCED_RANGE, PASS} +}; + +static HANDLE hEvent[sizeof(testCases)/sizeof(struct testCase)]; + +DWORD result[sizeof(testCases)/sizeof(struct testCase)]; + +int __cdecl main(int argc, char **argv) +{ + + BOOL bRet = TRUE; + const char *nonEventName = "aaaaaa"; + HANDLE hUnnamedEvent; + HANDLE hFMap; + DWORD dwRet; + int i; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + hUnnamedEvent = CreateEventA(0, TRUE, FALSE, NULL); + + if ( NULL == hUnnamedEvent ) + { + bRet = FALSE; + Trace ( "PALSUITE ERROR: CreateEventA (%d, %d, %d, NULL) call " + "returned NULL.\nGetLastError returned %u.\n", 0, TRUE, FALSE, + GetLastError()); + } + + if (!CloseHandle(hUnnamedEvent)) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventA: CloseHandle(%lp); call " + "failed\nGetLastError returned '%u'.\n", hUnnamedEvent, + GetLastError()); + } + + /* Create non-event with the same name as one of the testCases */ + hFMap = CreateFileMappingA( SWAPPTR, NULL, PAGE_READONLY, 0, 1, + nonEventName ); + + if ( NULL == hFMap ) + { + bRet = FALSE; + Trace ( "PALSUITE ERROR: CreateFileMapping (%p, %p, %d, %d, %d, %s)" + " call returned NULL.\nGetLastError returned %u.\n", + SWAPPTR, NULL, PAGE_READONLY, 0, 0, nonEventName, + GetLastError()); + goto done; + } + + /* Create Events */ + for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) + { + /* create name */ + memset (testCases[i].lpName, '\0', (MAX_PATH + 2)); + memset (testCases[i].lpName, 'a', testCases[i].dwNameLen ); + + SetLastError(ERROR_SUCCESS); + + hEvent[i] = CreateEventA( testCases[i].lpEventAttributes, + testCases[i].bManualReset, + testCases[i].bInitialState, + testCases[i].lpName); + + if (hEvent[i] != INVALID_HANDLE_VALUE) + { + DWORD dwError = GetLastError(); + + if (dwError != testCases[i].lastError) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s)" + "\nGetLastError returned '%u', it should have returned" + "'%d' at index '%d'.\n", testCases[i].lpEventAttributes, + testCases[i].bManualReset, testCases[i].bInitialState, + testCases[i].lpName, dwError, + testCases[i].lastError, i); + } + if ( ERROR_FILENAME_EXCED_RANGE == testCases[i].lastError ) + { + result [i] = 1; + } + if ( ERROR_INVALID_HANDLE == testCases[i].lastError ) + { + result [i] = 1; + } + /* + * If we expected the testcase to FAIL and it passed, + * report an error. + */ + if (testCases[i].bResult == FAIL) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s)" + "\nShould have returned INVALID_HANDLE_VALUE but " + "didn't at index '%d'.\n", + testCases[i].lpEventAttributes, + testCases[i].bManualReset, + testCases[i].bInitialState, + testCases[i].lpName, i); + } + /* + * If result hasn't been set already set it to 0 so all the + * resources will be freed. + */ + if (!result[i] ) + { + result[i] = 0; + } + } + else + { + /* + * If we get an INVALID_HANDLE_VALUE and we expected the + * test case to pass, report an error. + */ + result[i] = 1; + + if (testCases[i].bResult == PASS) + { + bRet = FALSE; + Trace ("PALSUITE ERROR:\nCreateEventA(%lp, %d, %d, %s);" + "\nReturned INVALID_HANDLE_VALUE at index '%d'.\n", + testCases[i].lpEventAttributes, + testCases[i].bManualReset, testCases[i].bInitialState, + testCases[i].lpName, i); + } + } + } + + /* cleanup */ + for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++) + { + if (result[i]) + { + continue; + } + dwRet = WaitForSingleObject ( hEvent[i], 0 ); + + if (dwRet != WAIT_TIMEOUT) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventA:\nWaitForSingleObject (%lp, " + "%d) call failed at index %d .\nGetLastError returned " + "'%u'.\n", hEvent[i], 0, i, GetLastError()); + } + + if (!CloseHandle(hEvent[i])) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventA: CloseHandle(%lp) call " + "failed at index %d\nGetLastError returned '%u'.\n", + hEvent[i], i, GetLastError()); + } + } + +done: + if (!CloseHandle(hFMap)) + { + bRet = FALSE; + Trace("PALSUITE ERROR: CreateEventW: CloseHandle(%p) call " + "failed\nGetLastError returned '%u'.\n", hFMap, + GetLastError()); + } + + if (FALSE == bRet) + { + bRet = FAIL; + } + else + { + bRet = PASS; + } + + PAL_TerminateEx(bRet); + + return(bRet); +} diff --git a/src/pal/tests/palsuite/threading/CreateEventA/test3/testinfo.dat b/src/pal/tests/palsuite/threading/CreateEventA/test3/testinfo.dat new file mode 100644 index 0000000000..687bad64cf --- /dev/null +++ b/src/pal/tests/palsuite/threading/CreateEventA/test3/testinfo.dat @@ -0,0 +1,16 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = threading +Function = CreateEventA +Name = Positive Test for CreateEventA +TYPE = DEFAULT +EXE1 = test3 +Description += Tests for CreateEventA. Create an unnamed event, create += an event with an empty name, create an event with a name longer than += MAX_PATH, MAX_PATH + 1, create an event with a name already taken += by a non-event object, create an event with a name already taken += by an event object. |