From be3a6b530452f57d19368e5a3b3190a95fd355db Mon Sep 17 00:00:00 2001 From: Julen Urizar Compains Date: Mon, 15 Apr 2024 21:28:20 +0200 Subject: [PATCH] [ROSTESTS] Add Pipes test based on the Kernel32 ReadFile work --- .../rostests/apitests/kernel32/CMakeLists.txt | 3 +- modules/rostests/apitests/kernel32/Pipes.c | 118 ++++++++++++++++++ modules/rostests/apitests/kernel32/testlist.c | 2 + 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 modules/rostests/apitests/kernel32/Pipes.c diff --git a/modules/rostests/apitests/kernel32/CMakeLists.txt b/modules/rostests/apitests/kernel32/CMakeLists.txt index 34b75d4054f05..ef8f8830a9e01 100644 --- a/modules/rostests/apitests/kernel32/CMakeLists.txt +++ b/modules/rostests/apitests/kernel32/CMakeLists.txt @@ -38,7 +38,8 @@ list(APPEND SOURCE TerminateProcess.c TunnelCache.c UEFIFirmware.c - WideCharToMultiByte.c) + WideCharToMultiByte.c + Pipes.c) list(APPEND PCH_SKIP_SOURCE testlist.c) diff --git a/modules/rostests/apitests/kernel32/Pipes.c b/modules/rostests/apitests/kernel32/Pipes.c new file mode 100644 index 0000000000000..3aae66b6fa5de --- /dev/null +++ b/modules/rostests/apitests/kernel32/Pipes.c @@ -0,0 +1,118 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GNU GPLv2 only as published by the Free Software Foundation + * PURPOSE: Test for pipe (CORE-17376) + * PROGRAMMER: Simone Mario Lombardo + */ + +#include "precomp.h" + +#define LP TEXT("\\\\.\\pipe\\rostest_pipe") + +#define MINBUFFERSIZE 1 +#define MAXBUFFERSIZE 255 + +static DWORD dReadBufferSize; + +DWORD +WINAPI +PipeWriter( + LPVOID lpParam) +{ + DWORD cbWritten; + HANDLE hPipe; + NTSTATUS lastError; + BOOL returnStatus; + LPSTR lpsInMsg = "Test"; + + hPipe = CreateFile(LP, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + ok(hPipe != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n"); + if (hPipe != INVALID_HANDLE_VALUE) + { + Sleep(1000); + returnStatus = WriteFile(hPipe, &lpsInMsg, 4, &cbWritten, (LPOVERLAPPED) NULL); + lastError = GetLastError(); + + ok(returnStatus, "Pipe's WriteFile returned FALSE, instead of expected TRUE\n"); + if(lastError != 0) + trace("Last Error = 0x%lX\n",lastError); + + ok(cbWritten > 0,"Pipe's Writefile has lpNumberOfBytesWritten <= 0\n"); + + CloseHandle(hPipe); + } + return 0; +} + +DWORD +WINAPI +PipeReader( + LPVOID lpParam) +{ + HANDLE hPipe; + DWORD cbRead; + HANDLE hThread; + NTSTATUS lastError; + BOOL returnStatus; + char lpsOutMsg[MAXBUFFERSIZE]; + + hPipe = CreateNamedPipeA(LP, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE,1,MAXBUFFERSIZE,MAXBUFFERSIZE,0,NULL); + ok(hPipe != INVALID_HANDLE_VALUE, "CreateNamedPipeA failed\n"); + if (hPipe != INVALID_HANDLE_VALUE) + { + hThread = CreateThread(NULL,0, PipeWriter, NULL, 0, NULL); + ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n"); + if (hThread != INVALID_HANDLE_VALUE) + { + Sleep(1000); + returnStatus = ReadFile(hPipe, &lpsOutMsg, dReadBufferSize, &cbRead, NULL); + lastError = GetLastError(); + + if(dReadBufferSize == MINBUFFERSIZE) + ok(!returnStatus, "Pipe's ReadFile returned TRUE, instead of expected FALSE\n"); + else{ + ok(returnStatus, "Pipe's ReadFile returned FALSE, instead of expected TRUE\n"); + if(lastError != 0) + trace("Last Error = 0x%lX\n",lastError); + } + + ok(cbRead > 0,"Pipe's Readfile has lpNumberOfBytesRead <= 0\n"); + + if(dReadBufferSize == MINBUFFERSIZE) + ok(lastError == ERROR_MORE_DATA, "Pipe's ReadFile last error is unexpected\n"); + + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + } + CloseHandle(hPipe); + } + return 0; +} + +VOID +StartTestCORE17376(DWORD adReadBufferSize) +{ + HANDLE hThread; + + trace("adReadBufferSize = %ld - START\n",adReadBufferSize); + + dReadBufferSize = adReadBufferSize; + + hThread = CreateThread(NULL,0, PipeReader, NULL, 0, NULL); + ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n"); + if (hThread != INVALID_HANDLE_VALUE) + { + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + } + + trace("adReadBufferSize = %ld - COMPLETED\n",adReadBufferSize); +} + +START_TEST(Pipes) +{ + StartTestCORE17376(MINBUFFERSIZE); + StartTestCORE17376(MAXBUFFERSIZE); +} + diff --git a/modules/rostests/apitests/kernel32/testlist.c b/modules/rostests/apitests/kernel32/testlist.c index 5fe42fb643cbe..aad7eba8d6d7e 100644 --- a/modules/rostests/apitests/kernel32/testlist.c +++ b/modules/rostests/apitests/kernel32/testlist.c @@ -39,6 +39,7 @@ extern void func_TerminateProcess(void); extern void func_TunnelCache(void); extern void func_UEFIFirmware(void); extern void func_WideCharToMultiByte(void); +extern void func_Pipes(void); const struct test winetest_testlist[] = { @@ -78,5 +79,6 @@ const struct test winetest_testlist[] = { "UEFIFirmware", func_UEFIFirmware }, { "WideCharToMultiByte", func_WideCharToMultiByte }, { "ActCtxWithXmlNamespaces", func_ActCtxWithXmlNamespaces }, + { "Pipes", func_Pipes }, { 0, 0 } };