Commit 50948335 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Get rid of duplicated winetest helpers.

parent e3b2cfed
......@@ -39,8 +39,6 @@
#include "ddk/hidsdi.h"
#include "ddk/hidport.h"
#include "wine/test.h"
#include "driver_hid.h"
#define EXPECT_VIDPID MAKELONG( 0x1209, 0x0001 )
......
......@@ -33,6 +33,7 @@
#include "wine/list.h"
#define WINE_DRIVER_TEST
#include "initguid.h"
#include "driver_hid.h"
......@@ -246,8 +247,8 @@ static void expect_queue_next( struct expect_queue *queue, ULONG code, HID_XFER_
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 (winetest_platform_is_wine && !tmp->todo) break;
if (!winetest_platform_is_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;
......@@ -260,7 +261,7 @@ static void expect_queue_next( struct expect_queue *queue, ULONG code, HID_XFER_
while (queue->pos < queue->end)
{
if (running_under_wine || !queue->pos->wine_only) break;
if (winetest_platform_is_wine || !queue->pos->wine_only) break;
queue->pos++;
}
......
......@@ -32,6 +32,7 @@
#include "wine/list.h"
#define WINE_DRIVER_TEST
#include "initguid.h"
#include "driver_hid.h"
......
......@@ -39,6 +39,8 @@
#include "ddk/hidport.h"
#include "ddk/hidclass.h"
#include "wine/test.h"
DEFINE_GUID(control_class,0xdeadbeef,0x29ef,0x4538,0xa5,0xfd,0xb6,0x95,0x73,0xa3,0x62,0xc0);
#define IOCTL_WINETEST_HID_SET_EXPECT CTL_CODE(FILE_DEVICE_KEYBOARD, 0x800, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
......@@ -175,89 +177,75 @@ static inline const char *debugstr_ioctl( ULONG code )
}
}
#ifndef __WINE_WINE_TEST_H
#ifdef __MINGW32__
#define __WINE_PRINTF_ATTR( fmt, args ) __attribute__((format( printf, fmt, args )))
#else
#define __WINE_PRINTF_ATTR( fmt, args )
#endif
#ifdef WINE_DRIVER_TEST
static HANDLE okfile;
static LONG successes;
static LONG failures;
static LONG skipped;
static LONG todo_successes;
static LONG todo_failures;
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];
LONG winetest_successes = 0;
LONG winetest_failures = 0;
LONG winetest_flaky_failures = 0;
LONG winetest_skipped = 0;
LONG winetest_todo_successes = 0;
LONG winetest_todo_failures = 0;
LONG winetest_muted_traces = 0;
LONG winetest_muted_skipped = 0;
LONG winetest_muted_todo_successes = 0;
const char *winetest_platform;
int winetest_platform_is_wine;
int winetest_debug;
int winetest_report_success;
int winetest_color = 0;
int winetest_time = 0;
int winetest_start_time, winetest_last_time;
/* 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 */
};
/* silence todos and skips above this threshold */
int winetest_mute_threshold = 42;
static KSPIN_LOCK tls_data_lock;
static struct tls_data tls_data_pool[128];
static struct winetest_thread_data tls_data_pool[128];
static HANDLE tls_data_thread[ARRAY_SIZE(tls_data_pool)];
static DWORD tls_data_count;
static inline struct tls_data *get_tls_data(void)
struct winetest_thread_data *winetest_get_thread_data(void)
{
static struct tls_data tls_overflow;
struct tls_data *data;
HANDLE thread = PsGetCurrentThreadId();
struct winetest_thread_data *data;
KIRQL irql;
UINT i;
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)
for (i = 0; i < tls_data_count; i++) if (tls_data_thread[i] == thread) break;
data = tls_data_pool + i;
if (tls_data_thread[i] != thread)
{
data->thread = thread;
tls_data_count = min(tls_data_count + 1, ARRAY_SIZE(tls_data_pool));
tls_data_thread[i] = 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 )
void winetest_print_lock(void)
{
}
void winetest_print_unlock(void)
{
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, va_list ap )
int winetest_vprintf( const char *format, va_list args )
{
struct tls_data *data = get_tls_data();
struct winetest_thread_data *data = winetest_get_thread_data();
IO_STATUS_BLOCK io;
int len = vsnprintf( data->str_pos, sizeof(data->strings) - (data->str_pos - data->strings), format, ap );
int len;
len = vsnprintf( data->str_pos, sizeof(data->strings) - (data->str_pos - data->strings), format, args );
data->str_pos += len;
if (len && data->str_pos[-1] == '\n')
......@@ -266,28 +254,13 @@ static inline void kvprintf( const char *format, va_list ap )
strlen( data->strings ), NULL, NULL );
data->str_pos = data->strings;
}
}
static inline void WINAPIV kprintf( const char *format, ... ) __WINE_PRINTF_ATTR( 1, 2 );
static inline void WINAPIV kprintf( const char *format, ... )
{
va_list valist;
va_start( valist, format );
kvprintf( format, valist );
va_end( valist );
return len;
}
static inline void WINAPIV winetest_printf( const char *msg, ... ) __WINE_PRINTF_ATTR( 1, 2 );
static inline void WINAPIV winetest_printf( const char *msg, ... )
int winetest_get_time(void)
{
struct tls_data *data = get_tls_data();
va_list valist;
kprintf( "%s:%d: ", data->current_file, data->current_line );
va_start( valist, msg );
kvprintf( msg, valist );
va_end( valist );
return 0;
}
static inline NTSTATUS winetest_init(void)
......@@ -314,7 +287,8 @@ static inline NTSTATUS winetest_init(void)
return ret;
}
data = addr;
running_under_wine = data->running_under_wine;
winetest_platform_is_wine = data->running_under_wine;
winetest_platform = winetest_platform_is_wine ? "wine" : "windows";
winetest_debug = data->winetest_debug;
winetest_report_success = data->winetest_report_success;
......@@ -348,10 +322,11 @@ static inline void winetest_cleanup_( const char *file )
if (winetest_debug)
{
kprintf( "%04lx:%s: %ld tests executed (%ld marked as todo, 0 as flaky, %ld %s), %ld skipped.\n",
winetest_printf( "%04lx:%s: %ld tests executed (%ld marked as todo, 0 as flaky, %ld %s), %ld skipped.\n",
(DWORD)(DWORD_PTR)PsGetCurrentProcessId(), test_name,
successes + failures + todo_successes + todo_failures, todo_successes, failures + todo_failures,
(failures + todo_failures != 1) ? "failures" : "failure", skipped );
winetest_successes + winetest_failures + winetest_todo_successes + winetest_todo_failures,
winetest_todo_successes, winetest_failures + winetest_todo_failures,
(winetest_failures + winetest_todo_failures != 1) ? "failures" : "failure", winetest_skipped );
}
RtlInitUnicodeString( &string, L"\\BaseNamedObjects\\winetest_dinput_section" );
......@@ -364,8 +339,8 @@ static inline void winetest_cleanup_( const char *file )
{
data = addr;
InterlockedExchangeAdd( &data->failures, failures );
InterlockedExchangeAdd( &data->todo_failures, todo_failures );
InterlockedExchangeAdd( &data->failures, winetest_failures );
InterlockedExchangeAdd( &data->todo_failures, winetest_todo_failures );
ZwUnmapViewOfSection( NtCurrentProcess(), addr );
}
......@@ -375,210 +350,6 @@ static inline void winetest_cleanup_( const char *file )
ZwClose( okfile );
}
static inline void winetest_print_context( const char *msgtype )
{
struct tls_data *data = get_tls_data();
unsigned int i;
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 );
return count;
}
static inline int winetest_vok( int condition, const char *msg, va_list args )
{
struct tls_data *data = get_tls_data();
if (data->todo_level)
{
if (condition)
{
winetest_print_context( "Test succeeded inside todo block: " );
kvprintf( msg, args );
InterlockedIncrement( &todo_failures );
return 0;
}
else
{
if (!winetest_debug || winetest_add_line() < winetest_mute_threshold)
{
if (winetest_debug > 0)
{
winetest_print_context( "Test marked todo: " );
kvprintf( msg, args );
}
InterlockedIncrement( &todo_successes );
}
else InterlockedIncrement( &muted_todo_successes );
return 1;
}
}
else
{
if (!condition)
{
winetest_print_context( "Test failed: " );
kvprintf( msg, args );
InterlockedIncrement( &failures );
return 0;
}
else
{
if (winetest_report_success) winetest_printf( "Test succeeded\n" );
InterlockedIncrement( &successes );
return 1;
}
}
}
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, ... )
{
va_list args;
va_start( args, msg );
winetest_vok( condition, msg, args );
va_end( args );
}
static inline void winetest_vskip( const char *msg, va_list args )
{
if (winetest_add_line() < winetest_mute_threshold)
{
winetest_print_context( "Driver tests skipped: " );
kvprintf( msg, args );
InterlockedIncrement( &skipped );
}
else InterlockedIncrement( &muted_skipped );
}
static inline void WINAPIV winetest_skip( const char *msg, ... ) __WINE_PRINTF_ATTR( 1, 2 );
static inline void WINAPIV winetest_skip( const char *msg, ... )
{
va_list args;
va_start( args, msg );
winetest_vskip( msg, args );
va_end( args );
}
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, ... )
{
va_list args;
va_start( args, msg );
if (!running_under_wine) winetest_vskip( msg, args );
else winetest_vok( 0, msg, args );
va_end( args );
}
static inline void WINAPIV winetest_trace( const char *msg, ... ) __WINE_PRINTF_ATTR( 1, 2 );
static inline void WINAPIV winetest_trace( const char *msg, ... )
{
va_list args;
if (!winetest_debug) return;
if (winetest_add_line() < winetest_mute_threshold)
{
winetest_print_context( "" );
va_start( args, msg );
kvprintf( msg, args );
va_end( args );
}
else InterlockedIncrement( &muted_traces );
}
static inline void winetest_start_todo( int is_todo )
{
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)
{
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)
{
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();
va_list valist;
if (data->context_count < ARRAY_SIZE(data->context))
{
va_start( valist, fmt );
vsnprintf( data->context[data->context_count], sizeof(data->context[data->context_count]), fmt, valist );
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 )
{
return !running_under_wine && condition;
}
#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)
#endif /* __WINE_WINE_TEST_H */
#endif /* WINE_DRIVER_TEST */
#endif /* __WINE_DRIVER_HID_H */
......@@ -32,6 +32,7 @@
#include "wine/list.h"
#define WINE_DRIVER_TEST
#include "initguid.h"
#include "driver_hid.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment