forked from Mirrors/wine-wine
ntoskrnl.exe/tests: Add a test for IoGetCurrentProcess().
Signed-off-by: Zebediah Figura <z.figura12@gmail.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>oldstable
parent
0dc84eada2
commit
80f82ee9d7
|
@ -1299,7 +1299,7 @@
|
|||
@ stdcall -private ZwCancelIoFile(long ptr) NtCancelIoFile
|
||||
@ stdcall -private ZwCancelTimer(long ptr) NtCancelTimer
|
||||
@ stdcall -private ZwClearEvent(long) NtClearEvent
|
||||
@ stdcall -private ZwClose(long) NtClose
|
||||
@ stdcall ZwClose(long) NtClose
|
||||
@ stub ZwCloseObjectAuditAlarm
|
||||
@ stdcall -private ZwConnectPort(ptr ptr ptr ptr ptr ptr ptr ptr) NtConnectPort
|
||||
@ stdcall -private ZwCreateDirectoryObject(ptr long ptr) NtCreateDirectoryObject
|
||||
|
@ -1335,7 +1335,7 @@
|
|||
@ stdcall -private ZwNotifyChangeKey(long long ptr ptr ptr long long ptr long long) NtNotifyChangeKey
|
||||
@ stdcall -private ZwOpenDirectoryObject(ptr long ptr) NtOpenDirectoryObject
|
||||
@ stdcall -private ZwOpenEvent(ptr long ptr) NtOpenEvent
|
||||
@ stdcall -private ZwOpenFile(ptr long ptr ptr long long) NtOpenFile
|
||||
@ stdcall ZwOpenFile(ptr long ptr ptr long long) NtOpenFile
|
||||
@ stdcall -private ZwOpenJobObject(ptr long ptr) NtOpenJobObject
|
||||
@ stdcall -private ZwOpenKey(ptr long ptr) NtOpenKey
|
||||
@ stdcall -private ZwOpenProcess(ptr long ptr ptr) NtOpenProcess
|
||||
|
@ -1403,7 +1403,7 @@
|
|||
@ stdcall -private ZwUnmapViewOfSection(long ptr) NtUnmapViewOfSection
|
||||
@ stdcall -private ZwWaitForMultipleObjects(long ptr long long ptr) NtWaitForMultipleObjects
|
||||
@ stdcall -private ZwWaitForSingleObject(long long ptr) NtWaitForSingleObject
|
||||
@ stdcall -private ZwWriteFile(long long ptr ptr ptr ptr long ptr ptr) NtWriteFile
|
||||
@ stdcall ZwWriteFile(long long ptr ptr ptr ptr long ptr ptr) NtWriteFile
|
||||
@ stdcall -private ZwYieldExecution() NtYieldExecution
|
||||
@ stdcall -private -arch=arm,x86_64 -norelay __chkstk()
|
||||
@ cdecl -private -arch=i386 _CIcos() msvcrt._CIcos
|
||||
|
@ -1439,7 +1439,7 @@
|
|||
@ cdecl -private _strrev(str) msvcrt._strrev
|
||||
@ cdecl -private _strset(str long) msvcrt._strset
|
||||
@ cdecl -private _strupr(str) msvcrt._strupr
|
||||
@ cdecl -private _vsnprintf(ptr long str ptr) msvcrt._vsnprintf
|
||||
@ cdecl _vsnprintf(ptr long str ptr) msvcrt._vsnprintf
|
||||
@ cdecl -private _vsnwprintf(ptr long wstr ptr) msvcrt._vsnwprintf
|
||||
@ cdecl -private _wcsicmp(wstr wstr) msvcrt._wcsicmp
|
||||
@ cdecl -private _wcslwr(wstr) msvcrt._wcslwr
|
||||
|
|
|
@ -37,6 +37,160 @@ static const WCHAR driver_device[] = {'\\','D','e','v','i','c','e',
|
|||
static const WCHAR driver_link[] = {'\\','D','o','s','D','e','v','i','c','e','s',
|
||||
'\\','W','i','n','e','T','e','s','t','D','r','i','v','e','r',0};
|
||||
|
||||
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 int running_under_wine;
|
||||
static int winetest_debug;
|
||||
static int winetest_report_success;
|
||||
|
||||
extern int CDECL _vsnprintf(char *str, size_t len, const char *format, __ms_va_list argptr);
|
||||
|
||||
static void kvprintf(const char *format, __ms_va_list ap)
|
||||
{
|
||||
static char buffer[512];
|
||||
LARGE_INTEGER offset;
|
||||
IO_STATUS_BLOCK io;
|
||||
|
||||
_vsnprintf(buffer, sizeof(buffer), format, ap);
|
||||
offset.QuadPart = -1;
|
||||
ZwWriteFile(okfile, NULL, NULL, NULL, &io, buffer, strlen(buffer), &offset, NULL);
|
||||
}
|
||||
|
||||
static void kprintf(const char *format, ...)
|
||||
{
|
||||
__ms_va_list valist;
|
||||
|
||||
__ms_va_start(valist, format);
|
||||
kvprintf(format, valist);
|
||||
__ms_va_end(valist);
|
||||
}
|
||||
|
||||
static void ok_(const char *file, int line, int condition, const char *msg, ...)
|
||||
{
|
||||
const char *current_file;
|
||||
__ms_va_list args;
|
||||
|
||||
if (!(current_file = strrchr(file, '/')) &&
|
||||
!(current_file = strrchr(file, '\\')))
|
||||
current_file = file;
|
||||
else
|
||||
current_file++;
|
||||
|
||||
__ms_va_start(args, msg);
|
||||
if (todo_level)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
kprintf("%s:%d: Test succeeded inside todo block: ", current_file, line);
|
||||
kvprintf(msg, args);
|
||||
InterlockedIncrement(&todo_failures);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (winetest_debug > 0)
|
||||
{
|
||||
kprintf("%s:%d: Test marked todo: ", current_file, line);
|
||||
kvprintf(msg, args);
|
||||
}
|
||||
InterlockedIncrement(&todo_successes);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
kprintf("%s:%d: Test failed: ", current_file, line);
|
||||
kvprintf(msg, args);
|
||||
InterlockedIncrement(&failures);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (winetest_report_success)
|
||||
kprintf("%s:%d: Test succeeded\n", current_file, line);
|
||||
InterlockedIncrement(&successes);
|
||||
}
|
||||
}
|
||||
__ms_va_end(args);
|
||||
}
|
||||
|
||||
static void winetest_start_todo( int is_todo )
|
||||
{
|
||||
todo_level = (todo_level << 1) | (is_todo != 0);
|
||||
todo_do_loop=1;
|
||||
}
|
||||
|
||||
static int winetest_loop_todo(void)
|
||||
{
|
||||
int do_loop=todo_do_loop;
|
||||
todo_do_loop=0;
|
||||
return do_loop;
|
||||
}
|
||||
|
||||
static void winetest_end_todo(void)
|
||||
{
|
||||
todo_level >>= 1;
|
||||
}
|
||||
|
||||
#define ok(condition, ...) ok_(__FILE__, __LINE__, condition, __VA_ARGS__)
|
||||
#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)
|
||||
|
||||
static void test_currentprocess(void)
|
||||
{
|
||||
PEPROCESS current;
|
||||
|
||||
current = IoGetCurrentProcess();
|
||||
todo_wine
|
||||
ok(current != NULL, "Expected current process to be non-NULL\n");
|
||||
}
|
||||
|
||||
static NTSTATUS main_test(IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info)
|
||||
{
|
||||
ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength;
|
||||
void *buffer = irp->AssociatedIrp.SystemBuffer;
|
||||
struct test_input *test_input = (struct test_input *)buffer;
|
||||
OBJECT_ATTRIBUTES attr = {0};
|
||||
UNICODE_STRING pathU;
|
||||
IO_STATUS_BLOCK io;
|
||||
|
||||
if (!buffer)
|
||||
return STATUS_ACCESS_VIOLATION;
|
||||
|
||||
if (length < sizeof(failures))
|
||||
return STATUS_BUFFER_TOO_SMALL;
|
||||
|
||||
attr.Length = sizeof(attr);
|
||||
RtlInitUnicodeString(&pathU, test_input->path);
|
||||
running_under_wine = test_input->running_under_wine;
|
||||
winetest_debug = test_input->winetest_debug;
|
||||
winetest_report_success = test_input->winetest_report_success;
|
||||
attr.ObjectName = &pathU;
|
||||
ZwOpenFile(&okfile, FILE_APPEND_DATA, &attr, &io, 0, 0);
|
||||
|
||||
test_currentprocess();
|
||||
|
||||
/* print process report */
|
||||
if (test_input->winetest_debug)
|
||||
{
|
||||
kprintf("%04x:ntoskrnl: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
|
||||
PsGetCurrentProcessId(), successes + failures + todo_successes + todo_failures,
|
||||
todo_successes, failures + todo_failures,
|
||||
(failures + todo_failures != 1) ? "failures" : "failure", skipped );
|
||||
}
|
||||
ZwClose(okfile);
|
||||
*((LONG *)buffer) = failures;
|
||||
*info = sizeof(failures);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS test_basic_ioctl(IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info)
|
||||
{
|
||||
ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength;
|
||||
|
@ -71,6 +225,9 @@ static NTSTATUS WINAPI driver_IoControl(DEVICE_OBJECT *device, IRP *irp)
|
|||
case IOCTL_WINETEST_BASIC_IOCTL:
|
||||
status = test_basic_ioctl(irp, stack, &irp->IoStatus.Information);
|
||||
break;
|
||||
case IOCTL_WINETEST_MAIN_TEST:
|
||||
status = main_test(irp, stack, &irp->IoStatus.Information);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -23,5 +23,14 @@
|
|||
|
||||
/* All custom IOCTLs need to have a function value >= 0x800. */
|
||||
#define IOCTL_WINETEST_BASIC_IOCTL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_WINETEST_MAIN_TEST CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
static const char teststr[] = "Wine is not an emulator";
|
||||
|
||||
struct test_input
|
||||
{
|
||||
int running_under_wine;
|
||||
int winetest_report_success;
|
||||
int winetest_debug;
|
||||
WCHAR path[1];
|
||||
};
|
||||
|
|
|
@ -20,10 +20,13 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "windows.h"
|
||||
#include "winsvc.h"
|
||||
#include "winioctl.h"
|
||||
#include "winternl.h"
|
||||
#include "wine/test.h"
|
||||
#include "wine/heap.h"
|
||||
|
||||
#include "driver.h"
|
||||
|
||||
|
@ -32,6 +35,8 @@ static const char device_path[] = "\\\\.\\WineTestDriver";
|
|||
|
||||
static HANDLE device;
|
||||
|
||||
static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)( LPCWSTR, PUNICODE_STRING, PWSTR*, CURDIR* );
|
||||
|
||||
static void load_resource(const char *name, char *filename)
|
||||
{
|
||||
static char path[MAX_PATH];
|
||||
|
@ -131,6 +136,47 @@ static SC_HANDLE load_driver(char *filename)
|
|||
return service;
|
||||
}
|
||||
|
||||
static void main_test(void)
|
||||
{
|
||||
static const WCHAR dokW[] = {'d','o','k',0};
|
||||
WCHAR temppathW[MAX_PATH], pathW[MAX_PATH];
|
||||
struct test_input *test_input;
|
||||
UNICODE_STRING pathU;
|
||||
DWORD written, read;
|
||||
LONG new_failures;
|
||||
char buffer[512];
|
||||
HANDLE okfile;
|
||||
BOOL res;
|
||||
|
||||
/* Create a temporary file that the driver will write ok/trace output to. */
|
||||
GetTempPathW(MAX_PATH, temppathW);
|
||||
GetTempFileNameW(temppathW, dokW, 0, pathW);
|
||||
pRtlDosPathNameToNtPathName_U( pathW, &pathU, NULL, NULL );
|
||||
|
||||
test_input = heap_alloc(sizeof(*test_input) + pathU.Length);
|
||||
test_input->running_under_wine = !strcmp(winetest_platform, "wine");
|
||||
test_input->winetest_report_success = winetest_report_success;
|
||||
test_input->winetest_debug = winetest_debug;
|
||||
lstrcpynW(test_input->path, pathU.Buffer, pathU.Length);
|
||||
res = DeviceIoControl(device, IOCTL_WINETEST_MAIN_TEST, test_input, sizeof(*test_input) + pathU.Length,
|
||||
&new_failures, sizeof(new_failures), &written, NULL);
|
||||
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
||||
ok(written == sizeof(new_failures), "got size %x\n", written);
|
||||
|
||||
okfile = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
ok(okfile != INVALID_HANDLE_VALUE, "failed to create %s: %u\n", wine_dbgstr_w(pathW), GetLastError());
|
||||
|
||||
/* Print the ok/trace output and then add to our failure count. */
|
||||
do {
|
||||
ReadFile(okfile, buffer, sizeof(buffer), &read, NULL);
|
||||
printf("%.*s", read, buffer);
|
||||
} while (read == sizeof(buffer));
|
||||
winetest_add_failures(new_failures);
|
||||
|
||||
CloseHandle(okfile);
|
||||
DeleteFileW(pathW);
|
||||
}
|
||||
|
||||
static void test_basic_ioctl(void)
|
||||
{
|
||||
DWORD written;
|
||||
|
@ -149,10 +195,14 @@ START_TEST(ntoskrnl)
|
|||
char filename[MAX_PATH];
|
||||
SC_HANDLE service;
|
||||
|
||||
HMODULE hntdll = GetModuleHandleA("ntdll.dll");
|
||||
pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
|
||||
|
||||
if (!(service = load_driver(filename)))
|
||||
return;
|
||||
|
||||
test_basic_ioctl();
|
||||
main_test();
|
||||
|
||||
unload_driver(service);
|
||||
ok(DeleteFileA(filename), "DeleteFile failed: %u\n", GetLastError());
|
||||
|
|
|
@ -52,6 +52,9 @@ extern int winetest_debug;
|
|||
/* running in interactive mode? */
|
||||
extern int winetest_interactive;
|
||||
|
||||
/* report successful tests (BOOL) */
|
||||
extern int winetest_report_success;
|
||||
|
||||
/* current platform */
|
||||
extern const char *winetest_platform;
|
||||
|
||||
|
@ -204,7 +207,7 @@ int winetest_interactive = 0;
|
|||
const char *winetest_platform = "windows";
|
||||
|
||||
/* report successful tests (BOOL) */
|
||||
static int report_success = 0;
|
||||
int winetest_report_success = 0;
|
||||
|
||||
/* passing arguments around */
|
||||
static int winetest_argc;
|
||||
|
@ -338,7 +341,7 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
|
|||
}
|
||||
else
|
||||
{
|
||||
if (report_success)
|
||||
if (winetest_report_success)
|
||||
printf( "%s:%d: Test succeeded\n",
|
||||
data->current_file, data->current_line);
|
||||
InterlockedIncrement(&successes);
|
||||
|
@ -668,7 +671,7 @@ int main( int argc, char **argv )
|
|||
|
||||
if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
|
||||
if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
|
||||
if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) report_success = atoi(p);
|
||||
if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) winetest_report_success = atoi(p);
|
||||
|
||||
if (!strcmp( winetest_platform, "windows" )) SetUnhandledExceptionFilter( exc_filter );
|
||||
if (!winetest_interactive) SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX );
|
||||
|
|
Loading…
Reference in New Issue