ReactOS 0.4.16-dev-329-g9223134
NpfsReadWrite.c File Reference
#include <kmt_test.h>
#include "npfs.h"
Include dependency graph for NpfsReadWrite.c:

Go to the source code of this file.

Classes

struct  _READ_WRITE_TEST_CONTEXT
 

Macros

#define MAX_INSTANCES   5
 
#define IN_QUOTA   4096
 
#define OUT_QUOTA   4096
 
#define MakeServer(ServerHandle, PipePath, ServerSynchronous)
 
#define CheckServer(ServerHandle, State)
 
#define CheckClient(ClientHandle, State)
 
#define CheckServerQuota(ServerHandle, InQ, OutQ)
 
#define CheckClientQuota(ClientHandle, InQ, OutQ)
 
#define CheckPipeContext(Context, ExpectedStatus, ExpectedBytes)
 

Typedefs

typedef struct _READ_WRITE_TEST_CONTEXT READ_WRITE_TEST_CONTEXT
 
typedef struct _READ_WRITE_TEST_CONTEXTPREAD_WRITE_TEST_CONTEXT
 

Functions

static VOID ConnectPipe (IN OUT PTHREAD_CONTEXT Context)
 
static VOID ListenPipe (IN OUT PTHREAD_CONTEXT Context)
 
static VOID ReadPipe (IN OUT PTHREAD_CONTEXT Context)
 
static VOID WritePipe (IN OUT PTHREAD_CONTEXT Context)
 
static BOOLEAN CheckConnectPipe (IN PTHREAD_CONTEXT Context, IN PCWSTR PipePath, IN BOOLEAN ClientSynchronous, IN ULONG MilliSeconds)
 
static BOOLEAN CheckListenPipe (IN PTHREAD_CONTEXT Context, IN HANDLE ServerHandle, IN ULONG MilliSeconds)
 
static BOOLEAN CheckReadPipe (IN PTHREAD_CONTEXT Context, IN HANDLE PipeHandle, OUT PVOID Buffer, IN ULONG BufferSize, IN ULONG MilliSeconds)
 
static BOOLEAN CheckWritePipe (IN PTHREAD_CONTEXT Context, IN HANDLE PipeHandle, IN const VOID *Buffer, IN ULONG BufferSize, IN ULONG MilliSeconds)
 
static VOID NTAPI TestReadWrite (IN PVOID Context)
 
 START_TEST (NpfsReadWrite)
 

Variables

static KSTART_ROUTINE TestReadWrite
 

Macro Definition Documentation

◆ CheckClient

#define CheckClient (   ClientHandle,
  State 
)
Value:
NpCheckClientPipe(ClientHandle, \
IN_QUOTA, 0, \
#define OUT_QUOTA
Definition: NpfsReadWrite.c:20
#define IN_QUOTA
Definition: NpfsReadWrite.c:19
#define MAX_INSTANCES
Definition: NpfsReadWrite.c:18
#define BYTE_STREAM
Definition: npfs.h:13
#define DUPLEX
Definition: npfs.h:21
#define QUEUE
Definition: npfs.h:17
#define NpCheckClientPipe(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps)
Definition: npfs.h:121

Definition at line 46 of file NpfsReadWrite.c.

◆ CheckClientQuota

#define CheckClientQuota (   ClientHandle,
  InQ,
  OutQ 
)
Value:
NpCheckClientPipe(ClientHandle, \
IN_QUOTA, InQ, \
OUT_QUOTA, OUT_QUOTA - (OutQ), \
#define FILE_PIPE_CONNECTED_STATE
Definition: winternl.h:792

Definition at line 62 of file NpfsReadWrite.c.

◆ CheckPipeContext

#define CheckPipeContext (   Context,
  ExpectedStatus,
  ExpectedBytes 
)
Value:
do \
{ \
ok_bool_true(Okay, "CheckPipeContext"); \
ok_eq_hex((Context)->ReadWrite.Status, ExpectedStatus); \
ok_eq_ulongptr((Context)->ReadWrite.BytesTransferred, ExpectedBytes); \
} while (0)
DRIVER_DISPATCH ReadWrite
Definition: readwrite.h:29

Definition at line 70 of file NpfsReadWrite.c.

◆ CheckServer

#define CheckServer (   ServerHandle,
  State 
)
Value:
NpCheckServerPipe(ServerHandle, \
IN_QUOTA, 0, \
#define NpCheckServerPipe(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps)
Definition: npfs.h:95

Definition at line 38 of file NpfsReadWrite.c.

◆ CheckServerQuota

#define CheckServerQuota (   ServerHandle,
  InQ,
  OutQ 
)
Value:

