From dcfd15ff93ab6120d5f1b7d96f5e92fe0d9e3c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Tue, 22 Mar 2022 11:41:41 +0100 Subject: [PATCH] dinput/tests: Remove now unused HID test driver. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RĂ©mi Bernon Signed-off-by: Alexandre Julliard --- dlls/dinput/tests/Makefile.in | 4 - dlls/dinput/tests/driver.c | 939 ---------------------------------- dlls/dinput/tests/driver.spec | 1 - dlls/dinput/tests/hid.c | 55 +- 4 files changed, 6 insertions(+), 993 deletions(-) delete mode 100644 dlls/dinput/tests/driver.c delete mode 100644 dlls/dinput/tests/driver.spec diff --git a/dlls/dinput/tests/Makefile.in b/dlls/dinput/tests/Makefile.in index e2764e5f4d6..73d8a2fc2a6 100644 --- a/dlls/dinput/tests/Makefile.in +++ b/dlls/dinput/tests/Makefile.in @@ -1,8 +1,6 @@ TESTDLL = dinput.dll IMPORTS = dinput dinput8 ole32 version user32 advapi32 hid uuid crypt32 newdev setupapi wintrust winmm -driver_IMPORTS = winecrt0 ntoskrnl hal hidclass -driver_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native driver_bus_IMPORTS = winecrt0 ntoskrnl hal driver_bus_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native driver_hid_IMPORTS = winecrt0 ntoskrnl hal hidclass @@ -14,8 +12,6 @@ SOURCES = \ device.c \ device8.c \ dinput.c \ - driver.c \ - driver.spec \ driver_bus.c \ driver_bus.spec \ driver_hid.c \ diff --git a/dlls/dinput/tests/driver.c b/dlls/dinput/tests/driver.c deleted file mode 100644 index 38b4776a3f0..00000000000 --- a/dlls/dinput/tests/driver.c +++ /dev/null @@ -1,939 +0,0 @@ -/* - * HID Plug and Play test driver - * - * Copyright 2021 Zebediah Figura - * - * 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 - */ - -#include -#include - -#include "ntstatus.h" -#define WIN32_NO_STATUS -#include "windef.h" -#include "winbase.h" -#include "winternl.h" -#include "winioctl.h" -#include "ddk/wdm.h" -#include "hidusage.h" -#include "ddk/hidpi.h" -#include "ddk/hidport.h" - -#include "wine/list.h" - -#include "initguid.h" -#include "driver_hid.h" - -static UNICODE_STRING control_symlink; - -static unsigned int got_start_device; -static HID_DEVICE_ATTRIBUTES attributes; -static char report_descriptor_buf[4096]; -static DWORD report_descriptor_len; -static HIDP_CAPS caps; -static DWORD report_id; -static DWORD polled; - -#define EXPECT_QUEUE_BUFFER_SIZE (64 * sizeof(struct hid_expect)) - -struct expect_queue -{ - KSPIN_LOCK lock; - struct hid_expect *pos; - struct hid_expect *end; - struct hid_expect spurious; - struct hid_expect *buffer; - IRP *pending_wait; - char context[64]; -}; - -static void expect_queue_init( struct expect_queue *queue ) -{ - KeInitializeSpinLock( &queue->lock ); - queue->buffer = ExAllocatePool( PagedPool, EXPECT_QUEUE_BUFFER_SIZE ); - RtlSecureZeroMemory( queue->buffer, EXPECT_QUEUE_BUFFER_SIZE ); - queue->pos = queue->buffer; - queue->end = queue->buffer; -} - -static void expect_queue_cleanup( struct expect_queue *queue ) -{ - KIRQL irql; - IRP *irp; - - KeAcquireSpinLock( &queue->lock, &irql ); - if ((irp = queue->pending_wait)) - { - queue->pending_wait = NULL; - if (!IoSetCancelRoutine( irp, NULL )) irp = NULL; - } - KeReleaseSpinLock( &queue->lock, irql ); - - if (irp) - { - irp->IoStatus.Information = 0; - irp->IoStatus.Status = STATUS_DELETE_PENDING; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - } - - ExFreePool( queue->buffer ); -} - -static void expect_queue_reset( struct expect_queue *queue, void *buffer, unsigned int size ) -{ - struct hid_expect *missing, *missing_end, *tmp; - char context[64]; - KIRQL irql; - - missing = ExAllocatePool( PagedPool, EXPECT_QUEUE_BUFFER_SIZE ); - RtlSecureZeroMemory( missing, EXPECT_QUEUE_BUFFER_SIZE ); - missing_end = missing; - - KeAcquireSpinLock( &queue->lock, &irql ); - tmp = queue->pos; - while (tmp < queue->end) *missing_end++ = *tmp++; - - queue->pos = queue->buffer; - queue->end = queue->buffer; - - if (size) memcpy( queue->end, buffer, size ); - queue->end = queue->end + size / sizeof(struct hid_expect); - memcpy( context, queue->context, sizeof(context) ); - KeReleaseSpinLock( &queue->lock, irql ); - - tmp = missing; - while (tmp != missing_end) - { - winetest_push_context( "%s expect[%Id]", context, tmp - missing ); - if (tmp->broken) - { - todo_wine_if( tmp->todo ) - win_skip( "broken (code %#lx id %u len %u)\n", tmp->code, tmp->report_id, tmp->report_len ); - } - else - { - todo_wine_if( tmp->todo ) - ok( tmp->wine_only, "missing (code %#lx id %u len %u)\n", tmp->code, tmp->report_id, tmp->report_len ); - } - winetest_pop_context(); - tmp++; - } - - ExFreePool( missing ); -} - -static void WINAPI wait_cancel_routine( DEVICE_OBJECT *device, IRP *irp ) -{ - struct expect_queue *queue = irp->Tail.Overlay.DriverContext[0]; - KIRQL irql; - - IoReleaseCancelSpinLock( irp->CancelIrql ); - - KeAcquireSpinLock( &queue->lock, &irql ); - queue->pending_wait = NULL; - KeReleaseSpinLock( &queue->lock, irql ); - - irp->IoStatus.Information = 0; - irp->IoStatus.Status = STATUS_CANCELLED; - IoCompleteRequest( irp, IO_NO_INCREMENT ); -} - -static NTSTATUS expect_queue_wait( struct expect_queue *queue, IRP *irp ) -{ - NTSTATUS status; - KIRQL irql; - - KeAcquireSpinLock( &queue->lock, &irql ); - if (queue->pos == queue->end) - status = STATUS_SUCCESS; - else - { - IoSetCancelRoutine( irp, wait_cancel_routine ); - if (irp->Cancel && !IoSetCancelRoutine( irp, NULL )) - status = STATUS_CANCELLED; - else - { - irp->Tail.Overlay.DriverContext[0] = queue; - IoMarkIrpPending( irp ); - queue->pending_wait = irp; - status = STATUS_PENDING; - } - } - KeReleaseSpinLock( &queue->lock, irql ); - - if (status == STATUS_SUCCESS) - { - irp->IoStatus.Status = STATUS_SUCCESS; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - } - - return status; -} - -static void expect_queue_next( struct expect_queue *queue, ULONG code, HID_XFER_PACKET *packet, - LONG *index, struct hid_expect *expect, BOOL compare_buf, - char *context, ULONG context_size ) -{ - struct hid_expect *missing, *missing_end, *tmp; - ULONG len = packet->reportBufferLen; - BYTE *buf = packet->reportBuffer; - BYTE id = packet->reportId; - IRP *irp = NULL; - KIRQL irql; - - missing = ExAllocatePool( PagedPool, EXPECT_QUEUE_BUFFER_SIZE ); - RtlSecureZeroMemory( missing, EXPECT_QUEUE_BUFFER_SIZE ); - missing_end = missing; - - KeAcquireSpinLock( &queue->lock, &irql ); - tmp = queue->pos; - while (tmp < queue->end) - { - if (running_under_wine && !tmp->todo) break; - if (!running_under_wine && !tmp->broken && !tmp->wine_only) break; - if (tmp->code == code && tmp->report_id == id && tmp->report_len == len && - (!compare_buf || RtlCompareMemory( tmp->report_buf, buf, len ) == len)) - break; - *missing_end++ = *tmp++; - } - *index = tmp - queue->buffer; - if (tmp < queue->end) queue->pos = tmp + 1; - else tmp = &queue->spurious; - *expect = *tmp; - - while (queue->pos < queue->end) - { - if (running_under_wine || !queue->pos->wine_only) break; - queue->pos++; - } - if (queue->pos == queue->end && (irp = queue->pending_wait)) - { - queue->pending_wait = NULL; - if (!IoSetCancelRoutine( irp, NULL )) irp = NULL; - } - memcpy( context, queue->context, context_size ); - KeReleaseSpinLock( &queue->lock, irql ); - - if (irp) - { - irp->IoStatus.Information = 0; - irp->IoStatus.Status = STATUS_SUCCESS; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - } - - ok( tmp != &queue->spurious, "%s got spurious packet\n", context ); - - winetest_push_context( "%s expect[%Id]", context, tmp - queue->buffer ); - todo_wine_if( tmp->todo ) - ok( !tmp->wine_only, "found code %#lx id %u len %u\n", tmp->code, tmp->report_id, tmp->report_len ); - winetest_pop_context(); - - tmp = missing; - while (tmp != missing_end) - { - winetest_push_context( "%s expect[%Id]", context, tmp - missing ); - if (tmp->broken) - { - todo_wine_if( tmp->todo ) - win_skip( "broken (code %#lx id %u len %u)\n", tmp->code, tmp->report_id, tmp->report_len ); - } - else - { - todo_wine_if( tmp->todo ) - ok( tmp->wine_only, "missing (code %#lx id %u len %u)\n", tmp->code, tmp->report_id, tmp->report_len ); - } - winetest_pop_context(); - tmp++; - } - - ExFreePool( missing ); -} - -static struct expect_queue expect_queue; - -struct irp_queue -{ - KSPIN_LOCK lock; - LIST_ENTRY list; -}; - -static IRP *irp_queue_pop( struct irp_queue *queue ) -{ - KIRQL irql; - IRP *irp; - - KeAcquireSpinLock( &queue->lock, &irql ); - if (IsListEmpty( &queue->list )) irp = NULL; - else irp = CONTAINING_RECORD( RemoveHeadList( &queue->list ), IRP, Tail.Overlay.ListEntry ); - KeReleaseSpinLock( &queue->lock, irql ); - - return irp; -} - -static void irp_queue_push( struct irp_queue *queue, IRP *irp ) -{ - KIRQL irql; - - KeAcquireSpinLock( &queue->lock, &irql ); - InsertTailList( &queue->list, &irp->Tail.Overlay.ListEntry ); - KeReleaseSpinLock( &queue->lock, irql ); -} - -static void irp_queue_clear( struct irp_queue *queue ) -{ - IRP *irp; - - while ((irp = irp_queue_pop( queue ))) - { - irp->IoStatus.Status = STATUS_DELETE_PENDING; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - } -} - -static void irp_queue_init( struct irp_queue *queue ) -{ - KeInitializeSpinLock( &queue->lock ); - InitializeListHead( &queue->list ); -} - -struct input_queue -{ - KSPIN_LOCK lock; - struct hid_expect *pos; - struct hid_expect *end; - struct hid_expect *buffer; - struct irp_queue pending; -}; - -static void input_queue_init( struct input_queue *queue ) -{ - KeInitializeSpinLock( &queue->lock ); - queue->buffer = ExAllocatePool( PagedPool, EXPECT_QUEUE_BUFFER_SIZE ); - RtlSecureZeroMemory( queue->buffer, EXPECT_QUEUE_BUFFER_SIZE ); - queue->pos = queue->buffer; - queue->end = queue->buffer; - irp_queue_init( &queue->pending ); -} - -static void input_queue_cleanup( struct input_queue *queue ) -{ - ExFreePool( queue->buffer ); -} - -static BOOL input_queue_read_locked( struct input_queue *queue, IRP *irp ) -{ - IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp ); - ULONG out_size = stack->Parameters.DeviceIoControl.OutputBufferLength; - struct hid_expect *tmp = queue->pos; - - if (tmp >= queue->end) return FALSE; - if (tmp->ret_length) out_size = tmp->ret_length; - - memcpy( irp->UserBuffer, tmp->report_buf, out_size ); - irp->IoStatus.Information = out_size; - irp->IoStatus.Status = tmp->ret_status; - if (tmp < queue->end) queue->pos = tmp + 1; - - /* loop on the queue data in polled mode */ - if (polled && queue->pos == queue->end) queue->pos = queue->buffer; - return TRUE; -} - -static NTSTATUS input_queue_read( struct input_queue *queue, IRP *irp ) -{ - NTSTATUS status; - KIRQL irql; - - KeAcquireSpinLock( &queue->lock, &irql ); - if (input_queue_read_locked( queue, irp )) status = STATUS_SUCCESS; - else - { - IoMarkIrpPending( irp ); - irp_queue_push( &queue->pending, irp ); - status = STATUS_PENDING; - } - KeReleaseSpinLock( &queue->lock, irql ); - - return status; -} - -static void input_queue_reset( struct input_queue *queue, void *in_buf, ULONG in_size ) -{ - struct irp_queue completed; - ULONG remaining; - KIRQL irql; - IRP *irp; - - irp_queue_init( &completed ); - - KeAcquireSpinLock( &queue->lock, &irql ); - remaining = queue->end - queue->pos; - queue->pos = queue->buffer; - queue->end = queue->buffer; - memcpy( queue->end, in_buf, in_size ); - queue->end += in_size / sizeof(struct hid_expect); - - while (!polled && queue->pos < queue->end && (irp = irp_queue_pop( &queue->pending ))) - { - input_queue_read_locked( queue, irp ); - irp_queue_push( &completed, irp ); - } - KeReleaseSpinLock( &queue->lock, irql ); - - if (!polled) ok( !remaining, "unread input\n" ); - - while ((irp = irp_queue_pop( &completed ))) IoCompleteRequest( irp, IO_NO_INCREMENT ); -} - -static struct input_queue input_queue; - -struct hid_device -{ - BOOL removed; - KSPIN_LOCK lock; -}; - -static DRIVER_OBJECT *expect_driver; -static DEVICE_OBJECT *expect_bus_pdo; -static DEVICE_OBJECT *expect_hid_fdo; -static DEVICE_OBJECT *expect_hid_pdo; -static struct hid_device *expect_hid_ext; - -static void check_device( DEVICE_OBJECT *device ) -{ - static int checked_fdo, checked_pdo; - HID_DEVICE_EXTENSION *ext = device->DeviceExtension; - - ok( device == expect_hid_pdo || device == expect_hid_fdo, "got device %p\n", device ); - ok( device->DriverObject == expect_driver, "got DriverObject %p\n", device->DriverObject ); - if (!device->NextDevice) ok( device == expect_hid_fdo, "got device %p\n", device ); - else ok( device->NextDevice == expect_hid_fdo, "got NextDevice %p\n", device->NextDevice ); - ok( !device->AttachedDevice, "got AttachedDevice %p\n", device->AttachedDevice ); - - if (device == expect_hid_pdo && checked_pdo++) return; - if (device == expect_hid_fdo && checked_fdo++) return; - - todo_wine_if( device != expect_hid_fdo ) - ok( ext->MiniDeviceExtension == expect_hid_ext, "got MiniDeviceExtension %p\n", ext->MiniDeviceExtension ); - if (ext->MiniDeviceExtension != expect_hid_ext) return; - ok( ext->PhysicalDeviceObject == expect_bus_pdo, "got PhysicalDeviceObject %p\n", ext->PhysicalDeviceObject ); - ok( ext->NextDeviceObject == expect_bus_pdo, "got NextDeviceObject %p\n", ext->NextDeviceObject ); -} - -static NTSTATUS WINAPI driver_pnp( DEVICE_OBJECT *device, IRP *irp ) -{ - IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp ); - HID_DEVICE_EXTENSION *ext = device->DeviceExtension; - struct hid_device *impl = ext->MiniDeviceExtension; - ULONG code = stack->MinorFunction; - KIRQL irql; - - if (winetest_debug > 1) trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_pnp(code) ); - - switch (code) - { - case IRP_MN_START_DEVICE: - ++got_start_device; - impl->removed = FALSE; - KeInitializeSpinLock( &impl->lock ); - IoSetDeviceInterfaceState( &control_symlink, TRUE ); - irp->IoStatus.Status = STATUS_SUCCESS; - break; - - case IRP_MN_SURPRISE_REMOVAL: - case IRP_MN_QUERY_REMOVE_DEVICE: - KeAcquireSpinLock( &impl->lock, &irql ); - impl->removed = TRUE; - KeReleaseSpinLock( &impl->lock, irql ); - irp_queue_clear( &input_queue.pending ); - irp->IoStatus.Status = STATUS_SUCCESS; - break; - - case IRP_MN_CANCEL_REMOVE_DEVICE: - KeAcquireSpinLock( &impl->lock, &irql ); - impl->removed = FALSE; - KeReleaseSpinLock( &impl->lock, irql ); - irp->IoStatus.Status = STATUS_SUCCESS; - break; - - case IRP_MN_STOP_DEVICE: - irp->IoStatus.Status = STATUS_SUCCESS; - break; - - case IRP_MN_REMOVE_DEVICE: - irp_queue_clear( &input_queue.pending ); - IoSetDeviceInterfaceState( &control_symlink, FALSE ); - irp->IoStatus.Status = STATUS_SUCCESS; - break; - } - - IoSkipCurrentIrpStackLocation( irp ); - return IoCallDriver( ext->NextDeviceObject, irp ); -} - -#define check_buffer( a, b ) check_buffer_( __LINE__, a, b ) -static void check_buffer_( int line, HID_XFER_PACKET *packet, struct hid_expect *expect ) -{ - ULONG match_len, i; - - match_len = RtlCompareMemory( packet->reportBuffer, expect->report_buf, expect->report_len ); - ok( match_len == expect->report_len, "unexpected data:\n" ); - if (match_len == expect->report_len) return; - - for (i = 0; i < packet->reportBufferLen;) - { - char buffer[256], *buf = buffer; - buf += sprintf( buf, "%08lx ", i ); - do buf += sprintf( buf, " %02x", packet->reportBuffer[i] ); - while (++i % 16 && i < packet->reportBufferLen); - ok( 0, " %s\n", buffer ); - } -} - -static NTSTATUS WINAPI driver_internal_ioctl( DEVICE_OBJECT *device, IRP *irp ) -{ - IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp ); - HID_DEVICE_EXTENSION *ext = device->DeviceExtension; - struct hid_device *impl = ext->MiniDeviceExtension; - const ULONG in_size = stack->Parameters.DeviceIoControl.InputBufferLength; - ULONG out_size = stack->Parameters.DeviceIoControl.OutputBufferLength; - const ULONG code = stack->Parameters.DeviceIoControl.IoControlCode; - struct hid_expect expect = {0}; - char context[64]; - NTSTATUS ret; - BOOL removed; - KIRQL irql; - LONG index; - - if (winetest_debug > 1) trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_ioctl(code) ); - - ok( expect_hid_fdo == device, "got device %p\n", device ); - check_device( device ); - - ok( got_start_device, "expected IRP_MN_START_DEVICE before any ioctls\n" ); - - irp->IoStatus.Information = 0; - - KeAcquireSpinLock( &impl->lock, &irql ); - removed = impl->removed; - KeReleaseSpinLock( &impl->lock, irql ); - - if (removed) - { - irp->IoStatus.Status = STATUS_DELETE_PENDING; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - return STATUS_DELETE_PENDING; - } - - winetest_push_context( "id %ld%s", report_id, polled ? " poll" : "" ); - - switch (code) - { - case IOCTL_HID_GET_DEVICE_DESCRIPTOR: - { - HID_DESCRIPTOR *desc = irp->UserBuffer; - - ok( !in_size, "got input size %lu\n", in_size ); - ok( out_size == sizeof(*desc), "got output size %lu\n", out_size ); - - if (out_size == sizeof(*desc)) - { - ok( !desc->bLength, "got size %u\n", desc->bLength ); - - desc->bLength = sizeof(*desc); - desc->bDescriptorType = HID_HID_DESCRIPTOR_TYPE; - desc->bcdHID = HID_REVISION; - desc->bCountry = 0; - desc->bNumDescriptors = 1; - desc->DescriptorList[0].bReportType = HID_REPORT_DESCRIPTOR_TYPE; - desc->DescriptorList[0].wReportLength = report_descriptor_len; - irp->IoStatus.Information = sizeof(*desc); - } - ret = STATUS_SUCCESS; - break; - } - - case IOCTL_HID_GET_REPORT_DESCRIPTOR: - ok( !in_size, "got input size %lu\n", in_size ); - ok( out_size == report_descriptor_len, "got output size %lu\n", out_size ); - - if (out_size == report_descriptor_len) - { - memcpy( irp->UserBuffer, report_descriptor_buf, report_descriptor_len ); - irp->IoStatus.Information = report_descriptor_len; - } - ret = STATUS_SUCCESS; - break; - - case IOCTL_HID_GET_DEVICE_ATTRIBUTES: - ok( !in_size, "got input size %lu\n", in_size ); - ok( out_size == sizeof(attributes), "got output size %lu\n", out_size ); - - if (out_size == sizeof(attributes)) - { - memcpy( irp->UserBuffer, &attributes, sizeof(attributes) ); - irp->IoStatus.Information = sizeof(attributes); - } - ret = STATUS_SUCCESS; - break; - - case IOCTL_HID_READ_REPORT: - { - ULONG expected_size = caps.InputReportByteLength - (report_id ? 0 : 1); - ok( !in_size, "got input size %lu\n", in_size ); - ok( out_size == expected_size, "got output size %lu\n", out_size ); - ret = input_queue_read( &input_queue, irp ); - break; - } - - case IOCTL_HID_WRITE_REPORT: - { - HID_XFER_PACKET *packet = irp->UserBuffer; - ULONG expected_size = caps.OutputReportByteLength - (report_id ? 0 : 1); - - ok( in_size == sizeof(*packet), "got input size %lu\n", in_size ); - ok( !out_size, "got output size %lu\n", out_size ); - ok( packet->reportBufferLen >= expected_size, "got report size %lu\n", packet->reportBufferLen ); - - expect_queue_next( &expect_queue, code, packet, &index, &expect, TRUE, context, sizeof(context) ); - winetest_push_context( "%s expect[%ld]", context, index ); - ok( code == expect.code, "got %#lx, expected %#lx\n", code, expect.code ); - ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId ); - ok( packet->reportBufferLen == expect.report_len, "got len %lu\n", packet->reportBufferLen ); - check_buffer( packet, &expect ); - winetest_pop_context(); - - irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len; - ret = expect.ret_status; - break; - } - - case IOCTL_HID_GET_INPUT_REPORT: - { - HID_XFER_PACKET *packet = irp->UserBuffer; - ULONG expected_size = caps.InputReportByteLength - (report_id ? 0 : 1); - ok( !in_size, "got input size %lu\n", in_size ); - ok( out_size == sizeof(*packet), "got output size %lu\n", out_size ); - - ok( packet->reportBufferLen >= expected_size, "got len %lu\n", packet->reportBufferLen ); - ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer ); - - expect_queue_next( &expect_queue, code, packet, &index, &expect, FALSE, context, sizeof(context) ); - winetest_push_context( "%s expect[%ld]", context, index ); - ok( code == expect.code, "got %#lx, expected %#lx\n", code, expect.code ); - ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId ); - ok( packet->reportBufferLen == expect.report_len, "got len %lu\n", packet->reportBufferLen ); - winetest_pop_context(); - - irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len; - memcpy( packet->reportBuffer, expect.report_buf, irp->IoStatus.Information ); - ret = expect.ret_status; - break; - } - - case IOCTL_HID_SET_OUTPUT_REPORT: - { - HID_XFER_PACKET *packet = irp->UserBuffer; - ULONG expected_size = caps.OutputReportByteLength - (report_id ? 0 : 1); - ok( in_size == sizeof(*packet), "got input size %lu\n", in_size ); - ok( !out_size, "got output size %lu\n", out_size ); - - ok( packet->reportBufferLen >= expected_size, "got len %lu\n", packet->reportBufferLen ); - ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer ); - - expect_queue_next( &expect_queue, code, packet, &index, &expect, TRUE, context, sizeof(context) ); - winetest_push_context( "%s expect[%ld]", context, index ); - ok( code == expect.code, "got %#lx, expected %#lx\n", code, expect.code ); - ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId ); - ok( packet->reportBufferLen == expect.report_len, "got len %lu\n", packet->reportBufferLen ); - check_buffer( packet, &expect ); - winetest_pop_context(); - - irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len; - ret = expect.ret_status; - break; - } - - case IOCTL_HID_GET_FEATURE: - { - HID_XFER_PACKET *packet = irp->UserBuffer; - ULONG expected_size = caps.FeatureReportByteLength - (report_id ? 0 : 1); - ok( !in_size, "got input size %lu\n", in_size ); - ok( out_size == sizeof(*packet), "got output size %lu\n", out_size ); - - ok( packet->reportBufferLen >= expected_size, "got len %lu\n", packet->reportBufferLen ); - ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer ); - - expect_queue_next( &expect_queue, code, packet, &index, &expect, FALSE, context, sizeof(context) ); - winetest_push_context( "%s expect[%ld]", context, index ); - ok( code == expect.code, "got %#lx, expected %#lx\n", code, expect.code ); - ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId ); - ok( packet->reportBufferLen == expect.report_len, "got len %lu\n", packet->reportBufferLen ); - winetest_pop_context(); - - irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len; - memcpy( packet->reportBuffer, expect.report_buf, irp->IoStatus.Information ); - ret = expect.ret_status; - break; - } - - case IOCTL_HID_SET_FEATURE: - { - HID_XFER_PACKET *packet = irp->UserBuffer; - ULONG expected_size = caps.FeatureReportByteLength - (report_id ? 0 : 1); - ok( in_size == sizeof(*packet), "got input size %lu\n", in_size ); - ok( !out_size, "got output size %lu\n", out_size ); - - ok( packet->reportBufferLen >= expected_size, "got len %lu\n", packet->reportBufferLen ); - ok( !!packet->reportBuffer, "got buffer %p\n", packet->reportBuffer ); - - expect_queue_next( &expect_queue, code, packet, &index, &expect, TRUE, context, sizeof(context) ); - winetest_push_context( "%s expect[%ld]", context, index ); - ok( code == expect.code, "got %#lx, expected %#lx\n", code, expect.code ); - ok( packet->reportId == expect.report_id, "got id %u\n", packet->reportId ); - ok( packet->reportBufferLen == expect.report_len, "got len %lu\n", packet->reportBufferLen ); - check_buffer( packet, &expect ); - winetest_pop_context(); - - irp->IoStatus.Information = expect.ret_length ? expect.ret_length : expect.report_len; - ret = expect.ret_status; - break; - } - - case IOCTL_HID_GET_STRING: - { - memcpy( irp->UserBuffer, L"Wine Test", sizeof(L"Wine Test") ); - irp->IoStatus.Information = sizeof(L"Wine Test"); - ret = STATUS_SUCCESS; - break; - } - - default: - ok( 0, "unexpected ioctl %#lx\n", code ); - ret = STATUS_NOT_IMPLEMENTED; - } - - winetest_pop_context(); - - if (ret != STATUS_PENDING) - { - irp->IoStatus.Status = ret; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - } - return ret; -} - -static NTSTATUS (WINAPI *hidclass_driver_ioctl)( DEVICE_OBJECT *device, IRP *irp ); -static NTSTATUS WINAPI driver_ioctl( DEVICE_OBJECT *device, IRP *irp ) -{ - IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp ); - ULONG in_size = stack->Parameters.DeviceIoControl.InputBufferLength; - ULONG code = stack->Parameters.DeviceIoControl.IoControlCode; - KIRQL irql; - - if (winetest_debug > 1) trace( "%s: device %p, code %#lx %s\n", __func__, device, code, debugstr_ioctl(code) ); - - if (!expect_hid_pdo) expect_hid_pdo = device; - else ok( expect_hid_pdo == device, "got device %p\n", device ); - check_device( device ); - - switch (code) - { - case IOCTL_WINETEST_HID_SET_EXPECT: - expect_queue_reset( &expect_queue, irp->AssociatedIrp.SystemBuffer, in_size ); - irp->IoStatus.Status = STATUS_SUCCESS; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - return STATUS_SUCCESS; - case IOCTL_WINETEST_HID_WAIT_EXPECT: - return expect_queue_wait( &expect_queue, irp ); - case IOCTL_WINETEST_HID_SEND_INPUT: - input_queue_reset( &input_queue, irp->AssociatedIrp.SystemBuffer, in_size ); - irp->IoStatus.Status = STATUS_SUCCESS; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - return STATUS_SUCCESS; - case IOCTL_WINETEST_HID_SET_CONTEXT: - KeAcquireSpinLock( &expect_queue.lock, &irql ); - memcpy( expect_queue.context, irp->AssociatedIrp.SystemBuffer, in_size ); - KeReleaseSpinLock( &expect_queue.lock, irql ); - - irp->IoStatus.Status = STATUS_SUCCESS; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - return STATUS_SUCCESS; - - case IOCTL_WINETEST_REMOVE_DEVICE: - case IOCTL_WINETEST_CREATE_DEVICE: - ok( 0, "unexpected call\n" ); - irp->IoStatus.Status = STATUS_NOT_SUPPORTED; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - return STATUS_NOT_SUPPORTED; - } - - return hidclass_driver_ioctl( device, irp ); -} - -static NTSTATUS WINAPI driver_add_device( DRIVER_OBJECT *driver, DEVICE_OBJECT *device ) -{ - HID_DEVICE_EXTENSION *ext = device->DeviceExtension; - NTSTATUS ret; - - if (winetest_debug > 1) trace( "%s: driver %p, device %p\n", __func__, driver, device ); - - expect_hid_fdo = device; - expect_bus_pdo = ext->PhysicalDeviceObject; - expect_hid_ext = ext->MiniDeviceExtension; - - todo_wine - ok( expect_bus_pdo->AttachedDevice == device, "got AttachedDevice %p\n", expect_bus_pdo->AttachedDevice ); - ok( driver == expect_driver, "got driver %p\n", driver ); - check_device( device ); - - ret = IoRegisterDeviceInterface( ext->PhysicalDeviceObject, &control_class, NULL, &control_symlink ); - ok( !ret, "got %#lx\n", ret ); - - if (winetest_debug > 1) trace( "Created HID FDO %p for Bus PDO %p\n", device, ext->PhysicalDeviceObject ); - - device->Flags &= ~DO_DEVICE_INITIALIZING; - return STATUS_SUCCESS; -} - -static NTSTATUS WINAPI driver_create( DEVICE_OBJECT *device, IRP *irp ) -{ - if (winetest_debug > 1) trace( "%s: device %p\n", __func__, device ); - ok( 0, "unexpected call\n" ); - irp->IoStatus.Status = STATUS_SUCCESS; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - return STATUS_SUCCESS; -} - -static NTSTATUS WINAPI driver_close( DEVICE_OBJECT *device, IRP *irp ) -{ - if (winetest_debug > 1) trace( "%s: device %p\n", __func__, device ); - ok( 0, "unexpected call\n" ); - irp->IoStatus.Status = STATUS_SUCCESS; - IoCompleteRequest( irp, IO_NO_INCREMENT ); - return STATUS_SUCCESS; -} - -static void WINAPI driver_unload( DRIVER_OBJECT *driver ) -{ - if (winetest_debug > 1) trace( "%s: driver %p\n", __func__, driver ); - input_queue_cleanup( &input_queue ); - expect_queue_cleanup( &expect_queue ); - winetest_cleanup(); -} - -NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *registry ) -{ - static const int info_size = offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ); - HID_MINIDRIVER_REGISTRATION params = - { - .Revision = HID_REVISION, - .DriverObject = driver, - .DeviceExtensionSize = sizeof(struct hid_device), - .RegistryPath = registry, - }; - UNICODE_STRING name_str; - OBJECT_ATTRIBUTES attr; - NTSTATUS ret; - char *buffer; - HANDLE hkey; - DWORD size; - - expect_driver = driver; - - if ((ret = winetest_init())) return ret; - if (winetest_debug > 1) trace( "%s: driver %p\n", __func__, driver ); - - InitializeObjectAttributes( &attr, registry, 0, NULL, NULL ); - ret = ZwOpenKey( &hkey, KEY_ALL_ACCESS, &attr ); - ok( !ret, "ZwOpenKey returned %#lx\n", ret ); - - buffer = ExAllocatePool( PagedPool, info_size + EXPECT_QUEUE_BUFFER_SIZE ); - ok( buffer != NULL, "ExAllocatePool failed\n" ); - if (!buffer) return STATUS_NO_MEMORY; - - RtlInitUnicodeString( &name_str, L"ReportID" ); - size = info_size + sizeof(report_id); - ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size ); - ok( !ret, "ZwQueryValueKey returned %#lx\n", ret ); - memcpy( &report_id, buffer + info_size, size - info_size ); - - RtlInitUnicodeString( &name_str, L"PolledMode" ); - size = info_size + sizeof(polled); - ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size ); - ok( !ret, "ZwQueryValueKey returned %#lx\n", ret ); - memcpy( &polled, buffer + info_size, size - info_size ); - params.DevicesArePolled = polled; - /* polled mode calls this in a state where printing anything locks the system up */ - if (polled) winetest_debug = 0; - - RtlInitUnicodeString( &name_str, L"Descriptor" ); - size = info_size + sizeof(report_descriptor_buf); - ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size ); - ok( !ret, "ZwQueryValueKey returned %#lx\n", ret ); - memcpy( report_descriptor_buf, buffer + info_size, size - info_size ); - report_descriptor_len = size - info_size; - - RtlInitUnicodeString( &name_str, L"Attributes" ); - size = info_size + sizeof(attributes); - ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size ); - ok( !ret, "ZwQueryValueKey returned %#lx\n", ret ); - memcpy( &attributes, buffer + info_size, size - info_size ); - - RtlInitUnicodeString( &name_str, L"Caps" ); - size = info_size + sizeof(caps); - ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size ); - ok( !ret, "ZwQueryValueKey returned %#lx\n", ret ); - memcpy( &caps, buffer + info_size, size - info_size ); - - expect_queue_init( &expect_queue ); - RtlInitUnicodeString( &name_str, L"Expect" ); - size = info_size + EXPECT_QUEUE_BUFFER_SIZE; - ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size ); - ok( !ret, "ZwQueryValueKey returned %#lx\n", ret ); - expect_queue_reset( &expect_queue, buffer + info_size, size - info_size ); - - input_queue_init( &input_queue ); - RtlInitUnicodeString( &name_str, L"Input" ); - size = info_size + EXPECT_QUEUE_BUFFER_SIZE; - ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size ); - ok( !ret, "ZwQueryValueKey returned %#lx\n", ret ); - input_queue_reset( &input_queue, buffer + info_size, size - info_size ); - - RtlInitUnicodeString( &name_str, L"Context" ); - size = info_size + sizeof(expect_queue.context); - ret = ZwQueryValueKey( hkey, &name_str, KeyValuePartialInformation, buffer, size, &size ); - ok( !ret, "ZwQueryValueKey returned %#lx\n", ret ); - memcpy( expect_queue.context, buffer + info_size, size - info_size ); - - driver->DriverExtension->AddDevice = driver_add_device; - driver->DriverUnload = driver_unload; - driver->MajorFunction[IRP_MJ_PNP] = driver_pnp; - driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = driver_ioctl; - driver->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = driver_internal_ioctl; - driver->MajorFunction[IRP_MJ_CREATE] = driver_create; - driver->MajorFunction[IRP_MJ_CLOSE] = driver_close; - - ExFreePool( buffer ); - - ret = HidRegisterMinidriver( ¶ms ); - ok( !ret, "got %#lx\n", ret ); - - hidclass_driver_ioctl = driver->MajorFunction[IRP_MJ_DEVICE_CONTROL]; - driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = driver_ioctl; - - return STATUS_SUCCESS; -} diff --git a/dlls/dinput/tests/driver.spec b/dlls/dinput/tests/driver.spec deleted file mode 100644 index ad33444716a..00000000000 --- a/dlls/dinput/tests/driver.spec +++ /dev/null @@ -1 +0,0 @@ -# nothing here yet diff --git a/dlls/dinput/tests/hid.c b/dlls/dinput/tests/hid.c index 5ac14031dde..de77c02540f 100644 --- a/dlls/dinput/tests/hid.c +++ b/dlls/dinput/tests/hid.c @@ -325,17 +325,10 @@ static const char inf_text[] = "Wine=mfg_section,NT" EXT "\n" "[mfg_section.NT" EXT "]\n" - "Wine test root driver=device_section,test_hardware_id\n" "Wine Test Bus Device=bus_section,WINETEST\\BUS\n" "Wine Test HID Device=hid_section,WINETEST\\WINE_COMP_HID\n" "Wine Test HID Polled Device=hid_poll_section,WINETEST\\WINE_COMP_POLLHID\n" - "[device_section.NT" EXT "]\n" - "CopyFiles=file_section\n" - - "[device_section.NT" EXT ".Services]\n" - "AddService=winetest,0x2,svc_section\n" - "[bus_section.NT" EXT "]\n" "CopyFiles=file_section\n" @@ -355,19 +348,16 @@ static const char inf_text[] = "AddService=winetest_hid_poll,0x2,hid_poll_service\n" "[file_section]\n" - "winetest.sys\n" "winetest_bus.sys\n" "winetest_hid.sys\n" "winetest_hid_poll.sys\n" "[SourceDisksFiles]\n" - "winetest.sys=1\n" "winetest_bus.sys=1\n" "winetest_hid.sys=1\n" "winetest_hid_poll.sys=1\n" "[SourceDisksNames]\n" - "1=,winetest.sys\n" "1=,winetest_bus.sys\n" "1=,winetest_hid.sys\n" "1=,winetest_hid_poll.sys\n" @@ -375,14 +365,6 @@ static const char inf_text[] = "[DestinationDirs]\n" "DefaultDestDir=12\n" - "[svc_section]\n" - "ServiceBinary=%12%\\winetest.sys\n" - "ServiceType=1\n" - "StartType=3\n" - "ErrorControl=1\n" - "LoadOrderGroup=WinePlugPlay\n" - "DisplayName=\"winetest bus driver\"\n" - "[bus_service]\n" "ServiceBinary=%12%\\winetest_bus.sys\n" "ServiceType=1\n" @@ -481,11 +463,11 @@ static void unload_driver( SC_HANDLE service ) CloseServiceHandle( service ); } -static void pnp_driver_stop( BOOL bus ) +void bus_device_stop(void) { - const WCHAR *service_name = bus ? L"winetest_bus" : L"winetest"; SP_DEVINFO_DATA device = {sizeof(SP_DEVINFO_DATA)}; WCHAR path[MAX_PATH], dest[MAX_PATH], *filepart; + const WCHAR *service_name = L"winetest_bus"; SC_HANDLE manager, service; char buffer[512]; HDEVINFO set; @@ -548,8 +530,6 @@ static void pnp_driver_stop( BOOL bus ) ok( ret, "Failed to delete file, error %lu\n", GetLastError() ); ret = DeleteFileW( L"winetest.inf" ); ok( ret, "Failed to delete file, error %lu\n", GetLastError() ); - ret = DeleteFileW( L"winetest.sys" ); - ok( ret, "Failed to delete file, error %lu\n", GetLastError() ); ret = DeleteFileW( L"winetest_bus.sys" ); ok( ret, "Failed to delete file, error %lu\n", GetLastError() ); ret = DeleteFileW( L"winetest_hid.sys" ); @@ -557,8 +537,6 @@ static void pnp_driver_stop( BOOL bus ) ret = DeleteFileW( L"winetest_hid_poll.sys" ); ok( ret, "Failed to delete file, error %lu\n", GetLastError() ); /* Windows 10 apparently deletes the image in SetupUninstallOEMInf(). */ - ret = DeleteFileW( L"C:/windows/system32/drivers/winetest.sys" ); - ok( ret || GetLastError() == ERROR_FILE_NOT_FOUND, "Failed to delete file, error %lu\n", GetLastError() ); ret = DeleteFileW( L"C:/windows/system32/drivers/winetest_bus.sys" ); ok( ret || GetLastError() == ERROR_FILE_NOT_FOUND, "Failed to delete file, error %lu\n", GetLastError() ); ret = DeleteFileW( L"C:/windows/system32/drivers/winetest_hid.sys" ); @@ -608,12 +586,11 @@ static BOOL find_hid_device_path( WCHAR *device_path ) return ret; } -static BOOL pnp_driver_start( BOOL bus ) +BOOL bus_device_start(void) { - static const WCHAR hardware_id[] = L"test_hardware_id\0"; static const WCHAR bus_hardware_id[] = L"WINETEST\\BUS"; - const WCHAR *service_name = bus ? L"winetest_bus" : L"winetest"; SP_DEVINFO_DATA device = {sizeof(SP_DEVINFO_DATA)}; + const WCHAR *service_name = L"winetest_bus"; WCHAR path[MAX_PATH], filename[MAX_PATH]; SC_HANDLE manager, service; const CERT_CONTEXT *cert; @@ -626,10 +603,6 @@ static BOOL pnp_driver_start( BOOL bus ) old_mute_threshold = winetest_mute_threshold; winetest_mute_threshold = 1; - load_resource( L"driver.dll", filename ); - ret = MoveFileExW( filename, L"winetest.sys", MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING ); - ok( ret, "failed to move file, error %lu\n", GetLastError() ); - load_resource( L"driver_bus.dll", filename ); ret = MoveFileExW( filename, L"winetest_bus.sys", MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING ); ok( ret, "failed to move file, error %lu\n", GetLastError() ); @@ -652,7 +625,6 @@ static BOOL pnp_driver_start( BOOL bus ) catalog = CryptCATOpen( (WCHAR *)L"winetest.cat", CRYPTCAT_OPEN_CREATENEW, 0, CRYPTCAT_VERSION_1, 0 ); ok( catalog != INVALID_HANDLE_VALUE, "Failed to create catalog, error %lu\n", GetLastError() ); - add_file_to_catalog( catalog, L"winetest.sys" ); add_file_to_catalog( catalog, L"winetest_bus.sys" ); add_file_to_catalog( catalog, L"winetest_hid.sys" ); add_file_to_catalog( catalog, L"winetest_hid_poll.sys" ); @@ -677,8 +649,6 @@ static BOOL pnp_driver_start( BOOL bus ) ok( ret, "Failed to delete file, error %lu\n", GetLastError() ); ret = DeleteFileW( L"winetest_hid_poll.sys" ); ok( ret, "Failed to delete file, error %lu\n", GetLastError() ); - ret = DeleteFileW( L"winetest.sys" ); - ok( ret, "Failed to delete file, error %lu\n", GetLastError() ); winetest_mute_threshold = old_mute_threshold; return FALSE; } @@ -691,9 +661,7 @@ static BOOL pnp_driver_start( BOOL bus ) ret = SetupDiCreateDeviceInfoW( set, L"root\\winetest\\0", &GUID_NULL, NULL, NULL, 0, &device ); ok( ret, "failed to create device, error %#lx\n", GetLastError() ); - ret = SetupDiSetDeviceRegistryPropertyW( set, &device, SPDRP_HARDWAREID, - bus ? (const BYTE *)bus_hardware_id : (const BYTE *)hardware_id, - bus ? sizeof(bus_hardware_id) : sizeof(hardware_id) ); + ret = SetupDiSetDeviceRegistryPropertyW( set, &device, SPDRP_HARDWAREID, (const BYTE *)bus_hardware_id, sizeof(bus_hardware_id) ); ok( ret, "failed to create set hardware ID, error %lu\n", GetLastError() ); ret = SetupDiCallClassInstaller( DIF_REGISTERDEVICE, set, &device ); @@ -704,8 +672,7 @@ static BOOL pnp_driver_start( BOOL bus ) GetFullPathNameW( L"winetest.inf", ARRAY_SIZE(path), path, NULL ); - ret = UpdateDriverForPlugAndPlayDevicesW( NULL, bus ? bus_hardware_id : hardware_id, path, - INSTALLFLAG_FORCE, &need_reboot ); + ret = UpdateDriverForPlugAndPlayDevicesW( NULL, bus_hardware_id, path, INSTALLFLAG_FORCE, &need_reboot ); ok( ret, "failed to install device, error %lu\n", GetLastError() ); ok( !need_reboot, "expected no reboot necessary\n" ); @@ -772,16 +739,6 @@ BOOL hid_device_start( struct hid_device_desc *desc ) return TRUE; } -void bus_device_stop(void) -{ - pnp_driver_stop( TRUE ); -} - -BOOL bus_device_start(void) -{ - return pnp_driver_start( TRUE ); -} - #define check_hidp_caps( a, b ) check_hidp_caps_( __LINE__, a, b ) static inline void check_hidp_caps_( int line, HIDP_CAPS *caps, const HIDP_CAPS *exp ) {