2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Driver
5 * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
11 #include <kmt_public.h>
15 extern HANDLE KmtestHandle
;
18 * @name KmtRunKernelTest
20 * Run the specified kernel-mode test part
23 * Name of the test to run
25 * @return Win32 error code as returned by DeviceIoControl
31 DWORD Error
= ERROR_SUCCESS
;
34 if (!DeviceIoControl(KmtestHandle
, IOCTL_KMTEST_RUN_TEST
, (PVOID
)TestName
, (DWORD
)strlen(TestName
), NULL
, 0, &BytesRead
, NULL
))
40 static WCHAR TestServiceName
[MAX_PATH
];
41 static SC_HANDLE TestServiceHandle
;
42 static HANDLE TestDeviceHandle
;
47 * Load the specified special-purpose driver (create/start the service)
50 * Name of the driver service (Kmtest- prefix will be added automatically)
51 * @param RestartIfRunning
52 * TRUE to stop and restart the service if it is already running
56 IN PCWSTR ServiceName
,
57 IN BOOLEAN RestartIfRunning
)
59 DWORD Error
= ERROR_SUCCESS
;
60 WCHAR ServicePath
[MAX_PATH
];
62 StringCbCopy(ServicePath
, sizeof ServicePath
, ServiceName
);
63 StringCbCat(ServicePath
, sizeof ServicePath
, L
"_drv.sys");
65 StringCbCopy(TestServiceName
, sizeof TestServiceName
, L
"Kmtest-");
66 StringCbCat(TestServiceName
, sizeof TestServiceName
, ServiceName
);
68 Error
= KmtCreateAndStartService(TestServiceName
, ServicePath
, NULL
, &TestServiceHandle
, RestartIfRunning
);
78 * @name KmtUnloadDriver
80 * Unload special-purpose driver (stop the service)
85 DWORD Error
= ERROR_SUCCESS
;
87 Error
= KmtStopService(TestServiceName
, &TestServiceHandle
);
99 * Open special-purpose driver (acquire a device handle)
104 DWORD Error
= ERROR_SUCCESS
;
105 WCHAR DevicePath
[MAX_PATH
];
107 StringCbCopy(DevicePath
, sizeof DevicePath
, L
"\\\\.\\Global\\GLOBALROOT\\Device\\");
108 StringCbCat(DevicePath
, sizeof DevicePath
, TestServiceName
);
110 TestDeviceHandle
= CreateFile(DevicePath
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
111 if (TestDeviceHandle
== INVALID_HANDLE_VALUE
)
123 * @name KmtCloseDriver
125 * Close special-purpose driver (close device handle)
130 DWORD Error
= ERROR_SUCCESS
;
132 if (TestDeviceHandle
&& !CloseHandle(TestDeviceHandle
))
143 * @name KmtSendToDriver
145 * Unload special-purpose driver (stop the service)
149 * @return Win32 error code as returned by DeviceIoControl
153 IN DWORD ControlCode
)
157 assert(ControlCode
< 0x400);
159 if (!DeviceIoControl(TestDeviceHandle
, KMT_MAKE_CODE(ControlCode
), NULL
, 0, NULL
, 0, &BytesRead
, NULL
))
160 return GetLastError();
162 return ERROR_SUCCESS
;
166 * @name KmtSendStringToDriver
168 * Unload special-purpose driver (stop the service)
173 * @return Win32 error code as returned by DeviceIoControl
176 KmtSendStringToDriver(
177 IN DWORD ControlCode
,
182 assert(ControlCode
< 0x400);
184 if (!DeviceIoControl(TestDeviceHandle
, KMT_MAKE_CODE(ControlCode
), (PVOID
)String
, (DWORD
)strlen(String
), NULL
, 0, &BytesRead
, NULL
))
185 return GetLastError();
187 return ERROR_SUCCESS
;
191 * @name KmtSendStringToDriver
193 * Unload special-purpose driver (stop the service)
198 * @return Win32 error code as returned by DeviceIoControl
201 KmtSendWStringToDriver(
202 IN DWORD ControlCode
,
207 assert(ControlCode
< 0x400);
209 if (!DeviceIoControl(TestDeviceHandle
, KMT_MAKE_CODE(ControlCode
), (PVOID
)String
, (DWORD
)wcslen(String
) * sizeof(WCHAR
), NULL
, 0, &BytesRead
, NULL
))
210 return GetLastError();
212 return ERROR_SUCCESS
;
216 * @name KmtSendBufferToDriver
223 * @return Win32 error code as returned by DeviceIoControl
226 KmtSendBufferToDriver(
227 IN DWORD ControlCode
,
228 IN OUT PVOID Buffer OPTIONAL
,
230 IN OUT PDWORD OutLength
)
233 assert(Buffer
|| (!InLength
&& !*OutLength
));
234 assert(ControlCode
< 0x400);
236 if (!DeviceIoControl(TestDeviceHandle
, KMT_MAKE_CODE(ControlCode
), Buffer
, InLength
, Buffer
, *OutLength
, OutLength
, NULL
))
237 return GetLastError();
239 return ERROR_SUCCESS
;