Definition at line 54 of file NpfsReadWrite.c.

◆ IN_QUOTA

#define IN_QUOTA   4096

Definition at line 19 of file NpfsReadWrite.c.

◆ MakeServer

#define MakeServer (   ServerHandle,
  PipePath,
  ServerSynchronous 
)
Value:
NpCreatePipeEx(ServerHandle, \
PipePath, \
QUEUE, \
(ServerSynchronous) ? FILE_SYNCHRONOUS_IO_NONALERT \
: 0, \
&DefaultTimeout)
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_OPEN_IF
Definition: from_kernel.h:56
NTSTATUS NpCreatePipeEx(OUT PHANDLE ServerHandle, IN PCWSTR PipePath, IN ULONG ReadMode, IN ULONG CompletionMode, IN ULONG NamedPipeType, IN ULONG ShareAccess, IN ULONG MaximumInstances, IN ULONG InboundQuota, IN ULONG OutboundQuota, IN ACCESS_MASK DesiredAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PLARGE_INTEGER DefaultTimeout OPTIONAL)
Definition: NpfsHelpers.c:12
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define GENERIC_WRITE
Definition: nt_native.h:90

Definition at line 22 of file NpfsReadWrite.c.

◆ MAX_INSTANCES

#define MAX_INSTANCES   5

Definition at line 18 of file NpfsReadWrite.c.

◆ OUT_QUOTA

#define OUT_QUOTA   4096

Definition at line 20 of file NpfsReadWrite.c.

Typedef Documentation

◆ PREAD_WRITE_TEST_CONTEXT

◆ READ_WRITE_TEST_CONTEXT

Function Documentation

◆ CheckConnectPipe()

static BOOLEAN CheckConnectPipe ( IN PTHREAD_CONTEXT  Context,
IN PCWSTR  PipePath,
IN BOOLEAN  ClientSynchronous,
IN ULONG  MilliSeconds 
)
static

Definition at line 127 of file NpfsReadWrite.c.

