ReactOS  0.4.14-dev-98-gb0d4763
NpfsConnect.c File Reference
#include <kmt_test.h>
#include "npfs.h"
Include dependency graph for NpfsConnect.c:

Go to the source code of this file.

Macros

#define MAX_INSTANCES   5
 
#define IN_QUOTA   4096
 
#define OUT_QUOTA   4096
 
#define CheckServer(ServerHandle, State)
 
#define CheckClient(ClientHandle, State)
 

Functions

static VOID ConnectPipe (IN OUT PTHREAD_CONTEXT Context)
 
static VOID ListenPipe (IN OUT PTHREAD_CONTEXT Context)
 
static BOOLEAN CheckConnectPipe (IN PTHREAD_CONTEXT Context, IN PCWSTR PipePath, IN ULONG MilliSeconds)
 
static BOOLEAN CheckListenPipe (IN PTHREAD_CONTEXT Context, IN HANDLE ServerHandle, IN ULONG MilliSeconds)
 
static VOID TestConnect (IN HANDLE ServerHandle, IN PCWSTR PipePath)
 
static VOID NTAPI RunTest (IN PVOID Context)
 
 START_TEST (NpfsConnect)
 

Variables

static KSTART_ROUTINE RunTest
 

Macro Definition Documentation

◆ CheckClient

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

Definition at line 23 of file NpfsConnect.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
#define DUPLEX
Definition: npfs.h:21
#define IN_QUOTA
Definition: NpfsConnect.c:12
#define BYTE_STREAM
Definition: npfs.h:13
#define QUEUE
Definition: npfs.h:17
#define OUT_QUOTA
Definition: NpfsConnect.c:13
#define MAX_INSTANCES
Definition: NpfsConnect.c:11

Definition at line 15 of file NpfsConnect.c.

◆ IN_QUOTA

#define IN_QUOTA   4096

Definition at line 12 of file NpfsConnect.c.

◆ MAX_INSTANCES

#define MAX_INSTANCES   5

Definition at line 11 of file NpfsConnect.c.

◆ OUT_QUOTA

#define OUT_QUOTA   4096

Definition at line 13 of file NpfsConnect.c.

Function Documentation

◆ CheckConnectPipe()

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

Definition at line 55 of file NpfsConnect.c.

