ReactOS 0.4.16-dev-258-g81860b4
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 OUT_QUOTA
Definition: NpfsConnect.c:13
#define IN_QUOTA
Definition: NpfsConnect.c:12
#define MAX_INSTANCES
Definition: NpfsConnect.c:11
#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 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

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}
static VOID ConnectPipe(IN OUT PTHREAD_CONTEXT Context)
Definition: NpfsConnect.c:33
BOOLEAN TriggerWork(IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
Definition: NpfsHelpers.c:710

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}
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}
#define NULL
Definition: types.h:112
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 {
262 TestConnect(ServerHandle, DEVICE_NAMED_PIPE L"\\KmtestNpfsConnectTestPipe");
263 }
264}
#define CheckServer(ServerHandle, State)
Definition: NpfsConnect.c:15
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
Status
Definition: gdiplustypes.h:25
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
#define DEVICE_NAMED_PIPE
Definition: npfs.h:11
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)
KMT_MESSAGE_HANDLER TestConnect
Definition: connect.c:257
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ START_TEST()

START_TEST ( NpfsConnect  )

Definition at line 266 of file NpfsConnect.c.

267{
269
272}
static KSTART_ROUTINE RunTest
Definition: NpfsConnect.c:238
_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)

◆ 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;
104 }
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);
115
116 /* Disconnecting the client should fail */
117 Status = NpDisconnectPipe(ClientHandle);
121
122 /* Listening on the client should fail */
123 Status = NpListenPipe(ClientHandle);
127
128 /* Close client */
129 if (ClientHandle)
130 ObCloseHandle(ClientHandle, KernelMode);
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);
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"))
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;
180 }
181 Okay = WaitForWork(&ListenContext, 100);
182 ok_bool_true(Okay, "WaitForWork returned");
183 ok_eq_hex(ListenContext.Listen.Status, STATUS_SUCCESS);
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);
192
193 /* Disconnect server */
194 Status = NpDisconnectPipe(ServerHandle);
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;
219 }
220 Okay = WaitForWork(&ListenContext, 100);
221 ok_bool_true(Okay, "WaitForWork returned");
222 ok_eq_hex(ListenContext.Listen.Status, STATUS_SUCCESS);
224
225 /* Close server */
226 Status = ObCloseHandle(ServerHandle, KernelMode);
229
230 /* Close client */
231 if (ClientHandle)
232 ObCloseHandle(ClientHandle, KernelMode);
233
234 FinishWorkerThread(&ListenContext);
235 FinishWorkerThread(&ConnectContext);
236}
static BOOLEAN CheckListenPipe(IN PTHREAD_CONTEXT Context, IN HANDLE ServerHandle, IN ULONG MilliSeconds)
Definition: NpfsConnect.c:67
#define CheckClient(ClientHandle, State)
Definition: NpfsConnect.c:23
static BOOLEAN CheckConnectPipe(IN PTHREAD_CONTEXT Context, IN PCWSTR PipePath, IN ULONG MilliSeconds)
Definition: NpfsConnect.c:55
unsigned char BOOLEAN
#define ok_bool_false(value, desc)
Definition: apitest.h:79
#define ok_bool_true(value, desc)
Definition: apitest.h:78
#define FILE_PIPE_DISCONNECTED_STATE
Definition: winternl.h:790
#define FILE_PIPE_CONNECTED_STATE
Definition: winternl.h:792
#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_NOT_AVAILABLE
Definition: ntstatus.h:408
#define STATUS_PIPE_CONNECTED
Definition: ntstatus.h:414
#define STATUS_ILLEGAL_FUNCTION
Definition: ntstatus.h:411
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
struct _THREAD_CONTEXT::@1623::@1625 Connect
struct _THREAD_CONTEXT::@1623::@1626 Listen

Variable Documentation

◆ RunTest

KSTART_ROUTINE RunTest
static

Definition at line 238 of file NpfsConnect.c.

Referenced by main(), CWineTest::Run(), and START_TEST().