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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index fc213948f35..cf4b9d811cb 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -1416,6 +1416,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; @@ -1462,6 +1463,29 @@ static void driver_start(struct testsign_context *ctx, const WCHAR *resource) ok(set != INVALID_HANDLE_VALUE, "failed to create device list, error %#x\n", GetLastError());
ret = SetupDiCreateDeviceInfoW(set, L"root\winetest\0", &GUID_NULL, NULL, NULL, 0, &device); + 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,