ReactOS 0.4.16-dev-334-g4d9f67c
IoReadWrite_user.c File Reference
#include <kmt_test.h>
#include "IoReadWrite.h"
Include dependency graph for IoReadWrite_user.c:

Go to the source code of this file.

Functions

static VOID TestRead (_In_ HANDLE FileHandle, _In_ BOOLEAN Cached, _In_ BOOLEAN UseFastIo, _In_ BOOLEAN ReturnPending)
 
static VOID TestWrite (_In_ HANDLE FileHandle, _In_ BOOLEAN Cached, _In_ BOOLEAN UseFastIo, _In_ BOOLEAN ReturnPending)
 
 START_TEST (IoReadWrite)
 

Function Documentation

◆ START_TEST()

START_TEST ( IoReadWrite  )

Definition at line 299 of file IoReadWrite_user.c.

300{
302 UNICODE_STRING CachedFileName = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-IoReadWrite\\Cached");
303 UNICODE_STRING NonCachedFileName = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-IoReadWrite\\NonCached");
307 DWORD Error;
308
309 Error = KmtLoadAndOpenDriver(L"IoReadWrite", FALSE);
311 if (Error)
312 return;
313
314 RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55);
316 &NonCachedFileName,
318 NULL,
319 NULL);
323 &IoStatus,
324 0,
328 if (!skip(NT_SUCCESS(Status), "No file\n"))
329 {
331 ok_eq_ulongptr(IoStatus.Information, FILE_OPENED);
332 trace("Non-Cached read, no FastIo, direct return\n");
334 trace("Non-Cached read, allow FastIo, direct return\n");
336 trace("Non-Cached read, no FastIo, pending return\n");
338 trace("Non-Cached read, allow FastIo, pending return\n");
340
341 trace("Non-Cached write, no FastIo, direct return\n");
343 trace("Non-Cached write, allow FastIo, direct return\n");
345 trace("Non-Cached write, no FastIo, pending return\n");
347 trace("Non-Cached write, allow FastIo, pending return\n");
350 }
351
352 RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55);
354 &CachedFileName,
356 NULL,
357 NULL);
361 &IoStatus,
362 0,
366 if (!skip(NT_SUCCESS(Status), "No file\n"))
367 {
369 ok_eq_ulongptr(IoStatus.Information, FILE_OPENED);
370 trace("Cached read, no FastIo, direct return\n");
372 trace("Cached read, allow FastIo, direct return\n");
374 trace("Cached read, no FastIo, pending return\n");
376 trace("Cached read, allow FastIo, pending return\n");
378
379 trace("Cached write, no FastIo, direct return\n");
381 trace("Cached write, allow FastIo, direct return\n");
383 trace("Cached write, no FastIo, pending return\n");
385 trace("Cached write, allow FastIo, pending return\n");
388 }
389
392}
static VOID TestRead(_In_ HANDLE FileHandle, _In_ BOOLEAN Cached, _In_ BOOLEAN UseFastIo, _In_ BOOLEAN ReturnPending)
static VOID TestWrite(_In_ HANDLE FileHandle, _In_ BOOLEAN Cached, _In_ BOOLEAN UseFastIo, _In_ BOOLEAN ReturnPending)
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_int(value, expected)
Definition: apitest.h:60
#define ok_eq_ulongptr(value, expected)
Definition: apitest.h:71
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
BOOL Error
Definition: chkdsk.c:66
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define FILE_OPENED
Definition: nt_native.h:769
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
DWORD KmtLoadAndOpenDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning)
Definition: support.c:213
VOID KmtCloseDriver(VOID)
Definition: support.c:236
VOID KmtUnloadDriver(VOID)
Definition: support.c:167
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ TestRead()

static VOID TestRead ( _In_ HANDLE  FileHandle,
_In_ BOOLEAN  Cached,
_In_ BOOLEAN  UseFastIo,
_In_ BOOLEAN  ReturnPending 
)
static

Definition at line 13 of file IoReadWrite_user.c.

