2018-04-30 20:59:58 +02:00
|
|
|
/*
|
|
|
|
* ntoskrnl.exe testing framework
|
|
|
|
*
|
|
|
|
* Copyright 2015 Sebastian Lackner
|
|
|
|
* Copyright 2015 Michael Müller
|
|
|
|
* Copyright 2015 Christian Costa
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2018-05-02 01:38:03 +02:00
|
|
|
#include <stdio.h>
|
2019-08-07 05:48:42 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2018-04-30 20:59:58 +02:00
|
|
|
#include "windows.h"
|
|
|
|
#include "winsvc.h"
|
|
|
|
#include "winioctl.h"
|
2018-05-02 01:38:03 +02:00
|
|
|
#include "winternl.h"
|
2020-06-17 19:22:00 +02:00
|
|
|
#include "winsock2.h"
|
2018-04-30 20:59:58 +02:00
|
|
|
#include "wine/test.h"
|
2018-05-02 01:38:03 +02:00
|
|
|
#include "wine/heap.h"
|
2018-04-30 20:59:58 +02:00
|
|
|
|
|
|
|
#include "driver.h"
|
|
|
|
|
|
|
|
static HANDLE device;
|
|
|
|
|
2019-05-03 17:17:17 +02:00
|
|
|
static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)(const WCHAR *, UNICODE_STRING *, WCHAR **, CURDIR *);
|
|
|
|
static BOOL (WINAPI *pRtlFreeUnicodeString)(UNICODE_STRING *);
|
|
|
|
static BOOL (WINAPI *pCancelIoEx)(HANDLE, OVERLAPPED *);
|
2019-05-07 16:15:33 +02:00
|
|
|
static BOOL (WINAPI *pSetFileCompletionNotificationModes)(HANDLE, UCHAR);
|
2018-05-02 01:38:03 +02:00
|
|
|
|
2018-04-30 20:59:58 +02:00
|
|
|
static void load_resource(const char *name, char *filename)
|
|
|
|
{
|
|
|
|
static char path[MAX_PATH];
|
|
|
|
DWORD written;
|
|
|
|
HANDLE file;
|
|
|
|
HRSRC res;
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
GetTempPathA(sizeof(path), path);
|
|
|
|
GetTempFileNameA(path, name, 0, filename);
|
|
|
|
|
|
|
|
file = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %d\n", filename, GetLastError());
|
|
|
|
|
|
|
|
res = FindResourceA(NULL, name, "TESTDLL");
|
|
|
|
ok( res != 0, "couldn't find resource\n" );
|
|
|
|
ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res ));
|
|
|
|
WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL );
|
|
|
|
ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
|
|
|
|
CloseHandle( file );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unload_driver(SC_HANDLE service)
|
|
|
|
{
|
|
|
|
SERVICE_STATUS status;
|
|
|
|
|
|
|
|
ControlService(service, SERVICE_CONTROL_STOP, &status);
|
|
|
|
while (status.dwCurrentState == SERVICE_STOP_PENDING)
|
|
|
|
{
|
2018-05-03 19:27:55 +02:00
|
|
|
BOOL ret;
|
2018-04-30 20:59:58 +02:00
|
|
|
Sleep(100);
|
2018-05-03 19:27:55 +02:00
|
|
|
ret = QueryServiceStatus(service, &status);
|
|
|
|
ok(ret, "QueryServiceStatus failed: %u\n", GetLastError());
|
2018-04-30 20:59:58 +02:00
|
|
|
}
|
|
|
|
ok(status.dwCurrentState == SERVICE_STOPPED,
|
|
|
|
"expected SERVICE_STOPPED, got %d\n", status.dwCurrentState);
|
|
|
|
|
|
|
|
DeleteService(service);
|
|
|
|
CloseServiceHandle(service);
|
|
|
|
}
|
|
|
|
|
2018-08-25 06:08:52 +02:00
|
|
|
static SC_HANDLE load_driver(char *filename, const char *resname, const char *driver_name)
|
2018-04-30 20:59:58 +02:00
|
|
|
{
|
|
|
|
SC_HANDLE manager, service;
|
|
|
|
|
|
|
|
manager = OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
|
|
|
if (!manager && GetLastError() == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
skip("Failed to open SC manager, not enough permissions\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ok(!!manager, "OpenSCManager failed\n");
|
|
|
|
|
2018-08-25 06:08:52 +02:00
|
|
|
/* stop any old drivers running under this name */
|
2018-04-30 20:59:58 +02:00
|
|
|
service = OpenServiceA(manager, driver_name, SERVICE_ALL_ACCESS);
|
|
|
|
if (service) unload_driver(service);
|
|
|
|
|
2018-08-25 06:08:52 +02:00
|
|
|
load_resource(resname, filename);
|
2018-04-30 20:59:58 +02:00
|
|
|
trace("Trying to load driver %s\n", filename);
|
|
|
|
|
|
|
|
service = CreateServiceA(manager, driver_name, driver_name,
|
|
|
|
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
|
|
|
|
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
|
|
|
|
filename, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
ok(!!service, "CreateService failed: %u\n", GetLastError());
|
2018-08-25 06:08:52 +02:00
|
|
|
|
2018-04-30 20:59:58 +02:00
|
|
|
CloseServiceHandle(manager);
|
2018-08-25 06:08:52 +02:00
|
|
|
return service;
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:47:45 +02:00
|
|
|
static BOOL start_driver(HANDLE service, BOOL vista_plus)
|
2018-08-25 06:08:52 +02:00
|
|
|
{
|
|
|
|
SERVICE_STATUS status;
|
|
|
|
BOOL ret;
|
2018-04-30 20:59:58 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = StartServiceA(service, 0, NULL);
|
2020-06-11 16:47:45 +02:00
|
|
|
if (!ret && (GetLastError() == ERROR_DRIVER_BLOCKED || GetLastError() == ERROR_INVALID_IMAGE_HASH
|
|
|
|
|| (vista_plus && GetLastError() == ERROR_FILE_NOT_FOUND)))
|
2018-04-30 20:59:58 +02:00
|
|
|
{
|
2020-06-11 16:47:45 +02:00
|
|
|
if (vista_plus && GetLastError() == ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
skip("Windows Vista or newer is required to run this service.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If Secure Boot is enabled or the machine is 64-bit, it will reject an unsigned driver. */
|
|
|
|
skip("Failed to start service; probably your machine doesn't accept unsigned drivers.\n");
|
|
|
|
}
|
2018-04-30 20:59:58 +02:00
|
|
|
DeleteService(service);
|
|
|
|
CloseServiceHandle(service);
|
2018-08-25 06:08:52 +02:00
|
|
|
return FALSE;
|
2018-04-30 20:59:58 +02:00
|
|
|
}
|
|
|
|
ok(ret, "StartService failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* wait for the service to start up properly */
|
2018-05-03 19:27:55 +02:00
|
|
|
ret = QueryServiceStatus(service, &status);
|
|
|
|
ok(ret, "QueryServiceStatus failed: %u\n", GetLastError());
|
2018-04-30 20:59:58 +02:00
|
|
|
while (status.dwCurrentState == SERVICE_START_PENDING)
|
|
|
|
{
|
|
|
|
Sleep(100);
|
2018-05-03 19:27:55 +02:00
|
|
|
ret = QueryServiceStatus(service, &status);
|
|
|
|
ok(ret, "QueryServiceStatus failed: %u\n", GetLastError());
|
2018-04-30 20:59:58 +02:00
|
|
|
}
|
|
|
|
ok(status.dwCurrentState == SERVICE_RUNNING,
|
|
|
|
"expected SERVICE_RUNNING, got %d\n", status.dwCurrentState);
|
2019-07-04 00:29:35 +02:00
|
|
|
ok(status.dwServiceType == SERVICE_KERNEL_DRIVER,
|
|
|
|
"expected SERVICE_KERNEL_DRIVER, got %#x\n", status.dwServiceType);
|
2018-04-30 20:59:58 +02:00
|
|
|
|
2018-08-25 06:08:52 +02:00
|
|
|
return TRUE;
|
2018-04-30 20:59:58 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:47:45 +02:00
|
|
|
static ULONG64 modified_value;
|
|
|
|
|
2018-05-02 01:38:03 +02:00
|
|
|
static void main_test(void)
|
|
|
|
{
|
|
|
|
WCHAR temppathW[MAX_PATH], pathW[MAX_PATH];
|
|
|
|
struct test_input *test_input;
|
2019-01-17 19:42:42 +01:00
|
|
|
DWORD len, written, read;
|
2020-05-31 17:26:25 +02:00
|
|
|
UNICODE_STRING pathU;
|
2018-05-02 01:38:03 +02:00
|
|
|
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);
|
2020-12-09 23:00:08 +01:00
|
|
|
GetTempFileNameW(temppathW, L"dok", 0, pathW);
|
2018-05-02 01:38:03 +02:00
|
|
|
pRtlDosPathNameToNtPathName_U( pathW, &pathU, NULL, NULL );
|
|
|
|
|
2019-01-17 19:42:42 +01:00
|
|
|
len = pathU.Length + sizeof(WCHAR);
|
|
|
|
test_input = heap_alloc( offsetof( struct test_input, path[len / sizeof(WCHAR)]) );
|
2018-05-02 01:38:03 +02:00
|
|
|
test_input->running_under_wine = !strcmp(winetest_platform, "wine");
|
|
|
|
test_input->winetest_report_success = winetest_report_success;
|
|
|
|
test_input->winetest_debug = winetest_debug;
|
2020-05-31 17:26:25 +02:00
|
|
|
test_input->process_id = GetCurrentProcessId();
|
|
|
|
test_input->teststr_offset = (SIZE_T)((BYTE *)&teststr - (BYTE *)NtCurrentTeb()->Peb->ImageBaseAddress);
|
|
|
|
test_input->modified_value = &modified_value;
|
|
|
|
modified_value = 0;
|
|
|
|
|
2019-01-17 19:42:42 +01:00
|
|
|
memcpy(test_input->path, pathU.Buffer, len);
|
2019-01-10 07:11:15 +01:00
|
|
|
res = DeviceIoControl(device, IOCTL_WINETEST_MAIN_TEST, test_input,
|
2019-01-17 19:42:42 +01:00
|
|
|
offsetof( struct test_input, path[len / sizeof(WCHAR)]),
|
2018-05-02 01:38:03 +02:00
|
|
|
&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);
|
|
|
|
|
2019-01-17 17:42:39 +01:00
|
|
|
pRtlFreeUnicodeString(&pathU);
|
|
|
|
heap_free(test_input);
|
2018-05-02 01:38:03 +02:00
|
|
|
CloseHandle(okfile);
|
|
|
|
DeleteFileW(pathW);
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:59:58 +02:00
|
|
|
static void test_basic_ioctl(void)
|
|
|
|
{
|
2019-11-04 03:20:35 +01:00
|
|
|
char inbuf[64], buf[32];
|
2018-04-30 20:59:58 +02:00
|
|
|
DWORD written;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
res = DeviceIoControl(device, IOCTL_WINETEST_BASIC_IOCTL, NULL, 0, buf,
|
|
|
|
sizeof(buf), &written, NULL);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
ok(written == sizeof(teststr), "got size %d\n", written);
|
|
|
|
ok(!strcmp(buf, teststr), "got '%s'\n", buf);
|
2019-11-04 03:20:35 +01:00
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
res = DeviceIoControl(device, IOCTL_WINETEST_BASIC_IOCTL, inbuf,
|
|
|
|
sizeof(inbuf), buf, 10, &written, NULL);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
ok(written == 10, "got size %d\n", written);
|
|
|
|
ok(!strcmp(buf, "Wine is no"), "got '%s'\n", buf);
|
2018-04-30 20:59:58 +02:00
|
|
|
}
|
|
|
|
|
2019-11-25 16:43:05 +01:00
|
|
|
static void test_mismatched_status_ioctl(void)
|
|
|
|
{
|
|
|
|
DWORD written;
|
|
|
|
char buf[32];
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
res = DeviceIoControl(device, IOCTL_WINETEST_MISMATCHED_STATUS, NULL, 0, buf,
|
|
|
|
sizeof(buf), &written, NULL);
|
|
|
|
todo_wine ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
todo_wine ok(!strcmp(buf, teststr), "got '%s'\n", buf);
|
|
|
|
}
|
|
|
|
|
2019-05-07 16:15:33 +02:00
|
|
|
static void test_overlapped(void)
|
2019-05-02 13:21:29 +02:00
|
|
|
{
|
2019-05-07 16:15:33 +02:00
|
|
|
OVERLAPPED overlapped, overlapped2, *o;
|
|
|
|
DWORD cancel_cnt, size;
|
|
|
|
HANDLE file, port;
|
|
|
|
ULONG_PTR key;
|
2019-05-02 13:21:29 +02:00
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
overlapped.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
overlapped2.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
2019-05-07 16:15:33 +02:00
|
|
|
file = CreateFileA("\\\\.\\WineTestDriver", FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
|
|
|
|
0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
2019-05-02 13:21:29 +02:00
|
|
|
ok(file != INVALID_HANDLE_VALUE, "failed to open device: %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* test cancelling all device requests */
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_RESET_CANCEL, NULL, 0, NULL, 0, NULL, &overlapped);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_TEST_CANCEL, NULL, 0, NULL, 0, NULL, &overlapped);
|
|
|
|
ok(!res && GetLastError() == ERROR_IO_PENDING, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_TEST_CANCEL, NULL, 0, NULL, 0, NULL, &overlapped2);
|
|
|
|
ok(!res && GetLastError() == ERROR_IO_PENDING, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
cancel_cnt = 0xdeadbeef;
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_GET_CANCEL_COUNT, NULL, 0, &cancel_cnt, sizeof(cancel_cnt), NULL, &overlapped);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
ok(cancel_cnt == 0, "cancel_cnt = %u\n", cancel_cnt);
|
|
|
|
|
|
|
|
CancelIo(file);
|
|
|
|
|
|
|
|
cancel_cnt = 0xdeadbeef;
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_GET_CANCEL_COUNT, NULL, 0, &cancel_cnt, sizeof(cancel_cnt), NULL, &overlapped);
|
2019-05-27 13:38:10 +02:00
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
2019-05-02 13:21:29 +02:00
|
|
|
ok(cancel_cnt == 2, "cancel_cnt = %u\n", cancel_cnt);
|
|
|
|
|
|
|
|
/* test cancelling selected overlapped event */
|
2019-05-03 17:17:17 +02:00
|
|
|
if (pCancelIoEx)
|
|
|
|
{
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_RESET_CANCEL, NULL, 0, NULL, 0, NULL, &overlapped);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_TEST_CANCEL, NULL, 0, NULL, 0, NULL, &overlapped);
|
|
|
|
ok(!res && GetLastError() == ERROR_IO_PENDING, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_TEST_CANCEL, NULL, 0, NULL, 0, NULL, &overlapped2);
|
|
|
|
ok(!res && GetLastError() == ERROR_IO_PENDING, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
pCancelIoEx(file, &overlapped);
|
|
|
|
|
|
|
|
cancel_cnt = 0xdeadbeef;
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_GET_CANCEL_COUNT, NULL, 0, &cancel_cnt, sizeof(cancel_cnt), NULL, &overlapped);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
ok(cancel_cnt == 1, "cancel_cnt = %u\n", cancel_cnt);
|
|
|
|
|
|
|
|
pCancelIoEx(file, &overlapped2);
|
|
|
|
|
|
|
|
cancel_cnt = 0xdeadbeef;
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_GET_CANCEL_COUNT, NULL, 0, &cancel_cnt, sizeof(cancel_cnt), NULL, &overlapped);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
ok(cancel_cnt == 2, "cancel_cnt = %u\n", cancel_cnt);
|
|
|
|
}
|
2019-05-02 13:21:29 +02:00
|
|
|
|
2019-05-07 16:15:33 +02:00
|
|
|
port = CreateIoCompletionPort(file, NULL, 0xdeadbeef, 0);
|
|
|
|
ok(port != NULL, "CreateIoCompletionPort failed, error %u\n", GetLastError());
|
|
|
|
res = GetQueuedCompletionStatus(port, &size, &key, &o, 0);
|
|
|
|
ok(!res && GetLastError() == WAIT_TIMEOUT, "GetQueuedCompletionStatus returned %x(%u)\n", res, GetLastError());
|
|
|
|
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_RESET_CANCEL, NULL, 0, NULL, 0, NULL, &overlapped);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
res = GetQueuedCompletionStatus(port, &size, &key, &o, 0);
|
|
|
|
ok(res, "GetQueuedCompletionStatus failed: %u\n", GetLastError());
|
|
|
|
ok(o == &overlapped, "o != overlapped\n");
|
|
|
|
|
|
|
|
if (pSetFileCompletionNotificationModes)
|
|
|
|
{
|
|
|
|
res = pSetFileCompletionNotificationModes(file, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS);
|
|
|
|
ok(res, "SetFileCompletionNotificationModes failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
res = DeviceIoControl(file, IOCTL_WINETEST_RESET_CANCEL, NULL, 0, NULL, 0, NULL, &overlapped);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
res = GetQueuedCompletionStatus(port, &size, &key, &o, 0);
|
|
|
|
ok(!res && GetLastError() == WAIT_TIMEOUT, "GetQueuedCompletionStatus returned %x(%u)\n", res, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(port);
|
2019-05-02 13:21:29 +02:00
|
|
|
CloseHandle(overlapped.hEvent);
|
|
|
|
CloseHandle(overlapped2.hEvent);
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
|
2018-08-25 06:08:52 +02:00
|
|
|
static void test_load_driver(SC_HANDLE service)
|
|
|
|
{
|
|
|
|
SERVICE_STATUS status;
|
|
|
|
BOOL load, res;
|
|
|
|
DWORD sz;
|
|
|
|
|
|
|
|
res = QueryServiceStatus(service, &status);
|
|
|
|
ok(res, "QueryServiceStatusEx failed: %u\n", GetLastError());
|
|
|
|
ok(status.dwCurrentState == SERVICE_STOPPED, "got state %#x\n", status.dwCurrentState);
|
|
|
|
|
|
|
|
load = TRUE;
|
|
|
|
res = DeviceIoControl(device, IOCTL_WINETEST_LOAD_DRIVER, &load, sizeof(load), NULL, 0, &sz, NULL);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
res = QueryServiceStatus(service, &status);
|
|
|
|
ok(res, "QueryServiceStatusEx failed: %u\n", GetLastError());
|
|
|
|
ok(status.dwCurrentState == SERVICE_RUNNING, "got state %#x\n", status.dwCurrentState);
|
|
|
|
|
|
|
|
load = FALSE;
|
|
|
|
res = DeviceIoControl(device, IOCTL_WINETEST_LOAD_DRIVER, &load, sizeof(load), NULL, 0, &sz, NULL);
|
|
|
|
ok(res, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
res = QueryServiceStatus(service, &status);
|
|
|
|
ok(res, "QueryServiceStatusEx failed: %u\n", GetLastError());
|
|
|
|
ok(status.dwCurrentState == SERVICE_STOPPED, "got state %#x\n", status.dwCurrentState);
|
|
|
|
}
|
|
|
|
|
2019-08-07 05:48:41 +02:00
|
|
|
static void test_file_handles(void)
|
|
|
|
{
|
|
|
|
DWORD count, ret_size;
|
|
|
|
HANDLE file, dup, file2;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_CREATE_COUNT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 2, "got %u\n", count);
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_CLOSE_COUNT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 1, "got %u\n", count);
|
|
|
|
|
|
|
|
file = CreateFileA("\\\\.\\WineTestDriver", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "failed to open device: %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_CREATE_COUNT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 3, "got %u\n", count);
|
|
|
|
|
|
|
|
file2 = CreateFileA("\\\\.\\WineTestDriver", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(file2 != INVALID_HANDLE_VALUE, "failed to open device: %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_CREATE_COUNT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 4, "got %u\n", count);
|
|
|
|
|
|
|
|
ret = DuplicateHandle(GetCurrentProcess(), file, GetCurrentProcess(), &dup, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
|
|
|
ok(ret, "failed to duplicate handle: %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_CREATE_COUNT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 4, "got %u\n", count);
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_FSCONTEXT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 1, "got %u\n", count);
|
|
|
|
|
|
|
|
ret = DeviceIoControl(file, IOCTL_WINETEST_GET_FSCONTEXT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 3, "got %u\n", count);
|
|
|
|
|
|
|
|
ret = DeviceIoControl(file2, IOCTL_WINETEST_GET_FSCONTEXT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 4, "got %u\n", count);
|
|
|
|
|
|
|
|
ret = DeviceIoControl(dup, IOCTL_WINETEST_GET_FSCONTEXT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 3, "got %u\n", count);
|
|
|
|
|
|
|
|
CloseHandle(dup);
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_CLOSE_COUNT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 1, "got %u\n", count);
|
|
|
|
|
|
|
|
CloseHandle(file2);
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_CLOSE_COUNT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 2, "got %u\n", count);
|
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_GET_CLOSE_COUNT, NULL, 0, &count, sizeof(count), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed: %u\n", GetLastError());
|
|
|
|
ok(count == 3, "got %u\n", count);
|
|
|
|
}
|
|
|
|
|
2019-08-07 05:48:42 +02:00
|
|
|
static void test_return_status(void)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
char buffer[7];
|
|
|
|
DWORD ret_size;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
strcpy(buffer, "abcdef");
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_RETURN_STATUS, &status,
|
|
|
|
sizeof(status), buffer, sizeof(buffer), &ret_size, NULL);
|
|
|
|
ok(ret, "ioctl failed\n");
|
|
|
|
ok(GetLastError() == 0xdeadbeef, "got error %u\n", GetLastError());
|
|
|
|
ok(!strcmp(buffer, "ghidef"), "got buffer %s\n", buffer);
|
|
|
|
ok(ret_size == 3, "got size %u\n", ret_size);
|
|
|
|
|
|
|
|
strcpy(buffer, "abcdef");
|
|
|
|
status = STATUS_TIMEOUT;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_RETURN_STATUS, &status,
|
|
|
|
sizeof(status), buffer, sizeof(buffer), &ret_size, NULL);
|
|
|
|
todo_wine ok(ret, "ioctl failed\n");
|
|
|
|
todo_wine ok(GetLastError() == 0xdeadbeef, "got error %u\n", GetLastError());
|
|
|
|
ok(!strcmp(buffer, "ghidef"), "got buffer %s\n", buffer);
|
|
|
|
ok(ret_size == 3, "got size %u\n", ret_size);
|
|
|
|
|
|
|
|
strcpy(buffer, "abcdef");
|
|
|
|
status = 0x0eadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_RETURN_STATUS, &status,
|
|
|
|
sizeof(status), buffer, sizeof(buffer), &ret_size, NULL);
|
|
|
|
todo_wine ok(ret, "ioctl failed\n");
|
|
|
|
todo_wine ok(GetLastError() == 0xdeadbeef, "got error %u\n", GetLastError());
|
|
|
|
ok(!strcmp(buffer, "ghidef"), "got buffer %s\n", buffer);
|
|
|
|
ok(ret_size == 3, "got size %u\n", ret_size);
|
|
|
|
|
|
|
|
strcpy(buffer, "abcdef");
|
|
|
|
status = 0x4eadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_RETURN_STATUS, &status,
|
|
|
|
sizeof(status), buffer, sizeof(buffer), &ret_size, NULL);
|
|
|
|
todo_wine ok(ret, "ioctl failed\n");
|
|
|
|
todo_wine ok(GetLastError() == 0xdeadbeef, "got error %u\n", GetLastError());
|
|
|
|
ok(!strcmp(buffer, "ghidef"), "got buffer %s\n", buffer);
|
|
|
|
ok(ret_size == 3, "got size %u\n", ret_size);
|
|
|
|
|
|
|
|
strcpy(buffer, "abcdef");
|
|
|
|
status = 0x8eadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_RETURN_STATUS, &status,
|
|
|
|
sizeof(status), buffer, sizeof(buffer), &ret_size, NULL);
|
|
|
|
ok(!ret, "ioctl succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_MR_MID_NOT_FOUND, "got error %u\n", GetLastError());
|
2019-08-08 04:10:12 +02:00
|
|
|
ok(!strcmp(buffer, "ghidef"), "got buffer %s\n", buffer);
|
2019-08-07 05:48:43 +02:00
|
|
|
ok(ret_size == 3, "got size %u\n", ret_size);
|
2019-08-07 05:48:42 +02:00
|
|
|
|
|
|
|
strcpy(buffer, "abcdef");
|
|
|
|
status = 0xceadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_RETURN_STATUS, &status,
|
|
|
|
sizeof(status), buffer, sizeof(buffer), &ret_size, NULL);
|
|
|
|
ok(!ret, "ioctl succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_MR_MID_NOT_FOUND, "got error %u\n", GetLastError());
|
|
|
|
ok(!strcmp(buffer, "abcdef"), "got buffer %s\n", buffer);
|
2019-08-07 05:48:43 +02:00
|
|
|
ok(ret_size == 3, "got size %u\n", ret_size);
|
2019-08-07 05:48:42 +02:00
|
|
|
}
|
|
|
|
|
2020-07-31 01:04:20 +02:00
|
|
|
static BOOL compare_unicode_string(const WCHAR *buffer, ULONG len, const WCHAR *expect)
|
|
|
|
{
|
|
|
|
return len == wcslen(expect) * sizeof(WCHAR) && !memcmp(buffer, expect, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_object_info(void)
|
|
|
|
{
|
|
|
|
char buffer[200];
|
|
|
|
OBJECT_NAME_INFORMATION *name_info = (OBJECT_NAME_INFORMATION *)buffer;
|
|
|
|
OBJECT_TYPE_INFORMATION *type_info = (OBJECT_TYPE_INFORMATION *)buffer;
|
2020-10-28 20:39:50 +01:00
|
|
|
FILE_FS_VOLUME_INFORMATION *volume_info = (FILE_FS_VOLUME_INFORMATION *)buffer;
|
2020-07-31 01:04:20 +02:00
|
|
|
FILE_NAME_INFORMATION *file_info = (FILE_NAME_INFORMATION *)buffer;
|
|
|
|
HANDLE file;
|
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
ULONG size;
|
|
|
|
|
|
|
|
status = NtQueryObject(device, ObjectNameInformation, buffer, sizeof(buffer), NULL);
|
|
|
|
ok(!status, "got %#x\n", status);
|
2020-09-22 16:56:42 +02:00
|
|
|
ok(compare_unicode_string(name_info->Name.Buffer, name_info->Name.Length, L"\\Device\\WineTestDriver"),
|
2020-07-31 01:04:20 +02:00
|
|
|
"wrong name %s\n", debugstr_w(name_info->Name.Buffer));
|
|
|
|
|
|
|
|
status = NtQueryObject(device, ObjectTypeInformation, buffer, sizeof(buffer), NULL);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(compare_unicode_string(type_info->TypeName.Buffer, type_info->TypeName.Length, L"File"),
|
|
|
|
"wrong name %s\n", debugstr_wn(type_info->TypeName.Buffer, type_info->TypeName.Length / sizeof(WCHAR)));
|
|
|
|
|
|
|
|
status = NtQueryInformationFile(device, &io, buffer, sizeof(buffer), FileNameInformation);
|
|
|
|
todo_wine ok(status == STATUS_INVALID_DEVICE_REQUEST, "got %#x\n", status);
|
|
|
|
|
2020-10-28 20:39:50 +01:00
|
|
|
status = NtQueryVolumeInformationFile(device, &io, buffer, sizeof(buffer), FileFsVolumeInformation);
|
|
|
|
todo_wine ok(status == STATUS_INVALID_DEVICE_REQUEST, "got %#x\n", status);
|
|
|
|
|
2020-07-31 01:04:20 +02:00
|
|
|
file = CreateFileA("\\\\.\\WineTestDriver\\subfile", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
todo_wine ok(file != INVALID_HANDLE_VALUE, "got error %u\n", GetLastError());
|
|
|
|
if (file == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
memset(buffer, 0xcc, sizeof(buffer));
|
|
|
|
status = NtQueryObject(file, ObjectNameInformation, buffer, sizeof(buffer), &size);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(size == sizeof(*name_info) + sizeof(L"\\Device\\WineTestDriver\\subfile"), "wrong size %u\n", size);
|
|
|
|
ok(compare_unicode_string(name_info->Name.Buffer, name_info->Name.Length, L"\\Device\\WineTestDriver\\subfile"),
|
|
|
|
"wrong name %s\n", debugstr_w(name_info->Name.Buffer));
|
|
|
|
|
|
|
|
memset(buffer, 0xcc, sizeof(buffer));
|
|
|
|
status = NtQueryObject(file, ObjectNameInformation, buffer, size - 2, &size);
|
|
|
|
ok(status == STATUS_BUFFER_OVERFLOW, "got %#x\n", status);
|
|
|
|
ok(size == sizeof(*name_info) + sizeof(L"\\Device\\WineTestDriver\\subfile"), "wrong size %u\n", size);
|
|
|
|
ok(compare_unicode_string(name_info->Name.Buffer, name_info->Name.Length, L"\\Device\\WineTestDriver\\subfil"),
|
|
|
|
"wrong name %s\n", debugstr_w(name_info->Name.Buffer));
|
|
|
|
|
|
|
|
memset(buffer, 0xcc, sizeof(buffer));
|
|
|
|
status = NtQueryObject(file, ObjectNameInformation, buffer, sizeof(*name_info), &size);
|
|
|
|
ok(status == STATUS_BUFFER_OVERFLOW, "got %#x\n", status);
|
|
|
|
ok(size == sizeof(*name_info) + sizeof(L"\\Device\\WineTestDriver\\subfile"), "wrong size %u\n", size);
|
|
|
|
|
|
|
|
status = NtQueryObject(file, ObjectTypeInformation, buffer, sizeof(buffer), NULL);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(compare_unicode_string(type_info->TypeName.Buffer, type_info->TypeName.Length, L"File"),
|
|
|
|
"wrong name %s\n", debugstr_wn(type_info->TypeName.Buffer, type_info->TypeName.Length / sizeof(WCHAR)));
|
|
|
|
|
|
|
|
status = NtQueryInformationFile(file, &io, buffer, sizeof(buffer), FileNameInformation);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(compare_unicode_string(file_info->FileName, file_info->FileNameLength, L"\\subfile"),
|
|
|
|
"wrong name %s\n", debugstr_wn(file_info->FileName, file_info->FileNameLength / sizeof(WCHAR)));
|
|
|
|
|
2020-10-28 20:39:50 +01:00
|
|
|
status = NtQueryVolumeInformationFile(file, &io, buffer, sizeof(buffer), FileFsVolumeInformation);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(volume_info->VolumeSerialNumber == 0xdeadbeef,
|
|
|
|
"wrong serial number 0x%08x\n", volume_info->VolumeSerialNumber);
|
|
|
|
ok(compare_unicode_string(volume_info->VolumeLabel, volume_info->VolumeLabelLength, L"WineTestDriver"),
|
|
|
|
"wrong name %s\n", debugstr_wn(volume_info->VolumeLabel, volume_info->VolumeLabelLength / sizeof(WCHAR)));
|
|
|
|
|
2020-07-31 01:04:20 +02:00
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
file = CreateFileA("\\\\.\\WineTestDriver\\notimpl", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "got error %u\n", GetLastError());
|
|
|
|
|
|
|
|
status = NtQueryObject(file, ObjectNameInformation, buffer, sizeof(buffer), NULL);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(compare_unicode_string(name_info->Name.Buffer, name_info->Name.Length, L"\\Device\\WineTestDriver"),
|
|
|
|
"wrong name %s\n", debugstr_w(name_info->Name.Buffer));
|
|
|
|
|
|
|
|
status = NtQueryInformationFile(file, &io, buffer, sizeof(buffer), FileNameInformation);
|
|
|
|
ok(status == STATUS_NOT_IMPLEMENTED, "got %#x\n", status);
|
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
file = CreateFileA("\\\\.\\WineTestDriver\\badparam", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "got error %u\n", GetLastError());
|
|
|
|
|
|
|
|
status = NtQueryObject(file, ObjectNameInformation, buffer, sizeof(buffer), NULL);
|
|
|
|
ok(!status, "got %#x\n", status);
|
|
|
|
ok(compare_unicode_string(name_info->Name.Buffer, name_info->Name.Length, L"\\Device\\WineTestDriver"),
|
|
|
|
"wrong name %s\n", debugstr_w(name_info->Name.Buffer));
|
|
|
|
|
|
|
|
status = NtQueryInformationFile(file, &io, buffer, sizeof(buffer), FileNameInformation);
|
|
|
|
ok(status == STATUS_INVALID_PARAMETER, "got %#x\n", status);
|
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
file = CreateFileA("\\\\.\\WineTestDriver\\genfail", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "got error %u\n", GetLastError());
|
|
|
|
|
|
|
|
status = NtQueryObject(file, ObjectNameInformation, buffer, sizeof(buffer), NULL);
|
|
|
|
ok(status == STATUS_UNSUCCESSFUL, "got %#x\n", status);
|
|
|
|
|
|
|
|
status = NtQueryInformationFile(file, &io, buffer, sizeof(buffer), FileNameInformation);
|
|
|
|
ok(status == STATUS_UNSUCCESSFUL, "got %#x\n", status);
|
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
file = CreateFileA("\\\\.\\WineTestDriver\\badtype", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "got error %u\n", GetLastError());
|
|
|
|
|
|
|
|
status = NtQueryObject(file, ObjectNameInformation, buffer, sizeof(buffer), NULL);
|
|
|
|
ok(status == STATUS_OBJECT_TYPE_MISMATCH, "got %#x\n", status);
|
|
|
|
|
|
|
|
status = NtQueryInformationFile(file, &io, buffer, sizeof(buffer), FileNameInformation);
|
|
|
|
ok(status == STATUS_OBJECT_TYPE_MISMATCH, "got %#x\n", status);
|
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
|
2018-09-06 11:01:28 +02:00
|
|
|
static void test_driver3(void)
|
|
|
|
{
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
SC_HANDLE service;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
service = load_driver(filename, "driver3.dll", "WineTestDriver3");
|
|
|
|
ok(service != NULL, "driver3 failed to load\n");
|
|
|
|
|
|
|
|
ret = StartServiceA(service, 0, NULL);
|
|
|
|
ok(!ret, "driver3 should fail to start\n");
|
2018-09-19 19:21:17 +02:00
|
|
|
ok(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ||
|
|
|
|
GetLastError() == ERROR_INVALID_FUNCTION ||
|
|
|
|
GetLastError() == ERROR_PROC_NOT_FOUND /* XP */ ||
|
2018-09-06 11:01:28 +02:00
|
|
|
GetLastError() == ERROR_FILE_NOT_FOUND /* Win7 */, "got %u\n", GetLastError());
|
|
|
|
|
|
|
|
DeleteService(service);
|
|
|
|
CloseServiceHandle(service);
|
|
|
|
DeleteFileA(filename);
|
|
|
|
}
|
|
|
|
|
2020-06-17 19:22:00 +02:00
|
|
|
static DWORD WINAPI wsk_test_thread(void *parameter)
|
|
|
|
{
|
2020-06-19 12:13:16 +02:00
|
|
|
static const char test_send_string[] = "Client test string 1.";
|
2020-06-17 19:22:00 +02:00
|
|
|
static const WORD version = MAKEWORD(2, 2);
|
2020-06-22 23:27:07 +02:00
|
|
|
SOCKET s_listen, s_accept, s_connect;
|
2020-06-17 19:22:00 +02:00
|
|
|
struct sockaddr_in addr;
|
2020-06-19 12:13:16 +02:00
|
|
|
char buffer[256];
|
2020-06-17 19:22:00 +02:00
|
|
|
int ret, err;
|
|
|
|
WSADATA data;
|
2020-06-22 23:27:07 +02:00
|
|
|
int opt_val;
|
2020-06-17 19:22:00 +02:00
|
|
|
|
|
|
|
ret = WSAStartup(version, &data);
|
|
|
|
ok(!ret, "WSAStartup() failed, ret %u.\n", ret);
|
|
|
|
|
2020-06-22 23:27:07 +02:00
|
|
|
s_connect = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
ok(s_connect != INVALID_SOCKET, "Error creating socket, WSAGetLastError() %u.\n", WSAGetLastError());
|
|
|
|
|
|
|
|
s_listen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
ok(s_listen != INVALID_SOCKET, "Error creating socket, WSAGetLastError() %u.\n", WSAGetLastError());
|
|
|
|
|
|
|
|
opt_val = 1;
|
|
|
|
setsockopt(s_listen, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt_val, sizeof(opt_val));
|
2020-06-17 19:22:00 +02:00
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sin_family = AF_INET;
|
2020-06-22 23:27:07 +02:00
|
|
|
addr.sin_port = htons(CLIENT_LISTEN_PORT);
|
2020-06-17 19:22:00 +02:00
|
|
|
addr.sin_addr.s_addr = htonl(0x7f000001);
|
2020-06-22 23:27:07 +02:00
|
|
|
ret = bind(s_listen, (struct sockaddr *)&addr, sizeof(addr));
|
|
|
|
ok(!ret, "Got unexpected ret %d, WSAGetLastError() %u.\n", ret, WSAGetLastError());
|
|
|
|
|
|
|
|
ret = listen(s_listen, SOMAXCONN);
|
|
|
|
ok(!ret, "Got unexpected ret %d, WSAGetLastError() %u.\n", ret, WSAGetLastError());
|
2020-06-17 19:22:00 +02:00
|
|
|
|
2020-06-22 23:27:07 +02:00
|
|
|
addr.sin_port = htons(SERVER_LISTEN_PORT);
|
|
|
|
|
|
|
|
ret = connect(s_connect, (struct sockaddr *)&addr, sizeof(addr));
|
2020-06-17 19:22:00 +02:00
|
|
|
while (ret && ((err = WSAGetLastError()) == WSAECONNREFUSED || err == WSAECONNABORTED))
|
|
|
|
{
|
|
|
|
SwitchToThread();
|
2020-06-22 23:27:07 +02:00
|
|
|
ret = connect(s_connect, (struct sockaddr *)&addr, sizeof(addr));
|
2020-06-17 19:22:00 +02:00
|
|
|
}
|
|
|
|
ok(!ret, "Error connecting, WSAGetLastError() %u.\n", WSAGetLastError());
|
|
|
|
|
2020-06-22 23:27:07 +02:00
|
|
|
ret = send(s_connect, test_send_string, sizeof(test_send_string), 0);
|
2020-06-19 12:13:16 +02:00
|
|
|
ok(ret == sizeof(test_send_string), "Got unexpected ret %d.\n", ret);
|
|
|
|
|
2020-06-22 23:27:07 +02:00
|
|
|
ret = recv(s_connect, buffer, sizeof(buffer), 0);
|
2020-06-19 12:13:16 +02:00
|
|
|
ok(ret == sizeof(buffer), "Got unexpected ret %d.\n", ret);
|
|
|
|
ok(!strcmp(buffer, "Server test string 1."), "Received unexpected data.\n");
|
|
|
|
|
2020-06-22 23:27:07 +02:00
|
|
|
s_accept = accept(s_listen, NULL, NULL);
|
|
|
|
ok(s_accept != INVALID_SOCKET, "Error creating socket, WSAGetLastError() %u.\n", WSAGetLastError());
|
|
|
|
|
|
|
|
closesocket(s_accept);
|
|
|
|
closesocket(s_connect);
|
|
|
|
closesocket(s_listen);
|
2020-06-17 19:22:00 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_driver4(void)
|
2020-06-11 16:47:45 +02:00
|
|
|
{
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
SC_HANDLE service;
|
2020-06-17 19:22:00 +02:00
|
|
|
HANDLE hthread;
|
2020-06-11 16:47:45 +02:00
|
|
|
DWORD written;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!(service = load_driver(filename, "driver4.dll", "WineTestDriver4")))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!start_driver(service, TRUE))
|
|
|
|
{
|
|
|
|
DeleteFileA(filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
device = CreateFileA("\\\\.\\WineTestDriver4", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(device != INVALID_HANDLE_VALUE, "failed to open device: %u\n", GetLastError());
|
|
|
|
|
2020-06-17 19:22:00 +02:00
|
|
|
hthread = CreateThread(NULL, 0, wsk_test_thread, NULL, 0, NULL);
|
2020-06-11 16:47:45 +02:00
|
|
|
main_test();
|
2020-06-17 19:22:00 +02:00
|
|
|
WaitForSingleObject(hthread, INFINITE);
|
2020-06-11 16:47:45 +02:00
|
|
|
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_DETACH, NULL, 0, NULL, 0, &written, NULL);
|
|
|
|
ok(ret, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(device);
|
|
|
|
|
|
|
|
unload_driver(service);
|
|
|
|
ret = DeleteFileA(filename);
|
|
|
|
ok(ret, "DeleteFile failed: %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:59:58 +02:00
|
|
|
START_TEST(ntoskrnl)
|
|
|
|
{
|
2018-08-25 06:08:52 +02:00
|
|
|
char filename[MAX_PATH], filename2[MAX_PATH];
|
|
|
|
SC_HANDLE service, service2;
|
2019-06-06 17:12:51 +02:00
|
|
|
DWORD written;
|
|
|
|
BOOL ret;
|
2018-04-30 20:59:58 +02:00
|
|
|
|
2018-05-02 01:38:03 +02:00
|
|
|
HMODULE hntdll = GetModuleHandleA("ntdll.dll");
|
|
|
|
pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
|
2019-01-17 17:42:39 +01:00
|
|
|
pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
|
2019-05-03 17:17:17 +02:00
|
|
|
pCancelIoEx = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "CancelIoEx");
|
2019-05-07 16:15:33 +02:00
|
|
|
pSetFileCompletionNotificationModes = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),
|
|
|
|
"SetFileCompletionNotificationModes");
|
2018-05-02 01:38:03 +02:00
|
|
|
|
2019-08-27 04:14:40 +02:00
|
|
|
subtest("driver");
|
2018-08-25 06:08:52 +02:00
|
|
|
if (!(service = load_driver(filename, "driver.dll", "WineTestDriver")))
|
|
|
|
return;
|
2020-06-11 16:47:45 +02:00
|
|
|
if (!start_driver(service, FALSE))
|
2018-08-25 06:08:52 +02:00
|
|
|
{
|
|
|
|
DeleteFileA(filename);
|
2018-04-30 20:59:58 +02:00
|
|
|
return;
|
2018-08-25 06:08:52 +02:00
|
|
|
}
|
|
|
|
service2 = load_driver(filename2, "driver2.dll", "WineTestDriver2");
|
|
|
|
|
|
|
|
device = CreateFileA("\\\\.\\WineTestDriver", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
ok(device != INVALID_HANDLE_VALUE, "failed to open device: %u\n", GetLastError());
|
2018-04-30 20:59:58 +02:00
|
|
|
|
|
|
|
test_basic_ioctl();
|
2019-11-25 16:43:05 +01:00
|
|
|
test_mismatched_status_ioctl();
|
2020-06-11 16:47:45 +02:00
|
|
|
|
2018-05-02 01:38:03 +02:00
|
|
|
main_test();
|
2020-06-11 16:47:45 +02:00
|
|
|
todo_wine ok(modified_value == 0xdeadbeeffeedcafe, "Got unexpected value %#I64x.\n", modified_value);
|
|
|
|
|
2019-05-07 16:15:33 +02:00
|
|
|
test_overlapped();
|
2018-08-25 06:08:52 +02:00
|
|
|
test_load_driver(service2);
|
2019-08-07 05:48:41 +02:00
|
|
|
test_file_handles();
|
2019-08-07 05:48:42 +02:00
|
|
|
test_return_status();
|
2020-07-31 01:04:20 +02:00
|
|
|
test_object_info();
|
2018-04-30 20:59:58 +02:00
|
|
|
|
2019-06-06 17:12:51 +02:00
|
|
|
/* We need a separate ioctl to call IoDetachDevice(); calling it in the
|
|
|
|
* driver unload routine causes a live-lock. */
|
|
|
|
ret = DeviceIoControl(device, IOCTL_WINETEST_DETACH, NULL, 0, NULL, 0, &written, NULL);
|
|
|
|
ok(ret, "DeviceIoControl failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(device);
|
|
|
|
|
2018-08-25 06:08:52 +02:00
|
|
|
unload_driver(service2);
|
2018-04-30 20:59:58 +02:00
|
|
|
unload_driver(service);
|
2019-06-09 18:17:21 +02:00
|
|
|
ret = DeleteFileA(filename);
|
|
|
|
ok(ret, "DeleteFile failed: %u\n", GetLastError());
|
|
|
|
ret = DeleteFileA(filename2);
|
|
|
|
ok(ret, "DeleteFile failed: %u\n", GetLastError());
|
2018-09-06 11:01:28 +02:00
|
|
|
|
|
|
|
test_driver3();
|
2020-06-11 16:47:45 +02:00
|
|
|
subtest("driver4");
|
|
|
|
test_driver4();
|
2018-04-30 20:59:58 +02:00
|
|
|
}
|