132{
133 Context->Work = ConnectPipe;
134 Context->Connect.PipePath = PipePath;
135 Context->Connect.ClientSynchronous = ClientSynchronous;
136 return TriggerWork(Context, MilliSeconds);
137}
static VOID ConnectPipe(IN OUT PTHREAD_CONTEXT Context)
Definition: NpfsReadWrite.c:79
BOOLEAN TriggerWork(IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
Definition: NpfsHelpers.c:710

Referenced by TestReadWrite().

◆ CheckListenPipe()

static BOOLEAN CheckListenPipe ( IN PTHREAD_CONTEXT  Context,
IN HANDLE  ServerHandle,
IN ULONG  MilliSeconds 
)
static

Definition at line 141 of file NpfsReadWrite.c.

145{
146 Context->Work = ListenPipe;
147 Context->Listen.ServerHandle = ServerHandle;
148 return TriggerWork(Context, MilliSeconds);
149}
static VOID ListenPipe(IN OUT PTHREAD_CONTEXT Context)
Definition: NpfsReadWrite.c:97

Referenced by TestReadWrite().

◆ CheckReadPipe()

static BOOLEAN CheckReadPipe ( IN PTHREAD_CONTEXT  Context,
IN HANDLE  PipeHandle,
OUT PVOID  Buffer,
IN ULONG  BufferSize,
IN ULONG  MilliSeconds 
)
static

Definition at line 153 of file NpfsReadWrite.c.

159{
160 Context->Work = ReadPipe;
161 Context->ReadWrite.PipeHandle = PipeHandle;
162 Context->ReadWrite.Buffer = Buffer;
163 Context->ReadWrite.BufferSize = BufferSize;
164 return TriggerWork(Context, MilliSeconds);
165}
static VOID ReadPipe(IN OUT PTHREAD_CONTEXT Context)
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22

Referenced by TestReadWrite().

◆ CheckWritePipe()

static BOOLEAN CheckWritePipe ( IN PTHREAD_CONTEXT  Context,
IN HANDLE  PipeHandle,
IN const VOID Buffer,
IN ULONG  BufferSize,
IN ULONG  MilliSeconds 
)
static

Definition at line 169 of file NpfsReadWrite.c.

175{
176 Context->Work = WritePipe;
177 Context->ReadWrite.PipeHandle = PipeHandle;
178 Context->ReadWrite.Buffer = (PVOID)Buffer;
179 Context->ReadWrite.BufferSize = BufferSize;
180 return TriggerWork(Context, MilliSeconds);
181}
static VOID WritePipe(IN OUT PTHREAD_CONTEXT Context)
void * PVOID
Definition: typedefs.h:50

Referenced by TestReadWrite().

◆ ConnectPipe()

static VOID ConnectPipe ( IN OUT PTHREAD_CONTEXT  Context)
static

Definition at line 79 of file NpfsReadWrite.c.

81{
82 HANDLE ClientHandle;
83
84 ClientHandle = NULL;
85 Context->Connect.Status = NpOpenPipeEx(&ClientHandle,
86 Context->Connect.PipePath,
90 Context->Connect.ClientSynchronous ? FILE_SYNCHRONOUS_IO_NONALERT
91 : 0);
92 Context->Connect.ClientHandle = ClientHandle;
93}
#define NULL
Definition: types.h:112
#define FILE_OPEN
Definition: from_kernel.h:54
NTSTATUS NpOpenPipeEx(OUT PHANDLE ClientHandle, IN PCWSTR PipePath, IN ACCESS_MASK DesiredAccess, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions)
Definition: NpfsHelpers.c:130

Referenced by CheckConnectPipe().

◆ ListenPipe()

static VOID ListenPipe ( IN OUT PTHREAD_CONTEXT  Context)
static

Definition at line 97 of file NpfsReadWrite.c.

99{
100 Context->Listen.Status = NpListenPipe(Context->Listen.ServerHandle);
101}
#define NpListenPipe(ServerHandle)
Definition: npfs.h:73

Referenced by CheckListenPipe().

◆ ReadPipe()

static VOID ReadPipe ( IN OUT PTHREAD_CONTEXT  Context)
static

Definition at line 105 of file NpfsReadWrite.c.

107{
108 Context->ReadWrite.Status = NpReadPipe(Context->ReadWrite.PipeHandle,
109 Context->ReadWrite.Buffer,
110 Context->ReadWrite.BufferSize,
111 (PULONG_PTR)&Context->ReadWrite.BytesTransferred);
112}
NTSTATUS NpReadPipe(IN HANDLE PipeHandle, OUT PVOID Buffer, IN ULONG BufferSize, OUT PULONG_PTR BytesRead)
Definition: NpfsHelpers.c:322
uint32_t * PULONG_PTR
Definition: typedefs.h:65

Referenced by CheckReadPipe().

◆ START_TEST()

START_TEST ( NpfsReadWrite  )

Definition at line 572 of file NpfsReadWrite.c.

573{
575 READ_WRITE_TEST_CONTEXT TestContext;
576
577 TestContext.PipePath = DEVICE_NAMED_PIPE L"\\KmtestNpfsReadWriteTestPipe";
578
579 TestContext.ServerSynchronous = TRUE;
580 TestContext.ClientSynchronous = TRUE;
581 Thread = KmtStartThread(TestReadWrite, &TestContext);
583
584 TestContext.ServerSynchronous = FALSE;
585 TestContext.ClientSynchronous = TRUE;
586 Thread = KmtStartThread(TestReadWrite, &TestContext);
588
589 TestContext.ServerSynchronous = TRUE;
590 TestContext.ClientSynchronous = FALSE;
591 Thread = KmtStartThread(TestReadWrite, &TestContext);
593
594 TestContext.ServerSynchronous = FALSE;
595 TestContext.ClientSynchronous = FALSE;
596 Thread = KmtStartThread(TestReadWrite, &TestContext);
598}
static KSTART_ROUTINE TestReadWrite
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
#define DEVICE_NAMED_PIPE
Definition: npfs.h:11
#define L(x)
Definition: ntvdm.h:50

◆ TestReadWrite()

static VOID NTAPI TestReadWrite ( IN PVOID  Context)
static

Server to client, write first, 1 byte

Server to client, read first, 1 byte

Client to server, write first, 1 byte

Client to server, read first, 1 byte

Server to client, write 0 bytes

Client to Server, write 0 bytes

Server to client, read 0 bytes blocks, write 0 bytes does not unblock, write 1 byte unblocks

Client to server, read 0 bytes blocks, write 0 bytes does not unblock, write 1 byte unblocks

Disconnect server with pending read on client

Close server with pending read on client

Close client with pending read on server

Write to server and disconnect, then read from client

Write to server and close, then read from client

Write to client and close, then read from server

Write to client and disconnect server, then read from server

Definition at line 187 of file NpfsReadWrite.c.

189{
190 PREAD_WRITE_TEST_CONTEXT TestContext = Context;
191 PCWSTR PipePath = TestContext->PipePath;
192 BOOLEAN ServerSynchronous = TestContext->ServerSynchronous;
193 BOOLEAN ClientSynchronous = TestContext->ClientSynchronous;
195 HANDLE ServerHandle;
196 LARGE_INTEGER DefaultTimeout;
197 THREAD_CONTEXT ConnectContext;
198 THREAD_CONTEXT ListenContext;
199 THREAD_CONTEXT ClientReadContext;
200 THREAD_CONTEXT ClientWriteContext;
201 THREAD_CONTEXT ServerReadContext;
202 THREAD_CONTEXT ServerWriteContext;
203 BOOLEAN Okay;
204 HANDLE ClientHandle;
205 UCHAR ReadBuffer[128];
206 UCHAR WriteBuffer[128];
207
208 StartWorkerThread(&ConnectContext);
209 StartWorkerThread(&ListenContext);
210 StartWorkerThread(&ClientReadContext);
211 StartWorkerThread(&ClientWriteContext);
212 StartWorkerThread(&ServerReadContext);
213 StartWorkerThread(&ServerWriteContext);
214
215 DefaultTimeout.QuadPart = -50 * 1000 * 10;
216
217 /* Server should start out listening */
218 Status = MakeServer(&ServerHandle, PipePath, ServerSynchronous);
221
222 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, NULL, 0, 100);
223 ok_bool_true(Okay, "CheckWritePipe returned");
224 ok_eq_ulongptr(ServerWriteContext.ReadWrite.BytesTransferred, 0);
225 ok_eq_hex(ServerWriteContext.ReadWrite.Status, STATUS_PIPE_LISTENING);
226
227 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, NULL, 0, 100);
228 ok_bool_true(Okay, "CheckReadPipe returned");
229 ok_eq_ulongptr(ServerReadContext.ReadWrite.BytesTransferred, 0);
230 ok_eq_hex(ServerReadContext.ReadWrite.Status, STATUS_PIPE_LISTENING);
231
232 /* Connect a client */
233 Okay = CheckConnectPipe(&ConnectContext, PipePath, ClientSynchronous, 100);
234 ok_bool_true(Okay, "CheckConnectPipe returned");
235 ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
236 ClientHandle = ConnectContext.Connect.ClientHandle;
239
241 WriteBuffer[0] = 'A';
242 ReadBuffer[0] = 'X';
243 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, WriteBuffer, 1, 100);
244 CheckPipeContext(&ServerWriteContext, STATUS_SUCCESS, 1);
245 CheckServerQuota(ServerHandle, 0, 1); CheckClientQuota(ClientHandle, 1, 0);
246 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
247 CheckPipeContext(&ClientReadContext, STATUS_SUCCESS, 1);
248 ok_eq_uint(ReadBuffer[0], 'A');
249 CheckServerQuota(ServerHandle, 0, 0); CheckClientQuota(ClientHandle, 0, 0);
250
252 WriteBuffer[0] = 'B';
253 ReadBuffer[0] = 'X';
254 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
255 ok_bool_false(Okay, "CheckReadPipe returned");
256 CheckServerQuota(ServerHandle, 0, 1);
257 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, WriteBuffer, 1, 100);
258 CheckPipeContext(&ServerWriteContext, STATUS_SUCCESS, 1);
259 Okay = WaitForWork(&ClientReadContext, 100);
260 CheckPipeContext(&ClientReadContext, STATUS_SUCCESS, 1);
261 ok_eq_uint(ReadBuffer[0], 'B');
262 CheckServerQuota(ServerHandle, 0, 0); CheckClientQuota(ClientHandle, 0, 0);
263
265 WriteBuffer[0] = 'C';
266 ReadBuffer[0] = 'X';
267 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, WriteBuffer, 1, 100);
268 CheckPipeContext(&ClientWriteContext, STATUS_SUCCESS, 1);
269 CheckClientQuota(ClientHandle, 0, 1); CheckServerQuota(ServerHandle, 1, 0);
270 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
271 CheckPipeContext(&ServerReadContext, STATUS_SUCCESS, 1);
272 ok_eq_uint(ReadBuffer[0], 'C');
273 CheckClientQuota(ClientHandle, 0, 0); CheckServerQuota(ServerHandle, 0, 0);
274
276 WriteBuffer[0] = 'D';
277 ReadBuffer[0] = 'X';
278 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
279 ok_bool_false(Okay, "CheckReadPipe returned");
280 CheckClientQuota(ClientHandle, 0, 1);
281 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, WriteBuffer, 1, 100);
282 CheckPipeContext(&ClientWriteContext, STATUS_SUCCESS, 1);
283 Okay = WaitForWork(&ServerReadContext, 100);
284 CheckPipeContext(&ServerReadContext, STATUS_SUCCESS, 1);
285 ok_eq_uint(ReadBuffer[0], 'D');
286 CheckClientQuota(ClientHandle, 0, 0); CheckServerQuota(ServerHandle, 0, 0);
287
289 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, (PVOID)1, 0, 100);
290 CheckPipeContext(&ServerWriteContext, STATUS_SUCCESS, 0);
291 CheckServerQuota(ServerHandle, 0, 0); CheckClientQuota(ClientHandle, 0, 0);
292
294 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, (PVOID)1, 0, 100);
295 CheckPipeContext(&ClientWriteContext, STATUS_SUCCESS, 0);
296 CheckClientQuota(ClientHandle, 0, 0); CheckServerQuota(ServerHandle, 0, 0);
297
299 WriteBuffer[0] = 'E';
300 ReadBuffer[0] = 'X';
301 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, (PVOID)1, 0, 100);
302 ok_bool_false(Okay, "CheckReadPipe returned");
303 CheckServerQuota(ServerHandle, 0, 0);
304 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, (PVOID)1, 0, 100);
305 CheckPipeContext(&ServerWriteContext, STATUS_SUCCESS, 0);
306 Okay = WaitForWork(&ClientReadContext, 100);
307 ok_bool_false(Okay, "WaitForWork returned");
308 CheckServerQuota(ServerHandle, 0, 0);
309 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, WriteBuffer, 1, 100);
310 CheckPipeContext(&ServerWriteContext, STATUS_SUCCESS, 1);
311 Okay = WaitForWork(&ClientReadContext, 100);
312 CheckPipeContext(&ClientReadContext, STATUS_SUCCESS, 0);
313 ok_eq_uint(ReadBuffer[0], 'X');
314 CheckServerQuota(ServerHandle, 0, 1); CheckClientQuota(ClientHandle, 1, 0);
315 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
316 CheckPipeContext(&ClientReadContext, STATUS_SUCCESS, 1);
317 ok_eq_uint(ReadBuffer[0], 'E');
318 CheckServerQuota(ServerHandle, 0, 0); CheckClientQuota(ClientHandle, 0, 0);
319
321 WriteBuffer[0] = 'F';
322 ReadBuffer[0] = 'X';
323 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, (PVOID)1, 0, 100);
324 ok_bool_false(Okay, "CheckReadPipe returned");
325 CheckClientQuota(ClientHandle, 0, 0);
326 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, (PVOID)1, 0, 100);
327 CheckPipeContext(&ClientWriteContext, STATUS_SUCCESS, 0);
328 Okay = WaitForWork(&ServerReadContext, 100);
329 ok_bool_false(Okay, "WaitForWork returned");
330 CheckClientQuota(ClientHandle, 0, 0);
331 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, WriteBuffer, 1, 100);
332 CheckPipeContext(&ClientWriteContext, STATUS_SUCCESS, 1);
333 Okay = WaitForWork(&ServerReadContext, 100);
334 CheckPipeContext(&ServerReadContext, STATUS_SUCCESS, 0);
335 ok_eq_uint(ReadBuffer[0], 'X');
336 CheckClientQuota(ClientHandle, 0, 1); CheckServerQuota(ServerHandle, 1, 0);
337 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
338 CheckPipeContext(&ServerReadContext, STATUS_SUCCESS, 1);
339 ok_eq_uint(ReadBuffer[0], 'F');
340 CheckClientQuota(ClientHandle, 0, 0); CheckServerQuota(ServerHandle, 0, 0);
341
343 WriteBuffer[0] = 'G';
344 ReadBuffer[0] = 'X';
345 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
346 ok_bool_false(Okay, "CheckReadPipe returned");
347 CheckServerQuota(ServerHandle, 0, 1);
348 Status = NpDisconnectPipe(ServerHandle);
350 Okay = WaitForWork(&ClientReadContext, 100);
351 CheckPipeContext(&ClientReadContext, STATUS_PIPE_DISCONNECTED, 0);
352 ok_eq_uint(ReadBuffer[0], 'X');
353
354 /* Read from server when disconnected */
355 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
356 CheckPipeContext(&ServerReadContext, STATUS_PIPE_DISCONNECTED, 0);
357
358 /* Write to server when disconnected */
359 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, WriteBuffer, 1, 100);
360 CheckPipeContext(&ServerWriteContext, STATUS_PIPE_DISCONNECTED, 0);
361
362 /* Read from client when disconnected */
363 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
364 CheckPipeContext(&ClientReadContext, STATUS_PIPE_DISCONNECTED, 0);
365
366 /* Write to client when disconnected */
367 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, WriteBuffer, 1, 100);
368 CheckPipeContext(&ClientWriteContext, STATUS_PIPE_DISCONNECTED, 0);
369 Status = ObCloseHandle(ClientHandle, KernelMode);
371
372 /* Restore the connection */
373 Okay = CheckListenPipe(&ListenContext, ServerHandle, 100);
374 ok_bool_false(Okay, "CheckListenPipe returned");
375 Okay = CheckConnectPipe(&ConnectContext, PipePath, ClientSynchronous, 100);
376 ok_bool_true(Okay, "CheckConnectPipe returned");
377 ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
378 Okay = WaitForWork(&ListenContext, 100);
379 ok_bool_true(Okay, "WaitForWork returned");
380 ok_eq_hex(ListenContext.Listen.Status, STATUS_SUCCESS);
381 ClientHandle = ConnectContext.Connect.ClientHandle;
384
386 WriteBuffer[0] = 'H';
387 ReadBuffer[0] = 'X';
388 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
389 ok_bool_false(Okay, "CheckReadPipe returned");
390 Status = ObCloseHandle(ServerHandle, KernelMode);
392 Okay = WaitForWork(&ClientReadContext, 100);
393 CheckPipeContext(&ClientReadContext, STATUS_PIPE_BROKEN, 0);
394 ok_eq_uint(ReadBuffer[0], 'X');
395
396 /* Read from client when closed */
397 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
398 CheckPipeContext(&ClientReadContext, STATUS_PIPE_BROKEN, 0);
399
400 /* Write to client when closed */
401 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, WriteBuffer, 1, 100);
402 CheckPipeContext(&ClientWriteContext, STATUS_PIPE_CLOSING, 0);
403 Status = ObCloseHandle(ClientHandle, KernelMode);
405
406 /* Restore the connection */
407 Status = MakeServer(&ServerHandle, PipePath, ServerSynchronous);
409 Okay = CheckConnectPipe(&ConnectContext, PipePath, ClientSynchronous, 100);
410 ok_bool_true(Okay, "CheckConnectPipe returned");
411 ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
412 ClientHandle = ConnectContext.Connect.ClientHandle;
415
417 WriteBuffer[0] = 'I';
418 ReadBuffer[0] = 'X';
419 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
420 ok_bool_false(Okay, "CheckReadPipe returned");
421 Status = ObCloseHandle(ClientHandle, KernelMode);
423 Okay = WaitForWork(&ServerReadContext, 100);
424 CheckPipeContext(&ServerReadContext, STATUS_PIPE_BROKEN, 0);
425 ok_eq_uint(ReadBuffer[0], 'X');
426
427 /* Read from server when closed */
428 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
429 CheckPipeContext(&ServerReadContext, STATUS_PIPE_BROKEN, 0);
430
431 /* Write to server when closed */
432 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, WriteBuffer, 1, 100);
433 CheckPipeContext(&ServerWriteContext, STATUS_PIPE_CLOSING, 0);
434 Status = ObCloseHandle(ServerHandle, KernelMode);
436
437 /* Restore the connection */
438 Status = MakeServer(&ServerHandle, PipePath, ServerSynchronous);
440 Okay = CheckConnectPipe(&ConnectContext, PipePath, ClientSynchronous, 100);
441 ok_bool_true(Okay, "CheckConnectPipe returned");
442 ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
443 ClientHandle = ConnectContext.Connect.ClientHandle;
446
448 WriteBuffer[0] = 'J';
449 ReadBuffer[0] = 'X';
450 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, WriteBuffer, 1, 100);
451 CheckPipeContext(&ServerWriteContext, STATUS_SUCCESS, 1);
452 CheckServerQuota(ServerHandle, 0, 1); CheckClientQuota(ClientHandle, 1, 0);
453 Status = NpDisconnectPipe(ServerHandle);
457 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
458 CheckPipeContext(&ClientReadContext, STATUS_PIPE_DISCONNECTED, 0);
459 ok_eq_uint(ReadBuffer[0], 'X');
460 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
461 CheckPipeContext(&ClientReadContext, STATUS_PIPE_DISCONNECTED, 0);
462 Status = ObCloseHandle(ClientHandle, KernelMode);
464
465 /* Restore the connection */
466 Okay = CheckListenPipe(&ListenContext, ServerHandle, 100);
467 ok_bool_false(Okay, "CheckListenPipe returned");
468 Okay = CheckConnectPipe(&ConnectContext, PipePath, ClientSynchronous, 100);
469 ok_bool_true(Okay, "CheckConnectPipe returned");
470 ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
471 Okay = WaitForWork(&ListenContext, 100);
472 ok_bool_true(Okay, "WaitForWork returned");
473 ok_eq_hex(ListenContext.Listen.Status, STATUS_SUCCESS);
474 ClientHandle = ConnectContext.Connect.ClientHandle;
477
479 WriteBuffer[0] = 'K';
480 ReadBuffer[0] = 'X';
481 Okay = CheckWritePipe(&ServerWriteContext, ServerHandle, WriteBuffer, 1, 100);
482 CheckPipeContext(&ServerWriteContext, STATUS_SUCCESS, 1);
483 CheckServerQuota(ServerHandle, 0, 1); CheckClientQuota(ClientHandle, 1, 0);
484 Status = ObCloseHandle(ServerHandle, KernelMode);
486 NpCheckClientPipe(ClientHandle,
488 MAX_INSTANCES, 1,
489 IN_QUOTA, 1,
492 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
493 CheckPipeContext(&ClientReadContext, STATUS_SUCCESS, 1);
494 ok_eq_uint(ReadBuffer[0], 'K');
495 Okay = CheckReadPipe(&ClientReadContext, ClientHandle, ReadBuffer, 1, 100);
496 CheckPipeContext(&ClientReadContext, STATUS_PIPE_BROKEN, 0);
497 Status = ObCloseHandle(ClientHandle, KernelMode);
499
500 /* Restore the connection */
501 Status = MakeServer(&ServerHandle, PipePath, ServerSynchronous);
503 Okay = CheckConnectPipe(&ConnectContext, PipePath, ClientSynchronous, 100);
504 ok_bool_true(Okay, "CheckConnectPipe returned");
505 ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
506 ClientHandle = ConnectContext.Connect.ClientHandle;
509
510
512 WriteBuffer[0] = 'L';
513 ReadBuffer[0] = 'X';
514 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, WriteBuffer, 1, 100);
515 CheckPipeContext(&ClientWriteContext, STATUS_SUCCESS, 1);
516 CheckClientQuota(ClientHandle, 0, 1); CheckServerQuota(ServerHandle, 1, 0);
517 Status = ObCloseHandle(ClientHandle, KernelMode);
519 NpCheckServerPipe(ServerHandle,
521 MAX_INSTANCES, 1,
522 IN_QUOTA, 1,
525 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
526 CheckPipeContext(&ServerReadContext, STATUS_SUCCESS, 1);
527 ok_eq_uint(ReadBuffer[0], 'L');
528 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
529 CheckPipeContext(&ServerReadContext, STATUS_PIPE_BROKEN, 0);
530 Status = ObCloseHandle(ServerHandle, KernelMode);
532
533 /* Restore the connection */
534 Status = MakeServer(&ServerHandle, PipePath, ServerSynchronous);
536 Okay = CheckConnectPipe(&ConnectContext, PipePath, ClientSynchronous, 100);
537 ok_bool_true(Okay, "CheckConnectPipe returned");
538 ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
539 ClientHandle = ConnectContext.Connect.ClientHandle;
542
544 WriteBuffer[0] = 'M';
545 ReadBuffer[0] = 'X';
546 Okay = CheckWritePipe(&ClientWriteContext, ClientHandle, WriteBuffer, 1, 100);
547 CheckPipeContext(&ClientWriteContext, STATUS_SUCCESS, 1);
548 CheckClientQuota(ClientHandle, 0, 1); CheckServerQuota(ServerHandle, 1, 0);
549 Status = NpDisconnectPipe(ServerHandle);
553 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
554 CheckPipeContext(&ServerReadContext, STATUS_PIPE_DISCONNECTED, 0);
555 ok_eq_uint(ReadBuffer[0], 'X');
556 Okay = CheckReadPipe(&ServerReadContext, ServerHandle, ReadBuffer, 1, 100);
557 CheckPipeContext(&ServerReadContext, STATUS_PIPE_DISCONNECTED, 0);
558 Status = ObCloseHandle(ClientHandle, KernelMode);
560
561 Status = ObCloseHandle(ServerHandle, KernelMode);
563
564 FinishWorkerThread(&ServerWriteContext);
565 FinishWorkerThread(&ServerReadContext);
566 FinishWorkerThread(&ClientWriteContext);
567 FinishWorkerThread(&ClientReadContext);
568 FinishWorkerThread(&ListenContext);
569 FinishWorkerThread(&ConnectContext);
570}
#define CheckServerQuota(ServerHandle, InQ, OutQ)
Definition: NpfsReadWrite.c:54
static BOOLEAN CheckListenPipe(IN PTHREAD_CONTEXT Context, IN HANDLE ServerHandle, IN ULONG MilliSeconds)
static BOOLEAN CheckReadPipe(IN PTHREAD_CONTEXT Context, IN HANDLE PipeHandle, OUT PVOID Buffer, IN ULONG BufferSize, IN ULONG MilliSeconds)
#define CheckClientQuota(ClientHandle, InQ, OutQ)
Definition: NpfsReadWrite.c:62
#define CheckClient(ClientHandle, State)
Definition: NpfsReadWrite.c:46
static BOOLEAN CheckConnectPipe(IN PTHREAD_CONTEXT Context, IN PCWSTR PipePath, IN BOOLEAN ClientSynchronous, IN ULONG MilliSeconds)
#define CheckPipeContext(Context, ExpectedStatus, ExpectedBytes)
Definition: NpfsReadWrite.c:70
#define CheckServer(ServerHandle, State)
Definition: NpfsReadWrite.c:38
#define MakeServer(ServerHandle, PipePath, ServerSynchronous)
Definition: NpfsReadWrite.c:22
static BOOLEAN CheckWritePipe(IN PTHREAD_CONTEXT Context, IN HANDLE PipeHandle, IN const VOID *Buffer, IN ULONG BufferSize, IN ULONG MilliSeconds)
unsigned char BOOLEAN
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_bool_false(value, desc)
Definition: apitest.h:79
#define ok_eq_uint(value, expected)
Definition: apitest.h:61
#define ok_bool_true(value, desc)
Definition: apitest.h:78
#define ok_eq_ulongptr(value, expected)
Definition: apitest.h:71
#define WriteBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:344
#define ReadBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:339
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:25
#define FILE_PIPE_DISCONNECTED_STATE
Definition: winternl.h:790
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
#define FILE_PIPE_CLOSING_STATE
Definition: winternl.h:793
#define NpDisconnectPipe(ServerHandle)
Definition: npfs.h:74
BOOLEAN WaitForWork(IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
Definition: NpfsHelpers.c:692
VOID FinishWorkerThread(IN PTHREAD_CONTEXT Context)
Definition: NpfsHelpers.c:685
VOID StartWorkerThread(OUT PTHREAD_CONTEXT Context)
Definition: NpfsHelpers.c:674
#define NpQueryPipe(h, es)
Definition: npfs.h:147
#define KernelMode
Definition: asm.h:34
#define STATUS_PIPE_DISCONNECTED
Definition: ntstatus.h:412
#define STATUS_PIPE_LISTENING
Definition: ntstatus.h:415
#define STATUS_PIPE_BROKEN
Definition: ntstatus.h:567
#define STATUS_PIPE_CLOSING
Definition: ntstatus.h:413
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _THREAD_CONTEXT::@1625::@1628 Listen
struct _THREAD_CONTEXT::@1625::@1627 Connect
struct _THREAD_CONTEXT::@1625::@1629 ReadWrite
const uint16_t * PCWSTR
Definition: typedefs.h:57
LONGLONG QuadPart
Definition: typedefs.h:114
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ WritePipe()

static VOID WritePipe ( IN OUT PTHREAD_CONTEXT  Context)
static

Definition at line 116 of file NpfsReadWrite.c.

118{
119 Context->ReadWrite.Status = NpWritePipe(Context->ReadWrite.PipeHandle,
120 Context->ReadWrite.Buffer,
121 Context->ReadWrite.BufferSize,
122 (PULONG_PTR)&Context->ReadWrite.BytesTransferred);
123}
NTSTATUS NpWritePipe(IN HANDLE PipeHandle, IN const VOID *Buffer, IN ULONG BufferSize, OUT PULONG_PTR BytesWritten)
Definition: NpfsHelpers.c:374

Referenced by CheckWritePipe().

Variable Documentation

◆ TestReadWrite

KSTART_ROUTINE TestReadWrite ( void  )
static

Definition at line 183 of file NpfsReadWrite.c.

Referenced by START_TEST().