18{
22 UCHAR Buffer[32];
24 ULONG BaseKey, StatusKey, Key;
25 DWORD WaitStatus;
26
27 BaseKey = (UseFastIo ? KEY_USE_FASTIO : 0) |
28 (ReturnPending ? KEY_RETURN_PENDING : 0);
29
31 ok(EventHandle != NULL, "CreateEvent failed with %lu\n", GetLastError());
32
33 for (StatusKey = KEY_SUCCEED ; StatusKey != 0xff; StatusKey = KEY_NEXT(StatusKey))
34 {
35 //trace("\tSTATUS KEY: %lx\n", StatusKey);
37 RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55);
38 Key = BaseKey | StatusKey | KEY_DATA(0x11);
39 Offset.QuadPart = 0;
42 NULL,
43 NULL,
44 &IoStatus,
45 NULL,
46 0,
47 &Offset,
48 &Key);
49 WaitStatus = WaitForSingleObject(EventHandle, 0);
50 if (ReturnPending)
52 else
54 if (Cached && UseFastIo && !ReturnPending)
55 {
56 ok_eq_ulong(WaitStatus, WAIT_OBJECT_0);
59 }
60 else
61 {
62 ok_eq_ulong(WaitStatus, WAIT_TIMEOUT);
63 ok_eq_hex(IoStatus.Status, 0x55555555);
64 ok_eq_ulongptr(IoStatus.Information, (ULONG_PTR)0x5555555555555555);
65 }
66
70 Key = BaseKey | StatusKey | KEY_DATA(0x22);
71 Offset.QuadPart = 0;
74 NULL,
75 NULL,
76 &IoStatus,
77 NULL,
79 &Offset,
80 &Key);
81 WaitStatus = WaitForSingleObject(EventHandle, 0);
82 ok_eq_ulong(WaitStatus, WAIT_TIMEOUT);
84 ok_eq_hex(IoStatus.Status, 0x55555555);
85 ok_eq_ulongptr(IoStatus.Information, (ULONG_PTR)0x5555555555555555);
87
91 Key = BaseKey | StatusKey | KEY_DATA(0x33);
92 Offset.QuadPart = 0;
95 NULL,
96 NULL,
97 &IoStatus,
98 Buffer,
99 0,
100 &Offset,
101 &Key);
102 WaitStatus = WaitForSingleObject(EventHandle, 0);
103 if (ReturnPending)
105 else
107 if (Cached && UseFastIo && !ReturnPending)
108 {
109 ok_eq_ulong(WaitStatus, WAIT_OBJECT_0);
112 }
113 else
114 {
115 ok_eq_ulong(WaitStatus, WAIT_TIMEOUT);
116 ok_eq_hex(IoStatus.Status, 0x55555555);
117 ok_eq_ulongptr(IoStatus.Information, (ULONG_PTR)0x5555555555555555);
118 }
119 ok_eq_uint(Buffer[0], 0x55);
120
122 RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55);
123 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
124 Key = BaseKey | StatusKey | KEY_DATA(0x44);
125 Offset.QuadPart = 0;
128 NULL,
129 NULL,
130 &IoStatus,
131 Buffer,
132 sizeof(Buffer),
133 &Offset,
134 &Key);
135 WaitStatus = WaitForSingleObject(EventHandle, 0);
137 if ((Cached && UseFastIo && !ReturnPending &&
138 (StatusKey == KEY_SUCCEED || StatusKey == KEY_FAIL_OVERFLOW || StatusKey == KEY_FAIL_EOF)) ||
139 !KEY_ERROR(StatusKey))
140 {
141 ok_eq_ulong(WaitStatus, WAIT_OBJECT_0);
142 ok_eq_hex(IoStatus.Status, TestGetReturnStatus(StatusKey));
144 }
145 else
146 {
147 ok_eq_ulong(WaitStatus, WAIT_TIMEOUT);
148 ok_eq_hex(IoStatus.Status, 0x55555555);
149 ok_eq_ulongptr(IoStatus.Information, (ULONG_PTR)0x5555555555555555);
150 }
151 if ((StatusKey != KEY_FAIL_VERIFY_REQUIRED && !KEY_ERROR(StatusKey)) ||
152 Cached)
153 {
154 ok_eq_uint(Buffer[0], 0x44);
155 ok_eq_uint(Buffer[TEST_FILE_SIZE - 1], 0x44);
157 }
158 else
159 {
160 ok_eq_uint(Buffer[0], 0x55);
161 }
162 }
163}
#define KEY_ERROR(key)
Definition: IoReadWrite.h:38
#define KEY_FAIL_VERIFY_REQUIRED
Definition: IoReadWrite.h:22
#define KEY_RETURN_PENDING
Definition: IoReadWrite.h:86
#define KEY_DATA(c)
Definition: IoReadWrite.h:88
#define KEY_NEXT(key)
Definition: IoReadWrite.h:33
#define KEY_SUCCEED
Definition: IoReadWrite.h:13
#define KEY_FAIL_OVERFLOW
Definition: IoReadWrite.h:19
#define KEY_USE_FASTIO
Definition: IoReadWrite.h:85
#define KEY_FAIL_EOF
Definition: IoReadWrite.h:28
static NTSTATUS TestGetReturnStatus(_In_ ULONG LockKey)
Definition: IoReadWrite.h:41
#define TEST_FILE_SIZE
Definition: IoReadWrite.h:11
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define ok_eq_uint(value, expected)
Definition: apitest.h:61
#define ok(value,...)
Definition: atltest.h:57
Definition: bufpool.h:45
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define KmtStartSeh()
Definition: kmt_test.h:282
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:288
if(dx< 0)
Definition: linetemp.h:194
_In_ ULONG _In_ BOOLEAN Cached
Definition: ndis.h:3789
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:714
else
Definition: tritemp.h:161
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:432
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857
ret QuadPart
Definition: rtlfuncs.h:3106
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by START_TEST().

