This should help with stale devices when some test crashed.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/ntoskrnl.exe/tests/ntoskrnl.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index c8c6354b793..b3ea894c947 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -1407,6 +1407,7 @@ static void driver_start(struct testsign_context *ctx, const WCHAR *resource) static const WCHAR hardware_id[] = L"test_hardware_id\0"; SP_DEVINFO_DATA device = {sizeof(SP_DEVINFO_DATA)}; WCHAR path[MAX_PATH], filename[MAX_PATH]; + SC_HANDLE manager, service; BOOL ret, need_reboot; HANDLE catalog; HDEVINFO set; @@ -1443,7 +1444,30 @@ static void driver_start(struct testsign_context *ctx, const WCHAR *resource) ok(set != INVALID_HANDLE_VALUE, "failed to create device list, error %u\n", GetLastError());
ret = SetupDiCreateDeviceInfoW(set, L"root\winetest\0", &GUID_NULL, NULL, NULL, 0, &device); - ok(ret, "failed to create device, error %u\n", GetLastError()); + if (!ret && GetLastError() == ERROR_DEVINST_ALREADY_EXISTS) + { + ret = SetupDiOpenDeviceInfoW(set, L"root\winetest\0", NULL, 0, &device); + ok(ret, "failed to open device, error %#x\n", GetLastError()); + + ret = SetupDiCallClassInstaller(DIF_REMOVE, set, &device); + ok(ret, "failed to remove device, error %u\n", GetLastError()); + + ret = SetupDiDeleteDeviceInfo(set, &device); + ok(ret, "failed to delete device info, error %u\n", GetLastError()); + + /* Windows stops the service but does not delete it. */ + manager = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT); + ok(!!manager, "failed to open service manager, error %u\n", GetLastError()); + + service = OpenServiceW(manager, L"winetest", SERVICE_STOP | DELETE); + if (service) unload_driver(service); + else ok(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST, "got error %u\n", GetLastError()); + + CloseServiceHandle(manager); + + ret = SetupDiCreateDeviceInfoW(set, L"root\winetest\0", &GUID_NULL, NULL, NULL, 0, &device); + } + ok(ret, "failed to create device, error %#x\n", GetLastError());
ret = SetupDiSetDeviceRegistryPropertyW( set, &device, SPDRP_HARDWAREID, (const BYTE *)hardware_id, sizeof(hardware_id) );