1 /* Unit test suite for Ntdll NamedPipe API functions
3 * Copyright 2011 Bernhard Loos
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_NO_STATUS
30 #include "wine/test.h"
34 #ifndef __WINE_WINTERNL_H
39 } FILE_PIPE_INFORMATION
;
43 ULONG NamedPipeConfiguration
;
44 ULONG MaximumInstances
;
45 ULONG CurrentInstances
;
47 ULONG ReadDataAvailable
;
49 ULONG WriteQuotaAvailable
;
52 } FILE_PIPE_LOCAL_INFORMATION
;
54 #ifndef FILE_SYNCHRONOUS_IO_ALERT
55 #define FILE_SYNCHRONOUS_IO_ALERT 0x10
58 #ifndef FILE_SYNCHRONOUS_IO_NONALERT
59 #define FILE_SYNCHRONOUS_IO_NONALERT 0x20
62 #ifndef FSCTL_PIPE_LISTEN
63 #define FSCTL_PIPE_LISTEN CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
67 static NTSTATUS (WINAPI
*pNtFsControlFile
) (HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
, PVOID apc_context
, PIO_STATUS_BLOCK io
, ULONG code
, PVOID in_buffer
, ULONG in_size
, PVOID out_buffer
, ULONG out_size
);
68 static NTSTATUS (WINAPI
*pNtCreateNamedPipeFile
) (PHANDLE handle
, ULONG access
,
69 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK iosb
,
70 ULONG sharing
, ULONG dispo
, ULONG options
,
71 ULONG pipe_type
, ULONG read_mode
,
72 ULONG completion_mode
, ULONG max_inst
,
73 ULONG inbound_quota
, ULONG outbound_quota
,
74 PLARGE_INTEGER timeout
);
75 static NTSTATUS (WINAPI
*pNtQueryInformationFile
) (IN HANDLE FileHandle
, OUT PIO_STATUS_BLOCK IoStatusBlock
, OUT PVOID FileInformation
, IN ULONG Length
, IN FILE_INFORMATION_CLASS FileInformationClass
);
76 static NTSTATUS (WINAPI
*pNtSetInformationFile
) (HANDLE handle
, PIO_STATUS_BLOCK io
, PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class);
77 static NTSTATUS (WINAPI
*pNtCancelIoFile
) (HANDLE hFile
, PIO_STATUS_BLOCK io_status
);
78 static NTSTATUS (WINAPI
*pNtCancelIoFileEx
) (HANDLE hFile
, IO_STATUS_BLOCK
*iosb
, IO_STATUS_BLOCK
*io_status
);
79 static void (WINAPI
*pRtlInitUnicodeString
) (PUNICODE_STRING target
, PCWSTR source
);
81 static HANDLE (WINAPI
*pOpenThread
)(DWORD dwDesiredAccess
, BOOL bInheritHandle
, DWORD dwThreadId
);
82 static DWORD (WINAPI
*pQueueUserAPC
)(PAPCFUNC pfnAPC
, HANDLE hThread
, ULONG_PTR dwData
);
85 static BOOL
init_func_ptrs(void)
87 HMODULE module
= GetModuleHandleA("ntdll.dll");
89 #define loadfunc(name) if (!(p##name = (void *)GetProcAddress(module, #name))) { \
90 trace("GetProcAddress(%s) failed\n", #name); \
94 loadfunc(NtFsControlFile
)
95 loadfunc(NtCreateNamedPipeFile
)
96 loadfunc(NtQueryInformationFile
)
97 loadfunc(NtSetInformationFile
)
98 loadfunc(NtCancelIoFile
)
99 loadfunc(NtCancelIoFileEx
)
100 loadfunc(RtlInitUnicodeString
)
103 module
= GetModuleHandleA("kernel32.dll");
104 pOpenThread
= (void *)GetProcAddress(module
, "OpenThread");
105 pQueueUserAPC
= (void *)GetProcAddress(module
, "QueueUserAPC");
109 static inline BOOL
is_signaled( HANDLE obj
)
111 return WaitForSingleObject( obj
, 0 ) == WAIT_OBJECT_0
;
114 static const WCHAR testpipe
[] = { '\\', '\\', '.', '\\', 'p', 'i', 'p', 'e', '\\',
115 't', 'e', 's', 't', 'p', 'i', 'p', 'e', 0 };
116 static const WCHAR testpipe_nt
[] = { '\\', '?', '?', '\\', 'p', 'i', 'p', 'e', '\\',
117 't', 'e', 's', 't', 'p', 'i', 'p', 'e', 0 };
119 static NTSTATUS
create_pipe(PHANDLE handle
, ULONG sharing
, ULONG options
)
121 IO_STATUS_BLOCK iosb
;
122 OBJECT_ATTRIBUTES attr
;
124 LARGE_INTEGER timeout
;
127 pRtlInitUnicodeString(&name
, testpipe_nt
);
129 attr
.Length
= sizeof(attr
);
130 attr
.RootDirectory
= 0;
131 attr
.ObjectName
= &name
;
132 attr
.Attributes
= 0x40; /*case insensitive */
133 attr
.SecurityDescriptor
= NULL
;
134 attr
.SecurityQualityOfService
= NULL
;
136 timeout
.QuadPart
= -100000000;
138 res
= pNtCreateNamedPipeFile(handle
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
, sharing
, 2 /*FILE_CREATE*/,
139 options
, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
143 static BOOL ioapc_called
;
144 static void CALLBACK
ioapc(void *arg
, PIO_STATUS_BLOCK io
, ULONG reserved
)
149 static NTSTATUS
listen_pipe(HANDLE hPipe
, HANDLE hEvent
, PIO_STATUS_BLOCK iosb
, BOOL use_apc
)
153 ioapc_called
= FALSE
;
155 return pNtFsControlFile(hPipe
, hEvent
, use_apc
? &ioapc
: NULL
, use_apc
? &dummy
: NULL
, iosb
, FSCTL_PIPE_LISTEN
, 0, 0, 0, 0);
158 static void test_create_invalid(void)
160 IO_STATUS_BLOCK iosb
;
161 OBJECT_ATTRIBUTES attr
;
163 LARGE_INTEGER timeout
;
165 HANDLE handle
, handle2
;
166 FILE_PIPE_LOCAL_INFORMATION info
;
168 pRtlInitUnicodeString(&name
, testpipe_nt
);
170 attr
.Length
= sizeof(attr
);
171 attr
.RootDirectory
= 0;
172 attr
.ObjectName
= &name
;
173 attr
.Attributes
= 0x40; /*case insensitive */
174 attr
.SecurityDescriptor
= NULL
;
175 attr
.SecurityQualityOfService
= NULL
;
177 timeout
.QuadPart
= -100000000;
179 /* create a pipe with FILE_OVERWRITE */
180 res
= pNtCreateNamedPipeFile(&handle
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
, FILE_SHARE_READ
, 4 /*FILE_OVERWRITE*/,
181 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
182 todo_wine
ok(res
== STATUS_INVALID_PARAMETER
, "NtCreateNamedPipeFile returned %x\n", res
);
186 /* create a pipe with FILE_OVERWRITE_IF */
187 res
= pNtCreateNamedPipeFile(&handle
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
, FILE_SHARE_READ
, 5 /*FILE_OVERWRITE_IF*/,
188 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
189 todo_wine
ok(res
== STATUS_INVALID_PARAMETER
, "NtCreateNamedPipeFile returned %x\n", res
);
193 /* create a pipe with sharing = 0 */
194 res
= pNtCreateNamedPipeFile(&handle
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
, 0, 2 /*FILE_CREATE*/,
195 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
196 ok(res
== STATUS_INVALID_PARAMETER
, "NtCreateNamedPipeFile returned %x\n", res
);
200 /* create a pipe without r/w access */
201 res
= pNtCreateNamedPipeFile(&handle
, SYNCHRONIZE
, &attr
, &iosb
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 2 /*FILE_CREATE*/,
202 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
203 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
205 res
= pNtQueryInformationFile(handle
, &iosb
, &info
, sizeof(info
), (FILE_INFORMATION_CLASS
)24);
206 ok(res
== STATUS_ACCESS_DENIED
, "NtQueryInformationFile returned %x\n", res
);
208 /* test FILE_CREATE creation disposition */
209 res
= pNtCreateNamedPipeFile(&handle2
, SYNCHRONIZE
, &attr
, &iosb
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 2 /*FILE_CREATE*/,
210 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
211 todo_wine
ok(res
== STATUS_ACCESS_DENIED
, "NtCreateNamedPipeFile returned %x\n", res
);
213 CloseHandle(handle2
);
218 static void test_create(void)
223 FILE_PIPE_LOCAL_INFORMATION info
;
224 IO_STATUS_BLOCK iosb
;
225 HANDLE hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
227 static const DWORD access
[] = { 0, GENERIC_READ
, GENERIC_WRITE
, GENERIC_READ
| GENERIC_WRITE
};
228 static const DWORD sharing
[] = { FILE_SHARE_READ
, FILE_SHARE_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
};
229 static const DWORD pipe_config
[]= { 1, 0, 2 };
231 for (j
= 0; j
< sizeof(sharing
) / sizeof(DWORD
); j
++) {
232 for (k
= 0; k
< sizeof(access
) / sizeof(DWORD
); k
++) {
234 BOOL should_succeed
= TRUE
;
236 res
= create_pipe(&hserver
, sharing
[j
], 0);
238 ok(0, "NtCreateNamedPipeFile returned %x, sharing: %x\n", res
, sharing
[j
]);
242 res
= listen_pipe(hserver
, hEvent
, &iosb
, FALSE
);
243 ok(res
== STATUS_PENDING
, "NtFsControlFile returned %x\n", res
);
245 res
= pNtQueryInformationFile(hserver
, &iosb
, &info
, sizeof(info
), (FILE_INFORMATION_CLASS
)24);
246 ok(!res
, "NtQueryInformationFile for server returned %x, sharing: %x\n", res
, sharing
[j
]);
247 ok(info
.NamedPipeConfiguration
== pipe_config
[j
], "wrong duplex status for pipe: %d, expected %d\n",
248 info
.NamedPipeConfiguration
, pipe_config
[j
]);
250 hclient
= CreateFileW(testpipe
, access
[k
], 0, 0, OPEN_EXISTING
, 0, 0);
251 if (hclient
!= INVALID_HANDLE_VALUE
) {
252 res
= pNtQueryInformationFile(hclient
, &iosb
, &info
, sizeof(info
), (FILE_INFORMATION_CLASS
)24);
253 ok(!res
, "NtQueryInformationFile for client returned %x, access: %x, sharing: %x\n",
254 res
, access
[k
], sharing
[j
]);
255 ok(info
.NamedPipeConfiguration
== pipe_config
[j
], "wrong duplex status for pipe: %d, expected %d\n",
256 info
.NamedPipeConfiguration
, pipe_config
[j
]);
257 CloseHandle(hclient
);
260 if (access
[k
] & GENERIC_WRITE
)
261 should_succeed
&= !!(sharing
[j
] & FILE_SHARE_WRITE
);
262 if (access
[k
] & GENERIC_READ
)
263 should_succeed
&= !!(sharing
[j
] & FILE_SHARE_READ
);
266 ok(hclient
!= INVALID_HANDLE_VALUE
, "CreateFile failed for sharing %x, access: %x, GetLastError: %d\n",
267 sharing
[j
], access
[k
], GetLastError());
269 ok(hclient
== INVALID_HANDLE_VALUE
, "CreateFile succeeded for sharing %x, access: %x\n", sharing
[j
], access
[k
]);
271 CloseHandle(hserver
);
277 static void test_overlapped(void)
279 IO_STATUS_BLOCK iosb
;
285 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
286 ok(hEvent
!= INVALID_HANDLE_VALUE
, "can't create event, GetLastError: %x\n", GetLastError());
288 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0 /* OVERLAPPED */);
289 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
291 memset(&iosb
, 0x55, sizeof(iosb
));
292 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
293 ok(res
== STATUS_PENDING
, "NtFsControlFile returned %x\n", res
);
294 ok(U(iosb
).Status
== 0x55555555, "iosb.Status got changed to %x\n", U(iosb
).Status
);
296 hClient
= CreateFileW(testpipe
, GENERIC_READ
| GENERIC_WRITE
, 0, 0, OPEN_EXISTING
, 0, 0);
297 ok(hClient
!= INVALID_HANDLE_VALUE
, "can't open pipe, GetLastError: %x\n", GetLastError());
299 ok(U(iosb
).Status
== 0, "Wrong iostatus %x\n", U(iosb
).Status
);
300 ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
302 ok(!ioapc_called
, "IOAPC ran too early\n");
304 SleepEx(0, TRUE
); /* alertable wait state */
306 ok(ioapc_called
, "IOAPC didn't run\n");
309 CloseHandle(hClient
);
311 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0 /* OVERLAPPED */);
312 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
314 hClient
= CreateFileW(testpipe
, GENERIC_READ
| GENERIC_WRITE
, 0, 0, OPEN_EXISTING
, 0, 0);
315 ok(hClient
!= INVALID_HANDLE_VALUE
|| broken(GetLastError() == ERROR_PIPE_BUSY
) /* > Win 8 */,
316 "can't open pipe, GetLastError: %x\n", GetLastError());
318 if (hClient
!= INVALID_HANDLE_VALUE
)
321 memset(&iosb
, 0x55, sizeof(iosb
));
322 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
323 ok(res
== STATUS_PIPE_CONNECTED
, "NtFsControlFile returned %x\n", res
);
324 ok(U(iosb
).Status
== 0x55555555, "iosb.Status got changed to %x\n", U(iosb
).Status
);
325 ok(!is_signaled(hEvent
), "hEvent not signaled\n");
327 CloseHandle(hClient
);
334 static BOOL userapc_called
;
335 static void CALLBACK
userapc(ULONG_PTR dwParam
)
337 userapc_called
= TRUE
;
340 static BOOL open_succeeded
;
341 static DWORD WINAPI
thread(PVOID main_thread
)
349 userapc_called
= FALSE
;
350 ret
= pQueueUserAPC(&userapc
, main_thread
, 0);
351 ok(ret
, "can't queue user apc, GetLastError: %x\n", GetLastError());
352 CloseHandle(main_thread
);
357 h
= CreateFileW(testpipe
, GENERIC_WRITE
| GENERIC_READ
, 0, 0, OPEN_EXISTING
, 0, 0);
359 if (h
!= INVALID_HANDLE_VALUE
) {
360 open_succeeded
= TRUE
;
364 open_succeeded
= FALSE
;
369 static void test_alertable(void)
371 IO_STATUS_BLOCK iosb
;
378 memset(&iosb
, 0x55, sizeof(iosb
));
380 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
381 ok(hEvent
!= INVALID_HANDLE_VALUE
, "can't create event, GetLastError: %x\n", GetLastError());
383 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_SYNCHRONOUS_IO_ALERT
);
384 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
386 /* queue an user apc before calling listen */
387 userapc_called
= FALSE
;
388 ret
= pQueueUserAPC(&userapc
, GetCurrentThread(), 0);
389 ok(ret
, "can't queue user apc, GetLastError: %x\n", GetLastError());
391 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
392 todo_wine
ok(res
== STATUS_CANCELLED
, "NtFsControlFile returned %x\n", res
);
394 todo_wine
ok(userapc_called
, "user apc didn't run\n");
395 ok(U(iosb
).Status
== 0x55555555, "iosb.Status got changed to %x\n", U(iosb
).Status
);
396 todo_wine
ok(WaitForSingleObjectEx(hEvent
, 0, TRUE
) == WAIT_TIMEOUT
, "hEvent signaled\n");
397 ok(!ioapc_called
, "IOAPC ran\n");
399 /* queue an user apc from a different thread */
400 hThread
= CreateThread(NULL
, 0, &thread
, pOpenThread(MAXIMUM_ALLOWED
, FALSE
, GetCurrentThreadId()), 0, 0);
401 ok(hThread
!= INVALID_HANDLE_VALUE
, "can't create thread, GetLastError: %x\n", GetLastError());
403 /* wine_todo: the earlier NtFsControlFile call gets cancelled after the pipe gets set into listen state
404 instead of before, so this NtFsControlFile will fail STATUS_INVALID_HANDLE */
405 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
406 todo_wine
ok(res
== STATUS_CANCELLED
, "NtFsControlFile returned %x\n", res
);
408 ok(userapc_called
, "user apc didn't run\n");
409 ok(U(iosb
).Status
== 0x55555555, "iosb.Status got changed to %x\n", U(iosb
).Status
);
410 ok(WaitForSingleObjectEx(hEvent
, 0, TRUE
) == WAIT_TIMEOUT
, "hEvent signaled\n");
411 ok(!ioapc_called
, "IOAPC ran\n");
413 WaitForSingleObject(hThread
, INFINITE
);
415 SleepEx(0, TRUE
); /* get rid of the userapc, if NtFsControlFile failed */
417 ok(open_succeeded
, "couldn't open client side pipe\n");
419 CloseHandle(hThread
);
420 DisconnectNamedPipe(hPipe
);
422 /* finally try without an apc */
423 hThread
= CreateThread(NULL
, 0, &thread
, 0, 0, 0);
424 ok(hThread
!= INVALID_HANDLE_VALUE
, "can't create thread, GetLastError: %x\n", GetLastError());
426 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
427 todo_wine
ok(!res
, "NtFsControlFile returned %x\n", res
);
429 ok(open_succeeded
, "couldn't open client side pipe\n");
430 ok(!U(iosb
).Status
, "Wrong iostatus %x\n", U(iosb
).Status
);
431 todo_wine
ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
433 WaitForSingleObject(hThread
, INFINITE
);
434 CloseHandle(hThread
);
439 static void test_nonalertable(void)
441 IO_STATUS_BLOCK iosb
;
448 memset(&iosb
, 0x55, sizeof(iosb
));
450 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
451 ok(hEvent
!= INVALID_HANDLE_VALUE
, "can't create event, GetLastError: %x\n", GetLastError());
453 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_SYNCHRONOUS_IO_NONALERT
);
454 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
456 hThread
= CreateThread(NULL
, 0, &thread
, 0, 0, 0);
457 ok(hThread
!= INVALID_HANDLE_VALUE
, "can't create thread, GetLastError: %x\n", GetLastError());
459 userapc_called
= FALSE
;
460 ret
= pQueueUserAPC(&userapc
, GetCurrentThread(), 0);
461 ok(ret
, "can't queue user apc, GetLastError: %x\n", GetLastError());
463 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
464 todo_wine
ok(!res
, "NtFsControlFile returned %x\n", res
);
466 ok(open_succeeded
, "couldn't open client side pipe\n");
467 todo_wine
ok(!U(iosb
).Status
, "Wrong iostatus %x\n", U(iosb
).Status
);
468 todo_wine
ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
470 ok(!ioapc_called
, "IOAPC ran too early\n");
471 ok(!userapc_called
, "user apc ran too early\n");
473 SleepEx(0, TRUE
); /* alertable wait state */
475 ok(ioapc_called
, "IOAPC didn't run\n");
476 ok(userapc_called
, "user apc didn't run\n");
478 WaitForSingleObject(hThread
, INFINITE
);
479 CloseHandle(hThread
);
484 static void test_cancelio(void)
486 IO_STATUS_BLOCK iosb
;
487 IO_STATUS_BLOCK cancel_sb
;
492 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
493 ok(hEvent
!= INVALID_HANDLE_VALUE
, "can't create event, GetLastError: %x\n", GetLastError());
495 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0 /* OVERLAPPED */);
496 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
498 memset(&iosb
, 0x55, sizeof(iosb
));
500 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
501 ok(res
== STATUS_PENDING
, "NtFsControlFile returned %x\n", res
);
503 res
= pNtCancelIoFile(hPipe
, &cancel_sb
);
504 ok(!res
, "NtCancelIoFile returned %x\n", res
);
506 ok(U(iosb
).Status
== STATUS_CANCELLED
, "Wrong iostatus %x\n", U(iosb
).Status
);
507 ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
509 ok(!ioapc_called
, "IOAPC ran too early\n");
511 SleepEx(0, TRUE
); /* alertable wait state */
513 ok(ioapc_called
, "IOAPC didn't run\n");
517 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0 /* OVERLAPPED */);
518 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
520 memset(&iosb
, 0x55, sizeof(iosb
));
521 res
= listen_pipe(hPipe
, hEvent
, &iosb
, FALSE
);
522 ok(res
== STATUS_PENDING
, "NtFsControlFile returned %x\n", res
);
524 res
= pNtCancelIoFileEx(hPipe
, &iosb
, &cancel_sb
);
525 ok(!res
, "NtCancelIoFileEx returned %x\n", res
);
527 ok(U(iosb
).Status
== STATUS_CANCELLED
, "Wrong iostatus %x\n", U(iosb
).Status
);
528 ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
534 static void _check_pipe_handle_state(int line
, HANDLE handle
, ULONG read
, ULONG completion
)
536 IO_STATUS_BLOCK iosb
;
537 FILE_PIPE_INFORMATION fpi
;
539 if (handle
!= INVALID_HANDLE_VALUE
)
541 memset(&fpi
, 0x55, sizeof(fpi
));
542 res
= pNtQueryInformationFile(handle
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
543 ok_(__FILE__
, line
)(!res
, "NtQueryInformationFile returned %x\n", res
);
544 ok_(__FILE__
, line
)(fpi
.ReadMode
== read
, "Unexpected ReadMode, expected %x, got %x\n",
546 ok_(__FILE__
, line
)(fpi
.CompletionMode
== completion
, "Unexpected CompletionMode, expected %x, got %x\n",
547 completion
, fpi
.CompletionMode
);
550 #define check_pipe_handle_state(handle, r, c) _check_pipe_handle_state(__LINE__, handle, r, c)
552 static void test_filepipeinfo(void)
554 IO_STATUS_BLOCK iosb
;
555 OBJECT_ATTRIBUTES attr
;
557 LARGE_INTEGER timeout
;
558 HANDLE hServer
, hClient
;
559 FILE_PIPE_INFORMATION fpi
;
562 pRtlInitUnicodeString(&name
, testpipe_nt
);
564 attr
.Length
= sizeof(attr
);
565 attr
.RootDirectory
= 0;
566 attr
.ObjectName
= &name
;
567 attr
.Attributes
= 0x40; /* case insensitive */
568 attr
.SecurityDescriptor
= NULL
;
569 attr
.SecurityQualityOfService
= NULL
;
571 timeout
.QuadPart
= -100000000;
573 /* test with INVALID_HANDLE_VALUE */
574 res
= pNtQueryInformationFile(INVALID_HANDLE_VALUE
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
575 ok(res
== STATUS_OBJECT_TYPE_MISMATCH
, "NtQueryInformationFile returned %x\n", res
);
578 fpi
.CompletionMode
= 0;
579 res
= pNtSetInformationFile(INVALID_HANDLE_VALUE
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
580 ok(res
== STATUS_OBJECT_TYPE_MISMATCH
, "NtSetInformationFile returned %x\n", res
);
582 /* server end with read-only attributes */
583 res
= pNtCreateNamedPipeFile(&hServer
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
,
584 FILE_SHARE_READ
| FILE_SHARE_WRITE
, 2 /* FILE_CREATE */,
585 0, 0, 0, 1, 0xFFFFFFFF, 500, 500, &timeout
);
586 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
588 check_pipe_handle_state(hServer
, 0, 1);
590 hClient
= CreateFileW(testpipe
, GENERIC_READ
| GENERIC_WRITE
, 0, 0, OPEN_EXISTING
, 0, 0);
591 ok(hClient
!= INVALID_HANDLE_VALUE
|| broken(GetLastError() == ERROR_PIPE_BUSY
) /* > Win 8 */,
592 "can't open pipe, GetLastError: %x\n", GetLastError());
594 check_pipe_handle_state(hServer
, 0, 1);
595 check_pipe_handle_state(hClient
, 0, 0);
598 fpi
.CompletionMode
= 0;
599 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
600 ok(res
== STATUS_ACCESS_DENIED
, "NtSetInformationFile returned %x\n", res
);
602 check_pipe_handle_state(hServer
, 0, 1);
603 check_pipe_handle_state(hClient
, 0, 0);
605 fpi
.ReadMode
= 1; /* invalid on a byte stream pipe */
606 fpi
.CompletionMode
= 1;
607 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
608 ok(res
== STATUS_ACCESS_DENIED
, "NtSetInformationFile returned %x\n", res
);
610 check_pipe_handle_state(hServer
, 0, 1);
611 check_pipe_handle_state(hClient
, 0, 0);
613 if (hClient
!= INVALID_HANDLE_VALUE
)
615 fpi
.ReadMode
= 1; /* invalid on a byte stream pipe */
616 fpi
.CompletionMode
= 1;
617 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
618 ok(res
== STATUS_INVALID_PARAMETER
, "NtSetInformationFile returned %x\n", res
);
621 check_pipe_handle_state(hServer
, 0, 1);
622 check_pipe_handle_state(hClient
, 0, 0);
624 if (hClient
!= INVALID_HANDLE_VALUE
)
627 fpi
.CompletionMode
= 1;
628 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
629 ok(!res
, "NtSetInformationFile returned %x\n", res
);
632 check_pipe_handle_state(hServer
, 0, 1);
633 check_pipe_handle_state(hClient
, 0, 1);
635 if (hClient
!= INVALID_HANDLE_VALUE
)
638 fpi
.CompletionMode
= 2; /* not in range 0-1 */
639 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
640 ok(res
== STATUS_INVALID_PARAMETER
|| broken(!res
) /* < Vista */, "NtSetInformationFile returned %x\n", res
);
642 fpi
.ReadMode
= 2; /* not in range 0-1 */
643 fpi
.CompletionMode
= 0;
644 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
645 ok(res
== STATUS_INVALID_PARAMETER
|| broken(!res
) /* < Vista */, "NtSetInformationFile returned %x\n", res
);
648 CloseHandle(hClient
);
650 check_pipe_handle_state(hServer
, 0, 1);
653 fpi
.CompletionMode
= 0;
654 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
655 ok(res
== STATUS_ACCESS_DENIED
, "NtSetInformationFile returned %x\n", res
);
657 CloseHandle(hServer
);
659 /* message mode server with read/write attributes */
660 res
= pNtCreateNamedPipeFile(&hServer
, FILE_READ_ATTRIBUTES
| FILE_WRITE_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
,
661 FILE_SHARE_READ
| FILE_SHARE_WRITE
, 2 /* FILE_CREATE */,
662 0, 1, 1, 0, 0xFFFFFFFF, 500, 500, &timeout
);
663 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
665 check_pipe_handle_state(hServer
, 1, 0);
667 hClient
= CreateFileW(testpipe
, GENERIC_READ
| GENERIC_WRITE
, 0, 0, OPEN_EXISTING
, 0, 0);
668 ok(hClient
!= INVALID_HANDLE_VALUE
|| broken(GetLastError() == ERROR_PIPE_BUSY
) /* > Win 8 */,
669 "can't open pipe, GetLastError: %x\n", GetLastError());
671 check_pipe_handle_state(hServer
, 1, 0);
672 check_pipe_handle_state(hClient
, 0, 0);
674 if (hClient
!= INVALID_HANDLE_VALUE
)
677 fpi
.CompletionMode
= 1;
678 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
679 ok(!res
, "NtSetInformationFile returned %x\n", res
);
682 check_pipe_handle_state(hServer
, 1, 0);
683 check_pipe_handle_state(hClient
, 1, 1);
686 fpi
.CompletionMode
= 1;
687 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
688 ok(!res
, "NtSetInformationFile returned %x\n", res
);
690 check_pipe_handle_state(hServer
, 0, 1);
691 check_pipe_handle_state(hClient
, 1, 1);
693 if (hClient
!= INVALID_HANDLE_VALUE
)
696 fpi
.CompletionMode
= 2; /* not in range 0-1 */
697 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
698 ok(res
== STATUS_INVALID_PARAMETER
|| broken(!res
) /* < Vista */, "NtSetInformationFile returned %x\n", res
);
700 fpi
.ReadMode
= 2; /* not in range 0-1 */
701 fpi
.CompletionMode
= 0;
702 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
703 ok(res
== STATUS_INVALID_PARAMETER
|| broken(!res
) /* < Vista */, "NtSetInformationFile returned %x\n", res
);
706 CloseHandle(hClient
);
708 check_pipe_handle_state(hServer
, 0, 1);
711 fpi
.CompletionMode
= 0;
712 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
713 ok(!res
, "NtSetInformationFile returned %x\n", res
);
715 check_pipe_handle_state(hServer
, 1, 0);
717 CloseHandle(hServer
);
720 static void WINAPI
apc( void *arg
, IO_STATUS_BLOCK
*iosb
, ULONG reserved
)
724 ok( !reserved
, "reserved is not 0: %x\n", reserved
);
727 static void test_peek(HANDLE pipe
)
729 FILE_PIPE_PEEK_BUFFER buf
;
730 IO_STATUS_BLOCK iosb
;
731 HANDLE event
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
734 memset(&iosb
, 0x55, sizeof(iosb
));
735 status
= NtFsControlFile(pipe
, NULL
, NULL
, NULL
, &iosb
, FSCTL_PIPE_PEEK
, NULL
, 0, &buf
, sizeof(buf
));
736 ok(!status
|| status
== STATUS_PENDING
, "NtFsControlFile failed: %x\n", status
);
737 ok(!iosb
.Status
, "iosb.Status = %x\n", iosb
.Status
);
738 ok(buf
.ReadDataAvailable
== 1, "ReadDataAvailable = %u\n", buf
.ReadDataAvailable
);
741 memset(&iosb
, 0x55, sizeof(iosb
));
742 status
= NtFsControlFile(pipe
, event
, NULL
, NULL
, &iosb
, FSCTL_PIPE_PEEK
, NULL
, 0, &buf
, sizeof(buf
));
743 ok(!status
|| status
== STATUS_PENDING
, "NtFsControlFile failed: %x\n", status
);
744 ok(buf
.ReadDataAvailable
== 1, "ReadDataAvailable = %u\n", buf
.ReadDataAvailable
);
745 ok(!iosb
.Status
, "iosb.Status = %x\n", iosb
.Status
);
747 ok(is_signaled(event
), "event is not signaled\n");
752 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_pipe.c"
754 static BOOL
create_pipe_pair( HANDLE
*read
, HANDLE
*write
, ULONG flags
, ULONG type
, ULONG size
)
756 const BOOL server_reader
= flags
& PIPE_ACCESS_INBOUND
;
757 HANDLE client
, server
;
759 server
= CreateNamedPipeA(PIPENAME
, flags
, PIPE_WAIT
| type
,
760 1, size
, size
, NMPWAIT_USE_DEFAULT_WAIT
, NULL
);
761 ok(server
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
763 client
= CreateFileA(PIPENAME
, server_reader
? GENERIC_WRITE
: GENERIC_READ
| FILE_WRITE_ATTRIBUTES
, 0,
764 NULL
, OPEN_EXISTING
, flags
& FILE_FLAG_OVERLAPPED
, 0);
765 ok(client
!= INVALID_HANDLE_VALUE
, "CreateFile failed (%d)\n", GetLastError());
774 if(type
& PIPE_READMODE_MESSAGE
)
776 DWORD read_mode
= PIPE_READMODE_MESSAGE
;
777 ok(SetNamedPipeHandleState(client
, &read_mode
, NULL
, NULL
), "Change mode\n");
786 static void read_pipe_test(ULONG pipe_flags
, ULONG pipe_type
)
788 IO_STATUS_BLOCK iosb
, iosb2
;
789 HANDLE handle
, read
, write
;
790 HANDLE event
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
797 if (!create_pipe_pair( &read
, &write
, FILE_FLAG_OVERLAPPED
| pipe_flags
, pipe_type
, 4096 )) return;
799 /* try read with no data */
800 U(iosb
).Status
= 0xdeadbabe;
801 iosb
.Information
= 0xdeadbeef;
802 ok( is_signaled( read
), "read handle is not signaled\n" );
803 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
804 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
805 ok( !is_signaled( read
), "read handle is signaled\n" );
806 ok( !is_signaled( event
), "event is signaled\n" );
807 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
808 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
809 ok( !apc_count
, "apc was called\n" );
810 ret
= WriteFile( write
, buffer
, 1, &written
, NULL
);
811 ok(ret
&& written
== 1, "WriteFile error %d\n", GetLastError());
812 /* iosb updated here by async i/o */
813 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
814 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
815 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
816 ok( !is_signaled( read
), "read handle is signaled\n" );
817 ok( is_signaled( event
), "event is not signaled\n" );
818 ok( !apc_count
, "apc was called\n" );
820 SleepEx( 1, FALSE
); /* non-alertable sleep */
821 ok( !apc_count
, "apc was called\n" );
822 SleepEx( 1, TRUE
); /* alertable sleep */
823 ok( apc_count
== 1, "apc not called\n" );
825 /* with no event, the pipe handle itself gets signaled */
827 U(iosb
).Status
= 0xdeadbabe;
828 iosb
.Information
= 0xdeadbeef;
829 ok( !is_signaled( read
), "read handle is signaled\n" );
830 status
= NtReadFile( read
, 0, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
831 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
832 ok( !is_signaled( read
), "read handle is signaled\n" );
833 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
834 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
835 ok( !apc_count
, "apc was called\n" );
836 ret
= WriteFile( write
, buffer
, 1, &written
, NULL
);
837 ok(ret
&& written
== 1, "WriteFile error %d\n", GetLastError());
838 /* iosb updated here by async i/o */
839 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
840 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
841 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
842 ok( is_signaled( read
), "read handle is not signaled\n" );
843 ok( !apc_count
, "apc was called\n" );
845 SleepEx( 1, FALSE
); /* non-alertable sleep */
846 ok( !apc_count
, "apc was called\n" );
847 SleepEx( 1, TRUE
); /* alertable sleep */
848 ok( apc_count
== 1, "apc not called\n" );
850 /* now read with data ready */
852 U(iosb
).Status
= 0xdeadbabe;
853 iosb
.Information
= 0xdeadbeef;
855 ret
= WriteFile( write
, buffer
, 1, &written
, NULL
);
856 ok(ret
&& written
== 1, "WriteFile error %d\n", GetLastError());
860 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
861 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
862 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
863 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
864 ok( is_signaled( event
), "event is not signaled\n" );
865 ok( !apc_count
, "apc was called\n" );
866 SleepEx( 1, FALSE
); /* non-alertable sleep */
867 ok( !apc_count
, "apc was called\n" );
868 SleepEx( 1, TRUE
); /* alertable sleep */
869 ok( apc_count
== 1, "apc not called\n" );
871 /* now partial read with data ready */
873 U(iosb
).Status
= 0xdeadbabe;
874 iosb
.Information
= 0xdeadbeef;
876 ret
= WriteFile( write
, buffer
, 2, &written
, NULL
);
877 ok(ret
&& written
== 2, "WriteFile error %d\n", GetLastError());
878 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
879 if (pipe_type
& PIPE_READMODE_MESSAGE
)
881 ok( status
== STATUS_BUFFER_OVERFLOW
, "wrong status %x\n", status
);
882 ok( U(iosb
).Status
== STATUS_BUFFER_OVERFLOW
, "wrong status %x\n", U(iosb
).Status
);
886 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
887 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
889 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
890 ok( is_signaled( event
), "event is not signaled\n" );
891 ok( !apc_count
, "apc was called\n" );
892 SleepEx( 1, FALSE
); /* non-alertable sleep */
893 ok( !apc_count
, "apc was called\n" );
894 SleepEx( 1, TRUE
); /* alertable sleep */
895 ok( apc_count
== 1, "apc not called\n" );
897 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
898 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
899 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
900 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
901 ok( is_signaled( event
), "event is not signaled\n" );
902 ok( !apc_count
, "apc was called\n" );
903 SleepEx( 1, FALSE
); /* non-alertable sleep */
904 ok( !apc_count
, "apc was called\n" );
905 SleepEx( 1, TRUE
); /* alertable sleep */
906 ok( apc_count
== 1, "apc not called\n" );
908 /* try read with no data */
910 U(iosb
).Status
= 0xdeadbabe;
911 iosb
.Information
= 0xdeadbeef;
912 ok( is_signaled( event
), "event is not signaled\n" ); /* check that read resets the event */
913 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
914 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
915 ok( !is_signaled( event
), "event is signaled\n" );
916 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
917 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
918 ok( !apc_count
, "apc was called\n" );
919 ret
= WriteFile( write
, buffer
, 1, &written
, NULL
);
920 ok(ret
&& written
== 1, "WriteFile error %d\n", GetLastError());
921 /* partial read is good enough */
922 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
923 ok( is_signaled( event
), "event is not signaled\n" );
924 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
925 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
926 ok( !apc_count
, "apc was called\n" );
927 SleepEx( 1, TRUE
); /* alertable sleep */
928 ok( apc_count
== 1, "apc was not called\n" );
930 /* read from disconnected pipe */
932 U(iosb
).Status
= 0xdeadbabe;
933 iosb
.Information
= 0xdeadbeef;
934 CloseHandle( write
);
935 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
936 ok( status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", status
);
937 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
938 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
939 ok( !is_signaled( event
), "event is signaled\n" );
940 ok( !apc_count
, "apc was called\n" );
941 SleepEx( 1, TRUE
); /* alertable sleep */
942 ok( !apc_count
, "apc was called\n" );
945 /* read from disconnected pipe, with invalid event handle */
947 U(iosb
).Status
= 0xdeadbabe;
948 iosb
.Information
= 0xdeadbeef;
949 status
= NtReadFile( read
, (HANDLE
)0xdeadbeef, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
950 ok( status
== STATUS_INVALID_HANDLE
, "wrong status %x\n", status
);
951 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
952 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
953 ok( !apc_count
, "apc was called\n" );
954 SleepEx( 1, TRUE
); /* alertable sleep */
955 ok( !apc_count
, "apc was called\n" );
958 /* read from closed handle */
960 U(iosb
).Status
= 0xdeadbabe;
961 iosb
.Information
= 0xdeadbeef;
963 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
964 ok( status
== STATUS_INVALID_HANDLE
, "wrong status %x\n", status
);
965 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
966 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
967 ok( is_signaled( event
), "event is not signaled\n" ); /* not reset on invalid handle */
968 ok( !apc_count
, "apc was called\n" );
969 SleepEx( 1, TRUE
); /* alertable sleep */
970 ok( !apc_count
, "apc was called\n" );
972 /* disconnect while async read is in progress */
973 if (!create_pipe_pair( &read
, &write
, FILE_FLAG_OVERLAPPED
| pipe_flags
, pipe_type
, 4096 )) return;
975 U(iosb
).Status
= 0xdeadbabe;
976 iosb
.Information
= 0xdeadbeef;
977 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
978 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
979 ok( !is_signaled( event
), "event is signaled\n" );
980 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
981 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
982 ok( !apc_count
, "apc was called\n" );
983 CloseHandle( write
);
984 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
985 todo_wine_if(!(pipe_type
& PIPE_TYPE_MESSAGE
) && (pipe_flags
& PIPE_ACCESS_OUTBOUND
))
986 ok( U(iosb
).Status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", U(iosb
).Status
);
987 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
988 ok( is_signaled( event
), "event is not signaled\n" );
989 ok( !apc_count
, "apc was called\n" );
990 SleepEx( 1, TRUE
); /* alertable sleep */
991 ok( apc_count
== 1, "apc was not called\n" );
994 if (!create_pipe_pair( &read
, &write
, FILE_FLAG_OVERLAPPED
| pipe_flags
, pipe_type
, 4096 )) return;
995 ret
= DuplicateHandle(GetCurrentProcess(), read
, GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
996 ok(ret
, "Failed to duplicate handle: %d\n", GetLastError());
999 U(iosb
).Status
= 0xdeadbabe;
1000 iosb
.Information
= 0xdeadbeef;
1001 status
= NtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
1002 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
1003 ok( !is_signaled( event
), "event is signaled\n" );
1004 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
1005 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
1006 ok( !apc_count
, "apc was called\n" );
1007 /* Cancel by other handle */
1008 status
= pNtCancelIoFile( read
, &iosb2
);
1009 ok(status
== STATUS_SUCCESS
, "failed to cancel by different handle: %x\n", status
);
1010 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
1011 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
1012 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
1013 ok( is_signaled( event
), "event is not signaled\n" );
1014 ok( !apc_count
, "apc was called\n" );
1015 SleepEx( 1, TRUE
); /* alertable sleep */
1016 ok( apc_count
== 1, "apc was not called\n" );
1019 U(iosb
).Status
= 0xdeadbabe;
1020 iosb
.Information
= 0xdeadbeef;
1021 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
1022 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
1023 ok( !is_signaled( event
), "event is signaled\n" );
1024 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
1025 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
1026 ok( !apc_count
, "apc was called\n" );
1027 /* Close queued handle */
1028 CloseHandle( read
);
1029 SleepEx( 1, TRUE
); /* alertable sleep */
1030 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
1031 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
1032 status
= pNtCancelIoFile( read
, &iosb2
);
1033 ok(status
== STATUS_INVALID_HANDLE
, "cancelled by closed handle?\n");
1034 status
= pNtCancelIoFile( handle
, &iosb2
);
1035 ok(status
== STATUS_SUCCESS
, "failed to cancel: %x\n", status
);
1036 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
1037 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
1038 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
1039 ok( is_signaled( event
), "event is not signaled\n" );
1040 ok( !apc_count
, "apc was called\n" );
1041 SleepEx( 1, TRUE
); /* alertable sleep */
1042 ok( apc_count
== 1, "apc was not called\n" );
1043 CloseHandle( handle
);
1044 CloseHandle( write
);
1046 if (pNtCancelIoFileEx
)
1048 /* Basic Cancel Ex */
1049 if (!create_pipe_pair( &read
, &write
, FILE_FLAG_OVERLAPPED
| pipe_flags
, pipe_type
, 4096 )) return;
1052 U(iosb
).Status
= 0xdeadbabe;
1053 iosb
.Information
= 0xdeadbeef;
1054 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
1055 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
1056 ok( !is_signaled( event
), "event is signaled\n" );
1057 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
1058 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
1059 ok( !apc_count
, "apc was called\n" );
1060 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
1061 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
1062 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
1063 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
1064 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
1065 ok( is_signaled( event
), "event is not signaled\n" );
1066 ok( !apc_count
, "apc was called\n" );
1067 SleepEx( 1, TRUE
); /* alertable sleep */
1068 ok( apc_count
== 1, "apc was not called\n" );
1070 /* Duplicate iosb */
1072 U(iosb
).Status
= 0xdeadbabe;
1073 iosb
.Information
= 0xdeadbeef;
1074 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
1075 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
1076 ok( !is_signaled( event
), "event is signaled\n" );
1077 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
1078 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
1079 ok( !apc_count
, "apc was called\n" );
1080 status
= NtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
1081 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
1082 ok( !is_signaled( event
), "event is signaled\n" );
1083 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
1084 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
1085 ok( !apc_count
, "apc was called\n" );
1086 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
1087 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
1088 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
1089 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
1090 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
1091 ok( is_signaled( event
), "event is not signaled\n" );
1092 ok( !apc_count
, "apc was called\n" );
1093 SleepEx( 1, TRUE
); /* alertable sleep */
1094 ok( apc_count
== 2, "apc was not called\n" );
1096 CloseHandle( read
);
1097 CloseHandle( write
);
1105 if (!init_func_ptrs())
1108 trace("starting invalid create tests\n");
1109 test_create_invalid();
1111 trace("starting create tests\n");
1114 trace("starting overlapped tests\n");
1117 trace("starting FILE_PIPE_INFORMATION tests\n");
1118 test_filepipeinfo();
1120 if (!pOpenThread
|| !pQueueUserAPC
)
1123 trace("starting alertable tests\n");
1126 trace("starting nonalertable tests\n");
1127 test_nonalertable();
1129 trace("starting cancelio tests\n");
1132 trace("starting byte read in byte mode client -> server\n");
1133 read_pipe_test(PIPE_ACCESS_INBOUND
, PIPE_TYPE_BYTE
);
1134 trace("starting byte read in message mode client -> server\n");
1135 read_pipe_test(PIPE_ACCESS_INBOUND
, PIPE_TYPE_MESSAGE
);
1136 trace("starting message read in message mode client -> server\n");
1137 read_pipe_test(PIPE_ACCESS_INBOUND
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
);
1138 trace("starting byte read in byte mode server -> client\n");
1139 read_pipe_test(PIPE_ACCESS_OUTBOUND
, PIPE_TYPE_BYTE
);
1140 trace("starting byte read in message mode server -> client\n");
1141 read_pipe_test(PIPE_ACCESS_OUTBOUND
, PIPE_TYPE_MESSAGE
);
1142 trace("starting message read in message mode server -> client\n");
1143 read_pipe_test(PIPE_ACCESS_OUTBOUND
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
);