59 {
60  Context->Work = ConnectPipe;
61  Context->Connect.PipePath = PipePath;
62  return TriggerWork(Context, MilliSeconds);
63 }
BOOLEAN TriggerWork(IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
Definition: NpfsHelpers.c:710
static VOID ConnectPipe(IN OUT PTHREAD_CONTEXT Context)
Definition: NpfsConnect.c:33

Referenced by TestConnect().

◆ CheckListenPipe()

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

Definition at line 67 of file NpfsConnect.c.

71 {
72  Context->Work = ListenPipe;
73  Context->Listen.ServerHandle = ServerHandle;
74  return TriggerWork(Context, MilliSeconds);
75 }
BOOLEAN TriggerWork(IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
Definition: NpfsHelpers.c:710
static VOID ListenPipe(IN OUT PTHREAD_CONTEXT Context)
Definition: NpfsConnect.c:47

Referenced by TestConnect().

◆ ConnectPipe()

static VOID ConnectPipe ( IN OUT PTHREAD_CONTEXT  Context)
static

Definition at line 33 of file NpfsConnect.c.

35 {
36  HANDLE ClientHandle;
37 
38  ClientHandle = NULL;
39  Context->Connect.Status = NpOpenPipe(&ClientHandle,
40  Context->Connect.PipePath,
42  Context->Connect.ClientHandle = ClientHandle;
43 }
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NpOpenPipe(OUT PHANDLE ClientHandle, IN PCWSTR PipePath, IN ULONG NamedPipeConfiguration)
Definition: NpfsHelpers.c:180
#define FILE_PIPE_FULL_DUPLEX
Definition: iotypes.h:83

Referenced by CheckConnectPipe().

◆ ListenPipe()

static VOID ListenPipe ( IN OUT PTHREAD_CONTEXT  Context)
static

Definition at line 47 of file NpfsConnect.c.

49 {
50  Context->Listen.Status = NpListenPipe(Context->Listen.ServerHandle);
51 }
#define NpListenPipe(ServerHandle)
Definition: npfs.h:73

Referenced by CheckListenPipe().

◆ RunTest()

static VOID NTAPI RunTest ( IN PVOID  Context)
static

Definition at line 242 of file NpfsConnect.c.

244 {
246  HANDLE ServerHandle;
247 
249 
250  ServerHandle = INVALID_HANDLE_VALUE;
251  Status = NpCreatePipe(&ServerHandle,
252  DEVICE_NAMED_PIPE L"\\KmtestNpfsConnectTestPipe",
255  IN_QUOTA,
256  OUT_QUOTA);
258  ok(ServerHandle != NULL && ServerHandle != INVALID_HANDLE_VALUE, "ServerHandle = %p\n", ServerHandle);
259  if (!skip(NT_SUCCESS(Status) && ServerHandle != NULL && ServerHandle != INVALID_HANDLE_VALUE, "No pipe\n"))
260  {
261  CheckServer(ServerHandle, FILE_PIPE_LISTENING_STATE);
262  TestConnect(ServerHandle, DEVICE_NAMED_PIPE L"\\KmtestNpfsConnectTestPipe");
263  }
264 }
NTSTATUS NpCreatePipe(OUT PHANDLE ServerHandle, IN PCWSTR PipePath, IN ULONG ReadMode, IN ULONG CompletionMode, IN ULONG NamedPipeType, IN ULONG NamedPipeConfiguration, IN ULONG MaximumInstances, IN ULONG InboundQuota, IN ULONG OutboundQuota)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
#define DEVICE_NAMED_PIPE
Definition: npfs.h:11
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define CheckServer(ServerHandle, State)
Definition: NpfsConnect.c:15
smooth NULL
Definition: ftsmooth.c:416
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
static VOID TestConnect(IN HANDLE ServerHandle, IN PCWSTR PipePath)
Definition: NpfsConnect.c:79
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DUPLEX
Definition: npfs.h:21
#define IN_QUOTA
Definition: NpfsConnect.c:12
static const WCHAR L[]
Definition: oid.c:1250
#define BYTE_STREAM
Definition: npfs.h:13
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57
#define QUEUE
Definition: npfs.h:17
#define skip(...)
Definition: atltest.h:64
#define OUT_QUOTA
Definition: NpfsConnect.c:13
#define MAX_INSTANCES
Definition: NpfsConnect.c:11
#define ok_eq_hex(value, expected)
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ START_TEST()

START_TEST ( NpfsConnect  )

Definition at line 266 of file NpfsConnect.c.

267 {
269 
272 }
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
static KSTART_ROUTINE RunTest
Definition: NpfsConnect.c:238

◆ TestConnect()

static VOID TestConnect ( IN HANDLE  ServerHandle,
IN PCWSTR  PipePath 
)
static

Definition at line 79 of file NpfsConnect.c.

82 {
84  THREAD_CONTEXT ConnectContext;
85  THREAD_CONTEXT ListenContext;
86  BOOLEAN Okay;
87  HANDLE ClientHandle;
88 
89  StartWorkerThread(&ConnectContext);
90  StartWorkerThread(&ListenContext);
91 
92  /* Server should start out listening */
94 
95  /* Connect a client */
96  ClientHandle = NULL;
97  Okay = CheckConnectPipe(&ConnectContext, PipePath, 100);
98  ok_bool_true(Okay, "CheckConnectPipe returned");
99  ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
100  if (NT_SUCCESS(ConnectContext.Connect.Status))
101  {
102  ClientHandle = ConnectContext.Connect.ClientHandle;
103  CheckClient(ClientHandle, FILE_PIPE_CONNECTED_STATE);
104  }
105  CheckServer(ServerHandle, FILE_PIPE_CONNECTED_STATE);
106 
107  /* Connect another client */
108  Okay = CheckConnectPipe(&ConnectContext, PipePath, 100);
109  ok_bool_true(Okay, "CheckConnectPipe returned");
110  ok_eq_hex(ConnectContext.Connect.Status, STATUS_PIPE_NOT_AVAILABLE);
111  if (NT_SUCCESS(ConnectContext.Connect.Status))
112  ObCloseHandle(ConnectContext.Connect.ClientHandle, KernelMode);
113  CheckClient(ClientHandle, FILE_PIPE_CONNECTED_STATE);
114  CheckServer(ServerHandle, FILE_PIPE_CONNECTED_STATE);
115 
116  /* Disconnecting the client should fail */
117  Status = NpDisconnectPipe(ClientHandle);
119  CheckClient(ClientHandle, FILE_PIPE_CONNECTED_STATE);
120  CheckServer(ServerHandle, FILE_PIPE_CONNECTED_STATE);
121 
122  /* Listening on the client should fail */
123  Status = NpListenPipe(ClientHandle);
125  CheckClient(ClientHandle, FILE_PIPE_CONNECTED_STATE);
126  CheckServer(ServerHandle, FILE_PIPE_CONNECTED_STATE);
127 
128  /* Close client */
129  if (ClientHandle)
130  ObCloseHandle(ClientHandle, KernelMode);
131  CheckServer(ServerHandle, FILE_PIPE_CLOSING_STATE);
132 
133  /* Connecting a client now should fail */
134  Okay = CheckConnectPipe(&ConnectContext, PipePath, 100);
135  ok_bool_true(Okay, "CheckConnectPipe returned");
136  ok_eq_hex(ConnectContext.Connect.Status, STATUS_PIPE_NOT_AVAILABLE);
137  if (NT_SUCCESS(ConnectContext.Connect.Status))
138  ObCloseHandle(ConnectContext.Connect.ClientHandle, KernelMode);
139  CheckServer(ServerHandle, FILE_PIPE_CLOSING_STATE);
140 
141  /* Listening should fail */
142  Okay = CheckListenPipe(&ListenContext, ServerHandle, 100);
143  ok_bool_true(Okay, "CheckListenPipe returned");
144  if (!skip(Okay, "Listen succeeded unexpectedly\n"))
145  CheckServer(ServerHandle, FILE_PIPE_CLOSING_STATE);
146 
147  /* Disconnect server */
148  Status = NpDisconnectPipe(ServerHandle);
151 
152  /* Disconnecting again should fail */
153  Status = NpDisconnectPipe(ServerHandle);
156 
157  /* Connecting a client now should fail */
158  Okay = CheckConnectPipe(&ConnectContext, PipePath, 100);
159  ok_bool_true(Okay, "CheckConnectPipe returned");
160  ok_eq_hex(ConnectContext.Connect.Status, STATUS_PIPE_NOT_AVAILABLE);
161  if (NT_SUCCESS(ConnectContext.Connect.Status))
162  ObCloseHandle(ConnectContext.Connect.ClientHandle, KernelMode);
164 
165  /**************************************************************************/
166  /* Now listen again */
167  Okay = CheckListenPipe(&ListenContext, ServerHandle, 100);
168  ok_bool_false(Okay, "CheckListenPipe returned");
169  //blocks: CheckServer(ServerHandle, FILE_PIPE_LISTENING_STATE);
170 
171  /* Connect client */
172  ClientHandle = NULL;
173  Okay = CheckConnectPipe(&ConnectContext, PipePath, 100);
174  ok_bool_true(Okay, "CheckConnectPipe returned");
175  ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
176  if (NT_SUCCESS(ConnectContext.Connect.Status))
177  {
178  ClientHandle = ConnectContext.Connect.ClientHandle;
179  CheckClient(ClientHandle, FILE_PIPE_CONNECTED_STATE);
180  }
181  Okay = WaitForWork(&ListenContext, 100);
182  ok_bool_true(Okay, "WaitForWork returned");
183  ok_eq_hex(ListenContext.Listen.Status, STATUS_SUCCESS);
184  CheckServer(ServerHandle, FILE_PIPE_CONNECTED_STATE);
185 
186  /* Listening again should fail */
187  Okay = CheckListenPipe(&ListenContext, ServerHandle, 100);
188  ok_bool_true(Okay, "CheckListenPipe returned");
189  ok_eq_hex(ListenContext.Listen.Status, STATUS_PIPE_CONNECTED);
190  CheckClient(ClientHandle, FILE_PIPE_CONNECTED_STATE);
191  CheckServer(ServerHandle, FILE_PIPE_CONNECTED_STATE);
192 
193  /* Disconnect server */
194  Status = NpDisconnectPipe(ServerHandle);
196  NpQueryPipe(ClientHandle, STATUS_PIPE_DISCONNECTED);
198 
199  /* Close client */
200  if (ClientHandle)
201  ObCloseHandle(ClientHandle, KernelMode);
203 
204  /**************************************************************************/
205  /* Listen once more */
206  Okay = CheckListenPipe(&ListenContext, ServerHandle, 100);
207  ok_bool_false(Okay, "CheckListenPipe returned");
208  //blocks: CheckServer(ServerHandle, FILE_PIPE_LISTENING_STATE);
209 
210  /* Connect client */
211  ClientHandle = NULL;
212  Okay = CheckConnectPipe(&ConnectContext, PipePath, 100);
213  ok_bool_true(Okay, "CheckConnectPipe returned");
214  ok_eq_hex(ConnectContext.Connect.Status, STATUS_SUCCESS);
215  if (NT_SUCCESS(ConnectContext.Connect.Status))
216  {
217  ClientHandle = ConnectContext.Connect.ClientHandle;
218  CheckClient(ClientHandle, FILE_PIPE_CONNECTED_STATE);
219  }
220  Okay = WaitForWork(&ListenContext, 100);
221  ok_bool_true(Okay, "WaitForWork returned");
222  ok_eq_hex(ListenContext.Listen.Status, STATUS_SUCCESS);
223  CheckServer(ServerHandle, FILE_PIPE_CONNECTED_STATE);
224 
225  /* Close server */
226  Status = ObCloseHandle(ServerHandle, KernelMode);
228  CheckClient(ClientHandle, FILE_PIPE_CLOSING_STATE);
229 
230  /* Close client */
231  if (ClientHandle)
232  ObCloseHandle(ClientHandle, KernelMode);
233 
234  FinishWorkerThread(&ListenContext);
235  FinishWorkerThread(&ConnectContext);
236 }
#define CheckClient(ClientHandle, State)
Definition: NpfsConnect.c:23
#define STATUS_PIPE_DISCONNECTED
Definition: ntstatus.h:398
VOID StartWorkerThread(OUT PTHREAD_CONTEXT Context)
Definition: NpfsHelpers.c:674
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_PIPE_CONNECTED_STATE
Definition: winternl.h:792
VOID FinishWorkerThread(IN PTHREAD_CONTEXT Context)
Definition: NpfsHelpers.c:685
#define CheckServer(ServerHandle, State)
Definition: NpfsConnect.c:15
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static BOOLEAN CheckListenPipe(IN PTHREAD_CONTEXT Context, IN HANDLE ServerHandle, IN ULONG MilliSeconds)
Definition: NpfsConnect.c:67
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NpDisconnectPipe(ServerHandle)
Definition: npfs.h:74
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
#define STATUS_PIPE_CONNECTED
Definition: ntstatus.h:400
struct _THREAD_CONTEXT::@1570::@1573 Listen
static BOOLEAN CheckConnectPipe(IN PTHREAD_CONTEXT Context, IN PCWSTR PipePath, IN ULONG MilliSeconds)
Definition: NpfsConnect.c:55
Status
Definition: gdiplustypes.h:24
BOOLEAN WaitForWork(IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
Definition: NpfsHelpers.c:692
#define FILE_PIPE_DISCONNECTED_STATE
Definition: winternl.h:790
#define NpQueryPipe(h, es)
Definition: npfs.h:147
struct _THREAD_CONTEXT::@1570::@1572 Connect
#define skip(...)
Definition: atltest.h:64
#define FILE_PIPE_CLOSING_STATE
Definition: winternl.h:793
#define ok_eq_hex(value, expected)
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_ILLEGAL_FUNCTION
Definition: ntstatus.h:397
#define STATUS_PIPE_NOT_AVAILABLE
Definition: ntstatus.h:394
#define NpListenPipe(ServerHandle)
Definition: npfs.h:73

Referenced by RunTest().

Variable Documentation

◆ RunTest

KSTART_ROUTINE RunTest
static

Definition at line 238 of file NpfsConnect.c.

Referenced by START_TEST().