From: Piotr Caban Subject: [PATCH 1/2] kernel: Added pipe buffer size tests Message-Id: <552D4D4B.3080708@codeweavers.com> Date: Tue, 14 Apr 2015 19:24:27 +0200 --- dlls/kernel32/tests/pipe.c | 69 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c index b115ed8..3d79c78 100644 --- a/dlls/kernel32/tests/pipe.c +++ b/dlls/kernel32/tests/pipe.c @@ -36,6 +36,7 @@ static HANDLE alarm_event; static BOOL (WINAPI *pDuplicateTokenEx)(HANDLE,DWORD,LPSECURITY_ATTRIBUTES, SECURITY_IMPERSONATION_LEVEL,TOKEN_TYPE,PHANDLE); static DWORD (WINAPI *pQueueUserAPC)(PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData); +static BOOL (WINAPI *pConvertFiberToThread)(void); static BOOL user_apc_ran; static void CALLBACK user_apc(ULONG_PTR param) @@ -1313,10 +1314,27 @@ static int test_DisconnectNamedPipe(void) return 0; } + +#define PIPE_NAME "\\\\.\\pipe\\named_pipe_test" + +static DWORD WINAPI test_pipe_quota(void *p) +{ + HANDLE pipewrite = p; + DWORD i, written; + char c = 'a'; + + for (i = 0; i < 50; i++) + { + ok(WriteFile(pipewrite, &c, 1, &written, NULL), "WriteFile failed\n"); + ok(written == 1, "written = %u\n", written); + } + return 0; +} + static void test_CreatePipe(void) { SECURITY_ATTRIBUTES pipe_attr; - HANDLE piperead, pipewrite; + HANDLE piperead, pipewrite, thread; DWORD written; DWORD read; DWORD i, size; @@ -1368,6 +1386,52 @@ static void test_CreatePipe(void) ok(CloseHandle(piperead), "CloseHandle for the read pipe failed\n"); HeapFree(GetProcessHeap(), 0, buffer); + if (pConvertFiberToThread) + { + ok(CreatePipe(&piperead, &pipewrite, NULL, 50), "CreatePipe failed\n"); + thread = CreateThread(NULL, 0, test_pipe_quota, pipewrite, 0, NULL); + ok(thread != NULL, "CreateThread failed\n"); + i = WaitForSingleObject(thread, 500); + todo_wine ok(i == WAIT_OBJECT_0, "CreatePipe test_pipe_quota thread still running\n"); + if (i != WAIT_OBJECT_0) + TerminateThread(thread, 0); + CloseHandle(piperead); + CloseHandle(pipewrite); + CloseHandle(thread); + + pipewrite = CreateNamedPipeA(PIPE_NAME, PIPE_ACCESS_DUPLEX, + PIPE_TYPE_BYTE, 1, 50, 1, NMPWAIT_USE_DEFAULT_WAIT, NULL); + ok(pipewrite != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n"); + piperead = CreateFileA(PIPE_NAME, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); + ok(piperead != INVALID_HANDLE_VALUE, "CreateFile failed\n"); + thread = CreateThread(NULL, 0, test_pipe_quota, pipewrite, 0, NULL); + ok(thread != NULL, "CreateThread failed\n"); + i = WaitForSingleObject(thread, 500); + todo_wine ok(i == WAIT_OBJECT_0, "server test_pipe_quota thread still running\n"); + if (i != WAIT_OBJECT_0) + TerminateThread(thread, 0); + CloseHandle(piperead); + CloseHandle(pipewrite); + CloseHandle(thread); + + piperead = CreateNamedPipeA(PIPE_NAME, PIPE_ACCESS_DUPLEX, + PIPE_TYPE_BYTE, 1, 1, 50, NMPWAIT_USE_DEFAULT_WAIT, NULL); + ok(piperead != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n"); + pipewrite = CreateFileA(PIPE_NAME, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); + ok(pipewrite != INVALID_HANDLE_VALUE, "CreateFile failed\n"); + thread = CreateThread(NULL, 0, test_pipe_quota, pipewrite, 0, NULL); + ok(thread != NULL, "CreateThread failed\n"); + i = WaitForSingleObject(thread, 500); + todo_wine ok(i == WAIT_OBJECT_0, "client test_pipe_quota thread still running\n"); + if (i != WAIT_OBJECT_0) + TerminateThread(thread, 0); + CloseHandle(piperead); + CloseHandle(pipewrite); + CloseHandle(thread); + } + else + win_skip("pipe quota tests\n"); + ok(user_apc_ran == FALSE, "user apc ran, pipe using alertable io mode\n"); SleepEx(0, TRUE); /* get rid of apc */ } @@ -1379,8 +1443,6 @@ struct named_pipe_client_params BOOL revert; }; -#define PIPE_NAME "\\\\.\\pipe\\named_pipe_test" - static DWORD CALLBACK named_pipe_client_func(LPVOID p) { struct named_pipe_client_params *params = p; @@ -2155,6 +2217,7 @@ START_TEST(pipe) pDuplicateTokenEx = (void *) GetProcAddress(hmod, "DuplicateTokenEx"); hmod = GetModuleHandleA("kernel32.dll"); pQueueUserAPC = (void *) GetProcAddress(hmod, "QueueUserAPC"); + pConvertFiberToThread = (void *) GetProcAddress(hmod, "ConvertFiberToThread"); if (test_DisconnectNamedPipe()) return;