summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/miscellaneous/CreatePipe
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/miscellaneous/CreatePipe')
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CreatePipe/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.c113
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/testinfo.dat15
4 files changed, 151 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/miscellaneous/CreatePipe/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CreatePipe/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/miscellaneous/CreatePipe/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/CMakeLists.txt
new file mode 100644
index 0000000000..af878cb873
--- /dev/null
+++ b/src/pal/tests/palsuite/miscellaneous/CreatePipe/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_createpipe_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createpipe_test1 coreclrpal)
+
+target_link_libraries(paltest_createpipe_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.c b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.c
new file mode 100644
index 0000000000..3930183b60
--- /dev/null
+++ b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/test1.c
@@ -0,0 +1,113 @@
+// 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 (CreatePipe)
+**
+** Purpose: Tests the PAL implementation of the CreatePipe function.
+** This test will create two pipes, a read and a write. Once
+** the pipes have been created, they will be tested by writing
+** and then reading, then comparing the results.
+**
+** Depends: WriteFile
+** ReadFile
+** memcmp
+** CloseHandle
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+const char* cTestString = "one fish, two fish, red fish, blue fish.";
+
+int __cdecl main(int argc, char **argv)
+{
+ HANDLE hReadPipe = NULL;
+ HANDLE hWritePipe = NULL;
+ BOOL bRetVal = FALSE;
+ DWORD dwBytesWritten;
+ DWORD dwBytesRead;
+ char buffer[256];
+
+ SECURITY_ATTRIBUTES lpPipeAttributes;
+
+ /*Initialize the PAL*/
+ if ((PAL_Initialize(argc, argv)) != 0)
+ {
+ return (FAIL);
+ }
+
+ /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/
+ lpPipeAttributes.nLength = sizeof(lpPipeAttributes);
+ lpPipeAttributes.lpSecurityDescriptor = NULL;
+ lpPipeAttributes.bInheritHandle = TRUE;
+
+ /*Create a Pipe*/
+ bRetVal = CreatePipe(&hReadPipe, /* read handle*/
+ &hWritePipe, /* write handle */
+ &lpPipeAttributes, /* security attributes*/
+ 0); /* pipe size*/
+ if (bRetVal == FALSE)
+ {
+ Fail("ERROR: %ld :Unable to create pipe\n", GetLastError());
+ }
+
+ /*Write to the write pipe handle*/
+ bRetVal = WriteFile(hWritePipe, /* handle to write pipe*/
+ cTestString, /* buffer to write*/
+ strlen(cTestString),/* number of bytes to write*/
+ &dwBytesWritten, /* number of bytes written*/
+ NULL); /* overlapped buffer*/
+ if (bRetVal == FALSE)
+ {
+ Fail("ERROR: %ld :unable to write to write pipe handle "
+ "hWritePipe=0x%lx\n", GetLastError(), hWritePipe);
+ }
+
+ /*Read, 256 bytes, more bytes then actually written.
+ This will give allow us to use the value that ReadFile
+ returns for comparision.*/
+ bRetVal = ReadFile(hReadPipe, /* handle to read pipe*/
+ buffer, /* buffer to write to*/
+ 256, /* number of bytes to read*/
+ &dwBytesRead, /* number of bytes read*/
+ NULL); /* overlapped buffer*/
+ if (bRetVal == FALSE)
+ {
+ Fail("ERROR: %ld : unable read hWritePipe=0x%lx\n",
+ GetLastError(), hWritePipe);
+ }
+
+ /*Compare what was read with what was written.*/
+ if ((memcmp(cTestString, buffer, dwBytesRead)) != 0)
+ {
+ Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString);
+ }
+
+ /*Compare values returned from WriteFile and ReadFile.*/
+ if (dwBytesWritten != dwBytesRead)
+ {
+ Fail("ERROR: WriteFile wrote \"%d\", but ReadFile read \"%d\","
+ " these should be the same\n", buffer, cTestString);
+ }
+
+ /*Close write pipe handle*/
+ if (CloseHandle(hWritePipe) == 0)
+ {
+ Fail("ERROR: %ld : Unable to close write pipe handle "
+ "hWritePipe=0x%lx\n",GetLastError(), hWritePipe);
+ }
+
+ /*Close Read pipe handle*/
+ if (CloseHandle(hReadPipe) == 0)
+ {
+ Fail("ERROR: %ld : Unable to close read pipe handle "
+ "hReadPipe=0x%lx\n", GetLastError(), hReadPipe);
+ }
+
+ PAL_Terminate();
+ return (PASS);
+}
diff --git a/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/testinfo.dat
new file mode 100644
index 0000000000..b9422b0627
--- /dev/null
+++ b/src/pal/tests/palsuite/miscellaneous/CreatePipe/test1/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 = Miscellaneous
+Function = CreatePipe
+Name = Test for CreatePipe
+TYPE = DEFAULT
+EXE1 = test1
+Description
+= Tests the PAL implementation of the CreatePipe function.
+= This test will create two pipes, a read and a write. Once
+= the pipes have been created, they will be tested by writing
+= and then reading, then comparing the results.