2015-02-24 05:42:03 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for thread pool functions
|
|
|
|
*
|
2016-08-20 21:22:54 +02:00
|
|
|
* Copyright 2015-2016 Sebastian Lackner
|
2015-02-24 05:42:03 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-04-11 07:16:26 +02:00
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
#define NONAMELESSUNION
|
2015-02-24 05:42:03 +01:00
|
|
|
#include "ntdll_test.h"
|
|
|
|
|
2015-07-01 02:57:32 +02:00
|
|
|
static NTSTATUS (WINAPI *pTpAllocCleanupGroup)(TP_CLEANUP_GROUP **);
|
2020-04-11 07:16:26 +02:00
|
|
|
static NTSTATUS (WINAPI *pTpAllocIoCompletion)(TP_IO **,HANDLE,PTP_IO_CALLBACK,void *,TP_CALLBACK_ENVIRON *);
|
2015-02-24 05:42:03 +01:00
|
|
|
static NTSTATUS (WINAPI *pTpAllocPool)(TP_POOL **,PVOID);
|
2015-07-03 01:58:45 +02:00
|
|
|
static NTSTATUS (WINAPI *pTpAllocTimer)(TP_TIMER **,PTP_TIMER_CALLBACK,PVOID,TP_CALLBACK_ENVIRON *);
|
2015-07-05 02:24:02 +02:00
|
|
|
static NTSTATUS (WINAPI *pTpAllocWait)(TP_WAIT **,PTP_WAIT_CALLBACK,PVOID,TP_CALLBACK_ENVIRON *);
|
2015-07-01 02:58:26 +02:00
|
|
|
static NTSTATUS (WINAPI *pTpAllocWork)(TP_WORK **,PTP_WORK_CALLBACK,PVOID,TP_CALLBACK_ENVIRON *);
|
2015-07-01 22:55:30 +02:00
|
|
|
static NTSTATUS (WINAPI *pTpCallbackMayRunLong)(TP_CALLBACK_INSTANCE *);
|
2015-07-01 22:57:16 +02:00
|
|
|
static VOID (WINAPI *pTpCallbackReleaseSemaphoreOnCompletion)(TP_CALLBACK_INSTANCE *,HANDLE,DWORD);
|
2020-04-11 07:16:26 +02:00
|
|
|
static void (WINAPI *pTpCancelAsyncIoOperation)(TP_IO *);
|
2015-07-03 01:57:38 +02:00
|
|
|
static VOID (WINAPI *pTpDisassociateCallback)(TP_CALLBACK_INSTANCE *);
|
2015-07-03 01:58:45 +02:00
|
|
|
static BOOL (WINAPI *pTpIsTimerSet)(TP_TIMER *);
|
2015-07-05 02:24:02 +02:00
|
|
|
static VOID (WINAPI *pTpReleaseWait)(TP_WAIT *);
|
2015-07-01 02:58:26 +02:00
|
|
|
static VOID (WINAPI *pTpPostWork)(TP_WORK *);
|
2015-07-01 02:57:32 +02:00
|
|
|
static VOID (WINAPI *pTpReleaseCleanupGroup)(TP_CLEANUP_GROUP *);
|
|
|
|
static VOID (WINAPI *pTpReleaseCleanupGroupMembers)(TP_CLEANUP_GROUP *,BOOL,PVOID);
|
2020-04-11 07:16:26 +02:00
|
|
|
static void (WINAPI *pTpReleaseIoCompletion)(TP_IO *);
|
2015-02-24 05:42:03 +01:00
|
|
|
static VOID (WINAPI *pTpReleasePool)(TP_POOL *);
|
2015-07-03 01:58:45 +02:00
|
|
|
static VOID (WINAPI *pTpReleaseTimer)(TP_TIMER *);
|
2015-07-01 02:58:26 +02:00
|
|
|
static VOID (WINAPI *pTpReleaseWork)(TP_WORK *);
|
2015-07-01 02:59:01 +02:00
|
|
|
static VOID (WINAPI *pTpSetPoolMaxThreads)(TP_POOL *,DWORD);
|
2015-07-03 01:58:45 +02:00
|
|
|
static VOID (WINAPI *pTpSetTimer)(TP_TIMER *,LARGE_INTEGER *,LONG,LONG);
|
2015-07-05 02:24:02 +02:00
|
|
|
static VOID (WINAPI *pTpSetWait)(TP_WAIT *,HANDLE,LARGE_INTEGER *);
|
2015-02-24 05:42:03 +01:00
|
|
|
static NTSTATUS (WINAPI *pTpSimpleTryPost)(PTP_SIMPLE_CALLBACK,PVOID,TP_CALLBACK_ENVIRON *);
|
2020-04-11 07:16:26 +02:00
|
|
|
static void (WINAPI *pTpStartAsyncIoOperation)(TP_IO *);
|
|
|
|
static void (WINAPI *pTpWaitForIoCompletion)(TP_IO *,BOOL);
|
2015-07-03 01:58:45 +02:00
|
|
|
static VOID (WINAPI *pTpWaitForTimer)(TP_TIMER *,BOOL);
|
2015-07-05 02:24:02 +02:00
|
|
|
static VOID (WINAPI *pTpWaitForWait)(TP_WAIT *,BOOL);
|
2015-07-01 02:58:26 +02:00
|
|
|
static VOID (WINAPI *pTpWaitForWork)(TP_WORK *,BOOL);
|
2015-02-24 05:42:03 +01:00
|
|
|
|
2020-04-11 07:16:27 +02:00
|
|
|
static void (WINAPI *pCancelThreadpoolIo)(TP_IO *);
|
|
|
|
static void (WINAPI *pCloseThreadpoolIo)(TP_IO *);
|
|
|
|
static TP_IO *(WINAPI *pCreateThreadpoolIo)(HANDLE, PTP_WIN32_IO_CALLBACK, void *, TP_CALLBACK_ENVIRON *);
|
|
|
|
static void (WINAPI *pStartThreadpoolIo)(TP_IO *);
|
|
|
|
static void (WINAPI *pWaitForThreadpoolIoCallbacks)(TP_IO *, BOOL);
|
|
|
|
|
|
|
|
#define GET_PROC(func) \
|
2015-02-24 05:42:03 +01:00
|
|
|
do \
|
|
|
|
{ \
|
2020-04-11 07:16:27 +02:00
|
|
|
p ## func = (void *)GetProcAddress(module, #func); \
|
2015-02-24 05:42:03 +01:00
|
|
|
if (!p ## func) trace("Failed to get address for %s\n", #func); \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
static BOOL init_threadpool(void)
|
|
|
|
{
|
2020-04-11 07:16:27 +02:00
|
|
|
HMODULE module = GetModuleHandleA("ntdll");
|
|
|
|
GET_PROC(TpAllocCleanupGroup);
|
|
|
|
GET_PROC(TpAllocIoCompletion);
|
|
|
|
GET_PROC(TpAllocPool);
|
|
|
|
GET_PROC(TpAllocTimer);
|
|
|
|
GET_PROC(TpAllocWait);
|
|
|
|
GET_PROC(TpAllocWork);
|
|
|
|
GET_PROC(TpCallbackMayRunLong);
|
|
|
|
GET_PROC(TpCallbackReleaseSemaphoreOnCompletion);
|
|
|
|
GET_PROC(TpCancelAsyncIoOperation);
|
|
|
|
GET_PROC(TpDisassociateCallback);
|
|
|
|
GET_PROC(TpIsTimerSet);
|
|
|
|
GET_PROC(TpPostWork);
|
|
|
|
GET_PROC(TpReleaseCleanupGroup);
|
|
|
|
GET_PROC(TpReleaseCleanupGroupMembers);
|
|
|
|
GET_PROC(TpReleaseIoCompletion);
|
|
|
|
GET_PROC(TpReleasePool);
|
|
|
|
GET_PROC(TpReleaseTimer);
|
|
|
|
GET_PROC(TpReleaseWait);
|
|
|
|
GET_PROC(TpReleaseWork);
|
|
|
|
GET_PROC(TpSetPoolMaxThreads);
|
|
|
|
GET_PROC(TpSetTimer);
|
|
|
|
GET_PROC(TpSetWait);
|
|
|
|
GET_PROC(TpSimpleTryPost);
|
|
|
|
GET_PROC(TpStartAsyncIoOperation);
|
|
|
|
GET_PROC(TpWaitForIoCompletion);
|
|
|
|
GET_PROC(TpWaitForTimer);
|
|
|
|
GET_PROC(TpWaitForWait);
|
|
|
|
GET_PROC(TpWaitForWork);
|
|
|
|
|
|
|
|
module = GetModuleHandleA("kernel32");
|
|
|
|
GET_PROC(CancelThreadpoolIo);
|
|
|
|
GET_PROC(CloseThreadpoolIo);
|
|
|
|
GET_PROC(CreateThreadpoolIo);
|
|
|
|
GET_PROC(StartThreadpoolIo);
|
|
|
|
GET_PROC(WaitForThreadpoolIoCallbacks);
|
2015-02-24 05:42:03 +01:00
|
|
|
|
|
|
|
if (!pTpAllocPool)
|
|
|
|
{
|
2015-07-01 02:55:27 +02:00
|
|
|
win_skip("Threadpool functions not supported, skipping tests\n");
|
2015-02-24 05:42:03 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef NTDLL_GET_PROC
|
|
|
|
|
|
|
|
|
2015-07-26 23:23:57 +02:00
|
|
|
static DWORD CALLBACK rtl_work_cb(void *userdata)
|
|
|
|
{
|
|
|
|
HANDLE semaphore = userdata;
|
|
|
|
ReleaseSemaphore(semaphore, 1, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_RtlQueueWorkItem(void)
|
|
|
|
{
|
|
|
|
HANDLE semaphore;
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
semaphore = CreateSemaphoreA(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphore != NULL, "CreateSemaphoreA failed %u\n", GetLastError());
|
|
|
|
|
|
|
|
status = RtlQueueWorkItem(rtl_work_cb, semaphore, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlQueueWorkItem failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
status = RtlQueueWorkItem(rtl_work_cb, semaphore, WT_EXECUTEINIOTHREAD);
|
|
|
|
ok(!status, "RtlQueueWorkItem failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
status = RtlQueueWorkItem(rtl_work_cb, semaphore, WT_EXECUTEINPERSISTENTTHREAD);
|
|
|
|
ok(!status, "RtlQueueWorkItem failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
status = RtlQueueWorkItem(rtl_work_cb, semaphore, WT_EXECUTELONGFUNCTION);
|
|
|
|
ok(!status, "RtlQueueWorkItem failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
status = RtlQueueWorkItem(rtl_work_cb, semaphore, WT_TRANSFER_IMPERSONATION);
|
|
|
|
ok(!status, "RtlQueueWorkItem failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
CloseHandle(semaphore);
|
|
|
|
}
|
|
|
|
|
2015-10-07 01:24:50 +02:00
|
|
|
struct rtl_wait_info
|
|
|
|
{
|
|
|
|
HANDLE semaphore1;
|
|
|
|
HANDLE semaphore2;
|
|
|
|
DWORD wait_result;
|
2015-10-09 06:37:57 +02:00
|
|
|
DWORD threadid;
|
2015-10-07 01:24:50 +02:00
|
|
|
LONG userdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void CALLBACK rtl_wait_cb(void *userdata, BOOLEAN timeout)
|
|
|
|
{
|
|
|
|
struct rtl_wait_info *info = userdata;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
if (!timeout)
|
|
|
|
InterlockedIncrement(&info->userdata);
|
|
|
|
else
|
|
|
|
InterlockedExchangeAdd(&info->userdata, 0x10000);
|
2015-10-09 06:37:57 +02:00
|
|
|
info->threadid = GetCurrentThreadId();
|
2015-10-07 01:24:50 +02:00
|
|
|
ReleaseSemaphore(info->semaphore1, 1, NULL);
|
|
|
|
|
|
|
|
if (info->semaphore2)
|
|
|
|
{
|
|
|
|
result = WaitForSingleObject(info->semaphore2, 200);
|
|
|
|
ok(result == info->wait_result, "expected %u, got %u\n", info->wait_result, result);
|
|
|
|
ReleaseSemaphore(info->semaphore1, 1, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-09 06:37:57 +02:00
|
|
|
static HANDLE rtl_wait_apc_semaphore;
|
|
|
|
|
|
|
|
static void CALLBACK rtl_wait_apc_cb(ULONG_PTR userdata)
|
|
|
|
{
|
|
|
|
if (rtl_wait_apc_semaphore)
|
|
|
|
ReleaseSemaphore(rtl_wait_apc_semaphore, 1, NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-07 01:24:50 +02:00
|
|
|
static void test_RtlRegisterWait(void)
|
|
|
|
{
|
2015-10-09 06:37:57 +02:00
|
|
|
HANDLE wait1, event, thread;
|
2015-10-07 01:24:50 +02:00
|
|
|
struct rtl_wait_info info;
|
|
|
|
HANDLE semaphores[2];
|
|
|
|
NTSTATUS status;
|
2021-02-10 12:56:04 +01:00
|
|
|
DWORD result, threadid;
|
2015-10-07 01:24:50 +02:00
|
|
|
|
|
|
|
semaphores[0] = CreateSemaphoreW(NULL, 0, 2, NULL);
|
|
|
|
ok(semaphores[0] != NULL, "failed to create semaphore\n");
|
|
|
|
semaphores[1] = CreateSemaphoreW(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphores[1] != NULL, "failed to create semaphore\n");
|
|
|
|
info.semaphore1 = semaphores[0];
|
|
|
|
info.semaphore2 = NULL;
|
|
|
|
|
|
|
|
event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
ok(event != NULL, "failed to create event\n");
|
|
|
|
|
|
|
|
/* basic test for RtlRegisterWait and RtlDeregisterWait */
|
|
|
|
wait1 = NULL;
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ok(wait1 != NULL, "expected wait1 != NULL\n");
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
|
|
|
|
/* infinite timeout, signal the semaphore two times */
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 2, "expected info.userdata = 2, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
2015-10-09 06:36:39 +02:00
|
|
|
Sleep(50);
|
2015-10-07 01:24:50 +02:00
|
|
|
status = RtlDeregisterWait(wait1);
|
2015-10-09 06:36:39 +02:00
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
2015-10-07 01:24:50 +02:00
|
|
|
|
|
|
|
/* repeat test with WT_EXECUTEONLYONCE */
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
2015-10-09 06:36:39 +02:00
|
|
|
Sleep(50);
|
2015-10-07 01:24:50 +02:00
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
|
|
|
|
|
|
|
/* finite timeout, no event */
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 200, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
2015-10-09 06:36:39 +02:00
|
|
|
Sleep(50);
|
2015-10-07 01:24:50 +02:00
|
|
|
status = RtlDeregisterWait(wait1);
|
2015-10-09 06:36:39 +02:00
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
2015-10-07 01:24:50 +02:00
|
|
|
|
|
|
|
/* finite timeout, with event */
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 200, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
2015-10-09 06:36:39 +02:00
|
|
|
Sleep(50);
|
2015-10-07 01:24:50 +02:00
|
|
|
status = RtlDeregisterWait(wait1);
|
2015-10-09 06:36:39 +02:00
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
2015-10-07 01:24:50 +02:00
|
|
|
|
2021-02-10 12:56:04 +01:00
|
|
|
/* test RtlRegisterWait WT_EXECUTEINWAITTHREAD flag */
|
|
|
|
info.userdata = 0;
|
|
|
|
info.threadid = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 200, WT_EXECUTEINWAITTHREAD|WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
ok(info.threadid && info.threadid != GetCurrentThreadId(), "unexpected wait thread id %x\n", info.threadid);
|
|
|
|
threadid = info.threadid;
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
|
|
|
|
|
|
|
info.userdata = 0;
|
|
|
|
info.threadid = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 200, WT_EXECUTEINWAITTHREAD|WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
2021-02-11 10:53:49 +01:00
|
|
|
ok(info.threadid == threadid, "unexpected different wait thread id %x\n", info.threadid);
|
2021-02-10 12:56:04 +01:00
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
|
|
|
|
|
|
|
/* test RtlRegisterWait WT_EXECUTEINWAITTHREAD flag with 0 timeout */
|
|
|
|
info.userdata = 0;
|
|
|
|
info.threadid = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 0, WT_EXECUTEINWAITTHREAD|WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
ok(info.threadid == threadid, "unexpected different wait thread id %x\n", info.threadid);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
|
|
|
|
|
|
|
/* test RtlRegisterWait WT_EXECUTEINWAITTHREAD flag with already signaled event */
|
|
|
|
info.userdata = 0;
|
|
|
|
info.threadid = 0;
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 200, WT_EXECUTEINWAITTHREAD|WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
2021-02-11 10:53:49 +01:00
|
|
|
ok(info.threadid == threadid, "unexpected different wait thread id %x\n", info.threadid);
|
2021-02-10 12:56:04 +01:00
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
|
|
|
|
2015-10-09 06:37:57 +02:00
|
|
|
/* test for IO threads */
|
|
|
|
info.userdata = 0;
|
|
|
|
info.threadid = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEINIOTHREAD);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
ok(info.threadid != 0, "expected info.threadid != 0, got %u\n", info.threadid);
|
|
|
|
thread = OpenThread(THREAD_SET_CONTEXT, FALSE, info.threadid);
|
|
|
|
ok(thread != NULL, "OpenThread failed with %u\n", GetLastError());
|
|
|
|
rtl_wait_apc_semaphore = semaphores[0];
|
|
|
|
result = QueueUserAPC(rtl_wait_apc_cb, thread, 0);
|
|
|
|
ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError());
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
rtl_wait_apc_semaphore = 0;
|
|
|
|
CloseHandle(thread);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 2, "expected info.userdata = 2, got %u\n", info.userdata);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
|
|
|
|
|
|
|
info.userdata = 0;
|
|
|
|
info.threadid = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
ok(info.threadid != 0, "expected info.threadid != 0, got %u\n", info.threadid);
|
|
|
|
thread = OpenThread(THREAD_SET_CONTEXT, FALSE, info.threadid);
|
|
|
|
ok(thread != NULL, "OpenThread failed with %u\n", GetLastError());
|
|
|
|
rtl_wait_apc_semaphore = semaphores[0];
|
|
|
|
result = QueueUserAPC(rtl_wait_apc_cb, thread, 0);
|
|
|
|
ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError());
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_TIMEOUT || broken(result == WAIT_OBJECT_0) /* >= Win Vista */,
|
|
|
|
"WaitForSingleObject returned %u\n", result);
|
|
|
|
rtl_wait_apc_semaphore = 0;
|
|
|
|
CloseHandle(thread);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 2, "expected info.userdata = 2, got %u\n", info.userdata);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(!status, "RtlDeregisterWait failed with status %x\n", status);
|
|
|
|
|
2015-10-07 01:24:50 +02:00
|
|
|
/* test RtlDeregisterWaitEx before wait expired */
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, NULL);
|
|
|
|
ok(!status, "RtlDeregisterWaitEx failed with status %x\n", status);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, INVALID_HANDLE_VALUE);
|
|
|
|
ok(!status, "RtlDeregisterWaitEx failed with status %x\n", status);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEDEFAULT);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, event);
|
|
|
|
ok(!status, "RtlDeregisterWaitEx failed with status %x\n", status);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(event, 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* test RtlDeregisterWaitEx after wait expired */
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 0, WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, NULL);
|
|
|
|
ok(!status, "RtlDeregisterWaitEx failed with status %x\n", status);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 0, WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, INVALID_HANDLE_VALUE);
|
|
|
|
ok(!status, "RtlDeregisterWaitEx failed with status %x\n", status);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, 0, WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
Sleep(50);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, event);
|
|
|
|
ok(!status, "RtlDeregisterWaitEx failed with status %x\n", status);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(event, 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* test RtlDeregisterWaitEx while callback is running */
|
|
|
|
info.semaphore2 = semaphores[1];
|
|
|
|
info.wait_result = WAIT_OBJECT_0;
|
|
|
|
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(status == STATUS_PENDING, "expected STATUS_PENDING, got %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
2021-02-10 12:56:04 +01:00
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEINWAITTHREAD|WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
status = RtlDeregisterWait(wait1);
|
|
|
|
ok(status == STATUS_PENDING, "expected STATUS_PENDING, got %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
2015-10-07 01:24:50 +02:00
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, NULL);
|
|
|
|
ok(status == STATUS_PENDING, "expected STATUS_PENDING, got %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
info.wait_result = WAIT_TIMEOUT;
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, INVALID_HANDLE_VALUE);
|
|
|
|
ok(!status, "RtlDeregisterWaitEx failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 0);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
2021-02-10 12:56:04 +01:00
|
|
|
|
|
|
|
info.wait_result = WAIT_TIMEOUT;
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEINWAITTHREAD|WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, INVALID_HANDLE_VALUE);
|
|
|
|
ok(!status, "RtlDeregisterWaitEx failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 0);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
2015-10-07 01:24:50 +02:00
|
|
|
|
|
|
|
info.wait_result = WAIT_OBJECT_0;
|
|
|
|
info.userdata = 0;
|
|
|
|
status = RtlRegisterWait(&wait1, semaphores[1], rtl_wait_cb, &info, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
ok(!status, "RtlRegisterWait failed with status %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
status = RtlDeregisterWaitEx(wait1, event);
|
|
|
|
ok(status == STATUS_PENDING, "expected STATUS_PENDING, got %x\n", status);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(event, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 0);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
CloseHandle(semaphores[0]);
|
|
|
|
CloseHandle(semaphores[1]);
|
|
|
|
CloseHandle(event);
|
|
|
|
}
|
|
|
|
|
2015-02-24 05:42:03 +01:00
|
|
|
static void CALLBACK simple_cb(TP_CALLBACK_INSTANCE *instance, void *userdata)
|
|
|
|
{
|
|
|
|
HANDLE semaphore = userdata;
|
|
|
|
ReleaseSemaphore(semaphore, 1, NULL);
|
|
|
|
}
|
|
|
|
|
2015-07-01 02:57:32 +02:00
|
|
|
static void CALLBACK simple2_cb(TP_CALLBACK_INSTANCE *instance, void *userdata)
|
|
|
|
{
|
|
|
|
Sleep(50);
|
|
|
|
InterlockedIncrement((LONG *)userdata);
|
|
|
|
}
|
|
|
|
|
2015-02-24 05:42:03 +01:00
|
|
|
static void test_tp_simple(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
2016-03-31 04:53:25 +02:00
|
|
|
TP_CALLBACK_ENVIRON_V3 environment3;
|
2015-07-01 02:57:32 +02:00
|
|
|
TP_CLEANUP_GROUP *group;
|
2015-02-24 05:42:03 +01:00
|
|
|
HANDLE semaphore;
|
|
|
|
NTSTATUS status;
|
|
|
|
TP_POOL *pool;
|
2015-07-01 02:57:32 +02:00
|
|
|
LONG userdata;
|
2015-02-24 05:42:03 +01:00
|
|
|
DWORD result;
|
2015-07-01 02:57:32 +02:00
|
|
|
int i;
|
2015-02-24 05:42:03 +01:00
|
|
|
|
|
|
|
semaphore = CreateSemaphoreA(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphore != NULL, "CreateSemaphoreA failed %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* post the callback using the default threadpool */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = NULL;
|
|
|
|
status = pTpSimpleTryPost(simple_cb, semaphore, &environment);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* allocate new threadpool */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* post the callback using the new threadpool */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
status = pTpSimpleTryPost(simple_cb, semaphore, &environment);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
2016-03-31 04:53:25 +02:00
|
|
|
|
|
|
|
/* test with environment version 3 */
|
|
|
|
memset(&environment3, 0, sizeof(environment3));
|
|
|
|
environment3.Version = 3;
|
|
|
|
environment3.Pool = pool;
|
|
|
|
environment3.Size = sizeof(environment3);
|
2019-03-13 07:28:45 +01:00
|
|
|
|
|
|
|
for (i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
environment3.CallbackPriority = TP_CALLBACK_PRIORITY_HIGH + i;
|
|
|
|
status = pTpSimpleTryPost(simple_cb, semaphore, (TP_CALLBACK_ENVIRON *)&environment3);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
environment3.CallbackPriority = 10;
|
2016-03-31 04:53:25 +02:00
|
|
|
status = pTpSimpleTryPost(simple_cb, semaphore, (TP_CALLBACK_ENVIRON *)&environment3);
|
2019-03-13 07:28:45 +01:00
|
|
|
ok(status == STATUS_INVALID_PARAMETER || broken(!status) /* Vista does not support priorities */,
|
|
|
|
"TpSimpleTryPost failed with status %x\n", status);
|
2015-02-24 05:42:03 +01:00
|
|
|
|
|
|
|
/* test with invalid version number */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 9999;
|
|
|
|
environment.Pool = pool;
|
|
|
|
status = pTpSimpleTryPost(simple_cb, semaphore, &environment);
|
2015-07-01 02:55:27 +02:00
|
|
|
todo_wine
|
2015-02-24 05:42:03 +01:00
|
|
|
ok(status == STATUS_INVALID_PARAMETER || broken(!status) /* Vista/2008 */,
|
|
|
|
"TpSimpleTryPost unexpectedly returned status %x\n", status);
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
}
|
|
|
|
|
2015-07-01 02:57:32 +02:00
|
|
|
/* allocate a cleanup group for synchronization */
|
|
|
|
group = NULL;
|
|
|
|
status = pTpAllocCleanupGroup(&group);
|
|
|
|
ok(!status, "TpAllocCleanupGroup failed with status %x\n", status);
|
|
|
|
ok(group != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* use cleanup group to wait for a simple callback */
|
|
|
|
userdata = 0;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
status = pTpSimpleTryPost(simple2_cb, &userdata, &environment);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, FALSE, NULL);
|
|
|
|
ok(userdata == 1, "expected userdata = 1, got %u\n", userdata);
|
|
|
|
|
|
|
|
/* test cancellation of pending simple callbacks */
|
|
|
|
userdata = 0;
|
2015-10-07 01:23:54 +02:00
|
|
|
pTpSetPoolMaxThreads(pool, 10);
|
2015-07-01 02:57:32 +02:00
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
{
|
|
|
|
status = pTpSimpleTryPost(simple2_cb, &userdata, &environment);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
}
|
|
|
|
pTpReleaseCleanupGroupMembers(group, TRUE, NULL);
|
|
|
|
ok(userdata < 100, "expected userdata < 100, got %u\n", userdata);
|
|
|
|
|
2015-02-24 05:42:03 +01:00
|
|
|
/* cleanup */
|
2015-07-01 02:57:32 +02:00
|
|
|
pTpReleaseCleanupGroup(group);
|
2015-02-24 05:42:03 +01:00
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphore);
|
|
|
|
}
|
|
|
|
|
2015-07-01 02:58:26 +02:00
|
|
|
static void CALLBACK work_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_WORK *work)
|
|
|
|
{
|
2016-08-20 21:18:33 +02:00
|
|
|
Sleep(100);
|
2015-07-01 02:58:26 +02:00
|
|
|
InterlockedIncrement((LONG *)userdata);
|
|
|
|
}
|
|
|
|
|
2015-07-01 02:59:01 +02:00
|
|
|
static void CALLBACK work2_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_WORK *work)
|
|
|
|
{
|
2016-08-20 21:18:33 +02:00
|
|
|
Sleep(100);
|
2015-07-01 02:59:01 +02:00
|
|
|
InterlockedExchangeAdd((LONG *)userdata, 0x10000);
|
|
|
|
}
|
|
|
|
|
2015-07-01 02:58:26 +02:00
|
|
|
static void test_tp_work(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
TP_WORK *work;
|
|
|
|
TP_POOL *pool;
|
|
|
|
NTSTATUS status;
|
|
|
|
LONG userdata;
|
|
|
|
int i;
|
|
|
|
|
2016-08-20 21:18:33 +02:00
|
|
|
/* allocate new threadpool with only one thread */
|
2015-07-01 02:58:26 +02:00
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
2016-08-20 21:18:33 +02:00
|
|
|
pTpSetPoolMaxThreads(pool, 1);
|
2015-07-01 02:58:26 +02:00
|
|
|
|
|
|
|
/* allocate new work item */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
status = pTpAllocWork(&work, work_cb, &userdata, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
|
2016-08-20 21:18:33 +02:00
|
|
|
/* post 5 identical work items at once */
|
2015-07-01 02:58:26 +02:00
|
|
|
userdata = 0;
|
2016-08-20 21:18:33 +02:00
|
|
|
for (i = 0; i < 5; i++)
|
2015-07-01 02:58:26 +02:00
|
|
|
pTpPostWork(work);
|
|
|
|
pTpWaitForWork(work, FALSE);
|
2016-08-20 21:18:33 +02:00
|
|
|
ok(userdata == 5, "expected userdata = 5, got %u\n", userdata);
|
2015-07-01 02:58:26 +02:00
|
|
|
|
|
|
|
/* add more tasks and cancel them immediately */
|
|
|
|
userdata = 0;
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
pTpPostWork(work);
|
|
|
|
pTpWaitForWork(work, TRUE);
|
|
|
|
ok(userdata < 10, "expected userdata < 10, got %u\n", userdata);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleaseWork(work);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
}
|
|
|
|
|
2015-07-01 02:59:01 +02:00
|
|
|
static void test_tp_work_scheduler(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
TP_CLEANUP_GROUP *group;
|
|
|
|
TP_WORK *work, *work2;
|
|
|
|
TP_POOL *pool;
|
|
|
|
NTSTATUS status;
|
|
|
|
LONG userdata;
|
|
|
|
int i;
|
|
|
|
|
2016-08-20 21:18:33 +02:00
|
|
|
/* allocate new threadpool with only one thread */
|
2015-07-01 02:59:01 +02:00
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
pTpSetPoolMaxThreads(pool, 1);
|
|
|
|
|
|
|
|
/* create a cleanup group */
|
|
|
|
group = NULL;
|
|
|
|
status = pTpAllocCleanupGroup(&group);
|
|
|
|
ok(!status, "TpAllocCleanupGroup failed with status %x\n", status);
|
|
|
|
ok(group != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* the first work item has no cleanup group associated */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
status = pTpAllocWork(&work, work_cb, &userdata, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
|
|
|
|
/* allocate a second work item with a cleanup group */
|
|
|
|
work2 = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
status = pTpAllocWork(&work2, work2_cb, &userdata, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work2 != NULL, "expected work2 != NULL\n");
|
|
|
|
|
|
|
|
/* the 'work' callbacks are not blocking execution of 'work2' callbacks */
|
|
|
|
userdata = 0;
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
pTpPostWork(work);
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
pTpPostWork(work2);
|
2016-08-20 21:18:33 +02:00
|
|
|
Sleep(500);
|
2015-07-01 02:59:01 +02:00
|
|
|
pTpWaitForWork(work, TRUE);
|
|
|
|
pTpWaitForWork(work2, TRUE);
|
|
|
|
ok(userdata & 0xffff, "expected userdata & 0xffff != 0, got %u\n", userdata & 0xffff);
|
|
|
|
ok(userdata >> 16, "expected userdata >> 16 != 0, got %u\n", userdata >> 16);
|
|
|
|
|
|
|
|
/* test TpReleaseCleanupGroupMembers on a work item */
|
|
|
|
userdata = 0;
|
|
|
|
for (i = 0; i < 10; i++)
|
2016-08-20 21:18:33 +02:00
|
|
|
pTpPostWork(work);
|
|
|
|
for (i = 0; i < 3; i++)
|
2015-07-01 02:59:01 +02:00
|
|
|
pTpPostWork(work2);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, FALSE, NULL);
|
|
|
|
pTpWaitForWork(work, TRUE);
|
2016-08-20 21:18:33 +02:00
|
|
|
ok((userdata & 0xffff) < 10, "expected userdata & 0xffff < 10, got %u\n", userdata & 0xffff);
|
|
|
|
ok((userdata >> 16) == 3, "expected userdata >> 16 == 3, got %u\n", userdata >> 16);
|
2015-07-01 02:59:01 +02:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleaseWork(work);
|
|
|
|
pTpReleaseCleanupGroup(group);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
}
|
|
|
|
|
2016-08-20 22:38:43 +02:00
|
|
|
static void CALLBACK simple_release_cb(TP_CALLBACK_INSTANCE *instance, void *userdata)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
ReleaseSemaphore(semaphores, 1, NULL);
|
|
|
|
Sleep(200); /* wait until main thread is in TpReleaseCleanupGroupMembers */
|
|
|
|
}
|
|
|
|
|
2016-08-20 21:22:54 +02:00
|
|
|
static void CALLBACK work_release_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_WORK *work)
|
|
|
|
{
|
|
|
|
HANDLE semaphore = userdata;
|
|
|
|
ReleaseSemaphore(semaphore, 1, NULL);
|
|
|
|
Sleep(200); /* wait until main thread is in TpReleaseCleanupGroupMembers */
|
|
|
|
pTpReleaseWork(work);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK timer_release_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_TIMER *timer)
|
|
|
|
{
|
|
|
|
HANDLE semaphore = userdata;
|
|
|
|
ReleaseSemaphore(semaphore, 1, NULL);
|
|
|
|
Sleep(200); /* wait until main thread is in TpReleaseCleanupGroupMembers */
|
|
|
|
pTpReleaseTimer(timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK wait_release_cb(TP_CALLBACK_INSTANCE *instance, void *userdata,
|
|
|
|
TP_WAIT *wait, TP_WAIT_RESULT result)
|
|
|
|
{
|
|
|
|
HANDLE semaphore = userdata;
|
|
|
|
ReleaseSemaphore(semaphore, 1, NULL);
|
|
|
|
Sleep(200); /* wait until main thread is in TpReleaseCleanupGroupMembers */
|
|
|
|
pTpReleaseWait(wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tp_group_wait(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
TP_CLEANUP_GROUP *group;
|
|
|
|
LARGE_INTEGER when;
|
|
|
|
HANDLE semaphore;
|
|
|
|
NTSTATUS status;
|
|
|
|
TP_TIMER *timer;
|
|
|
|
TP_WAIT *wait;
|
|
|
|
TP_WORK *work;
|
|
|
|
TP_POOL *pool;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
semaphore = CreateSemaphoreA(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphore != NULL, "CreateSemaphoreA failed %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* allocate new threadpool */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* allocate a cleanup group */
|
|
|
|
group = NULL;
|
|
|
|
status = pTpAllocCleanupGroup(&group);
|
|
|
|
ok(!status, "TpAllocCleanupGroup failed with status %x\n", status);
|
|
|
|
ok(group != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* release work object during TpReleaseCleanupGroupMembers */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
status = pTpAllocWork(&work, work_release_cb, semaphore, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
pTpPostWork(work);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, FALSE, NULL);
|
|
|
|
|
|
|
|
/* release timer object during TpReleaseCleanupGroupMembers */
|
|
|
|
timer = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
status = pTpAllocTimer(&timer, timer_release_cb, semaphore, &environment);
|
|
|
|
ok(!status, "TpAllocTimer failed with status %x\n", status);
|
|
|
|
ok(timer != NULL, "expected timer != NULL\n");
|
|
|
|
when.QuadPart = 0;
|
|
|
|
pTpSetTimer(timer, &when, 0, 0);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, FALSE, NULL);
|
|
|
|
|
|
|
|
/* release wait object during TpReleaseCleanupGroupMembers */
|
|
|
|
wait = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
status = pTpAllocWait(&wait, wait_release_cb, semaphore, &environment);
|
|
|
|
ok(!status, "TpAllocWait failed with status %x\n", status);
|
|
|
|
ok(wait != NULL, "expected wait != NULL\n");
|
|
|
|
when.QuadPart = 0;
|
|
|
|
pTpSetWait(wait, INVALID_HANDLE_VALUE, &when);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, FALSE, NULL);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleaseCleanupGroup(group);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphore);
|
|
|
|
}
|
|
|
|
|
2015-07-01 22:53:09 +02:00
|
|
|
static DWORD group_cancel_tid;
|
|
|
|
|
2016-08-20 21:23:24 +02:00
|
|
|
static void CALLBACK simple_group_cancel_cb(TP_CALLBACK_INSTANCE *instance, void *userdata)
|
2015-07-01 22:53:09 +02:00
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
2015-07-01 22:55:30 +02:00
|
|
|
NTSTATUS status;
|
2015-07-01 22:53:09 +02:00
|
|
|
DWORD result;
|
2016-08-20 21:23:24 +02:00
|
|
|
int i;
|
2015-07-01 22:55:30 +02:00
|
|
|
|
|
|
|
status = pTpCallbackMayRunLong(instance);
|
|
|
|
ok(status == STATUS_TOO_MANY_THREADS || broken(status == 1) /* Win Vista / 2008 */,
|
|
|
|
"expected STATUS_TOO_MANY_THREADS, got %08x\n", status);
|
|
|
|
|
2016-08-20 21:18:33 +02:00
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
2016-08-20 21:23:24 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
}
|
2015-07-01 22:53:09 +02:00
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
}
|
|
|
|
|
2016-08-20 21:23:48 +02:00
|
|
|
static void CALLBACK work_group_cancel_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_WORK *work)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
}
|
|
|
|
|
2015-07-01 22:53:09 +02:00
|
|
|
static void CALLBACK group_cancel_cleanup_release_cb(void *object, void *userdata)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
group_cancel_tid = GetCurrentThreadId();
|
2016-08-20 21:23:24 +02:00
|
|
|
ok(object == (void *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", object);
|
2015-07-01 22:53:09 +02:00
|
|
|
ReleaseSemaphore(semaphores[0], 1, NULL);
|
|
|
|
}
|
|
|
|
|
2016-08-20 21:23:48 +02:00
|
|
|
static void CALLBACK group_cancel_cleanup_release2_cb(void *object, void *userdata)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
group_cancel_tid = GetCurrentThreadId();
|
|
|
|
ok(object == userdata, "expected %p, got %p\n", userdata, object);
|
|
|
|
ReleaseSemaphore(semaphores[0], 1, NULL);
|
|
|
|
}
|
|
|
|
|
2015-07-01 22:53:09 +02:00
|
|
|
static void CALLBACK group_cancel_cleanup_increment_cb(void *object, void *userdata)
|
|
|
|
{
|
|
|
|
group_cancel_tid = GetCurrentThreadId();
|
|
|
|
InterlockedIncrement((LONG *)userdata);
|
|
|
|
}
|
|
|
|
|
2016-08-20 21:23:24 +02:00
|
|
|
static void CALLBACK unexpected_simple_cb(TP_CALLBACK_INSTANCE *instance, void *userdata)
|
|
|
|
{
|
|
|
|
ok(0, "Unexpected callback\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK unexpected_work_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_WORK *work)
|
|
|
|
{
|
|
|
|
ok(0, "Unexpected callback\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK unexpected_timer_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_TIMER *timer)
|
|
|
|
{
|
|
|
|
ok(0, "Unexpected callback\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK unexpected_wait_cb(TP_CALLBACK_INSTANCE *instance, void *userdata,
|
|
|
|
TP_WAIT *wait, TP_WAIT_RESULT result)
|
2015-07-01 22:53:09 +02:00
|
|
|
{
|
|
|
|
ok(0, "Unexpected callback\n");
|
|
|
|
}
|
|
|
|
|
2016-08-20 21:23:48 +02:00
|
|
|
static void CALLBACK unexpected_group_cancel_cleanup_cb(void *object, void *userdata)
|
|
|
|
{
|
|
|
|
ok(0, "Unexpected callback\n");
|
|
|
|
}
|
|
|
|
|
2015-07-01 22:53:09 +02:00
|
|
|
static void test_tp_group_cancel(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
TP_CLEANUP_GROUP *group;
|
|
|
|
LONG userdata, userdata2;
|
|
|
|
HANDLE semaphores[2];
|
|
|
|
NTSTATUS status;
|
2016-08-20 21:23:24 +02:00
|
|
|
TP_TIMER *timer;
|
|
|
|
TP_WAIT *wait;
|
2015-07-01 22:53:09 +02:00
|
|
|
TP_WORK *work;
|
|
|
|
TP_POOL *pool;
|
|
|
|
DWORD result;
|
|
|
|
int i;
|
|
|
|
|
2016-08-20 21:23:24 +02:00
|
|
|
semaphores[0] = CreateSemaphoreA(NULL, 0, 4, NULL);
|
2015-07-01 22:53:09 +02:00
|
|
|
ok(semaphores[0] != NULL, "CreateSemaphoreA failed %u\n", GetLastError());
|
|
|
|
semaphores[1] = CreateSemaphoreA(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphores[1] != NULL, "CreateSemaphoreA failed %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* allocate new threadpool with only one thread */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
pTpSetPoolMaxThreads(pool, 1);
|
|
|
|
|
|
|
|
/* allocate a cleanup group */
|
|
|
|
group = NULL;
|
|
|
|
status = pTpAllocCleanupGroup(&group);
|
|
|
|
ok(!status, "TpAllocCleanupGroup failed with status %x\n", status);
|
|
|
|
ok(group != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* test execution of cancellation callback */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
2016-08-20 21:23:24 +02:00
|
|
|
status = pTpSimpleTryPost(simple_group_cancel_cb, semaphores, &environment);
|
2015-07-01 22:53:09 +02:00
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
2016-08-20 21:18:33 +02:00
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
2015-07-01 22:53:09 +02:00
|
|
|
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
environment.CleanupGroupCancelCallback = group_cancel_cleanup_release_cb;
|
2016-08-20 21:23:24 +02:00
|
|
|
status = pTpSimpleTryPost(unexpected_simple_cb, (void *)0xdeadbeef, &environment);
|
2015-07-01 22:53:09 +02:00
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
|
2016-08-20 21:23:24 +02:00
|
|
|
work = NULL;
|
|
|
|
status = pTpAllocWork(&work, unexpected_work_cb, (void *)0xdeadbeef, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
|
|
|
|
timer = NULL;
|
|
|
|
status = pTpAllocTimer(&timer, unexpected_timer_cb, (void *)0xdeadbeef, &environment);
|
|
|
|
ok(!status, "TpAllocTimer failed with status %x\n", status);
|
|
|
|
ok(timer != NULL, "expected timer != NULL\n");
|
|
|
|
|
|
|
|
wait = NULL;
|
|
|
|
status = pTpAllocWait(&wait, unexpected_wait_cb, (void *)0xdeadbeef, &environment);
|
|
|
|
ok(!status, "TpAllocWait failed with status %x\n", status);
|
|
|
|
ok(wait != NULL, "expected wait != NULL\n");
|
|
|
|
|
2015-07-01 22:53:09 +02:00
|
|
|
group_cancel_tid = 0xdeadbeef;
|
|
|
|
pTpReleaseCleanupGroupMembers(group, TRUE, semaphores);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(group_cancel_tid == GetCurrentThreadId(), "expected tid %x, got %x\n",
|
|
|
|
GetCurrentThreadId(), group_cancel_tid);
|
|
|
|
|
2016-08-20 21:23:48 +02:00
|
|
|
/* test if cancellation callbacks are executed before or after wait */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
environment.CleanupGroupCancelCallback = group_cancel_cleanup_release2_cb;
|
|
|
|
status = pTpAllocWork(&work, work_group_cancel_cb, semaphores, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
pTpPostWork(work);
|
|
|
|
pTpPostWork(work);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
group_cancel_tid = 0xdeadbeef;
|
|
|
|
pTpReleaseCleanupGroupMembers(group, TRUE, semaphores);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(group_cancel_tid == GetCurrentThreadId(), "expected tid %x, got %x\n",
|
|
|
|
GetCurrentThreadId(), group_cancel_tid);
|
|
|
|
|
|
|
|
/* group cancel callback is not executed if object is destroyed while waiting */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
environment.CleanupGroupCancelCallback = unexpected_group_cancel_cleanup_cb;
|
|
|
|
status = pTpAllocWork(&work, work_release_cb, semaphores[1], &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
pTpPostWork(work);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, TRUE, NULL);
|
|
|
|
|
2016-08-20 22:38:43 +02:00
|
|
|
/* terminated simple callbacks should not trigger the group cancel callback */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
environment.CleanupGroupCancelCallback = unexpected_group_cancel_cleanup_cb;
|
|
|
|
status = pTpSimpleTryPost(simple_release_cb, semaphores[1], &environment);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, TRUE, semaphores);
|
|
|
|
|
2015-07-01 22:53:09 +02:00
|
|
|
/* test cancellation callback for objects with multiple instances */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
environment.CleanupGroupCancelCallback = group_cancel_cleanup_increment_cb;
|
|
|
|
status = pTpAllocWork(&work, work_cb, &userdata, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
|
|
|
|
/* post 10 identical work items at once */
|
|
|
|
userdata = userdata2 = 0;
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
pTpPostWork(work);
|
|
|
|
|
|
|
|
/* check if we get multiple cancellation callbacks */
|
|
|
|
group_cancel_tid = 0xdeadbeef;
|
|
|
|
pTpReleaseCleanupGroupMembers(group, TRUE, &userdata2);
|
2016-08-20 21:18:33 +02:00
|
|
|
ok(userdata <= 5, "expected userdata <= 5, got %u\n", userdata);
|
2015-07-01 22:53:09 +02:00
|
|
|
ok(userdata2 == 1, "expected only one cancellation callback, got %u\n", userdata2);
|
|
|
|
ok(group_cancel_tid == GetCurrentThreadId(), "expected tid %x, got %x\n",
|
|
|
|
GetCurrentThreadId(), group_cancel_tid);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleaseCleanupGroup(group);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphores[0]);
|
|
|
|
CloseHandle(semaphores[1]);
|
|
|
|
}
|
|
|
|
|
2015-07-01 22:57:16 +02:00
|
|
|
static void CALLBACK instance_semaphore_completion_cb(TP_CALLBACK_INSTANCE *instance, void *userdata)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
pTpCallbackReleaseSemaphoreOnCompletion(instance, semaphores[0], 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK instance_finalization_cb(TP_CALLBACK_INSTANCE *instance, void *userdata)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
DWORD result;
|
|
|
|
|
2021-02-10 12:56:03 +01:00
|
|
|
Sleep(50);
|
2015-07-01 22:57:16 +02:00
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tp_instance(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
HANDLE semaphores[2];
|
|
|
|
NTSTATUS status;
|
|
|
|
TP_POOL *pool;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
semaphores[0] = CreateSemaphoreW(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphores[0] != NULL, "failed to create semaphore\n");
|
|
|
|
semaphores[1] = CreateSemaphoreW(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphores[1] != NULL, "failed to create semaphore\n");
|
|
|
|
|
|
|
|
/* allocate new threadpool */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* test for TpCallbackReleaseSemaphoreOnCompletion */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
status = pTpSimpleTryPost(instance_semaphore_completion_cb, semaphores, &environment);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* test for finalization callback */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.FinalizationCallback = instance_finalization_cb;
|
|
|
|
status = pTpSimpleTryPost(instance_semaphore_completion_cb, semaphores, &environment);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphores[0]);
|
|
|
|
CloseHandle(semaphores[1]);
|
|
|
|
}
|
|
|
|
|
2015-07-03 01:57:38 +02:00
|
|
|
static void CALLBACK disassociate_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_WORK *work)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
pTpDisassociateCallback(instance);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK disassociate2_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_WORK *work)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
pTpDisassociateCallback(instance);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK disassociate3_cb(TP_CALLBACK_INSTANCE *instance, void *userdata)
|
|
|
|
{
|
|
|
|
HANDLE *semaphores = userdata;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
pTpDisassociateCallback(instance);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tp_disassociate(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
TP_CLEANUP_GROUP *group;
|
|
|
|
HANDLE semaphores[2];
|
|
|
|
NTSTATUS status;
|
|
|
|
TP_POOL *pool;
|
|
|
|
TP_WORK *work;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
semaphores[0] = CreateSemaphoreW(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphores[0] != NULL, "failed to create semaphore\n");
|
|
|
|
semaphores[1] = CreateSemaphoreW(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphores[1] != NULL, "failed to create semaphore\n");
|
|
|
|
|
|
|
|
/* allocate new threadpool and cleanup group */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
group = NULL;
|
|
|
|
status = pTpAllocCleanupGroup(&group);
|
|
|
|
ok(!status, "TpAllocCleanupGroup failed with status %x\n", status);
|
|
|
|
ok(group != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* test TpDisassociateCallback on work objects without group */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
status = pTpAllocWork(&work, disassociate_cb, semaphores, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
|
|
|
|
pTpPostWork(work);
|
|
|
|
pTpWaitForWork(work, FALSE);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphores[1], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ReleaseSemaphore(semaphores[0], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpReleaseWork(work);
|
|
|
|
|
|
|
|
/* test TpDisassociateCallback on work objects with group (1) */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
status = pTpAllocWork(&work, disassociate_cb, semaphores, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
|
|
|
|
pTpPostWork(work);
|
|
|
|
pTpWaitForWork(work, FALSE);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphores[1], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ReleaseSemaphore(semaphores[0], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, FALSE, NULL);
|
|
|
|
|
|
|
|
/* test TpDisassociateCallback on work objects with group (2) */
|
|
|
|
work = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
status = pTpAllocWork(&work, disassociate2_cb, semaphores, &environment);
|
|
|
|
ok(!status, "TpAllocWork failed with status %x\n", status);
|
|
|
|
ok(work != NULL, "expected work != NULL\n");
|
|
|
|
|
|
|
|
pTpPostWork(work);
|
|
|
|
pTpReleaseCleanupGroupMembers(group, FALSE, NULL);
|
|
|
|
|
|
|
|
ReleaseSemaphore(semaphores[0], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* test TpDisassociateCallback on simple callbacks */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
environment.CleanupGroup = group;
|
|
|
|
status = pTpSimpleTryPost(disassociate3_cb, semaphores, &environment);
|
|
|
|
ok(!status, "TpSimpleTryPost failed with status %x\n", status);
|
|
|
|
|
|
|
|
pTpReleaseCleanupGroupMembers(group, FALSE, NULL);
|
|
|
|
|
|
|
|
ReleaseSemaphore(semaphores[0], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleaseCleanupGroup(group);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphores[0]);
|
|
|
|
CloseHandle(semaphores[1]);
|
|
|
|
}
|
|
|
|
|
2015-07-03 01:58:45 +02:00
|
|
|
static void CALLBACK timer_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_TIMER *timer)
|
|
|
|
{
|
|
|
|
HANDLE semaphore = userdata;
|
|
|
|
ReleaseSemaphore(semaphore, 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tp_timer(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
DWORD result, ticks;
|
|
|
|
LARGE_INTEGER when;
|
|
|
|
HANDLE semaphore;
|
|
|
|
NTSTATUS status;
|
|
|
|
TP_TIMER *timer;
|
|
|
|
TP_POOL *pool;
|
|
|
|
BOOL success;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
semaphore = CreateSemaphoreA(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphore != NULL, "CreateSemaphoreA failed %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* allocate new threadpool */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* allocate new timer */
|
|
|
|
timer = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
status = pTpAllocTimer(&timer, timer_cb, semaphore, &environment);
|
|
|
|
ok(!status, "TpAllocTimer failed with status %x\n", status);
|
|
|
|
ok(timer != NULL, "expected timer != NULL\n");
|
|
|
|
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(!success, "TpIsTimerSet returned TRUE\n");
|
|
|
|
|
|
|
|
/* test timer with a relative timeout */
|
|
|
|
when.QuadPart = (ULONGLONG)200 * -10000;
|
|
|
|
pTpSetTimer(timer, &when, 0, 0);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(success, "TpIsTimerSet returned FALSE\n");
|
|
|
|
|
|
|
|
pTpWaitForTimer(timer, FALSE);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphore, 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphore, 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(success, "TpIsTimerSet returned FALSE\n");
|
|
|
|
|
|
|
|
/* test timer with an absolute timeout */
|
|
|
|
NtQuerySystemTime( &when );
|
|
|
|
when.QuadPart += (ULONGLONG)200 * 10000;
|
|
|
|
pTpSetTimer(timer, &when, 0, 0);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(success, "TpIsTimerSet returned FALSE\n");
|
|
|
|
|
|
|
|
pTpWaitForTimer(timer, FALSE);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphore, 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphore, 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(success, "TpIsTimerSet returned FALSE\n");
|
|
|
|
|
|
|
|
/* test timer with zero timeout */
|
|
|
|
when.QuadPart = 0;
|
|
|
|
pTpSetTimer(timer, &when, 0, 0);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(success, "TpIsTimerSet returned FALSE\n");
|
|
|
|
|
|
|
|
pTpWaitForTimer(timer, FALSE);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphore, 50);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(success, "TpIsTimerSet returned FALSE\n");
|
|
|
|
|
|
|
|
/* unset the timer */
|
|
|
|
pTpSetTimer(timer, NULL, 0, 0);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(!success, "TpIsTimerSet returned TRUE\n");
|
|
|
|
pTpWaitForTimer(timer, TRUE);
|
|
|
|
|
|
|
|
pTpReleaseTimer(timer);
|
|
|
|
CloseHandle(semaphore);
|
|
|
|
|
|
|
|
semaphore = CreateSemaphoreA(NULL, 0, 3, NULL);
|
|
|
|
ok(semaphore != NULL, "CreateSemaphoreA failed %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* allocate a new timer */
|
|
|
|
timer = NULL;
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
status = pTpAllocTimer(&timer, timer_cb, semaphore, &environment);
|
|
|
|
ok(!status, "TpAllocTimer failed with status %x\n", status);
|
|
|
|
ok(timer != NULL, "expected timer != NULL\n");
|
|
|
|
|
|
|
|
/* test a relative timeout repeated periodically */
|
|
|
|
when.QuadPart = (ULONGLONG)200 * -10000;
|
|
|
|
pTpSetTimer(timer, &when, 200, 0);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(success, "TpIsTimerSet returned FALSE\n");
|
|
|
|
|
|
|
|
/* wait until the timer was triggered three times */
|
|
|
|
ticks = GetTickCount();
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
}
|
|
|
|
ticks = GetTickCount() - ticks;
|
|
|
|
ok(ticks >= 500 && (ticks <= 700 || broken(ticks <= 750)) /* Win 7 */,
|
|
|
|
"expected approximately 600 ticks, got %u\n", ticks);
|
|
|
|
|
|
|
|
/* unset the timer */
|
|
|
|
pTpSetTimer(timer, NULL, 0, 0);
|
|
|
|
success = pTpIsTimerSet(timer);
|
|
|
|
ok(!success, "TpIsTimerSet returned TRUE\n");
|
|
|
|
pTpWaitForTimer(timer, TRUE);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleaseTimer(timer);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphore);
|
|
|
|
}
|
|
|
|
|
2015-07-03 01:59:02 +02:00
|
|
|
struct window_length_info
|
|
|
|
{
|
|
|
|
HANDLE semaphore;
|
|
|
|
DWORD ticks;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void CALLBACK window_length_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_TIMER *timer)
|
|
|
|
{
|
|
|
|
struct window_length_info *info = userdata;
|
|
|
|
info->ticks = GetTickCount();
|
|
|
|
ReleaseSemaphore(info->semaphore, 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tp_window_length(void)
|
|
|
|
{
|
|
|
|
struct window_length_info info1, info2;
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
TP_TIMER *timer1, *timer2;
|
|
|
|
LARGE_INTEGER when;
|
|
|
|
HANDLE semaphore;
|
|
|
|
NTSTATUS status;
|
|
|
|
TP_POOL *pool;
|
|
|
|
DWORD result;
|
2015-10-07 01:23:27 +02:00
|
|
|
BOOL merged;
|
2015-07-03 01:59:02 +02:00
|
|
|
|
|
|
|
semaphore = CreateSemaphoreA(NULL, 0, 2, NULL);
|
|
|
|
ok(semaphore != NULL, "CreateSemaphoreA failed %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* allocate new threadpool */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* allocate two identical timers */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
|
|
|
|
timer1 = NULL;
|
|
|
|
info1.semaphore = semaphore;
|
|
|
|
status = pTpAllocTimer(&timer1, window_length_cb, &info1, &environment);
|
|
|
|
ok(!status, "TpAllocTimer failed with status %x\n", status);
|
|
|
|
ok(timer1 != NULL, "expected timer1 != NULL\n");
|
|
|
|
|
|
|
|
timer2 = NULL;
|
|
|
|
info2.semaphore = semaphore;
|
|
|
|
status = pTpAllocTimer(&timer2, window_length_cb, &info2, &environment);
|
|
|
|
ok(!status, "TpAllocTimer failed with status %x\n", status);
|
|
|
|
ok(timer2 != NULL, "expected timer2 != NULL\n");
|
|
|
|
|
|
|
|
/* choose parameters so that timers are not merged */
|
|
|
|
info1.ticks = 0;
|
|
|
|
info2.ticks = 0;
|
|
|
|
|
|
|
|
NtQuerySystemTime( &when );
|
|
|
|
when.QuadPart += (ULONGLONG)250 * 10000;
|
|
|
|
pTpSetTimer(timer2, &when, 0, 0);
|
|
|
|
Sleep(50);
|
|
|
|
when.QuadPart -= (ULONGLONG)150 * 10000;
|
|
|
|
pTpSetTimer(timer1, &when, 0, 75);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info1.ticks != 0 && info2.ticks != 0, "expected that ticks are nonzero\n");
|
|
|
|
ok(info2.ticks >= info1.ticks + 75 || broken(info2.ticks < info1.ticks + 75) /* Win 2008 */,
|
|
|
|
"expected that timers are not merged\n");
|
|
|
|
|
|
|
|
/* timers will be merged */
|
|
|
|
info1.ticks = 0;
|
|
|
|
info2.ticks = 0;
|
|
|
|
|
|
|
|
NtQuerySystemTime( &when );
|
|
|
|
when.QuadPart += (ULONGLONG)250 * 10000;
|
|
|
|
pTpSetTimer(timer2, &when, 0, 0);
|
|
|
|
Sleep(50);
|
|
|
|
when.QuadPart -= (ULONGLONG)150 * 10000;
|
|
|
|
pTpSetTimer(timer1, &when, 0, 200);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info1.ticks != 0 && info2.ticks != 0, "expected that ticks are nonzero\n");
|
2015-10-07 01:23:27 +02:00
|
|
|
merged = info2.ticks >= info1.ticks - 50 && info2.ticks <= info1.ticks + 50;
|
|
|
|
ok(merged || broken(!merged) /* Win 10 */, "expected that timers are merged\n");
|
2015-07-03 01:59:02 +02:00
|
|
|
|
|
|
|
/* on Windows the timers also get merged in this case */
|
|
|
|
info1.ticks = 0;
|
|
|
|
info2.ticks = 0;
|
|
|
|
|
|
|
|
NtQuerySystemTime( &when );
|
|
|
|
when.QuadPart += (ULONGLONG)100 * 10000;
|
|
|
|
pTpSetTimer(timer1, &when, 0, 200);
|
|
|
|
Sleep(50);
|
|
|
|
when.QuadPart += (ULONGLONG)150 * 10000;
|
|
|
|
pTpSetTimer(timer2, &when, 0, 0);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphore, 1000);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info1.ticks != 0 && info2.ticks != 0, "expected that ticks are nonzero\n");
|
2015-10-07 01:23:27 +02:00
|
|
|
merged = info2.ticks >= info1.ticks - 50 && info2.ticks <= info1.ticks + 50;
|
2015-07-03 01:59:02 +02:00
|
|
|
todo_wine
|
2015-10-07 01:23:27 +02:00
|
|
|
ok(merged || broken(!merged) /* Win 10 */, "expected that timers are merged\n");
|
2015-07-03 01:59:02 +02:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleaseTimer(timer1);
|
|
|
|
pTpReleaseTimer(timer2);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphore);
|
|
|
|
}
|
|
|
|
|
2015-07-05 02:24:02 +02:00
|
|
|
struct wait_info
|
|
|
|
{
|
|
|
|
HANDLE semaphore;
|
|
|
|
LONG userdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void CALLBACK wait_cb(TP_CALLBACK_INSTANCE *instance, void *userdata,
|
|
|
|
TP_WAIT *wait, TP_WAIT_RESULT result)
|
|
|
|
{
|
|
|
|
struct wait_info *info = userdata;
|
|
|
|
if (result == WAIT_OBJECT_0)
|
|
|
|
InterlockedIncrement(&info->userdata);
|
|
|
|
else if (result == WAIT_TIMEOUT)
|
|
|
|
InterlockedExchangeAdd(&info->userdata, 0x10000);
|
|
|
|
else
|
|
|
|
ok(0, "unexpected result %u\n", result);
|
|
|
|
ReleaseSemaphore(info->semaphore, 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tp_wait(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
TP_WAIT *wait1, *wait2;
|
|
|
|
struct wait_info info;
|
|
|
|
HANDLE semaphores[2];
|
|
|
|
LARGE_INTEGER when;
|
|
|
|
NTSTATUS status;
|
|
|
|
TP_POOL *pool;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
semaphores[0] = CreateSemaphoreW(NULL, 0, 2, NULL);
|
|
|
|
ok(semaphores[0] != NULL, "failed to create semaphore\n");
|
|
|
|
semaphores[1] = CreateSemaphoreW(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphores[1] != NULL, "failed to create semaphore\n");
|
|
|
|
info.semaphore = semaphores[0];
|
|
|
|
|
|
|
|
/* allocate new threadpool */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
/* allocate new wait items */
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
|
|
|
|
wait1 = NULL;
|
|
|
|
status = pTpAllocWait(&wait1, wait_cb, &info, &environment);
|
|
|
|
ok(!status, "TpAllocWait failed with status %x\n", status);
|
|
|
|
ok(wait1 != NULL, "expected wait1 != NULL\n");
|
|
|
|
|
|
|
|
wait2 = NULL;
|
|
|
|
status = pTpAllocWait(&wait2, wait_cb, &info, &environment);
|
|
|
|
ok(!status, "TpAllocWait failed with status %x\n", status);
|
|
|
|
ok(wait2 != NULL, "expected wait2 != NULL\n");
|
|
|
|
|
|
|
|
/* infinite timeout, signal the semaphore immediately */
|
|
|
|
info.userdata = 0;
|
|
|
|
pTpSetWait(wait1, semaphores[1], NULL);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* relative timeout, no event */
|
|
|
|
info.userdata = 0;
|
|
|
|
when.QuadPart = (ULONGLONG)200 * -10000;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* repeat test with call to TpWaitForWait(..., TRUE) */
|
|
|
|
info.userdata = 0;
|
|
|
|
when.QuadPart = (ULONGLONG)200 * -10000;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpWaitForWait(wait1, TRUE);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_OBJECT_0 || broken(result == WAIT_TIMEOUT) /* Win 8 */,
|
|
|
|
"WaitForSingleObject returned %u\n", result);
|
|
|
|
if (result == WAIT_OBJECT_0)
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
else
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* relative timeout, with event */
|
|
|
|
info.userdata = 0;
|
|
|
|
when.QuadPart = (ULONGLONG)200 * -10000;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* repeat test with call to TpWaitForWait(..., TRUE) */
|
|
|
|
info.userdata = 0;
|
|
|
|
when.QuadPart = (ULONGLONG)200 * -10000;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpWaitForWait(wait1, TRUE);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0 || broken(result == WAIT_TIMEOUT) /* Win 8 */,
|
|
|
|
"WaitForSingleObject returned %u\n", result);
|
|
|
|
if (result == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* absolute timeout, no event */
|
|
|
|
info.userdata = 0;
|
|
|
|
NtQuerySystemTime( &when );
|
|
|
|
when.QuadPart += (ULONGLONG)200 * 10000;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 200);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* absolute timeout, with event */
|
|
|
|
info.userdata = 0;
|
|
|
|
NtQuerySystemTime( &when );
|
|
|
|
when.QuadPart += (ULONGLONG)200 * 10000;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* test timeout of zero */
|
|
|
|
info.userdata = 0;
|
|
|
|
when.QuadPart = 0;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* cancel a pending wait */
|
|
|
|
info.userdata = 0;
|
|
|
|
when.QuadPart = (ULONGLONG)250 * -10000;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
pTpSetWait(wait1, NULL, (void *)0xdeadbeef);
|
|
|
|
Sleep(50);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0, "expected info.userdata = 0, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* test with INVALID_HANDLE_VALUE */
|
|
|
|
info.userdata = 0;
|
|
|
|
when.QuadPart = 0;
|
|
|
|
pTpSetWait(wait1, INVALID_HANDLE_VALUE, &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
|
|
|
|
/* cancel a pending wait with INVALID_HANDLE_VALUE */
|
|
|
|
info.userdata = 0;
|
|
|
|
when.QuadPart = (ULONGLONG)250 * -10000;
|
|
|
|
pTpSetWait(wait1, semaphores[1], &when);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
when.QuadPart = 0;
|
|
|
|
pTpSetWait(wait1, INVALID_HANDLE_VALUE, &when);
|
|
|
|
Sleep(50);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 0x10000, "expected info.userdata = 0x10000, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
CloseHandle(semaphores[1]);
|
|
|
|
semaphores[1] = CreateSemaphoreW(NULL, 0, 2, NULL);
|
|
|
|
ok(semaphores[1] != NULL, "failed to create semaphore\n");
|
|
|
|
|
|
|
|
/* add two wait objects with the same semaphore */
|
|
|
|
info.userdata = 0;
|
|
|
|
pTpSetWait(wait1, semaphores[1], NULL);
|
|
|
|
pTpSetWait(wait2, semaphores[1], NULL);
|
|
|
|
Sleep(50);
|
|
|
|
ReleaseSemaphore(semaphores[1], 1, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 1, "expected info.userdata = 1, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* repeat test above with release count 2 */
|
|
|
|
info.userdata = 0;
|
|
|
|
pTpSetWait(wait1, semaphores[1], NULL);
|
|
|
|
pTpSetWait(wait2, semaphores[1], NULL);
|
|
|
|
Sleep(50);
|
|
|
|
result = ReleaseSemaphore(semaphores[1], 2, NULL);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
result = WaitForSingleObject(semaphores[0], 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(info.userdata == 2, "expected info.userdata = 2, got %u\n", info.userdata);
|
|
|
|
result = WaitForSingleObject(semaphores[1], 0);
|
|
|
|
ok(result == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", result);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
pTpReleaseWait(wait1);
|
|
|
|
pTpReleaseWait(wait2);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphores[0]);
|
|
|
|
CloseHandle(semaphores[1]);
|
|
|
|
}
|
|
|
|
|
2015-07-05 02:24:49 +02:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
HANDLE semaphore;
|
|
|
|
DWORD result;
|
|
|
|
} multi_wait_info;
|
|
|
|
|
|
|
|
static void CALLBACK multi_wait_cb(TP_CALLBACK_INSTANCE *instance, void *userdata, TP_WAIT *wait, TP_WAIT_RESULT result)
|
|
|
|
{
|
|
|
|
DWORD index = (DWORD)(DWORD_PTR)userdata;
|
|
|
|
|
|
|
|
if (result == WAIT_OBJECT_0)
|
|
|
|
multi_wait_info.result = index;
|
|
|
|
else if (result == WAIT_TIMEOUT)
|
|
|
|
multi_wait_info.result = 0x10000 | index;
|
|
|
|
else
|
|
|
|
ok(0, "unexpected result %u\n", result);
|
|
|
|
ReleaseSemaphore(multi_wait_info.semaphore, 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tp_multi_wait(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
HANDLE semaphores[512];
|
|
|
|
TP_WAIT *waits[512];
|
|
|
|
LARGE_INTEGER when;
|
|
|
|
HANDLE semaphore;
|
|
|
|
NTSTATUS status;
|
|
|
|
TP_POOL *pool;
|
|
|
|
DWORD result;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
semaphore = CreateSemaphoreW(NULL, 0, 512, NULL);
|
|
|
|
ok(semaphore != NULL, "failed to create semaphore\n");
|
|
|
|
multi_wait_info.semaphore = semaphore;
|
|
|
|
|
|
|
|
/* allocate new threadpool */
|
|
|
|
pool = NULL;
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "TpAllocPool failed with status %x\n", status);
|
|
|
|
ok(pool != NULL, "expected pool != NULL\n");
|
|
|
|
|
|
|
|
memset(&environment, 0, sizeof(environment));
|
|
|
|
environment.Version = 1;
|
|
|
|
environment.Pool = pool;
|
|
|
|
|
|
|
|
/* create semaphores and corresponding wait objects */
|
2018-06-21 23:06:11 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(semaphores); i++)
|
2015-07-05 02:24:49 +02:00
|
|
|
{
|
|
|
|
semaphores[i] = CreateSemaphoreW(NULL, 0, 1, NULL);
|
|
|
|
ok(semaphores[i] != NULL, "failed to create semaphore %i\n", i);
|
|
|
|
|
|
|
|
waits[i] = NULL;
|
|
|
|
status = pTpAllocWait(&waits[i], multi_wait_cb, (void *)(DWORD_PTR)i, &environment);
|
|
|
|
ok(!status, "TpAllocWait failed with status %x\n", status);
|
|
|
|
ok(waits[i] != NULL, "expected waits[%d] != NULL\n", i);
|
|
|
|
|
|
|
|
pTpSetWait(waits[i], semaphores[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release all semaphores and wait for callback */
|
2018-06-21 23:06:11 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(semaphores); i++)
|
2015-07-05 02:24:49 +02:00
|
|
|
{
|
|
|
|
multi_wait_info.result = 0;
|
|
|
|
ReleaseSemaphore(semaphores[i], 1, NULL);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphore, 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(multi_wait_info.result == i, "expected result %d, got %u\n", i, multi_wait_info.result);
|
|
|
|
|
|
|
|
pTpSetWait(waits[i], semaphores[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* repeat the same test in reverse order */
|
2018-06-21 23:06:11 +02:00
|
|
|
for (i = ARRAY_SIZE(semaphores) - 1; i >= 0; i--)
|
2015-07-05 02:24:49 +02:00
|
|
|
{
|
|
|
|
multi_wait_info.result = 0;
|
|
|
|
ReleaseSemaphore(semaphores[i], 1, NULL);
|
|
|
|
|
|
|
|
result = WaitForSingleObject(semaphore, 100);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
ok(multi_wait_info.result == i, "expected result %d, got %u\n", i, multi_wait_info.result);
|
|
|
|
|
|
|
|
pTpSetWait(waits[i], semaphores[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test timeout of wait objects */
|
|
|
|
multi_wait_info.result = 0;
|
2018-06-21 23:06:11 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(semaphores); i++)
|
2015-07-05 02:24:49 +02:00
|
|
|
{
|
|
|
|
when.QuadPart = (ULONGLONG)50 * -10000;
|
|
|
|
pTpSetWait(waits[i], semaphores[i], &when);
|
|
|
|
}
|
|
|
|
|
2018-06-21 23:06:11 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(semaphores); i++)
|
2015-07-05 02:24:49 +02:00
|
|
|
{
|
|
|
|
result = WaitForSingleObject(semaphore, 150);
|
|
|
|
ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(multi_wait_info.result >> 16, "expected multi_wait_info.result >> 16 != 0\n");
|
|
|
|
|
|
|
|
/* destroy the wait objects and semaphores while waiting */
|
2018-06-21 23:06:11 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(semaphores); i++)
|
2015-07-05 02:24:49 +02:00
|
|
|
{
|
|
|
|
pTpSetWait(waits[i], semaphores[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sleep(50);
|
|
|
|
|
2018-06-21 23:06:11 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(semaphores); i++)
|
2015-07-05 02:24:49 +02:00
|
|
|
{
|
|
|
|
pTpReleaseWait(waits[i]);
|
|
|
|
NtClose(semaphores[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
CloseHandle(semaphore);
|
|
|
|
}
|
|
|
|
|
2020-04-11 07:16:26 +02:00
|
|
|
struct io_cb_ctx
|
|
|
|
{
|
|
|
|
unsigned int count;
|
|
|
|
void *ovl;
|
|
|
|
NTSTATUS ret;
|
|
|
|
ULONG_PTR length;
|
|
|
|
TP_IO *io;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void CALLBACK io_cb(TP_CALLBACK_INSTANCE *instance, void *userdata,
|
|
|
|
void *cvalue, IO_STATUS_BLOCK *iosb, TP_IO *io)
|
|
|
|
{
|
|
|
|
struct io_cb_ctx *ctx = userdata;
|
|
|
|
++ctx->count;
|
|
|
|
ctx->ovl = cvalue;
|
|
|
|
ctx->ret = iosb->u.Status;
|
|
|
|
ctx->length = iosb->Information;
|
|
|
|
ctx->io = io;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI io_wait_thread(void *arg)
|
|
|
|
{
|
|
|
|
TP_IO *io = arg;
|
|
|
|
pTpWaitForIoCompletion(io, FALSE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tp_io(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment = {.Version = 1};
|
|
|
|
OVERLAPPED ovl = {}, ovl2 = {};
|
|
|
|
HANDLE client, server, thread;
|
|
|
|
struct io_cb_ctx userdata;
|
|
|
|
char in[1], in2[1];
|
|
|
|
const char out[1];
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD ret_size;
|
|
|
|
TP_POOL *pool;
|
|
|
|
TP_IO *io;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "failed to allocate pool, status %#x\n", status);
|
|
|
|
|
|
|
|
server = CreateNamedPipeA("\\\\.\\pipe\\wine_tp_test",
|
|
|
|
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0, 1, 1024, 1024, 0, NULL);
|
|
|
|
ok(server != INVALID_HANDLE_VALUE, "Failed to create server pipe, error %u.\n", GetLastError());
|
|
|
|
client = CreateFileA("\\\\.\\pipe\\wine_tp_test", GENERIC_READ | GENERIC_WRITE,
|
|
|
|
0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(client != INVALID_HANDLE_VALUE, "Failed to create client pipe, error %u.\n", GetLastError());
|
|
|
|
|
|
|
|
environment.Pool = pool;
|
|
|
|
io = NULL;
|
|
|
|
status = pTpAllocIoCompletion(&io, server, io_cb, &userdata, &environment);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(!!io, "expected non-NULL TP_IO\n");
|
|
|
|
|
|
|
|
pTpWaitForIoCompletion(io, FALSE);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pTpStartAsyncIoOperation(io);
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, io_wait_thread, io, 0, NULL);
|
|
|
|
ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "TpWaitForIoCompletion() should not return\n");
|
|
|
|
|
|
|
|
ret = ReadFile(server, in, sizeof(in), NULL, &ovl);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = WriteFile(client, out, sizeof(out), &ret_size, NULL);
|
|
|
|
ok(ret, "WriteFile() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
pTpWaitForIoCompletion(io, FALSE);
|
|
|
|
ok(userdata.count == 1, "callback ran %u times\n", userdata.count);
|
|
|
|
ok(userdata.ovl == &ovl, "expected %p, got %p\n", &ovl, userdata.ovl);
|
|
|
|
ok(userdata.ret == STATUS_SUCCESS, "got status %#x\n", userdata.ret);
|
|
|
|
ok(userdata.length == 1, "got length %lu\n", userdata.length);
|
|
|
|
ok(userdata.io == io, "expected %p, got %p\n", io, userdata.io);
|
|
|
|
|
|
|
|
ok(!WaitForSingleObject(thread, 1000), "wait timed out\n");
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pTpStartAsyncIoOperation(io);
|
|
|
|
pTpStartAsyncIoOperation(io);
|
|
|
|
|
|
|
|
ret = ReadFile(server, in, sizeof(in), NULL, &ovl);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "wrong error %u\n", GetLastError());
|
|
|
|
ret = ReadFile(server, in2, sizeof(in2), NULL, &ovl2);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = WriteFile(client, out, sizeof(out), &ret_size, NULL);
|
|
|
|
ok(ret, "WriteFile() failed, error %u\n", GetLastError());
|
|
|
|
ret = WriteFile(client, out, sizeof(out), &ret_size, NULL);
|
|
|
|
ok(ret, "WriteFile() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
pTpWaitForIoCompletion(io, FALSE);
|
|
|
|
ok(userdata.count == 2, "callback ran %u times\n", userdata.count);
|
|
|
|
ok(userdata.ret == STATUS_SUCCESS, "got status %#x\n", userdata.ret);
|
|
|
|
ok(userdata.length == 1, "got length %lu\n", userdata.length);
|
|
|
|
ok(userdata.io == io, "expected %p, got %p\n", io, userdata.io);
|
|
|
|
|
|
|
|
/* The documentation is a bit unclear about passing TRUE to
|
|
|
|
* WaitForThreadpoolIoCallbacks()—"pending I/O requests are not canceled"
|
|
|
|
* [as with CancelIoEx()], but pending threadpool callbacks are, even those
|
|
|
|
* which have not yet reached the completion port [as with
|
|
|
|
* TpCancelAsyncIoOperation()]. */
|
|
|
|
userdata.count = 0;
|
|
|
|
pTpStartAsyncIoOperation(io);
|
|
|
|
|
|
|
|
pTpWaitForIoCompletion(io, TRUE);
|
|
|
|
ok(!userdata.count, "callback ran %u times\n", userdata.count);
|
|
|
|
|
|
|
|
pTpStartAsyncIoOperation(io);
|
|
|
|
|
|
|
|
ret = WriteFile(client, out, sizeof(out), &ret_size, NULL);
|
|
|
|
ok(ret, "WriteFile() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = ReadFile(server, in, sizeof(in), NULL, &ovl);
|
|
|
|
ok(ret, "wrong ret %d\n", ret);
|
|
|
|
|
|
|
|
pTpWaitForIoCompletion(io, FALSE);
|
|
|
|
ok(userdata.count == 1, "callback ran %u times\n", userdata.count);
|
|
|
|
ok(userdata.ovl == &ovl, "expected %p, got %p\n", &ovl, userdata.ovl);
|
|
|
|
ok(userdata.ret == STATUS_SUCCESS, "got status %#x\n", userdata.ret);
|
|
|
|
ok(userdata.length == 1, "got length %lu\n", userdata.length);
|
|
|
|
ok(userdata.io == io, "expected %p, got %p\n", io, userdata.io);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pTpStartAsyncIoOperation(io);
|
|
|
|
|
|
|
|
ret = ReadFile(server, NULL, 1, NULL, &ovl);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
pTpCancelAsyncIoOperation(io);
|
|
|
|
pTpWaitForIoCompletion(io, FALSE);
|
|
|
|
ok(!userdata.count, "callback ran %u times\n", userdata.count);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pTpStartAsyncIoOperation(io);
|
|
|
|
|
|
|
|
ret = ReadFile(server, in, sizeof(in), NULL, &ovl);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "wrong error %u\n", GetLastError());
|
|
|
|
ret = CancelIo(server);
|
|
|
|
ok(ret, "CancelIo() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
pTpWaitForIoCompletion(io, FALSE);
|
|
|
|
ok(userdata.count == 1, "callback ran %u times\n", userdata.count);
|
|
|
|
ok(userdata.ovl == &ovl, "expected %p, got %p\n", &ovl, userdata.ovl);
|
|
|
|
ok(userdata.ret == STATUS_CANCELLED, "got status %#x\n", userdata.ret);
|
|
|
|
ok(!userdata.length, "got length %lu\n", userdata.length);
|
|
|
|
ok(userdata.io == io, "expected %p, got %p\n", io, userdata.io);
|
|
|
|
|
|
|
|
CloseHandle(ovl.hEvent);
|
|
|
|
CloseHandle(client);
|
|
|
|
CloseHandle(server);
|
|
|
|
pTpReleaseIoCompletion(io);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
}
|
|
|
|
|
2020-04-11 07:16:27 +02:00
|
|
|
static void CALLBACK kernel32_io_cb(TP_CALLBACK_INSTANCE *instance, void *userdata,
|
|
|
|
void *ovl, ULONG ret, ULONG_PTR length, TP_IO *io)
|
|
|
|
{
|
|
|
|
struct io_cb_ctx *ctx = userdata;
|
|
|
|
++ctx->count;
|
|
|
|
ctx->ovl = ovl;
|
|
|
|
ctx->ret = ret;
|
|
|
|
ctx->length = length;
|
|
|
|
ctx->io = io;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_kernel32_tp_io(void)
|
|
|
|
{
|
|
|
|
TP_CALLBACK_ENVIRON environment = {.Version = 1};
|
|
|
|
OVERLAPPED ovl = {}, ovl2 = {};
|
|
|
|
HANDLE client, server, thread;
|
|
|
|
struct io_cb_ctx userdata;
|
|
|
|
char in[1], in2[1];
|
|
|
|
const char out[1];
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD ret_size;
|
|
|
|
TP_POOL *pool;
|
|
|
|
TP_IO *io;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
|
|
|
status = pTpAllocPool(&pool, NULL);
|
|
|
|
ok(!status, "failed to allocate pool, status %#x\n", status);
|
|
|
|
|
|
|
|
server = CreateNamedPipeA("\\\\.\\pipe\\wine_tp_test",
|
|
|
|
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0, 1, 1024, 1024, 0, NULL);
|
|
|
|
ok(server != INVALID_HANDLE_VALUE, "Failed to create server pipe, error %u.\n", GetLastError());
|
|
|
|
client = CreateFileA("\\\\.\\pipe\\wine_tp_test", GENERIC_READ | GENERIC_WRITE,
|
|
|
|
0, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(client != INVALID_HANDLE_VALUE, "Failed to create client pipe, error %u.\n", GetLastError());
|
|
|
|
|
|
|
|
environment.Pool = pool;
|
|
|
|
io = NULL;
|
|
|
|
io = pCreateThreadpoolIo(server, kernel32_io_cb, &userdata, &environment);
|
2020-04-15 02:00:18 +02:00
|
|
|
ok(!!io, "expected non-NULL TP_IO\n");
|
2020-04-11 07:16:27 +02:00
|
|
|
|
|
|
|
pWaitForThreadpoolIoCallbacks(io, FALSE);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pStartThreadpoolIo(io);
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, io_wait_thread, io, 0, NULL);
|
|
|
|
ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "TpWaitForIoCompletion() should not return\n");
|
|
|
|
|
|
|
|
ret = ReadFile(server, in, sizeof(in), NULL, &ovl);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = WriteFile(client, out, sizeof(out), &ret_size, NULL);
|
|
|
|
ok(ret, "WriteFile() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
pWaitForThreadpoolIoCallbacks(io, FALSE);
|
|
|
|
ok(userdata.count == 1, "callback ran %u times\n", userdata.count);
|
|
|
|
ok(userdata.ovl == &ovl, "expected %p, got %p\n", &ovl, userdata.ovl);
|
|
|
|
ok(userdata.ret == ERROR_SUCCESS, "got status %#x\n", userdata.ret);
|
|
|
|
ok(userdata.length == 1, "got length %lu\n", userdata.length);
|
|
|
|
ok(userdata.io == io, "expected %p, got %p\n", io, userdata.io);
|
|
|
|
|
|
|
|
ok(!WaitForSingleObject(thread, 1000), "wait timed out\n");
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pStartThreadpoolIo(io);
|
|
|
|
pStartThreadpoolIo(io);
|
|
|
|
|
|
|
|
ret = ReadFile(server, in, sizeof(in), NULL, &ovl);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "wrong error %u\n", GetLastError());
|
|
|
|
ret = ReadFile(server, in2, sizeof(in2), NULL, &ovl2);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = WriteFile(client, out, sizeof(out), &ret_size, NULL);
|
|
|
|
ok(ret, "WriteFile() failed, error %u\n", GetLastError());
|
|
|
|
ret = WriteFile(client, out, sizeof(out), &ret_size, NULL);
|
|
|
|
ok(ret, "WriteFile() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
pWaitForThreadpoolIoCallbacks(io, FALSE);
|
|
|
|
ok(userdata.count == 2, "callback ran %u times\n", userdata.count);
|
|
|
|
ok(userdata.ret == STATUS_SUCCESS, "got status %#x\n", userdata.ret);
|
|
|
|
ok(userdata.length == 1, "got length %lu\n", userdata.length);
|
|
|
|
ok(userdata.io == io, "expected %p, got %p\n", io, userdata.io);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pStartThreadpoolIo(io);
|
|
|
|
pWaitForThreadpoolIoCallbacks(io, TRUE);
|
|
|
|
ok(!userdata.count, "callback ran %u times\n", userdata.count);
|
|
|
|
|
|
|
|
pStartThreadpoolIo(io);
|
|
|
|
|
|
|
|
ret = WriteFile(client, out, sizeof(out), &ret_size, NULL);
|
|
|
|
ok(ret, "WriteFile() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = ReadFile(server, in, sizeof(in), NULL, &ovl);
|
|
|
|
ok(ret, "wrong ret %d\n", ret);
|
|
|
|
|
|
|
|
pWaitForThreadpoolIoCallbacks(io, FALSE);
|
|
|
|
ok(userdata.count == 1, "callback ran %u times\n", userdata.count);
|
|
|
|
ok(userdata.ovl == &ovl, "expected %p, got %p\n", &ovl, userdata.ovl);
|
|
|
|
ok(userdata.ret == ERROR_SUCCESS, "got status %#x\n", userdata.ret);
|
|
|
|
ok(userdata.length == 1, "got length %lu\n", userdata.length);
|
|
|
|
ok(userdata.io == io, "expected %p, got %p\n", io, userdata.io);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pStartThreadpoolIo(io);
|
|
|
|
|
|
|
|
ret = ReadFile(server, NULL, 1, NULL, &ovl);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
pCancelThreadpoolIo(io);
|
|
|
|
pWaitForThreadpoolIoCallbacks(io, FALSE);
|
|
|
|
ok(!userdata.count, "callback ran %u times\n", userdata.count);
|
|
|
|
|
|
|
|
userdata.count = 0;
|
|
|
|
pStartThreadpoolIo(io);
|
|
|
|
|
|
|
|
ret = ReadFile(server, in, sizeof(in), NULL, &ovl);
|
|
|
|
ok(!ret, "wrong ret %d\n", ret);
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "wrong error %u\n", GetLastError());
|
|
|
|
ret = CancelIo(server);
|
|
|
|
ok(ret, "CancelIo() failed, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
pWaitForThreadpoolIoCallbacks(io, FALSE);
|
|
|
|
ok(userdata.count == 1, "callback ran %u times\n", userdata.count);
|
|
|
|
ok(userdata.ovl == &ovl, "expected %p, got %p\n", &ovl, userdata.ovl);
|
|
|
|
ok(userdata.ret == ERROR_OPERATION_ABORTED, "got status %#x\n", userdata.ret);
|
|
|
|
ok(!userdata.length, "got length %lu\n", userdata.length);
|
|
|
|
ok(userdata.io == io, "expected %p, got %p\n", io, userdata.io);
|
|
|
|
|
|
|
|
CloseHandle(ovl.hEvent);
|
|
|
|
CloseHandle(client);
|
|
|
|
CloseHandle(server);
|
|
|
|
pCloseThreadpoolIo(io);
|
|
|
|
pTpReleasePool(pool);
|
|
|
|
}
|
|
|
|
|
2015-02-24 05:42:03 +01:00
|
|
|
START_TEST(threadpool)
|
|
|
|
{
|
2015-07-26 23:23:57 +02:00
|
|
|
test_RtlQueueWorkItem();
|
2015-10-07 01:24:50 +02:00
|
|
|
test_RtlRegisterWait();
|
2015-07-26 23:23:57 +02:00
|
|
|
|
2015-02-24 05:42:03 +01:00
|
|
|
if (!init_threadpool())
|
|
|
|
return;
|
|
|
|
|
|
|
|
test_tp_simple();
|
2015-07-01 02:58:26 +02:00
|
|
|
test_tp_work();
|
2015-07-01 02:59:01 +02:00
|
|
|
test_tp_work_scheduler();
|
2016-08-20 21:22:54 +02:00
|
|
|
test_tp_group_wait();
|
2015-07-01 22:53:09 +02:00
|
|
|
test_tp_group_cancel();
|
2015-07-01 22:57:16 +02:00
|
|
|
test_tp_instance();
|
2015-07-03 01:57:38 +02:00
|
|
|
test_tp_disassociate();
|
2015-07-03 01:58:45 +02:00
|
|
|
test_tp_timer();
|
2015-07-03 01:59:02 +02:00
|
|
|
test_tp_window_length();
|
2015-07-05 02:24:02 +02:00
|
|
|
test_tp_wait();
|
2015-07-05 02:24:49 +02:00
|
|
|
test_tp_multi_wait();
|
2020-04-11 07:16:26 +02:00
|
|
|
test_tp_io();
|
2020-04-11 07:16:27 +02:00
|
|
|
test_kernel32_tp_io();
|
2015-02-24 05:42:03 +01:00
|
|
|
}
|