Reactos

[KMTEST] Handle failure in KmtLoadDriver and KmtOpenDriver

+125 -57
+5 -3
modules/rostests/kmtests/example/Example_user.c
··· 15 15 SYSTEM_INFO SystemInfo; 16 16 MY_STRUCT MyStruct[2] = { { 123, ":D" }, { 0 } }; 17 17 DWORD Length = sizeof MyStruct; 18 + DWORD Error; 18 19 19 20 trace("Message from user-mode\n"); 20 21 ··· 26 27 KmtRunKernelTest("Example"); 27 28 28 29 /* now start the special-purpose driver */ 29 - KmtLoadDriver(L"Example", FALSE); 30 - trace("After Entry\n"); 31 - KmtOpenDriver(); 30 + Error = KmtLoadAndOpenDriver(L"Example", FALSE); 31 + ok_eq_int(Error, ERROR_SUCCESS); 32 + if (Error) 33 + return; 32 34 trace("After Create\n"); 33 35 34 36 ok(KmtSendToDriver(IOCTL_NOTIFY) == ERROR_SUCCESS, "\n");
+5 -3
modules/rostests/kmtests/hidparse/HidP_user.c
··· 22 22 KmtStartService(L"hidusb", &ServiceHandle); 23 23 CloseServiceHandle(ServiceHandle); 24 24 25 - KmtLoadDriver(L"HidP", FALSE); 26 - KmtOpenDriver(); 25 + Error = KmtLoadAndOpenDriver(L"HidP", FALSE); 26 + ok_eq_int(Error, ERROR_SUCCESS); 27 + if (Error) 28 + return; 27 29 28 30 Error = KmtSendToDriver(IOCTL_TEST_DESCRIPTION); 29 31 ok(Error == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lx\n", Error); 30 32 31 33 KmtCloseDriver(); 32 34 KmtUnloadDriver(); 33 - } 35 + }
+3 -2
modules/rostests/kmtests/include/kmt_test.h
··· 169 169 #elif defined KMT_USER_MODE 170 170 DWORD KmtRunKernelTest(IN PCSTR TestName); 171 171 172 - VOID KmtLoadDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning); 172 + DWORD KmtLoadDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning); 173 173 VOID KmtUnloadDriver(VOID); 174 - VOID KmtOpenDriver(VOID); 174 + DWORD KmtOpenDriver(VOID); 175 175 VOID KmtCloseDriver(VOID); 176 + DWORD KmtLoadAndOpenDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning); 176 177 177 178 DWORD KmtSendToDriver(IN DWORD ControlCode); 178 179 DWORD KmtSendStringToDriver(IN DWORD ControlCode, IN PCSTR String);
+5 -2
modules/rostests/kmtests/kernel32/FileAttributes_user.c
··· 15 15 PCWSTR FileName = L"\\\\.\\Global\\GLOBALROOT\\Device\\Kmtest-kernel32\\Somefile"; 16 16 BOOL Ret; 17 17 DWORD Attributes; 18 + DWORD Error; 18 19 19 - KmtLoadDriver(L"kernel32", FALSE); 20 - KmtOpenDriver(); 20 + Error = KmtLoadAndOpenDriver(L"kernel32", FALSE); 21 + ok_eq_int(Error, ERROR_SUCCESS); 22 + if (Error) 23 + return; 21 24 22 25 /* Set read-only attribute */ 23 26 KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL);
+5 -2
modules/rostests/kmtests/kernel32/FindFile_user.c
··· 97 97 const INT TestCount = sizeof(Tests) / sizeof(Tests[0]); 98 98 INT i; 99 99 WCHAR ExpressionBuffer[MAX_PATH]; 100 + DWORD Error; 100 101 101 - KmtLoadDriver(L"kernel32", FALSE); 102 - KmtOpenDriver(); 102 + Error = KmtLoadAndOpenDriver(L"kernel32", FALSE); 103 + ok_eq_int(Error, ERROR_SUCCESS); 104 + if (Error) 105 + return; 103 106 104 107 for (i = 0; i < TestCount; i++) 105 108 {
+26 -16
modules/rostests/kmtests/kmtest/support.c
··· 124 124 * @param RestartIfRunning 125 125 * TRUE to stop and restart the service if it is already running 126 126 */ 127 - VOID 127 + DWORD 128 128 KmtLoadDriver( 129 129 IN PCWSTR ServiceName, 130 130 IN BOOLEAN RestartIfRunning) 131 131 { 132 - DWORD Error = ERROR_SUCCESS; 133 132 WCHAR ServicePath[MAX_PATH]; 134 133 135 134 StringCbCopyW(ServicePath, sizeof(ServicePath), ServiceName); ··· 138 137 StringCbCopyW(TestServiceName, sizeof(TestServiceName), L"Kmtest-"); 139 138 StringCbCatW(TestServiceName, sizeof(TestServiceName), ServiceName); 140 139 141 - Error = KmtCreateAndStartService(TestServiceName, ServicePath, NULL, &TestServiceHandle, RestartIfRunning); 142 - 143 - if (Error) 144 - { 145 - // TODO 146 - __debugbreak(); 147 - } 140 + return KmtCreateAndStartService(TestServiceName, ServicePath, NULL, &TestServiceHandle, RestartIfRunning); 148 141 } 149 142 150 143 /** ··· 177 170 * 178 171 * Open special-purpose driver (acquire a device handle) 179 172 */ 180 - VOID 173 + DWORD 181 174 KmtOpenDriver(VOID) 182 175 { 183 176 DWORD Error = ERROR_SUCCESS; ··· 190 183 if (TestDeviceHandle == INVALID_HANDLE_VALUE) 191 184 error(Error); 192 185 186 + return Error; 187 + } 188 + 189 + /** 190 + * @name KmtOpenDriver 191 + * 192 + * Load and open special-purpose driver (acquire a device handle) 193 + */ 194 + DWORD 195 + KmtLoadAndOpenDriver( 196 + IN PCWSTR ServiceName, 197 + IN BOOLEAN RestartIfRunning) 198 + { 199 + DWORD Error; 200 + 201 + Error = KmtLoadDriver(ServiceName, RestartIfRunning); 193 202 if (Error) 194 - { 195 - // TODO 196 - __debugbreak(); 197 - } 203 + return Error; 204 + 205 + Error = KmtOpenDriver(); 206 + if (Error) 207 + return Error; 198 208 209 + return ERROR_SUCCESS; 199 210 } 200 211 201 212 /** ··· 213 224 214 225 if (Error) 215 226 { 216 - // TODO 217 - __debugbreak(); 227 + DPRINT1("CloseHandle failed: 0x%lx\n", Error); 218 228 } 219 229 } 220 230
+5 -2
modules/rostests/kmtests/ntos_cc/CcCopyRead_user.c
··· 20 20 UNICODE_STRING ReallySmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\ReallySmallAlignmentTest"); 21 21 UNICODE_STRING FileBig = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\FileBig"); 22 22 UNICODE_STRING BehaviourTestFile = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\BehaviourTestFile"); 23 + DWORD Error; 23 24 24 - KmtLoadDriver(L"CcCopyRead", FALSE); 25 - KmtOpenDriver(); 25 + Error = KmtLoadAndOpenDriver(L"CcCopyRead", FALSE); 26 + ok_eq_int(Error, ERROR_SUCCESS); 27 + if (Error) 28 + return; 26 29 27 30 InitializeObjectAttributes(&ObjectAttributes, &SmallAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL); 28 31 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
+5 -2
modules/rostests/kmtests/ntos_cc/CcCopyWrite_user.c
··· 20 20 UNICODE_STRING VerySmallFile = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyWrite\\VerySmallFile"); 21 21 UNICODE_STRING NormalFile = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyWrite\\NormalFile"); 22 22 UNICODE_STRING BehaviourTestFile = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyWrite\\BehaviourTestFile"); 23 + DWORD Error; 23 24 24 - KmtLoadDriver(L"CcCopyWrite", FALSE); 25 - KmtOpenDriver(); 25 + Error = KmtLoadAndOpenDriver(L"CcCopyWrite", FALSE); 26 + ok_eq_int(Error, ERROR_SUCCESS); 27 + if (Error) 28 + return; 26 29 27 30 InitializeObjectAttributes(&ObjectAttributes, &VerySmallFile, OBJ_CASE_INSENSITIVE, NULL, NULL); 28 31 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
+4 -2
modules/rostests/kmtests/ntos_cc/CcMapData_user.c
··· 15 15 DWORD Ret; 16 16 ULONG TestId; 17 17 18 - KmtLoadDriver(L"CcMapData", FALSE); 19 - KmtOpenDriver(); 18 + Ret = KmtLoadAndOpenDriver(L"CcMapData", FALSE); 19 + ok_eq_int(Ret, ERROR_SUCCESS); 20 + if (Ret) 21 + return; 20 22 21 23 /* 3 tests for offset 22 24 * 1 test for BCB
+4 -2
modules/rostests/kmtests/ntos_cc/CcPinMappedData_user.c
··· 15 15 DWORD Ret; 16 16 ULONG TestId; 17 17 18 - KmtLoadDriver(L"CcPinMappedData", FALSE); 19 - KmtOpenDriver(); 18 + Ret = KmtLoadAndOpenDriver(L"CcPinMappedData", FALSE); 19 + ok_eq_int(Ret, ERROR_SUCCESS); 20 + if (Ret) 21 + return; 20 22 21 23 /* 1 basic test */ 22 24 for (TestId = 0; TestId < 5; ++TestId)
+4 -2
modules/rostests/kmtests/ntos_cc/CcPinRead_user.c
··· 15 15 DWORD Ret; 16 16 ULONG TestId; 17 17 18 - KmtLoadDriver(L"CcPinRead", FALSE); 19 - KmtOpenDriver(); 18 + Ret = KmtLoadAndOpenDriver(L"CcPinRead", FALSE); 19 + ok_eq_int(Ret, ERROR_SUCCESS); 20 + if (Ret) 21 + return; 20 22 21 23 /* 3 tests for offset 22 24 * 1 test for BCB
+4 -2
modules/rostests/kmtests/ntos_cc/CcSetFileSizes_user.c
··· 15 15 DWORD Ret; 16 16 ULONG TestId; 17 17 18 - KmtLoadDriver(L"CcSetFileSizes", FALSE); 19 - KmtOpenDriver(); 18 + Ret = KmtLoadAndOpenDriver(L"CcSetFileSizes", FALSE); 19 + ok_eq_int(Ret, ERROR_SUCCESS); 20 + if (Ret) 21 + return; 20 22 21 23 /* 0: mapped data - only FS 22 24 * 1: copy read - only FS
+4 -2
modules/rostests/kmtests/ntos_io/IoCreateFile_user.c
··· 18 18 19 19 KmtRunKernelTest("IoCreateFile"); 20 20 21 - KmtLoadDriver(L"IoCreateFile", FALSE); 22 - KmtOpenDriver(); 21 + Error = KmtLoadAndOpenDriver(L"IoCreateFile", FALSE); 22 + ok_eq_int(Error, ERROR_SUCCESS); 23 + if (Error) 24 + return; 23 25 24 26 Error = KmtSendStringToDriver(IOCTL_CALL_CREATE, NonSymlinkedFileName); 25 27 ok(Error == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lx\n", Error);
+11 -3
modules/rostests/kmtests/ntos_io/IoDeviceObject_user.c
··· 9 9 10 10 START_TEST(IoDeviceObject) 11 11 { 12 + DWORD Error; 13 + 12 14 /* make sure IoHelper has an existing service key, but is not started */ 13 - KmtLoadDriver(L"IoHelper", FALSE); 15 + Error = KmtLoadDriver(L"IoHelper", FALSE); 16 + ok_eq_int(Error, ERROR_SUCCESS); 17 + if (Error) 18 + return; 14 19 KmtUnloadDriver(); 15 20 16 - KmtLoadDriver(L"IoDeviceObject", TRUE); 17 - KmtOpenDriver(); 21 + Error = KmtLoadAndOpenDriver(L"IoDeviceObject", TRUE); 22 + ok_eq_int(Error, ERROR_SUCCESS); 23 + if (Error) 24 + return; 25 + 18 26 KmtCloseDriver(); 19 27 KmtUnloadDriver(); 20 28 }
+5 -2
modules/rostests/kmtests/ntos_io/IoReadWrite_user.c
··· 304 304 OBJECT_ATTRIBUTES ObjectAttributes; 305 305 IO_STATUS_BLOCK IoStatus; 306 306 NTSTATUS Status; 307 + DWORD Error; 307 308 308 - KmtLoadDriver(L"IoReadWrite", FALSE); 309 - KmtOpenDriver(); 309 + Error = KmtLoadAndOpenDriver(L"IoReadWrite", FALSE); 310 + ok_eq_int(Error, ERROR_SUCCESS); 311 + if (Error) 312 + return; 310 313 311 314 RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55); 312 315 InitializeObjectAttributes(&ObjectAttributes,
+5 -2
modules/rostests/kmtests/ntos_mm/MmMapLockedPagesSpecifyCache_user.c
··· 86 86 SYSTEM_BASIC_INFORMATION BasicInfo; 87 87 NTSTATUS Status; 88 88 ULONG_PTR HighestAddress; 89 + DWORD Error; 89 90 90 - KmtLoadDriver(L"MmMapLockedPagesSpecifyCache", FALSE); 91 - KmtOpenDriver(); 91 + Error = KmtLoadAndOpenDriver(L"MmMapLockedPagesSpecifyCache", FALSE); 92 + ok_eq_int(Error, ERROR_SUCCESS); 93 + if (Error) 94 + return; 92 95 93 96 // Less than a page 94 97 SET_BUFFER_LENGTH(BufferLength, 2048);
+5 -2
modules/rostests/kmtests/ntos_mm/NtCreateSection_user.c
··· 19 19 UNICODE_STRING InitOnCreate = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InitOnCreate"); 20 20 UNICODE_STRING InitOnRW = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InitOnRW"); 21 21 UNICODE_STRING InvalidInit = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InvalidInit"); 22 + DWORD Error; 22 23 23 - KmtLoadDriver(L"NtCreateSection", FALSE); 24 - KmtOpenDriver(); 24 + Error = KmtLoadAndOpenDriver(L"NtCreateSection", FALSE); 25 + ok_eq_int(Error, ERROR_SUCCESS); 26 + if (Error) 27 + return; 25 28 26 29 /* Test 0 */ 27 30 InitializeObjectAttributes(&ObjectAttributes, &InvalidInit, OBJ_CASE_INSENSITIVE, NULL, NULL);
+7 -2
modules/rostests/kmtests/ntos_po/PoIrp_user.c
··· 10 10 11 11 START_TEST(PoIrp) 12 12 { 13 + DWORD Error; 14 + 13 15 #if defined(_M_AMD64) 14 16 if (TRUE) 15 17 { ··· 18 20 } 19 21 #endif 20 22 21 - KmtLoadDriver(L"PoIrp", TRUE); 22 - KmtOpenDriver(); 23 + Error = KmtLoadAndOpenDriver(L"PoIrp", TRUE); 24 + ok_eq_int(Error, ERROR_SUCCESS); 25 + if (Error) 26 + return; 27 + 23 28 KmtSendToDriver(IOCTL_RUN_TEST); 24 29 KmtCloseDriver(); 25 30 KmtUnloadDriver();
+13 -4
modules/rostests/kmtests/tcpip/TcpIp_user.c
··· 11 11 #include "tcpip.h" 12 12 13 13 static 14 - void 14 + DWORD 15 15 LoadTcpIpTestDriver(void) 16 16 { 17 + DWORD Error; 18 + 17 19 /* Start the special-purpose driver */ 18 - KmtLoadDriver(L"TcpIp", FALSE); 19 - KmtOpenDriver(); 20 + Error = KmtLoadAndOpenDriver(L"TcpIp", FALSE); 21 + ok_eq_int(Error, ERROR_SUCCESS); 22 + if (Error) 23 + return Error; 24 + 25 + return ERROR_SUCCESS; 20 26 } 21 27 22 28 static ··· 32 38 { 33 39 DWORD Error; 34 40 35 - LoadTcpIpTestDriver(); 41 + Error = LoadTcpIpTestDriver(); 42 + ok_eq_int(Error, 0); 43 + if (Error) 44 + return; 36 45 37 46 Error = KmtSendToDriver(IOCTL_TEST_TDI); 38 47 ok_eq_ulong(Error, ERROR_SUCCESS);