From 2f233ce1f90262486a6fe68dfaaa5ce73357cc26 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Fri, 25 Sep 2015 14:44:38 +0000 Subject: [PATCH] [KERNEL32_APITEST] Add a test for CORE-10188 (which was fixed by Thomas in r69236). It is based on Nikita Pechenkin's patch with a few modifications by me to avoid race condition on start (and avoid flappy test) and to match more closely our coding style ROSTESTS-190 #resolve #comment Committed in r69351. Thanks! svn path=/trunk/; revision=69351 --- rostests/apitests/kernel32/CMakeLists.txt | 3 +- rostests/apitests/kernel32/Mailslot.c | 83 +++++++++++++++++++++++ rostests/apitests/kernel32/testlist.c | 2 + 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 rostests/apitests/kernel32/Mailslot.c diff --git a/rostests/apitests/kernel32/CMakeLists.txt b/rostests/apitests/kernel32/CMakeLists.txt index f329e3c2e5b..b0569cf5345 100644 --- a/rostests/apitests/kernel32/CMakeLists.txt +++ b/rostests/apitests/kernel32/CMakeLists.txt @@ -13,7 +13,8 @@ list(APPEND SOURCE SetUnhandledExceptionFilter.c TerminateProcess.c TunnelCache.c - testlist.c) + testlist.c + Mailslot.c) add_executable(kernel32_apitest ${SOURCE}) target_link_libraries(kernel32_apitest wine ${PSEH_LIB}) diff --git a/rostests/apitests/kernel32/Mailslot.c b/rostests/apitests/kernel32/Mailslot.c new file mode 100644 index 00000000000..4cd701f2f9a --- /dev/null +++ b/rostests/apitests/kernel32/Mailslot.c @@ -0,0 +1,83 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GNU GPLv2 only as published by the Free Software Foundation + * PURPOSE: Test for mailslot (CORE-10188) + * PROGRAMMER: Nikita Pechenkin (n.pechenkin@mail.ru) + */ + +#include + +#define WIN32_NO_STATUS +#include + +#define LMS TEXT("\\\\.\\mailslot\\rostest_slot") +#define MSG (0x50DA) + +static DWORD dInMsg = MSG; +static DWORD dOutMsg = 0x0; + +DWORD +WINAPI +MailSlotWriter( + LPVOID lpParam) +{ + DWORD cbWritten; + HANDLE hMailslot; + + hMailslot = CreateFile(LMS, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + ok(hMailslot != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n"); + if (hMailslot != INVALID_HANDLE_VALUE) + { + Sleep(1000); + ok(WriteFile(hMailslot, &dInMsg, sizeof(dInMsg), &cbWritten, (LPOVERLAPPED) NULL), "Slot write failed\n"); + CloseHandle(hMailslot); + } + return 0; +} + +DWORD +WINAPI +MailSlotReader( + LPVOID lpParam) +{ + HANDLE hMailslotClient; + DWORD cbRead; + HANDLE hThread; + + hMailslotClient = CreateMailslot(LMS, 0L, MAILSLOT_WAIT_FOREVER, (LPSECURITY_ATTRIBUTES) NULL); + ok(hMailslotClient != INVALID_HANDLE_VALUE, "CreateMailslot failed\n"); + if (hMailslotClient != INVALID_HANDLE_VALUE) + { + hThread = CreateThread(NULL,0, MailSlotWriter, NULL, 0, NULL); + ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n"); + if (hThread != INVALID_HANDLE_VALUE) + { + ok(ReadFile(hMailslotClient, &dOutMsg, sizeof(dOutMsg), &cbRead, NULL), "Slot read failed\n"); + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + } + CloseHandle(hMailslotClient); + } + return 0; +} + +VOID +StartTestCORE10188(VOID) +{ + HANDLE hThread; + + hThread = CreateThread(NULL,0, MailSlotReader, NULL, 0, NULL); + ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n"); + if (hThread != INVALID_HANDLE_VALUE) + { + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + } + ok(dInMsg == dOutMsg, "Transfer data failed\n"); +} + +START_TEST(Mailslot) +{ + StartTestCORE10188(); +} diff --git a/rostests/apitests/kernel32/testlist.c b/rostests/apitests/kernel32/testlist.c index a4c04169f9a..178e1e621ee 100644 --- a/rostests/apitests/kernel32/testlist.c +++ b/rostests/apitests/kernel32/testlist.c @@ -10,6 +10,7 @@ extern void func_GetDriveType(void); extern void func_GetModuleFileName(void); extern void func_interlck(void); extern void func_lstrcpynW(void); +extern void func_Mailslot(void); extern void func_MultiByteToWideChar(void); extern void func_PrivMoveFileIdentityW(void); extern void func_SetCurrentDirectory(void); @@ -26,6 +27,7 @@ const struct test winetest_testlist[] = { "GetModuleFileName", func_GetModuleFileName }, { "interlck", func_interlck }, { "lstrcpynW", func_lstrcpynW }, + { "Mailslot", func_Mailslot }, { "MultiByteToWideChar", func_MultiByteToWideChar }, { "PrivMoveFileIdentityW", func_PrivMoveFileIdentityW }, { "SetCurrentDirectory", func_SetCurrentDirectory },