◆ TestWrite()

static VOID TestWrite ( _In_ HANDLE  FileHandle,
_In_ BOOLEAN  Cached,
_In_ BOOLEAN  UseFastIo,
_In_ BOOLEAN  ReturnPending 
)
static

Definition at line 167 of file IoReadWrite_user.c.

172{
176 UCHAR Buffer[32];
178 ULONG BaseKey, StatusKey, Key;
179 DWORD WaitStatus;
180
181 BaseKey = (UseFastIo ? KEY_USE_FASTIO : 0) |
182 (ReturnPending ? KEY_RETURN_PENDING : 0);
183
185 ok(EventHandle != NULL, "CreateEvent failed with %lu\n", GetLastError());
186
187 for (StatusKey = KEY_SUCCEED ; StatusKey != 0xff; StatusKey = KEY_NEXT(StatusKey))
188 {
189 //trace("\tSTATUS KEY: %lx\n", StatusKey);
191 RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55);
192 Key = BaseKey | StatusKey | KEY_DATA(0x11);
193 Offset.QuadPart = 0;
196 NULL,
197 NULL,
198 &IoStatus,
199 NULL,
200 0,
201 &Offset,
202 &Key);
203 WaitStatus = WaitForSingleObject(EventHandle, 0);
205 if (!KEY_ERROR(StatusKey))
206 {
207 ok_eq_ulong(WaitStatus, WAIT_OBJECT_0);
208 ok_eq_hex(IoStatus.Status, TestGetReturnStatus(StatusKey));
209 ok_eq_ulongptr(IoStatus.Information, 0);
210 }
211 else
212 {
213 ok_eq_ulong(WaitStatus, WAIT_TIMEOUT);
214 ok_eq_hex(IoStatus.Status, 0x55555555);
215 ok_eq_ulongptr(IoStatus.Information, (ULONG_PTR)0x5555555555555555);
216 }
217
221 Key = BaseKey | StatusKey | KEY_DATA(0x22);
222 Offset.QuadPart = 0;
225 NULL,
226 NULL,
227 &IoStatus,
228 NULL,
229 sizeof(Buffer),
230 &Offset,
231 &Key);
232 WaitStatus = WaitForSingleObject(EventHandle, 0);
233 ok_eq_ulong(WaitStatus, WAIT_TIMEOUT);
235 ok_eq_hex(IoStatus.Status, 0x55555555);
236 ok_eq_ulongptr(IoStatus.Information, (ULONG_PTR)0x5555555555555555);
238
242 Key = BaseKey | StatusKey | KEY_DATA(0x33);
243 Offset.QuadPart = 0;
246 NULL,
247 NULL,
248 &IoStatus,
249 Buffer,
250 0,
251 &Offset,
252 &Key);
253 WaitStatus = WaitForSingleObject(EventHandle, 0);
255 if (!KEY_ERROR(StatusKey))
256 {
257 ok_eq_ulong(WaitStatus, WAIT_OBJECT_0);
258 ok_eq_hex(IoStatus.Status, TestGetReturnStatus(StatusKey));
259 ok_eq_ulongptr(IoStatus.Information, 0);
260 }
261 else
262 {
263 ok_eq_ulong(WaitStatus, WAIT_TIMEOUT);
264 ok_eq_hex(IoStatus.Status, 0x55555555);
265 ok_eq_ulongptr(IoStatus.Information, (ULONG_PTR)0x5555555555555555);
266 }
267
269 RtlFillMemory(&IoStatus, sizeof(IoStatus), 0x55);
270 RtlFillMemory(Buffer, sizeof(Buffer), 0x44);
271 Key = BaseKey | StatusKey | KEY_DATA(0x44);
272 Offset.QuadPart = 0;
275 NULL,
276 NULL,
277 &IoStatus,
278 Buffer,
279 sizeof(Buffer),
280 &Offset,
281 &Key);
282 WaitStatus = WaitForSingleObject(EventHandle, 0);
284 if (!KEY_ERROR(StatusKey))
285 {
286 ok_eq_ulong(WaitStatus, WAIT_OBJECT_0);
287 ok_eq_hex(IoStatus.Status, TestGetReturnStatus(StatusKey));
288 ok_eq_ulongptr(IoStatus.Information, sizeof(Buffer));
289 }
290 else
291 {
292 ok_eq_ulong(WaitStatus, WAIT_TIMEOUT);
293 ok_eq_hex(IoStatus.Status, 0x55555555);
294 ok_eq_ulongptr(IoStatus.Information, (ULONG_PTR)0x5555555555555555);
295 }
296 }
297}
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)

Referenced by START_TEST().