Adding support for thread local test data and context.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
v2: Adapt wine/test.h code instead of copying it and including wine/test.h
dlls/ntoskrnl.exe/tests/Makefile.in | 10 +- dlls/ntoskrnl.exe/tests/driver.c | 32 +-- dlls/ntoskrnl.exe/tests/driver.h | 10 +- dlls/ntoskrnl.exe/tests/driver_netio.c | 2 +- dlls/ntoskrnl.exe/tests/ntoskrnl.c | 1 + dlls/ntoskrnl.exe/tests/utils.h | 290 ++++++++++++++++++++----- 6 files changed, 258 insertions(+), 87 deletions(-)
diff --git a/dlls/ntoskrnl.exe/tests/Makefile.in b/dlls/ntoskrnl.exe/tests/Makefile.in index 863fad30f63..85a6925138a 100644 --- a/dlls/ntoskrnl.exe/tests/Makefile.in +++ b/dlls/ntoskrnl.exe/tests/Makefile.in @@ -1,15 +1,15 @@ TESTDLL = ntoskrnl.exe IMPORTS = advapi32 crypt32 newdev setupapi user32 wintrust ws2_32 hid
-driver_IMPORTS = winecrt0 ntoskrnl +driver_IMPORTS = winecrt0 ntoskrnl hal driver_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native -driver2_IMPORTS = winecrt0 ntoskrnl +driver2_IMPORTS = winecrt0 ntoskrnl hal driver2_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native -driver3_IMPORTS = winecrt0 ntoskrnl +driver3_IMPORTS = winecrt0 ntoskrnl hal driver3_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native -driver_hid_IMPORTS = winecrt0 ntoskrnl hidclass +driver_hid_IMPORTS = winecrt0 ntoskrnl hal hidclass driver_hid_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native -driver_netio_IMPORTS = winecrt0 ntoskrnl netio +driver_netio_IMPORTS = winecrt0 ntoskrnl hal netio driver_netio_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native driver_pnp_IMPORTS = winecrt0 ntoskrnl hal driver_pnp_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 94139b4b654..1fe3ec2e558 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -999,41 +999,41 @@ static void test_call_driver(DEVICE_OBJECT *device) irp = IoBuildAsynchronousFsdRequest(IRP_MJ_FLUSH_BUFFERS, device, NULL, 0, NULL, &iosb); ok(irp->UserIosb == &iosb, "unexpected UserIosb\n"); ok(!irp->Cancel, "Cancel = %x\n", irp->Cancel); - ok(!irp->CancelRoutine, "CancelRoutine = %x\n", irp->CancelRoutine); + ok(!irp->CancelRoutine, "CancelRoutine = %p\n", irp->CancelRoutine); ok(!irp->UserEvent, "UserEvent = %p\n", irp->UserEvent); ok(irp->CurrentLocation == 2, "CurrentLocation = %u\n", irp->CurrentLocation); ok(irp->Tail.Overlay.Thread == (PETHREAD)KeGetCurrentThread(), "IRP thread is not the current thread\n"); ok(!irp->IoStatus.Status, "got status %#x\n", irp->IoStatus.Status); - ok(!irp->IoStatus.Information, "got information %#x\n", irp->IoStatus.Information); + ok(!irp->IoStatus.Information, "got information %#I64x\n", (UINT64)irp->IoStatus.Information); ok(iosb.Status == 0xdeadbeef, "got status %#x\n", iosb.Status); - ok(iosb.Information == 0xdeadbeef, "got information %#x\n", iosb.Information); + ok(iosb.Information == 0xdeadbeef, "got information %#I64x\n", (UINT64)iosb.Information);
irpsp = IoGetNextIrpStackLocation(irp); ok(irpsp->MajorFunction == IRP_MJ_FLUSH_BUFFERS, "MajorFunction = %u\n", irpsp->MajorFunction); - ok(!irpsp->DeviceObject, "DeviceObject = %u\n", irpsp->DeviceObject); - ok(!irpsp->FileObject, "FileObject = %u\n", irpsp->FileObject); + ok(!irpsp->DeviceObject, "DeviceObject = %p\n", irpsp->DeviceObject); + ok(!irpsp->FileObject, "FileObject = %p\n", irpsp->FileObject); ok(!irpsp->CompletionRoutine, "CompletionRoutine = %p\n", irpsp->CompletionRoutine);
status = IoCallDriver(device, irp); ok(status == STATUS_PENDING, "IoCallDriver returned %#x\n", status); ok(!irp->IoStatus.Status, "got status %#x\n", irp->IoStatus.Status); - ok(!irp->IoStatus.Information, "got information %#x\n", irp->IoStatus.Information); + ok(!irp->IoStatus.Information, "got information %#I64x\n", (UINT64)irp->IoStatus.Information); ok(iosb.Status == 0xdeadbeef, "got status %#x\n", iosb.Status); - ok(iosb.Information == 0xdeadbeef, "got information %#x\n", iosb.Information); + ok(iosb.Information == 0xdeadbeef, "got information %#I64x\n", (UINT64)iosb.Information);
irp->IoStatus.Status = STATUS_SUCCESS; irp->IoStatus.Information = 123; IoCompleteRequest(irp, IO_NO_INCREMENT); ok(iosb.Status == STATUS_SUCCESS, "got status %#x\n", iosb.Status); - ok(iosb.Information == 123, "got information %#x\n", iosb.Information); + ok(iosb.Information == 123, "got information %#I64x\n", (UINT64)iosb.Information);
KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildSynchronousFsdRequest(IRP_MJ_FLUSH_BUFFERS, device, NULL, 0, NULL, &event, &iosb); ok(irp->UserIosb == &iosb, "unexpected UserIosb\n"); ok(!irp->Cancel, "Cancel = %x\n", irp->Cancel); - ok(!irp->CancelRoutine, "CancelRoutine = %x\n", irp->CancelRoutine); + ok(!irp->CancelRoutine, "CancelRoutine = %p\n", irp->CancelRoutine); ok(irp->UserEvent == &event, "UserEvent = %p\n", irp->UserEvent); ok(irp->CurrentLocation == 2, "CurrentLocation = %u\n", irp->CurrentLocation); ok(irp->Tail.Overlay.Thread == (PETHREAD)KeGetCurrentThread(), @@ -1041,8 +1041,8 @@ static void test_call_driver(DEVICE_OBJECT *device)
irpsp = IoGetNextIrpStackLocation(irp); ok(irpsp->MajorFunction == IRP_MJ_FLUSH_BUFFERS, "MajorFunction = %u\n", irpsp->MajorFunction); - ok(!irpsp->DeviceObject, "DeviceObject = %u\n", irpsp->DeviceObject); - ok(!irpsp->FileObject, "FileObject = %u\n", irpsp->FileObject); + ok(!irpsp->DeviceObject, "DeviceObject = %p\n", irpsp->DeviceObject); + ok(!irpsp->FileObject, "FileObject = %p\n", irpsp->FileObject); ok(!irpsp->CompletionRoutine, "CompletionRoutine = %p\n", irpsp->CompletionRoutine);
status = wait_single(&event, 0); @@ -1118,7 +1118,7 @@ static void test_cancel_irp(DEVICE_OBJECT *device)
ok(irp->CurrentLocation == 1, "CurrentLocation = %u\n", irp->CurrentLocation); irpsp = IoGetCurrentIrpStackLocation(irp); - ok(irpsp->DeviceObject == device, "DeviceObject = %u\n", irpsp->DeviceObject); + ok(irpsp->DeviceObject == device, "DeviceObject = %p\n", irpsp->DeviceObject);
IoSetCancelRoutine(irp, cancel_irp); cancel_cnt = 0; @@ -1432,16 +1432,16 @@ static void check_resource_(int line, ERESOURCE *resource, ULONG exclusive_waite ULONG count;
count = ExGetExclusiveWaiterCount(resource); - ok_(__FILE__, line, count == exclusive_waiters, + ok_(__FILE__, line)(count == exclusive_waiters, "expected %u exclusive waiters, got %u\n", exclusive_waiters, count); count = ExGetSharedWaiterCount(resource); - ok_(__FILE__, line, count == shared_waiters, + ok_(__FILE__, line)(count == shared_waiters, "expected %u shared waiters, got %u\n", shared_waiters, count); ret = ExIsResourceAcquiredExclusiveLite(resource); - ok_(__FILE__, line, ret == exclusive, + ok_(__FILE__, line)(ret == exclusive, "expected exclusive %u, got %u\n", exclusive, ret); count = ExIsResourceAcquiredSharedLite(resource); - ok_(__FILE__, line, count == shared_count, + ok_(__FILE__, line)(count == shared_count, "expected shared %u, got %u\n", shared_count, count); } #define check_resource(a,b,c,d,e) check_resource_(__LINE__,a,b,c,d,e) diff --git a/dlls/ntoskrnl.exe/tests/driver.h b/dlls/ntoskrnl.exe/tests/driver.h index 455695ad36b..8c41010c503 100644 --- a/dlls/ntoskrnl.exe/tests/driver.h +++ b/dlls/ntoskrnl.exe/tests/driver.h @@ -54,7 +54,8 @@ struct test_data int running_under_wine; int winetest_report_success; int winetest_debug; - int successes, failures, skipped, todo_successes, todo_failures; + int failures; + int todo_failures; };
struct main_test_input @@ -64,13 +65,6 @@ struct main_test_input ULONG64 *modified_value; };
-static inline char *drv_strrchr( const char *str, char ch ) -{ - char *ret = NULL; - do { if (*str == ch) ret = (char *)(ULONG_PTR)str; } while (*str++); - return ret; -} - static const GUID control_class = {0xdeadbeef, 0x29ef, 0x4538, {0xa5, 0xfd, 0xb6, 0x95, 0x73, 0xa3, 0x62, 0xc0}};
#define SERVER_LISTEN_PORT 9374 diff --git a/dlls/ntoskrnl.exe/tests/driver_netio.c b/dlls/ntoskrnl.exe/tests/driver_netio.c index ea9cfd1a4c5..4ebacc7cf14 100644 --- a/dlls/ntoskrnl.exe/tests/driver_netio.c +++ b/dlls/ntoskrnl.exe/tests/driver_netio.c @@ -141,7 +141,7 @@ static void test_wsk_get_address_info(void) { struct sockaddr_in *addr = (struct sockaddr_in *)addr_info->ai_addr;
- ok(addr_info->ai_addrlen == sizeof(*addr), "Got unexpected ai_addrlen %u.\n", addr_info->ai_addrlen); + ok(addr_info->ai_addrlen == sizeof(*addr), "Got unexpected ai_addrlen %I64u.\n", (UINT64)addr_info->ai_addrlen); ok(addr->sin_family == AF_INET, "Got unexpected sin_family %u.\n", addr->sin_family); ok(ntohs(addr->sin_port) == 12345, "Got unexpected sin_port %u.\n", ntohs(addr->sin_port)); ok(ntohl(addr->sin_addr.s_addr) == 0x7f000001, "Got unexpected sin_addr %#x.\n", diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index 71dbfe1a5e9..797421904c8 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -386,6 +386,7 @@ static void cat_okfile(void) SetEndOfFile(okfile);
winetest_add_failures(InterlockedExchange(&test_data->failures, 0)); + winetest_add_failures(InterlockedExchange(&test_data->todo_failures, 0)); }
static ULONG64 modified_value; diff --git a/dlls/ntoskrnl.exe/tests/utils.h b/dlls/ntoskrnl.exe/tests/utils.h index 6a0e00428a5..f73f6f938ca 100644 --- a/dlls/ntoskrnl.exe/tests/utils.h +++ b/dlls/ntoskrnl.exe/tests/utils.h @@ -22,25 +22,103 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#include <stdarg.h> +#include <stdlib.h> +#include <windef.h> +#include <winbase.h> +#include <winternl.h> + +#include <ddk/wdm.h> + +#if !defined(__WINE_USE_MSVCRT) || defined(__MINGW32__) +#define __WINE_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args))) +#else +#define __WINE_PRINTF_ATTR(fmt,args) +#endif + static HANDLE okfile; static LONG successes; static LONG failures; static LONG skipped; static LONG todo_successes; static LONG todo_failures; -static int todo_level, todo_do_loop; +static LONG muted_traces; +static LONG muted_skipped; +static LONG muted_todo_successes; + static int running_under_wine; static int winetest_debug; static int winetest_report_success;
+/* silence todos and skips above this threshold */ +static int winetest_mute_threshold = 42; + +/* counts how many times a given line printed a message */ +static LONG line_counters[16384]; + +/* The following data must be kept track of on a per-thread basis */ +struct tls_data +{ + HANDLE thread; + const char* current_file; /* file of current check */ + int current_line; /* line of current check */ + unsigned int todo_level; /* current todo nesting level */ + int todo_do_loop; + char *str_pos; /* position in debug buffer */ + char strings[2000]; /* buffer for debug strings */ + char context[8][128]; /* data to print before messages */ + unsigned int context_count; /* number of context prefixes */ +}; + +static KSPIN_LOCK tls_data_lock; +static struct tls_data tls_data_pool[128]; +static DWORD tls_data_count; + +static inline struct tls_data *get_tls_data(void) +{ + static struct tls_data tls_overflow; + struct tls_data *data; + HANDLE thread = PsGetCurrentThreadId(); + KIRQL irql; + + KeAcquireSpinLock(&tls_data_lock, &irql); + for (data = tls_data_pool; data != tls_data_pool + tls_data_count; ++data) + if (data->thread == thread) break; + if (data == tls_data_pool + ARRAY_SIZE(tls_data_pool)) + data = &tls_overflow; + else if (data == tls_data_pool + tls_data_count) + { + data->thread = thread; + data->str_pos = data->strings; + tls_data_count++; + } + KeReleaseSpinLock(&tls_data_lock, irql); + + return data; +} + +static inline void winetest_set_location( const char* file, int line ) +{ + struct tls_data *data = get_tls_data(); + data->current_file=strrchr(file,'/'); + if (data->current_file==NULL) + data->current_file=strrchr(file,'\'); + if (data->current_file==NULL) + data->current_file=file; + else + data->current_file++; + data->current_line=line; +} + static inline void kvprintf(const char *format, __ms_va_list ap) { - static char buffer[512]; + struct tls_data *data = get_tls_data(); IO_STATUS_BLOCK io; - int len = vsnprintf(buffer, sizeof(buffer), format, ap); - ZwWriteFile(okfile, NULL, NULL, NULL, &io, buffer, len, NULL, NULL); + int len = vsnprintf(data->strings, sizeof(data->strings), format, ap); + ZwWriteFile(okfile, NULL, NULL, NULL, &io, data->strings, len, NULL, NULL); }
+static inline void WINAPIV kprintf(const char *format, ...) __WINE_PRINTF_ATTR(1,2); static inline void WINAPIV kprintf(const char *format, ...) { __ms_va_list valist; @@ -50,6 +128,18 @@ static inline void WINAPIV kprintf(const char *format, ...) __ms_va_end(valist); }
+static inline void WINAPIV winetest_printf( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2); +static inline void WINAPIV winetest_printf( const char *msg, ... ) +{ + struct tls_data *data = get_tls_data(); + __ms_va_list valist; + + kprintf( "%s:%d: ", data->current_file, data->current_line ); + __ms_va_start( valist, msg ); + kvprintf( msg, valist ); + __ms_va_end( valist ); +} + static inline NTSTATUS winetest_init(void) { const struct test_data *data; @@ -61,6 +151,8 @@ static inline NTSTATUS winetest_init(void) HANDLE section; NTSTATUS ret;
+ KeInitializeSpinLock(&tls_data_lock); + RtlInitUnicodeString(&string, L"\BaseNamedObjects\winetest_ntoskrnl_section"); /* OBJ_KERNEL_HANDLE is necessary for the file to be accessible from system threads */ InitializeObjectAttributes(&attr, &string, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, 0, NULL); @@ -98,7 +190,7 @@ static inline void winetest_cleanup(void) if (winetest_debug) { kprintf("%04x:ntoskrnl: %d tests executed (%d marked as todo, %d %s), %d skipped.\n", - PsGetCurrentProcessId(), successes + failures + todo_successes + todo_failures, + (DWORD)(DWORD_PTR)PsGetCurrentProcessId(), successes + failures + todo_successes + todo_failures, todo_successes, failures + todo_failures, (failures + todo_failures != 1) ? "failures" : "failure", skipped ); } @@ -114,10 +206,7 @@ static inline void winetest_cleanup(void) { data = addr;
- InterlockedExchangeAdd(&data->successes, successes); InterlockedExchangeAdd(&data->failures, failures); - InterlockedExchangeAdd(&data->skipped, skipped); - InterlockedExchangeAdd(&data->todo_successes, todo_successes); InterlockedExchangeAdd(&data->todo_failures, todo_failures);
ZwUnmapViewOfSection(NtCurrentProcess(), addr); @@ -128,118 +217,185 @@ static inline void winetest_cleanup(void) ZwClose(okfile); }
-static inline void WINAPIV vok_(const char *file, int line, int condition, const char *msg, __ms_va_list args) +static inline void winetest_print_context( const char *msgtype ) { - const char *current_file; + struct tls_data *data = get_tls_data(); + unsigned int i;
- if (!(current_file = drv_strrchr(file, '/')) && - !(current_file = drv_strrchr(file, '\'))) - current_file = file; - else - current_file++; + winetest_printf( "%s", msgtype ); + for (i = 0; i < data->context_count; ++i) + kprintf( "%s: ", data->context[i] ); +} + +static inline LONG winetest_add_line( void ) +{ + struct tls_data *data; + int index, count; + + if (winetest_debug > 1) + return 0; + + data = get_tls_data(); + index = data->current_line % ARRAY_SIZE(line_counters); + count = InterlockedIncrement(line_counters + index) - 1; + if (count == winetest_mute_threshold) + winetest_printf( "Line has been silenced after %d occurrences\n", winetest_mute_threshold );
- if (todo_level) + return count; +} + +static inline int winetest_vok( int condition, const char *msg, __ms_va_list args ) +{ + struct tls_data *data = get_tls_data(); + + if (data->todo_level) { if (condition) { - kprintf("%s:%d: Test succeeded inside todo block: ", current_file, line); + winetest_print_context( "Test succeeded inside todo block: " ); kvprintf(msg, args); InterlockedIncrement(&todo_failures); + return 0; } else { - if (winetest_debug > 0) + if (!winetest_debug || + winetest_add_line() < winetest_mute_threshold) { - kprintf("%s:%d: Test marked todo: ", current_file, line); - kvprintf(msg, args); + if (winetest_debug > 0) + { + winetest_print_context( "Test marked todo: " ); + kvprintf(msg, args); + } + InterlockedIncrement(&todo_successes); } - InterlockedIncrement(&todo_successes); + else + InterlockedIncrement(&muted_todo_successes); + return 1; } } else { if (!condition) { - kprintf("%s:%d: Test failed: ", current_file, line); + winetest_print_context( "Test failed: " ); kvprintf(msg, args); InterlockedIncrement(&failures); + return 0; } else { if (winetest_report_success) - kprintf("%s:%d: Test succeeded\n", current_file, line); + winetest_printf("Test succeeded\n"); InterlockedIncrement(&successes); + return 1; } } }
-static inline void WINAPIV ok_(const char *file, int line, int condition, const char *msg, ...) +static inline void WINAPIV winetest_ok( int condition, const char *msg, ... ) __WINE_PRINTF_ATTR(2,3); +static inline void WINAPIV winetest_ok( int condition, const char *msg, ... ) { __ms_va_list args; __ms_va_start(args, msg); - vok_(file, line, condition, msg, args); + winetest_vok(condition, msg, args); __ms_va_end(args); }
-static inline void vskip_(const char *file, int line, const char *msg, __ms_va_list args) +static inline void winetest_vskip( const char *msg, __ms_va_list args ) { - const char *current_file; - - if (!(current_file = drv_strrchr(file, '/')) && - !(current_file = drv_strrchr(file, '\'))) - current_file = file; + if (winetest_add_line() < winetest_mute_threshold) + { + winetest_print_context( "Tests skipped: " ); + kvprintf(msg, args); + InterlockedIncrement(&skipped); + } else - current_file++; + InterlockedIncrement(&muted_skipped); +}
- kprintf("%s:%d: Tests skipped: ", current_file, line); - kvprintf(msg, args); - skipped++; +static inline void WINAPIV winetest_skip( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2); +static inline void WINAPIV winetest_skip( const char *msg, ... ) +{ + __ms_va_list args; + __ms_va_start(args, msg); + winetest_vskip(msg, args); + __ms_va_end(args); }
-static inline void WINAPIV win_skip_(const char *file, int line, const char *msg, ...) +static inline void WINAPIV winetest_win_skip( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2); +static inline void WINAPIV winetest_win_skip( const char *msg, ... ) { __ms_va_list args; __ms_va_start(args, msg); if (running_under_wine) - vok_(file, line, 0, msg, args); + winetest_vskip(msg, args); else - vskip_(file, line, msg, args); + winetest_vok(0, msg, args); __ms_va_end(args); }
-static inline void WINAPIV trace_(const char *file, int line, const char *msg, ...) +static inline void WINAPIV winetest_trace( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2); +static inline void WINAPIV winetest_trace( const char *msg, ... ) { - const char *current_file; __ms_va_list args;
- if (!(current_file = drv_strrchr(file, '/')) && - !(current_file = drv_strrchr(file, '\'))) - current_file = file; + if (!winetest_debug) + return; + if (winetest_add_line() < winetest_mute_threshold) + { + winetest_print_context( "" ); + __ms_va_start(args, msg); + kvprintf( msg, args ); + __ms_va_end(args); + } else - current_file++; - - __ms_va_start(args, msg); - kprintf("%s:%d: ", current_file, line); - kvprintf(msg, args); - __ms_va_end(args); + InterlockedIncrement(&muted_traces); }
static inline void winetest_start_todo( int is_todo ) { - todo_level = (todo_level << 1) | (is_todo != 0); - todo_do_loop=1; + struct tls_data *data = get_tls_data(); + data->todo_level = (data->todo_level << 1) | (is_todo != 0); + data->todo_do_loop=1; }
static inline int winetest_loop_todo(void) { - int do_loop=todo_do_loop; - todo_do_loop=0; + struct tls_data *data = get_tls_data(); + int do_loop=data->todo_do_loop; + data->todo_do_loop=0; return do_loop; }
static inline void winetest_end_todo(void) { - todo_level >>= 1; + struct tls_data *data = get_tls_data(); + data->todo_level >>= 1; +} + +static inline void WINAPIV winetest_push_context( const char *fmt, ... ) __WINE_PRINTF_ATTR(1, 2); +static inline void WINAPIV winetest_push_context( const char *fmt, ... ) +{ + struct tls_data *data = get_tls_data(); + __ms_va_list valist; + + if (data->context_count < ARRAY_SIZE(data->context)) + { + __ms_va_start(valist, fmt); + vsnprintf( data->context[data->context_count], sizeof(data->context[data->context_count]), fmt, valist ); + __ms_va_end(valist); + data->context[data->context_count][sizeof(data->context[data->context_count]) - 1] = 0; + } + ++data->context_count; +} + +static inline void winetest_pop_context(void) +{ + struct tls_data *data = get_tls_data(); + + if (data->context_count) + --data->context_count; }
static inline int broken(int condition) @@ -247,11 +403,31 @@ static inline int broken(int condition) return !running_under_wine && condition; }
-#define ok(condition, ...) ok_(__FILE__, __LINE__, condition, __VA_ARGS__) +#ifdef WINETEST_NO_LINE_NUMBERS +# define subtest_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_subtest +# define ignore_exceptions_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_ignore_exceptions +# define ok_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_ok +# define skip_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_skip +# define win_skip_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_win_skip +# define trace_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_trace +# define wait_child_process_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_wait_child_process +#else +# define subtest_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_subtest +# define ignore_exceptions_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ignore_exceptions +# define ok_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ok +# define skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_skip +# define win_skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_win_skip +# define trace_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_trace +# define wait_child_process_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_wait_child_process +#endif + +#define ok ok_(__FILE__, __LINE__) +#define skip skip_(__FILE__, __LINE__) +#define trace trace_(__FILE__, __LINE__) +#define win_skip win_skip_(__FILE__, __LINE__) + #define todo_if(is_todo) for (winetest_start_todo(is_todo); \ winetest_loop_todo(); \ winetest_end_todo()) #define todo_wine todo_if(running_under_wine) #define todo_wine_if(is_todo) todo_if((is_todo) && running_under_wine) -#define win_skip(...) win_skip_(__FILE__, __LINE__, __VA_ARGS__) -#define trace(...) trace_(__FILE__, __LINE__, __VA_ARGS__)
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/ntoskrnl.exe/tests/ntoskrnl.c | 52 +++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 12 deletions(-)
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index 797421904c8..a34c467ecb7 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -1842,6 +1842,8 @@ static void test_hidp(HANDLE file, int report_id) { .DataIndex = 1, }, { .DataIndex = 5, .RawValue = 1, }, { .DataIndex = 7, .RawValue = 1, }, + { .DataIndex = 19, .RawValue = 1, }, + { .DataIndex = 21, .RawValue = 1, }, { .DataIndex = 30, }, { .DataIndex = 31, }, { .DataIndex = 32, .RawValue = 0xfeedcafe, }, @@ -2200,6 +2202,20 @@ static void test_hidp(HANDLE file, int report_id) report, caps.InputReportByteLength); ok(status == HIDP_STATUS_SUCCESS, "HidP_SetUsages returned %#x\n", status);
+ usages[0] = 0x9; + usages[1] = 0xb; + usages[2] = 0xa; + value = 3; + ok(report[6] == 0, "got report[6] %x expected 0\n", report[6]); + ok(report[7] == 0, "got report[7] %x expected 0\n", report[7]); + memcpy(buffer, report, caps.InputReportByteLength); + status = HidP_SetUsages(HidP_Input, HID_USAGE_PAGE_KEYBOARD, 0, usages, &value, preparsed_data, + report, caps.InputReportByteLength); + todo_wine ok(status == HIDP_STATUS_BUFFER_TOO_SMALL, "HidP_SetUsages returned %#x\n", status); + buffer[6] = 2; + buffer[7] = 4; + todo_wine ok(!memcmp(buffer, report, caps.InputReportByteLength), "unexpected report data\n"); + status = HidP_SetUsageValue(HidP_Input, HID_USAGE_PAGE_LED, 0, 6, 1, preparsed_data, report, caps.InputReportByteLength); ok(status == HIDP_STATUS_USAGE_NOT_FOUND, "HidP_SetUsageValue returned %#x\n", status); @@ -2238,23 +2254,35 @@ static void test_hidp(HANDLE file, int report_id) status = HidP_GetUsagesEx(HidP_Input, 0, usage_and_pages, &value, preparsed_data, report, caps.InputReportByteLength); ok(status == HIDP_STATUS_SUCCESS, "HidP_GetUsagesEx returned %#x\n", status); - ok(value == 4, "got usage count %d, expected %d\n", value, 4); + todo_wine ok(value == 6, "got usage count %d, expected %d\n", value, 4); ok(usage_and_pages[0].UsagePage == HID_USAGE_PAGE_BUTTON, "got usage_and_pages[0] UsagePage %x, expected %x\n", usage_and_pages[0].UsagePage, HID_USAGE_PAGE_BUTTON); ok(usage_and_pages[1].UsagePage == HID_USAGE_PAGE_BUTTON, "got usage_and_pages[1] UsagePage %x, expected %x\n", usage_and_pages[1].UsagePage, HID_USAGE_PAGE_BUTTON); - ok(usage_and_pages[2].UsagePage == HID_USAGE_PAGE_LED, "got usage_and_pages[2] UsagePage %x, expected %x\n", - usage_and_pages[2].UsagePage, HID_USAGE_PAGE_LED); - ok(usage_and_pages[3].UsagePage == HID_USAGE_PAGE_LED, "got usage_and_pages[3] UsagePage %x, expected %x\n", - usage_and_pages[3].UsagePage, HID_USAGE_PAGE_LED); + ok(usage_and_pages[2].UsagePage == HID_USAGE_PAGE_KEYBOARD, "got usage_and_pages[2] UsagePage %x, expected %x\n", + usage_and_pages[2].UsagePage, HID_USAGE_PAGE_KEYBOARD); + ok(usage_and_pages[3].UsagePage == HID_USAGE_PAGE_KEYBOARD, "got usage_and_pages[3] UsagePage %x, expected %x\n", + usage_and_pages[3].UsagePage, HID_USAGE_PAGE_KEYBOARD); + todo_wine + ok(usage_and_pages[4].UsagePage == HID_USAGE_PAGE_LED, "got usage_and_pages[4] UsagePage %x, expected %x\n", + usage_and_pages[4].UsagePage, HID_USAGE_PAGE_LED); + ok(usage_and_pages[5].UsagePage == HID_USAGE_PAGE_LED, "got usage_and_pages[5] UsagePage %x, expected %x\n", + usage_and_pages[5].UsagePage, HID_USAGE_PAGE_LED); ok(usage_and_pages[0].Usage == 4, "got usage_and_pages[0] Usage %x, expected %x\n", usage_and_pages[0].Usage, 4); ok(usage_and_pages[1].Usage == 6, "got usage_and_pages[1] Usage %x, expected %x\n", usage_and_pages[1].Usage, 6); - ok(usage_and_pages[2].Usage == 6, "got usage_and_pages[2] Usage %x, expected %x\n", - usage_and_pages[2].Usage, 6); - ok(usage_and_pages[3].Usage == 4, "got usage_and_pages[3] Usage %x, expected %x\n", - usage_and_pages[3].Usage, 4); + ok(usage_and_pages[2].Usage == 9, "got usage_and_pages[2] Usage %x, expected %x\n", + usage_and_pages[2].Usage, 9); + todo_wine + ok(usage_and_pages[3].Usage == 11, "got usage_and_pages[3] Usage %x, expected %x\n", + usage_and_pages[3].Usage, 11); + todo_wine + ok(usage_and_pages[4].Usage == 6, "got usage_and_pages[4] Usage %x, expected %x\n", + usage_and_pages[4].Usage, 6); + todo_wine + ok(usage_and_pages[5].Usage == 4, "got usage_and_pages[5] Usage %x, expected %x\n", + usage_and_pages[5].Usage, 4);
value = HidP_MaxDataListLength(HidP_Feature + 1, preparsed_data); ok(value == 0, "HidP_MaxDataListLength(HidP_Feature + 1) returned %d, expected %d\n", value, 0); @@ -2268,15 +2296,15 @@ static void test_hidp(HANDLE file, int report_id) value = 1; status = HidP_GetData(HidP_Input, data, &value, preparsed_data, report, caps.InputReportByteLength); ok(status == HIDP_STATUS_BUFFER_TOO_SMALL, "HidP_GetData returned %#x\n", status); - ok(value == 9, "got data count %d, expected %d\n", value, 9); + todo_wine ok(value == 11, "got data count %d, expected %d\n", value, 11); memset(data, 0, sizeof(data)); status = HidP_GetData(HidP_Input, data, &value, preparsed_data, report, caps.InputReportByteLength); ok(status == HIDP_STATUS_SUCCESS, "HidP_GetData returned %#x\n", status); for (i = 0; i < ARRAY_SIZE(expect_data); ++i) { winetest_push_context("data[%d]", i); - check_member(data[i], expect_data[i], "%d", DataIndex); - check_member(data[i], expect_data[i], "%d", RawValue); + todo_wine_if(i >= 4) check_member(data[i], expect_data[i], "%d", DataIndex); + todo_wine_if(i >= 4) check_member(data[i], expect_data[i], "%d", RawValue); winetest_pop_context(); }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/ntoskrnl.exe/tests/driver_hid.c | 21 ++++++++++ dlls/ntoskrnl.exe/tests/ntoskrnl.c | 63 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+)
diff --git a/dlls/ntoskrnl.exe/tests/driver_hid.c b/dlls/ntoskrnl.exe/tests/driver_hid.c index acb51d99816..793b25f3189 100644 --- a/dlls/ntoskrnl.exe/tests/driver_hid.c +++ b/dlls/ntoskrnl.exe/tests/driver_hid.c @@ -382,6 +382,27 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp) break; }
+ case IOCTL_HID_GET_INPUT_REPORT: + { + HID_XFER_PACKET *packet = irp->UserBuffer; + ULONG expected_size = 23; + ok(!in_size, "got input size %u\n", in_size); + ok(out_size == sizeof(*packet), "got output size %u\n", out_size); + + todo_wine_if(packet->reportId == 0x5a) + ok(packet->reportId == report_id, "got packet report id %u\n", packet->reportId); + todo_wine_if(packet->reportBufferLen == 21 || packet->reportBufferLen == 22) + ok(packet->reportBufferLen >= expected_size, "got packet buffer len %u, expected %d or more\n", + packet->reportBufferLen, expected_size); + ok(!!packet->reportBuffer, "got packet buffer %p\n", packet->reportBuffer); + + memset(packet->reportBuffer, 0xa5, 3); + if (report_id) ((char *)packet->reportBuffer)[0] = report_id; + irp->IoStatus.Information = 3; + ret = STATUS_SUCCESS; + break; + } + case IOCTL_HID_GET_STRING: ok(!in_size, "got input size %u\n", in_size); ok(out_size == 128, "got output size %u\n", out_size); diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index a34c467ecb7..875aa62e6a1 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -1661,6 +1661,21 @@ static inline void check_hidp_value_caps_(int line, HIDP_VALUE_CAPS *caps, const } }
+static BOOL sync_ioctl(HANDLE file, DWORD code, void *in_buf, DWORD in_len, void *out_buf, DWORD *ret_len) +{ + OVERLAPPED ovl = {0}; + DWORD out_len = ret_len ? *ret_len : 0; + BOOL ret; + + ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); + ret = DeviceIoControl(file, code, in_buf, in_len, out_buf, out_len, &out_len, &ovl); + if (!ret && GetLastError() == ERROR_IO_PENDING) ret = GetOverlappedResult(file, &ovl, &out_len, TRUE); + CloseHandle(ovl.hEvent); + + if (ret_len) *ret_len = out_len; + return ret; +} + static void test_hidp(HANDLE file, int report_id) { const HIDP_CAPS expect_hidp_caps[] = @@ -2419,6 +2434,54 @@ static void test_hidp(HANDLE file, int report_id) memset(buffer + 16, 0xff, 8); ok(!memcmp(buffer, buffer + 16, 16), "unexpected report value\n");
+ + memset(report, 0xcd, sizeof(report)); + status = HidP_InitializeReportForID(HidP_Input, report_id, preparsed_data, report, caps.InputReportByteLength); + ok(status == HIDP_STATUS_SUCCESS, "HidP_InitializeReportForID returned %#x\n", status); + + SetLastError(0xdeadbeef); + ret = HidD_GetInputReport(file, report, 0); + ok(!ret, "HidD_GetInputReport succeeded\n"); + todo_wine ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "HidD_GetInputReport returned error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = HidD_GetInputReport(file, report, caps.InputReportByteLength - 1); + todo_wine + ok(!ret, "HidD_GetInputReport succeeded\n"); + todo_wine + ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_CRC), + "HidD_GetInputReport returned error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + memset(buffer, 0x5a, sizeof(buffer)); + ret = HidD_GetInputReport(file, buffer, caps.InputReportByteLength); + if (report_id || broken(!ret) /* w7u */) + { + todo_wine + ok(!ret, "HidD_GetInputReport succeeded, last error %u\n", GetLastError()); + todo_wine + ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_CRC), + "HidD_GetInputReport returned error %u\n", GetLastError()); + } + else + { + ok(ret, "HidD_GetInputReport failed, last error %u\n", GetLastError()); + todo_wine ok(buffer[0] == 0x5a, "got buffer[0] %x, expected 0x5a\n", (BYTE)buffer[0]); + } + + SetLastError(0xdeadbeef); + ret = HidD_GetInputReport(file, report, caps.InputReportByteLength); + ok(ret, "HidD_GetInputReport failed, last error %u\n", GetLastError()); + ok(report[0] == report_id, "got report[0] %02x, expected %02x\n", report[0], report_id); + + SetLastError(0xdeadbeef); + value = caps.InputReportByteLength * 2; + ret = sync_ioctl(file, IOCTL_HID_GET_INPUT_REPORT, NULL, 0, report, &value); + ok(ret, "IOCTL_HID_GET_INPUT_REPORT failed, last error %u\n", GetLastError()); + todo_wine ok(value == 3, "got length %u, expected 3\n", value); + ok(report[0] == report_id, "got report[0] %02x, expected %02x\n", report[0], report_id); + + HidD_FreePreparsedData(preparsed_data); CloseHandle(file); }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/ntoskrnl.exe/tests/driver_hid.c | 21 ++++++++++++ dlls/ntoskrnl.exe/tests/ntoskrnl.c | 49 ++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+)
diff --git a/dlls/ntoskrnl.exe/tests/driver_hid.c b/dlls/ntoskrnl.exe/tests/driver_hid.c index 793b25f3189..ae039c061de 100644 --- a/dlls/ntoskrnl.exe/tests/driver_hid.c +++ b/dlls/ntoskrnl.exe/tests/driver_hid.c @@ -403,6 +403,27 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp) break; }
+ case IOCTL_HID_GET_FEATURE: + { + HID_XFER_PACKET *packet = irp->UserBuffer; + ULONG expected_size = 17; + ok(!in_size, "got input size %u\n", in_size); + ok(out_size == sizeof(*packet), "got output size %u\n", out_size); + + todo_wine_if(packet->reportId == 0x5a || packet->reportId == 0xa5) + ok(packet->reportId == report_id, "got packet report id %u\n", packet->reportId); + todo_wine_if(packet->reportBufferLen == 16) + ok(packet->reportBufferLen >= expected_size, "got packet buffer len %u, expected %d or more\n", + packet->reportBufferLen, expected_size); + ok(!!packet->reportBuffer, "got packet buffer %p\n", packet->reportBuffer); + + memset(packet->reportBuffer, 0xa5, 3); + if (report_id) ((char *)packet->reportBuffer)[0] = report_id; + irp->IoStatus.Information = 3; + ret = STATUS_SUCCESS; + break; + } + case IOCTL_HID_GET_STRING: ok(!in_size, "got input size %u\n", in_size); ok(out_size == 128, "got output size %u\n", out_size); diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index 875aa62e6a1..8539e2ee921 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -2482,6 +2482,55 @@ static void test_hidp(HANDLE file, int report_id) ok(report[0] == report_id, "got report[0] %02x, expected %02x\n", report[0], report_id);
+ memset(report, 0xcd, sizeof(report)); + status = HidP_InitializeReportForID(HidP_Feature, report_id, preparsed_data, report, caps.FeatureReportByteLength); + ok(status == HIDP_STATUS_SUCCESS, "HidP_InitializeReportForID returned %#x\n", status); + + SetLastError(0xdeadbeef); + ret = HidD_GetFeature(file, report, 0); + ok(!ret, "HidD_GetFeature succeeded\n"); + todo_wine ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "HidD_GetFeature returned error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = HidD_GetFeature(file, report, caps.FeatureReportByteLength - 1); + todo_wine + ok(!ret, "HidD_GetFeature succeeded\n"); + todo_wine + ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_CRC), + "HidD_GetFeature returned error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + memset(buffer, 0x5a, sizeof(buffer)); + ret = HidD_GetFeature(file, buffer, caps.FeatureReportByteLength); + if (report_id || broken(!ret)) + { + todo_wine + ok(!ret, "HidD_GetFeature succeeded, last error %u\n", GetLastError()); + todo_wine + ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_CRC), + "HidD_GetFeature returned error %u\n", GetLastError()); + } + else + { + ok(ret, "HidD_GetFeature failed, last error %u\n", GetLastError()); + todo_wine ok(buffer[0] == 0x5a, "got buffer[0] %x, expected 0x5a\n", (BYTE)buffer[0]); + } + + SetLastError(0xdeadbeef); + ret = HidD_GetFeature(file, report, caps.FeatureReportByteLength); + ok(ret, "HidD_GetFeature failed, last error %u\n", GetLastError()); + todo_wine_if(!report_id) + ok(report[0] == report_id, "got report[0] %02x, expected %02x\n", report[0], report_id); + + value = caps.FeatureReportByteLength * 2; + SetLastError(0xdeadbeef); + ret = sync_ioctl(file, IOCTL_HID_GET_FEATURE, NULL, 0, report, &value); + ok(ret, "IOCTL_HID_GET_FEATURE failed, last error %u\n", GetLastError()); + todo_wine ok(value == 3, "got length %u, expected 3\n", value); + todo_wine_if(!report_id) + ok(report[0] == report_id, "got report[0] %02x, expected %02x\n", report[0], report_id); + + HidD_FreePreparsedData(preparsed_data); CloseHandle(file); }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=93606
Your paranoid android.
=== w1064_tsign (64 bit report) ===
ntoskrnl.exe: driver.c:398: Test failed: Got unexpected test_load_image_notify_count 0.
On 7/5/21 11:15 AM, Marvin wrote:
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=93606
Your paranoid android.
=== w1064_tsign (64 bit report) ===
ntoskrnl.exe: driver.c:398: Test failed: Got unexpected test_load_image_notify_count 0.
I sent a separate patch to fix these spurious failures, they are unrelated to the changes here.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/ntoskrnl.exe/tests/driver_hid.c | 19 +++++++++++ dlls/ntoskrnl.exe/tests/ntoskrnl.c | 49 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
diff --git a/dlls/ntoskrnl.exe/tests/driver_hid.c b/dlls/ntoskrnl.exe/tests/driver_hid.c index ae039c061de..7c85e9a67db 100644 --- a/dlls/ntoskrnl.exe/tests/driver_hid.c +++ b/dlls/ntoskrnl.exe/tests/driver_hid.c @@ -424,6 +424,25 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp) break; }
+ case IOCTL_HID_SET_FEATURE: + { + HID_XFER_PACKET *packet = irp->UserBuffer; + ULONG expected_size = 17; + todo_wine ok(in_size == sizeof(*packet), "got input size %u\n", in_size); + todo_wine ok(!out_size, "got output size %u\n", out_size); + + todo_wine_if(packet->reportId != report_id) + ok(packet->reportId == report_id, "got packet report id %u\n", packet->reportId); + todo_wine_if(packet->reportBufferLen == 0 || packet->reportBufferLen == 16) + ok(packet->reportBufferLen >= expected_size, "got packet buffer len %u, expected %d or more\n", + packet->reportBufferLen, expected_size); + ok(!!packet->reportBuffer, "got packet buffer %p\n", packet->reportBuffer); + + irp->IoStatus.Information = 3; + ret = STATUS_SUCCESS; + break; + } + case IOCTL_HID_GET_STRING: ok(!in_size, "got input size %u\n", in_size); ok(out_size == 128, "got output size %u\n", out_size); diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index 8539e2ee921..af30829da99 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -2531,6 +2531,55 @@ static void test_hidp(HANDLE file, int report_id) ok(report[0] == report_id, "got report[0] %02x, expected %02x\n", report[0], report_id);
+ memset(report, 0xcd, sizeof(report)); + status = HidP_InitializeReportForID(HidP_Feature, report_id, preparsed_data, report, caps.FeatureReportByteLength); + ok(status == HIDP_STATUS_SUCCESS, "HidP_InitializeReportForID returned %#x\n", status); + + SetLastError(0xdeadbeef); + ret = HidD_SetFeature(file, report, 0); + todo_wine ok(!ret, "HidD_SetFeature succeeded\n"); + todo_wine ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "HidD_SetFeature returned error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = HidD_SetFeature(file, report, caps.FeatureReportByteLength - 1); + todo_wine + ok(!ret, "HidD_SetFeature succeeded\n"); + todo_wine + ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_CRC), + "HidD_SetFeature returned error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + memset(buffer, 0x5a, sizeof(buffer)); + ret = HidD_SetFeature(file, buffer, caps.FeatureReportByteLength); + if (report_id || broken(!ret)) + { + todo_wine + ok(!ret, "HidD_SetFeature succeeded, last error %u\n", GetLastError()); + todo_wine + ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_CRC), + "HidD_SetFeature returned error %u\n", GetLastError()); + } + else + { + ok(ret, "HidD_SetFeature failed, last error %u\n", GetLastError()); + } + + SetLastError(0xdeadbeef); + ret = HidD_SetFeature(file, report, caps.FeatureReportByteLength); + ok(ret, "HidD_SetFeature failed, last error %u\n", GetLastError()); + + value = caps.FeatureReportByteLength * 2; + SetLastError(0xdeadbeef); + ret = sync_ioctl(file, IOCTL_HID_SET_FEATURE, NULL, 0, report, &value); + todo_wine ok(!ret, "IOCTL_HID_SET_FEATURE succeeded\n"); + todo_wine ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "IOCTL_HID_SET_FEATURE returned error %u\n", GetLastError()); + value = 0; + SetLastError(0xdeadbeef); + ret = sync_ioctl(file, IOCTL_HID_SET_FEATURE, report, caps.FeatureReportByteLength * 2, NULL, &value); + ok(ret, "IOCTL_HID_SET_FEATURE failed, last error %u\n", GetLastError()); + todo_wine ok(value == 3, "got length %u, expected 3\n", value); + + HidD_FreePreparsedData(preparsed_data); CloseHandle(file); }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/ntoskrnl.exe/tests/driver_hid.c | 39 ++++++++++++++++++ dlls/ntoskrnl.exe/tests/ntoskrnl.c | 61 ++++++++++++++++++++++++++-- 2 files changed, 96 insertions(+), 4 deletions(-)
diff --git a/dlls/ntoskrnl.exe/tests/driver_hid.c b/dlls/ntoskrnl.exe/tests/driver_hid.c index 7c85e9a67db..049b4232753 100644 --- a/dlls/ntoskrnl.exe/tests/driver_hid.c +++ b/dlls/ntoskrnl.exe/tests/driver_hid.c @@ -290,6 +290,26 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp) REPORT_SIZE(1, 1), FEATURE(1, Data|Var|Abs), END_COLLECTION, + + USAGE_PAGE(1, HID_USAGE_PAGE_LED), + USAGE(1, HID_USAGE_LED_GREEN), + COLLECTION(1, Report), + REPORT_ID_OR_USAGE_PAGE(1, report_id, 0), + USAGE_PAGE(1, HID_USAGE_PAGE_LED), + REPORT_COUNT(1, 8), + REPORT_SIZE(1, 1), + OUTPUT(1, Cnst|Var|Abs), + END_COLLECTION, + + USAGE_PAGE(1, HID_USAGE_PAGE_LED), + USAGE(1, HID_USAGE_LED_RED), + COLLECTION(1, Report), + REPORT_ID_OR_USAGE_PAGE(1, report_id, 1), + USAGE_PAGE(1, HID_USAGE_PAGE_LED), + REPORT_COUNT(1, 8), + REPORT_SIZE(1, 1), + OUTPUT(1, Cnst|Var|Abs), + END_COLLECTION, END_COLLECTION, }; #undef REPORT_ID_OR_USAGE_PAGE @@ -403,6 +423,25 @@ static NTSTATUS WINAPI driver_internal_ioctl(DEVICE_OBJECT *device, IRP *irp) break; }
+ case IOCTL_HID_SET_OUTPUT_REPORT: + { + HID_XFER_PACKET *packet = irp->UserBuffer; + ULONG expected_size = 2; + todo_wine ok(in_size == sizeof(*packet), "got input size %u\n", in_size); + todo_wine ok(!out_size, "got output size %u\n", out_size); + + todo_wine_if(packet->reportId != report_id) + ok(packet->reportId == report_id, "got packet report id %u\n", packet->reportId); + todo_wine_if(packet->reportBufferLen == 0 || packet->reportBufferLen == 1) + ok(packet->reportBufferLen >= expected_size, "got packet buffer len %u, expected %d or more\n", + packet->reportBufferLen, expected_size); + ok(!!packet->reportBuffer, "got packet buffer %p\n", packet->reportBuffer); + + irp->IoStatus.Information = 3; + ret = STATUS_SUCCESS; + break; + } + case IOCTL_HID_GET_FEATURE: { HID_XFER_PACKET *packet = irp->UserBuffer; diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index af30829da99..7e42c2e5cac 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -1685,8 +1685,9 @@ static void test_hidp(HANDLE file, int report_id) .Usage = HID_USAGE_GENERIC_JOYSTICK, .UsagePage = HID_USAGE_PAGE_GENERIC, .InputReportByteLength = 24, + .OutputReportByteLength = 3, .FeatureReportByteLength = 18, - .NumberLinkCollectionNodes = 8, + .NumberLinkCollectionNodes = 10, .NumberInputButtonCaps = 13, .NumberInputValueCaps = 7, .NumberInputDataIndices = 43, @@ -1699,8 +1700,9 @@ static void test_hidp(HANDLE file, int report_id) .Usage = HID_USAGE_GENERIC_JOYSTICK, .UsagePage = HID_USAGE_PAGE_GENERIC, .InputReportByteLength = 23, + .OutputReportByteLength = 2, .FeatureReportByteLength = 17, - .NumberLinkCollectionNodes = 8, + .NumberLinkCollectionNodes = 10, .NumberInputButtonCaps = 13, .NumberInputValueCaps = 7, .NumberInputDataIndices = 43, @@ -1842,8 +1844,8 @@ static void test_hidp(HANDLE file, int report_id) .LinkUsage = HID_USAGE_GENERIC_JOYSTICK, .LinkUsagePage = HID_USAGE_PAGE_GENERIC, .CollectionType = 1, - .NumberOfChildren = 5, - .FirstChild = 7, + .NumberOfChildren = 7, + .FirstChild = 9, }, { .LinkUsage = HID_USAGE_GENERIC_JOYSTICK, @@ -2580,6 +2582,57 @@ static void test_hidp(HANDLE file, int report_id) todo_wine ok(value == 3, "got length %u, expected 3\n", value);
+ memset(report, 0xcd, sizeof(report)); + status = HidP_InitializeReportForID(HidP_Output, report_id, preparsed_data, report, caps.OutputReportByteLength); + ok(status == HIDP_STATUS_REPORT_DOES_NOT_EXIST, "HidP_InitializeReportForID returned %#x\n", status); + memset(report, 0, caps.OutputReportByteLength); + report[0] = report_id; + + SetLastError(0xdeadbeef); + ret = HidD_SetOutputReport(file, report, 0); + todo_wine ok(!ret, "HidD_SetOutputReport succeeded\n"); + todo_wine ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "HidD_SetOutputReport returned error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = HidD_SetOutputReport(file, report, caps.OutputReportByteLength - 1); + todo_wine + ok(!ret, "HidD_SetOutputReport succeeded\n"); + todo_wine + ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_CRC), + "HidD_SetOutputReport returned error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + memset(buffer, 0x5a, sizeof(buffer)); + ret = HidD_SetOutputReport(file, buffer, caps.OutputReportByteLength); + if (report_id || broken(!ret)) + { + todo_wine + ok(!ret, "HidD_SetOutputReport succeeded, last error %u\n", GetLastError()); + todo_wine + ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_CRC), + "HidD_SetOutputReport returned error %u\n", GetLastError()); + } + else + { + ok(ret, "HidD_SetOutputReport failed, last error %u\n", GetLastError()); + } + + SetLastError(0xdeadbeef); + ret = HidD_SetOutputReport(file, report, caps.OutputReportByteLength); + ok(ret, "HidD_SetOutputReport failed, last error %u\n", GetLastError()); + + value = caps.OutputReportByteLength * 2; + SetLastError(0xdeadbeef); + ret = sync_ioctl(file, IOCTL_HID_SET_OUTPUT_REPORT, NULL, 0, report, &value); + todo_wine ok(!ret, "IOCTL_HID_SET_OUTPUT_REPORT succeeded\n"); + todo_wine ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "IOCTL_HID_SET_OUTPUT_REPORT returned error %u\n", GetLastError()); + value = 0; + SetLastError(0xdeadbeef); + ret = sync_ioctl(file, IOCTL_HID_SET_OUTPUT_REPORT, report, caps.OutputReportByteLength * 2, NULL, &value); + ok(ret, "IOCTL_HID_SET_OUTPUT_REPORT failed, last error %u\n", GetLastError()); + todo_wine ok(value == 3, "got length %u, expected 3\n", value); + + HidD_FreePreparsedData(preparsed_data); CloseHandle(file); }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=93608
Your paranoid android.
=== w1064_tsign (64 bit report) ===
ntoskrnl.exe: driver.c:398: Test failed: Got unexpected test_load_image_notify_count 0.