2 * ntoskrnl.exe testing framework
4 * Copyright 2015 Sebastian Lackner
5 * Copyright 2015 Michael Müller
6 * Copyright 2015 Christian Costa
7 * Copyright 2020-2021 Zebediah Figura for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define WIN32_NO_STATUS
42 #include "ddk/hidclass.h"
43 #include "ddk/hidsdi.h"
44 #include "ddk/hidpi.h"
45 #include "wine/test.h"
46 #include "wine/heap.h"
47 #include "wine/mssign.h"
51 static const GUID GUID_NULL
;
55 static struct test_data
*test_data
;
57 static BOOL (WINAPI
*pRtlDosPathNameToNtPathName_U
)(const WCHAR
*, UNICODE_STRING
*, WCHAR
**, CURDIR
*);
58 static BOOL (WINAPI
*pRtlFreeUnicodeString
)(UNICODE_STRING
*);
59 static BOOL (WINAPI
*pCancelIoEx
)(HANDLE
, OVERLAPPED
*);
60 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, BOOL
*);
61 static BOOL (WINAPI
*pSetFileCompletionNotificationModes
)(HANDLE
, UCHAR
);
62 static HRESULT (WINAPI
*pSignerSign
)(SIGNER_SUBJECT_INFO
*subject
, SIGNER_CERT
*cert
,
63 SIGNER_SIGNATURE_INFO
*signature
, SIGNER_PROVIDER_INFO
*provider
,
64 const WCHAR
*timestamp
, CRYPT_ATTRIBUTES
*attr
, void *sip_data
);
66 static void load_resource(const WCHAR
*name
, WCHAR
*filename
)
68 static WCHAR path
[MAX_PATH
];
74 GetTempPathW(ARRAY_SIZE(path
), path
);
75 GetTempFileNameW(path
, name
, 0, filename
);
77 file
= CreateFileW(filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
78 ok(file
!= INVALID_HANDLE_VALUE
, "failed to create %s, error %lu\n", debugstr_w(filename
), GetLastError());
80 res
= FindResourceW(NULL
, name
, L
"TESTDLL");
81 ok( res
!= 0, "couldn't find resource\n" );
82 ptr
= LockResource( LoadResource( GetModuleHandleA(NULL
), res
));
83 WriteFile( file
, ptr
, SizeofResource( GetModuleHandleA(NULL
), res
), &written
, NULL
);
84 ok( written
== SizeofResource( GetModuleHandleA(NULL
), res
), "couldn't write resource\n" );
88 struct testsign_context
91 const CERT_CONTEXT
*cert
, *root_cert
, *publisher_cert
;
92 HCERTSTORE root_store
, publisher_store
;
95 static BOOL
testsign_create_cert(struct testsign_context
*ctx
)
97 BYTE encoded_name
[100], encoded_key_id
[200], public_key_info_buffer
[1000];
98 WCHAR container_name
[26];
99 BYTE hash_buffer
[16], cert_buffer
[1000], provider_nameA
[100], serial
[16];
100 CERT_PUBLIC_KEY_INFO
*public_key_info
= (CERT_PUBLIC_KEY_INFO
*)public_key_info_buffer
;
101 CRYPT_KEY_PROV_INFO provider_info
= {0};
102 CRYPT_ALGORITHM_IDENTIFIER algid
= {0};
103 CERT_AUTHORITY_KEY_ID_INFO key_info
;
104 CERT_INFO cert_info
= {0};
105 WCHAR provider_nameW
[100];
106 CERT_EXTENSION extension
;
111 memset(ctx
, 0, sizeof(*ctx
));
114 swprintf(container_name
, ARRAY_SIZE(container_name
), L
"wine_testsign%u", rand());
116 ret
= CryptAcquireContextW(&ctx
->provider
, container_name
, NULL
, PROV_RSA_FULL
, CRYPT_NEWKEYSET
);
117 ok(ret
, "Failed to create container, error %#lx\n", GetLastError());
119 ret
= CryptGenKey(ctx
->provider
, AT_SIGNATURE
, CRYPT_EXPORTABLE
, &key
);
120 ok(ret
, "Failed to create key, error %#lx\n", GetLastError());
121 ret
= CryptDestroyKey(key
);
122 ok(ret
, "Failed to destroy key, error %#lx\n", GetLastError());
123 ret
= CryptGetUserKey(ctx
->provider
, AT_SIGNATURE
, &key
);
124 ok(ret
, "Failed to get user key, error %#lx\n", GetLastError());
125 ret
= CryptDestroyKey(key
);
126 ok(ret
, "Failed to destroy key, error %#lx\n", GetLastError());
128 size
= sizeof(encoded_name
);
129 ret
= CertStrToNameA(X509_ASN_ENCODING
, "CN=winetest_cert", CERT_X500_NAME_STR
, NULL
, encoded_name
, &size
, NULL
);
130 ok(ret
, "Failed to convert name, error %#lx\n", GetLastError());
131 key_info
.CertIssuer
.cbData
= size
;
132 key_info
.CertIssuer
.pbData
= encoded_name
;
134 size
= sizeof(public_key_info_buffer
);
135 ret
= CryptExportPublicKeyInfo(ctx
->provider
, AT_SIGNATURE
, X509_ASN_ENCODING
, public_key_info
, &size
);
136 ok(ret
, "Failed to export public key, error %#lx\n", GetLastError());
137 cert_info
.SubjectPublicKeyInfo
= *public_key_info
;
139 size
= sizeof(hash_buffer
);
140 ret
= CryptHashPublicKeyInfo(ctx
->provider
, CALG_MD5
, 0, X509_ASN_ENCODING
, public_key_info
, hash_buffer
, &size
);
141 ok(ret
, "Failed to hash public key, error %#lx\n", GetLastError());
143 key_info
.KeyId
.cbData
= size
;
144 key_info
.KeyId
.pbData
= hash_buffer
;
146 RtlGenRandom(serial
, sizeof(serial
));
147 key_info
.CertSerialNumber
.cbData
= sizeof(serial
);
148 key_info
.CertSerialNumber
.pbData
= serial
;
150 size
= sizeof(encoded_key_id
);
151 ret
= CryptEncodeObject(X509_ASN_ENCODING
, X509_AUTHORITY_KEY_ID
, &key_info
, encoded_key_id
, &size
);
152 ok(ret
, "Failed to convert name, error %#lx\n", GetLastError());
154 extension
.pszObjId
= (char *)szOID_AUTHORITY_KEY_IDENTIFIER
;
155 extension
.fCritical
= TRUE
;
156 extension
.Value
.cbData
= size
;
157 extension
.Value
.pbData
= encoded_key_id
;
159 cert_info
.dwVersion
= CERT_V3
;
160 cert_info
.SerialNumber
= key_info
.CertSerialNumber
;
161 cert_info
.SignatureAlgorithm
.pszObjId
= (char *)szOID_RSA_SHA1RSA
;
162 cert_info
.Issuer
= key_info
.CertIssuer
;
163 GetSystemTimeAsFileTime(&cert_info
.NotBefore
);
164 GetSystemTimeAsFileTime(&cert_info
.NotAfter
);
165 cert_info
.NotAfter
.dwHighDateTime
+= 1;
166 cert_info
.Subject
= key_info
.CertIssuer
;
167 cert_info
.cExtension
= 1;
168 cert_info
.rgExtension
= &extension
;
169 algid
.pszObjId
= (char *)szOID_RSA_SHA1RSA
;
170 size
= sizeof(cert_buffer
);
171 ret
= CryptSignAndEncodeCertificate(ctx
->provider
, AT_SIGNATURE
, X509_ASN_ENCODING
,
172 X509_CERT_TO_BE_SIGNED
, &cert_info
, &algid
, NULL
, cert_buffer
, &size
);
173 ok(ret
, "Failed to create certificate, error %#lx\n", GetLastError());
175 ctx
->cert
= CertCreateCertificateContext(X509_ASN_ENCODING
, cert_buffer
, size
);
176 ok(!!ctx
->cert
, "Failed to create context, error %#lx\n", GetLastError());
178 size
= sizeof(provider_nameA
);
179 ret
= CryptGetProvParam(ctx
->provider
, PP_NAME
, provider_nameA
, &size
, 0);
180 ok(ret
, "Failed to get prov param, error %#lx\n", GetLastError());
181 MultiByteToWideChar(CP_ACP
, 0, (char *)provider_nameA
, -1, provider_nameW
, ARRAY_SIZE(provider_nameW
));
183 provider_info
.pwszContainerName
= (WCHAR
*)container_name
;
184 provider_info
.pwszProvName
= provider_nameW
;
185 provider_info
.dwProvType
= PROV_RSA_FULL
;
186 provider_info
.dwKeySpec
= AT_SIGNATURE
;
187 ret
= CertSetCertificateContextProperty(ctx
->cert
, CERT_KEY_PROV_INFO_PROP_ID
, 0, &provider_info
);
188 ok(ret
, "Failed to set provider info, error %#lx\n", GetLastError());
190 ctx
->root_store
= CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_A
, 0, 0, CERT_SYSTEM_STORE_LOCAL_MACHINE
, "root");
191 if (!ctx
->root_store
&& GetLastError() == ERROR_ACCESS_DENIED
)
193 skip("Failed to open root store.\n");
195 ret
= CertFreeCertificateContext(ctx
->cert
);
196 ok(ret
, "Failed to free certificate, error %lu\n", GetLastError());
197 ret
= CryptReleaseContext(ctx
->provider
, 0);
198 ok(ret
, "failed to release context, error %lu\n", GetLastError());
202 ok(!!ctx
->root_store
, "Failed to open store, error %lu\n", GetLastError());
203 ret
= CertAddCertificateContextToStore(ctx
->root_store
, ctx
->cert
, CERT_STORE_ADD_ALWAYS
, &ctx
->root_cert
);
204 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
206 skip("Failed to add self-signed certificate to store.\n");
208 ret
= CertFreeCertificateContext(ctx
->cert
);
209 ok(ret
, "Failed to free certificate, error %lu\n", GetLastError());
210 ret
= CertCloseStore(ctx
->root_store
, CERT_CLOSE_STORE_CHECK_FLAG
);
211 ok(ret
, "Failed to close store, error %lu\n", GetLastError());
212 ret
= CryptReleaseContext(ctx
->provider
, 0);
213 ok(ret
, "failed to release context, error %lu\n", GetLastError());
217 ok(ret
, "Failed to add certificate, error %lu\n", GetLastError());
219 ctx
->publisher_store
= CertOpenStore(CERT_STORE_PROV_SYSTEM_REGISTRY_A
, 0, 0,
220 CERT_SYSTEM_STORE_LOCAL_MACHINE
, "trustedpublisher");
221 ok(!!ctx
->publisher_store
, "Failed to open store, error %lu\n", GetLastError());
222 ret
= CertAddCertificateContextToStore(ctx
->publisher_store
, ctx
->cert
,
223 CERT_STORE_ADD_ALWAYS
, &ctx
->publisher_cert
);
224 ok(ret
, "Failed to add certificate, error %lu\n", GetLastError());
229 static void testsign_cleanup(struct testsign_context
*ctx
)
233 ret
= CertFreeCertificateContext(ctx
->cert
);
234 ok(ret
, "Failed to free certificate, error %lu\n", GetLastError());
236 ret
= CertFreeCertificateContext(ctx
->root_cert
);
237 ok(ret
, "Failed to free certificate context, error %lu\n", GetLastError());
238 ret
= CertCloseStore(ctx
->root_store
, CERT_CLOSE_STORE_CHECK_FLAG
);
239 ok(ret
, "Failed to close store, error %lu\n", GetLastError());
241 ret
= CertFreeCertificateContext(ctx
->publisher_cert
);
242 ok(ret
, "Failed to free certificate context, error %lu\n", GetLastError());
243 ret
= CertCloseStore(ctx
->publisher_store
, CERT_CLOSE_STORE_CHECK_FLAG
);
244 ok(ret
, "Failed to close store, error %lu\n", GetLastError());
246 ret
= CryptReleaseContext(ctx
->provider
, 0);
247 ok(ret
, "failed to release context, error %lu\n", GetLastError());
250 static void testsign_sign(struct testsign_context
*ctx
, const WCHAR
*filename
)
252 SIGNER_ATTR_AUTHCODE authcode
= {sizeof(authcode
)};
253 SIGNER_SIGNATURE_INFO signature
= {sizeof(signature
)};
254 SIGNER_SUBJECT_INFO subject
= {sizeof(subject
)};
255 SIGNER_CERT_STORE_INFO store
= {sizeof(store
)};
256 SIGNER_CERT cert_info
= {sizeof(cert_info
)};
257 SIGNER_FILE_INFO file
= {sizeof(file
)};
261 subject
.dwSubjectChoice
= 1;
262 subject
.pdwIndex
= &index
;
263 subject
.pSignerFileInfo
= &file
;
264 file
.pwszFileName
= (WCHAR
*)filename
;
265 cert_info
.dwCertChoice
= 2;
266 cert_info
.pCertStoreInfo
= &store
;
267 store
.pSigningCert
= ctx
->cert
;
268 store
.dwCertPolicy
= 0;
269 signature
.algidHash
= CALG_SHA_256
;
270 signature
.dwAttrChoice
= SIGNER_AUTHCODE_ATTR
;
271 signature
.pAttrAuthcode
= &authcode
;
272 authcode
.pwszName
= L
"";
273 authcode
.pwszInfo
= L
"";
274 hr
= pSignerSign(&subject
, &cert_info
, &signature
, NULL
, NULL
, NULL
, NULL
);
275 todo_wine
ok(hr
== S_OK
|| broken(hr
== NTE_BAD_ALGID
) /* < 7 */, "Failed to sign, hr %#lx\n", hr
);
278 static void unload_driver(SC_HANDLE service
)
280 SERVICE_STATUS status
;
282 ControlService(service
, SERVICE_CONTROL_STOP
, &status
);
283 while (status
.dwCurrentState
== SERVICE_STOP_PENDING
)
287 ret
= QueryServiceStatus(service
, &status
);
288 ok(ret
, "QueryServiceStatus failed: %lu\n", GetLastError());
290 ok(status
.dwCurrentState
== SERVICE_STOPPED
,
291 "expected SERVICE_STOPPED, got %ld\n", status
.dwCurrentState
);
293 DeleteService(service
);
294 CloseServiceHandle(service
);
297 static SC_HANDLE
load_driver(struct testsign_context
*ctx
, WCHAR
*filename
,
298 const WCHAR
*resname
, const WCHAR
*driver_name
)
300 SC_HANDLE manager
, service
;
302 manager
= OpenSCManagerA(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
303 if (!manager
&& GetLastError() == ERROR_ACCESS_DENIED
)
305 skip("Failed to open SC manager, not enough permissions\n");
308 ok(!!manager
, "OpenSCManager failed\n");
310 /* stop any old drivers running under this name */
311 service
= OpenServiceW(manager
, driver_name
, SERVICE_ALL_ACCESS
);
312 if (service
) unload_driver(service
);
314 load_resource(resname
, filename
);
315 testsign_sign(ctx
, filename
);
316 trace("Trying to load driver %s\n", debugstr_w(filename
));
318 service
= CreateServiceW(manager
, driver_name
, driver_name
,
319 SERVICE_ALL_ACCESS
, SERVICE_KERNEL_DRIVER
,
320 SERVICE_DEMAND_START
, SERVICE_ERROR_NORMAL
,
321 filename
, NULL
, NULL
, NULL
, NULL
, NULL
);
322 ok(!!service
, "CreateService failed: %lu\n", GetLastError());
324 CloseServiceHandle(manager
);
328 static BOOL
start_driver(HANDLE service
, BOOL vista_plus
)
330 SERVICE_STATUS status
;
333 SetLastError(0xdeadbeef);
334 ret
= StartServiceA(service
, 0, NULL
);
335 if (!ret
&& (GetLastError() == ERROR_DRIVER_BLOCKED
|| GetLastError() == ERROR_INVALID_IMAGE_HASH
336 || (vista_plus
&& GetLastError() == ERROR_FILE_NOT_FOUND
)))
338 if (vista_plus
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
340 skip("Windows Vista or newer is required to run this service.\n");
344 /* If Secure Boot is enabled or the machine is 64-bit, it will reject an unsigned driver. */
345 skip("Failed to start service; probably your machine doesn't accept unsigned drivers.\n");
347 DeleteService(service
);
348 CloseServiceHandle(service
);
351 ok(ret
, "StartService failed: %lu\n", GetLastError());
353 /* wait for the service to start up properly */
354 ret
= QueryServiceStatus(service
, &status
);
355 ok(ret
, "QueryServiceStatus failed: %lu\n", GetLastError());
356 while (status
.dwCurrentState
== SERVICE_START_PENDING
)
359 ret
= QueryServiceStatus(service
, &status
);
360 ok(ret
, "QueryServiceStatus failed: %lu\n", GetLastError());
362 ok(status
.dwCurrentState
== SERVICE_RUNNING
,
363 "expected SERVICE_RUNNING, got %ld\n", status
.dwCurrentState
);
364 ok(status
.dwServiceType
== SERVICE_KERNEL_DRIVER
,
365 "expected SERVICE_KERNEL_DRIVER, got %#lx\n", status
.dwServiceType
);
370 static HANDLE okfile
;
372 static void cat_okfile(void)
377 SetFilePointer(okfile
, 0, NULL
, FILE_BEGIN
);
381 ReadFile(okfile
, buffer
, sizeof(buffer
), &size
, NULL
);
382 printf("%.*s", (int)size
, buffer
);
383 } while (size
== sizeof(buffer
));
385 SetFilePointer(okfile
, 0, NULL
, FILE_BEGIN
);
386 SetEndOfFile(okfile
);
388 winetest_add_failures(InterlockedExchange(&test_data
->failures
, 0));
389 winetest_add_failures(InterlockedExchange(&test_data
->todo_failures
, 0));
392 static ULONG64 modified_value
;
394 static void main_test(void)
396 struct main_test_input
*test_input
;
400 test_input
= heap_alloc( sizeof(*test_input
) );
401 test_input
->process_id
= GetCurrentProcessId();
402 test_input
->teststr_offset
= (SIZE_T
)((BYTE
*)&teststr
- (BYTE
*)NtCurrentTeb()->Peb
->ImageBaseAddress
);
403 test_input
->modified_value
= &modified_value
;
406 res
= DeviceIoControl(device
, IOCTL_WINETEST_MAIN_TEST
, test_input
, sizeof(*test_input
), NULL
, 0, &size
, NULL
);
407 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
408 ok(!size
, "got size %lu\n", size
);
410 heap_free(test_input
);
413 static void test_basic_ioctl(void)
415 char inbuf
[64], buf
[32];
419 res
= DeviceIoControl(device
, IOCTL_WINETEST_BASIC_IOCTL
, NULL
, 0, buf
,
420 sizeof(buf
), &written
, NULL
);
421 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
422 ok(written
== sizeof(teststr
), "got size %ld\n", written
);
423 ok(!strcmp(buf
, teststr
), "got '%s'\n", buf
);
425 memset(buf
, 0, sizeof(buf
));
426 res
= DeviceIoControl(device
, IOCTL_WINETEST_BASIC_IOCTL
, inbuf
,
427 sizeof(inbuf
), buf
, 10, &written
, NULL
);
428 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
429 ok(written
== 10, "got size %ld\n", written
);
430 ok(!strcmp(buf
, "Wine is no"), "got '%s'\n", buf
);
433 static void test_overlapped(void)
435 OVERLAPPED overlapped
, overlapped2
, *o
;
436 DWORD cancel_cnt
, size
;
441 overlapped
.hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
442 overlapped2
.hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
444 file
= CreateFileA("\\\\.\\WineTestDriver", FILE_READ_ATTRIBUTES
| FILE_WRITE_ATTRIBUTES
,
445 0, NULL
, OPEN_EXISTING
, FILE_FLAG_OVERLAPPED
, NULL
);
446 ok(file
!= INVALID_HANDLE_VALUE
, "failed to open device: %lu\n", GetLastError());
448 /* test cancelling all device requests */
449 res
= DeviceIoControl(file
, IOCTL_WINETEST_RESET_CANCEL
, NULL
, 0, NULL
, 0, NULL
, &overlapped
);
450 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
452 res
= DeviceIoControl(file
, IOCTL_WINETEST_TEST_CANCEL
, NULL
, 0, NULL
, 0, NULL
, &overlapped
);
453 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "DeviceIoControl failed: %lu\n", GetLastError());
455 res
= DeviceIoControl(file
, IOCTL_WINETEST_TEST_CANCEL
, NULL
, 0, NULL
, 0, NULL
, &overlapped2
);
456 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "DeviceIoControl failed: %lu\n", GetLastError());
458 cancel_cnt
= 0xdeadbeef;
459 res
= DeviceIoControl(file
, IOCTL_WINETEST_GET_CANCEL_COUNT
, NULL
, 0, &cancel_cnt
, sizeof(cancel_cnt
), NULL
, &overlapped
);
460 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
461 ok(cancel_cnt
== 0, "cancel_cnt = %lu\n", cancel_cnt
);
465 cancel_cnt
= 0xdeadbeef;
466 res
= DeviceIoControl(file
, IOCTL_WINETEST_GET_CANCEL_COUNT
, NULL
, 0, &cancel_cnt
, sizeof(cancel_cnt
), NULL
, &overlapped
);
467 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
468 ok(cancel_cnt
== 2, "cancel_cnt = %lu\n", cancel_cnt
);
470 /* test cancelling selected overlapped event */
473 res
= DeviceIoControl(file
, IOCTL_WINETEST_RESET_CANCEL
, NULL
, 0, NULL
, 0, NULL
, &overlapped
);
474 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
476 res
= DeviceIoControl(file
, IOCTL_WINETEST_TEST_CANCEL
, NULL
, 0, NULL
, 0, NULL
, &overlapped
);
477 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "DeviceIoControl failed: %lu\n", GetLastError());
479 res
= DeviceIoControl(file
, IOCTL_WINETEST_TEST_CANCEL
, NULL
, 0, NULL
, 0, NULL
, &overlapped2
);
480 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "DeviceIoControl failed: %lu\n", GetLastError());
482 pCancelIoEx(file
, &overlapped
);
484 cancel_cnt
= 0xdeadbeef;
485 res
= DeviceIoControl(file
, IOCTL_WINETEST_GET_CANCEL_COUNT
, NULL
, 0, &cancel_cnt
, sizeof(cancel_cnt
), NULL
, &overlapped
);
486 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
487 ok(cancel_cnt
== 1, "cancel_cnt = %lu\n", cancel_cnt
);
489 pCancelIoEx(file
, &overlapped2
);
491 cancel_cnt
= 0xdeadbeef;
492 res
= DeviceIoControl(file
, IOCTL_WINETEST_GET_CANCEL_COUNT
, NULL
, 0, &cancel_cnt
, sizeof(cancel_cnt
), NULL
, &overlapped
);
493 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
494 ok(cancel_cnt
== 2, "cancel_cnt = %lu\n", cancel_cnt
);
497 port
= CreateIoCompletionPort(file
, NULL
, 0xdeadbeef, 0);
498 ok(port
!= NULL
, "CreateIoCompletionPort failed, error %lu\n", GetLastError());
499 res
= GetQueuedCompletionStatus(port
, &size
, &key
, &o
, 0);
500 ok(!res
&& GetLastError() == WAIT_TIMEOUT
, "GetQueuedCompletionStatus returned %x(%lu)\n", res
, GetLastError());
502 res
= DeviceIoControl(file
, IOCTL_WINETEST_RESET_CANCEL
, NULL
, 0, NULL
, 0, NULL
, &overlapped
);
503 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
504 res
= GetQueuedCompletionStatus(port
, &size
, &key
, &o
, 0);
505 ok(res
, "GetQueuedCompletionStatus failed: %lu\n", GetLastError());
506 ok(o
== &overlapped
, "o != overlapped\n");
508 if (pSetFileCompletionNotificationModes
)
510 res
= pSetFileCompletionNotificationModes(file
, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
);
511 ok(res
, "SetFileCompletionNotificationModes failed: %lu\n", GetLastError());
513 res
= DeviceIoControl(file
, IOCTL_WINETEST_RESET_CANCEL
, NULL
, 0, NULL
, 0, NULL
, &overlapped
);
514 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
515 res
= GetQueuedCompletionStatus(port
, &size
, &key
, &o
, 0);
516 ok(!res
&& GetLastError() == WAIT_TIMEOUT
, "GetQueuedCompletionStatus returned %x(%lu)\n", res
, GetLastError());
520 CloseHandle(overlapped
.hEvent
);
521 CloseHandle(overlapped2
.hEvent
);
525 static void test_load_driver(SC_HANDLE service
)
527 SERVICE_STATUS status
;
531 res
= QueryServiceStatus(service
, &status
);
532 ok(res
, "QueryServiceStatusEx failed: %lu\n", GetLastError());
533 ok(status
.dwCurrentState
== SERVICE_STOPPED
, "got state %#lx\n", status
.dwCurrentState
);
536 res
= DeviceIoControl(device
, IOCTL_WINETEST_LOAD_DRIVER
, &load
, sizeof(load
), NULL
, 0, &sz
, NULL
);
537 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
539 res
= QueryServiceStatus(service
, &status
);
540 ok(res
, "QueryServiceStatusEx failed: %lu\n", GetLastError());
541 ok(status
.dwCurrentState
== SERVICE_RUNNING
, "got state %#lx\n", status
.dwCurrentState
);
544 res
= DeviceIoControl(device
, IOCTL_WINETEST_LOAD_DRIVER
, &load
, sizeof(load
), NULL
, 0, &sz
, NULL
);
545 ok(res
, "DeviceIoControl failed: %lu\n", GetLastError());
547 res
= QueryServiceStatus(service
, &status
);
548 ok(res
, "QueryServiceStatusEx failed: %lu\n", GetLastError());
549 ok(status
.dwCurrentState
== SERVICE_STOPPED
, "got state %#lx\n", status
.dwCurrentState
);
552 static void test_file_handles(void)
554 DWORD count
, ret_size
;
555 HANDLE file
, dup
, file2
;
558 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_CREATE_COUNT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
559 ok(ret
, "ioctl failed: %lu\n", GetLastError());
560 ok(count
== 2, "got %lu\n", count
);
562 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_CLOSE_COUNT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
563 ok(ret
, "ioctl failed: %lu\n", GetLastError());
564 ok(count
== 1, "got %lu\n", count
);
566 file
= CreateFileA("\\\\.\\WineTestDriver", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
567 ok(file
!= INVALID_HANDLE_VALUE
, "failed to open device: %lu\n", GetLastError());
569 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_CREATE_COUNT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
570 ok(ret
, "ioctl failed: %lu\n", GetLastError());
571 ok(count
== 3, "got %lu\n", count
);
573 file2
= CreateFileA("\\\\.\\WineTestDriver", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
574 ok(file2
!= INVALID_HANDLE_VALUE
, "failed to open device: %lu\n", GetLastError());
576 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_CREATE_COUNT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
577 ok(ret
, "ioctl failed: %lu\n", GetLastError());
578 ok(count
== 4, "got %lu\n", count
);
580 ret
= DuplicateHandle(GetCurrentProcess(), file
, GetCurrentProcess(), &dup
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
581 ok(ret
, "failed to duplicate handle: %lu\n", GetLastError());
583 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_CREATE_COUNT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
584 ok(ret
, "ioctl failed: %lu\n", GetLastError());
585 ok(count
== 4, "got %lu\n", count
);
587 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_FSCONTEXT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
588 ok(ret
, "ioctl failed: %lu\n", GetLastError());
589 ok(count
== 1, "got %lu\n", count
);
591 ret
= DeviceIoControl(file
, IOCTL_WINETEST_GET_FSCONTEXT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
592 ok(ret
, "ioctl failed: %lu\n", GetLastError());
593 ok(count
== 3, "got %lu\n", count
);
595 ret
= DeviceIoControl(file2
, IOCTL_WINETEST_GET_FSCONTEXT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
596 ok(ret
, "ioctl failed: %lu\n", GetLastError());
597 ok(count
== 4, "got %lu\n", count
);
599 ret
= DeviceIoControl(dup
, IOCTL_WINETEST_GET_FSCONTEXT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
600 ok(ret
, "ioctl failed: %lu\n", GetLastError());
601 ok(count
== 3, "got %lu\n", count
);
605 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_CLOSE_COUNT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
606 ok(ret
, "ioctl failed: %lu\n", GetLastError());
607 ok(count
== 1, "got %lu\n", count
);
611 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_CLOSE_COUNT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
612 ok(ret
, "ioctl failed: %lu\n", GetLastError());
613 ok(count
== 2, "got %lu\n", count
);
617 ret
= DeviceIoControl(device
, IOCTL_WINETEST_GET_CLOSE_COUNT
, NULL
, 0, &count
, sizeof(count
), &ret_size
, NULL
);
618 ok(ret
, "ioctl failed: %lu\n", GetLastError());
619 ok(count
== 3, "got %lu\n", count
);
622 static unsigned int got_return_status_apc
;
624 static void WINAPI
return_status_apc(void *apc_user
, IO_STATUS_BLOCK
*io
, ULONG reserved
)
626 ++got_return_status_apc
;
627 ok(apc_user
== (void *)456, "got %p\n", apc_user
);
628 ok(!reserved
, "got reserved %#lx\n", reserved
);
631 static void do_return_status(ULONG ioctl
, struct return_status_params
*params
)
633 const char *expect_buffer
;
634 LARGE_INTEGER zero
= {{0}};
635 HANDLE file
, port
, event
;
636 NTSTATUS expect_status
;
637 ULONG_PTR key
, value
;
643 if (params
->ret_status
== STATUS_PENDING
&& !params
->pending
)
645 /* this causes kernel hangs under certain conditions */
649 event
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
651 if (ioctl
!= IOCTL_WINETEST_RETURN_STATUS_BUFFERED
)
652 expect_buffer
= "ghijkl";
653 else if (NT_ERROR(params
->iosb_status
))
654 expect_buffer
= "abcdef";
656 expect_buffer
= "ghidef";
658 /* Test the non-overlapped case. */
660 expect_status
= (params
->ret_status
== STATUS_PENDING
? params
->iosb_status
: params
->ret_status
);
662 strcpy(buffer
, "abcdef");
664 SetLastError(0xdeadf00d);
665 ret
= DeviceIoControl(device
, ioctl
, params
, sizeof(*params
), buffer
, sizeof(buffer
), &size
, NULL
);
666 todo_wine_if (params
->ret_status
== STATUS_PENDING
&& params
->iosb_status
== STATUS_PENDING
)
667 ok(ret
== NT_SUCCESS(expect_status
), "got %d\n", ret
);
668 if (NT_SUCCESS(expect_status
))
670 todo_wine_if (params
->ret_status
== STATUS_PENDING
&& params
->iosb_status
== STATUS_PENDING
)
671 ok(GetLastError() == 0xdeadf00d, "got error %lu\n", GetLastError());
675 ok(GetLastError() == RtlNtStatusToDosError(expect_status
), "got error %lu\n", GetLastError());
677 if (NT_ERROR(expect_status
))
678 ok(size
== 0xdeadf00d, "got size %lu\n", size
);
679 else if (!NT_ERROR(params
->iosb_status
))
680 ok(size
== 3, "got size %lu\n", size
);
681 /* size is garbage if !NT_ERROR(expect_status) && NT_ERROR(iosb_status) */
682 ok(!strcmp(buffer
, expect_buffer
), "got buffer %s\n", buffer
);
684 strcpy(buffer
, "abcdef");
685 io
.Status
= 0xdeadf00d;
686 io
.Information
= 0xdeadf00d;
687 ret
= NtDeviceIoControlFile(device
, NULL
, NULL
, NULL
, &io
,
688 ioctl
, params
, sizeof(*params
), buffer
, sizeof(buffer
));
689 ok(ret
== expect_status
, "got %#x\n", ret
);
690 if (NT_ERROR(params
->iosb_status
))
692 ok(io
.Status
== 0xdeadf00d, "got %#lx\n", io
.Status
);
693 ok(io
.Information
== 0xdeadf00d, "got size %Iu\n", io
.Information
);
697 ok(io
.Status
== params
->iosb_status
, "got %#lx\n", io
.Status
);
698 ok(io
.Information
== 3, "got size %Iu\n", io
.Information
);
700 ok(!strcmp(buffer
, expect_buffer
), "got buffer %s\n", buffer
);
702 /* Test the overlapped case. */
704 file
= CreateFileA("\\\\.\\WineTestDriver", FILE_ALL_ACCESS
,
705 0, NULL
, OPEN_EXISTING
, FILE_FLAG_OVERLAPPED
, NULL
);
706 ok(file
!= INVALID_HANDLE_VALUE
, "failed to open device, error %lu\n", GetLastError());
707 port
= CreateIoCompletionPort(file
, NULL
, 123, 0);
708 ok(port
!= NULL
, "failed to create port, error %lu\n", GetLastError());
710 ret
= WaitForSingleObject(file
, 0);
711 ok(!ret
, "got %d\n", ret
);
714 strcpy(buffer
, "abcdef");
715 io
.Status
= 0xdeadf00d;
716 io
.Information
= 0xdeadf00d;
717 ret
= NtDeviceIoControlFile(file
, event
, NULL
, (void *)456, &io
,
718 ioctl
, params
, sizeof(*params
), buffer
, sizeof(buffer
));
719 ok(ret
== params
->ret_status
720 || broken(NT_WARNING(params
->ret_status
) && ret
== STATUS_PENDING
), /* win10 */
722 if (!params
->pending
&& NT_ERROR(params
->iosb_status
))
724 ok(io
.Status
== 0xdeadf00d, "got %#lx\n", io
.Status
);
725 ok(io
.Information
== 0xdeadf00d, "got size %Iu\n", io
.Information
);
726 ret
= WaitForSingleObject(event
, 0);
727 ok(ret
== WAIT_TIMEOUT
, "got %d\n", ret
);
731 ok(io
.Status
== params
->iosb_status
, "got %#lx\n", io
.Status
);
732 ok(io
.Information
== 3, "got size %Iu\n", io
.Information
);
733 ret
= WaitForSingleObject(event
, 0);
734 ok(!ret
, "got %d\n", ret
);
736 ok(!strcmp(buffer
, expect_buffer
), "got buffer %s\n", buffer
);
738 ret
= WaitForSingleObject(file
, 0);
739 ok(ret
== WAIT_TIMEOUT
, "got %d\n", ret
);
743 memset(&io
, 0xcc, sizeof(io
));
744 ret
= NtRemoveIoCompletion(port
, &key
, &value
, &io
, &zero
);
745 if (!params
->pending
&& NT_ERROR(params
->iosb_status
))
747 ok(ret
== STATUS_TIMEOUT
, "got %#x\n", ret
);
751 ok(!ret
, "got %#x\n", ret
);
752 ok(key
== 123, "got key %Iu\n", key
);
753 ok(value
== 456, "got value %Iu\n", value
);
754 ok(io
.Status
== params
->iosb_status
, "got iosb status %#lx\n", io
.Status
);
755 ok(io
.Information
== 3, "got information %Iu\n", io
.Information
);
758 /* As above, but set the event first, to show that the event is always
761 strcpy(buffer
, "abcdef");
762 io
.Status
= 0xdeadf00d;
763 io
.Information
= 0xdeadf00d;
764 ret
= NtDeviceIoControlFile(file
, event
, NULL
, NULL
, &io
,
765 ioctl
, params
, sizeof(*params
), buffer
, sizeof(buffer
));
766 ok(ret
== params
->ret_status
767 || broken(NT_WARNING(params
->ret_status
) && ret
== STATUS_PENDING
), /* win10 */
769 if (!params
->pending
&& NT_ERROR(params
->iosb_status
))
771 ok(io
.Status
== 0xdeadf00d, "got %#lx\n", io
.Status
);
772 ok(io
.Information
== 0xdeadf00d, "got size %Iu\n", io
.Information
);
773 ret
= WaitForSingleObject(event
, 0);
774 ok(ret
== WAIT_TIMEOUT
, "got %d\n", ret
);
778 ok(io
.Status
== params
->iosb_status
, "got %#lx\n", io
.Status
);
779 ok(io
.Information
== 3, "got size %Iu\n", io
.Information
);
780 ret
= WaitForSingleObject(event
, 0);
781 ok(!ret
, "got %d\n", ret
);
783 ok(!strcmp(buffer
, expect_buffer
), "got buffer %s\n", buffer
);
785 /* As above, but use the file handle instead of an event. */
786 ret
= WaitForSingleObject(file
, 0);
787 ok(ret
== WAIT_TIMEOUT
, "got %d\n", ret
);
789 strcpy(buffer
, "abcdef");
790 io
.Status
= 0xdeadf00d;
791 io
.Information
= 0xdeadf00d;
792 ret
= NtDeviceIoControlFile(file
, NULL
, NULL
, NULL
, &io
,
793 ioctl
, params
, sizeof(*params
), buffer
, sizeof(buffer
));
794 ok(ret
== params
->ret_status
795 || broken(NT_WARNING(params
->ret_status
) && ret
== STATUS_PENDING
), /* win10 */
797 if (!params
->pending
&& NT_ERROR(params
->iosb_status
))
799 ok(io
.Status
== 0xdeadf00d, "got %#lx\n", io
.Status
);
800 ok(io
.Information
== 0xdeadf00d, "got size %Iu\n", io
.Information
);
801 ret
= WaitForSingleObject(file
, 0);
802 ok(ret
== WAIT_TIMEOUT
, "got %d\n", ret
);
806 ok(io
.Status
== params
->iosb_status
, "got %#lx\n", io
.Status
);
807 ok(io
.Information
== 3, "got size %Iu\n", io
.Information
);
808 ret
= WaitForSingleObject(file
, 0);
809 ok(!ret
, "got %d\n", ret
);
811 ok(!strcmp(buffer
, expect_buffer
), "got buffer %s\n", buffer
);
813 /* Test FILE_SKIP_COMPLETION_PORT_ON_SUCCESS. */
815 if (pSetFileCompletionNotificationModes
)
817 ret
= pSetFileCompletionNotificationModes(file
, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
);
818 ok(ret
, "got error %lu\n", GetLastError());
821 strcpy(buffer
, "abcdef");
822 io
.Status
= 0xdeadf00d;
823 io
.Information
= 0xdeadf00d;
824 ret
= NtDeviceIoControlFile(file
, event
, NULL
, (void *)456, &io
,
825 ioctl
, params
, sizeof(*params
), buffer
, sizeof(buffer
));
826 ok(ret
== params
->ret_status
827 || broken(NT_WARNING(params
->ret_status
) && ret
== STATUS_PENDING
), /* win10 */
829 if (!params
->pending
&& NT_ERROR(params
->iosb_status
))
831 ok(io
.Status
== 0xdeadf00d, "got %#lx\n", io
.Status
);
832 ok(io
.Information
== 0xdeadf00d, "got size %Iu\n", io
.Information
);
833 ret
= WaitForSingleObject(event
, 0);
834 ok(ret
== WAIT_TIMEOUT
, "got %d\n", ret
);
838 ok(io
.Status
== params
->iosb_status
, "got %#lx\n", io
.Status
);
839 ok(io
.Information
== 3, "got size %Iu\n", io
.Information
);
840 ret
= WaitForSingleObject(event
, 0);
841 ok(!ret
, "got %d\n", ret
);
843 ok(!strcmp(buffer
, expect_buffer
), "got buffer %s\n", buffer
);
847 memset(&io
, 0xcc, sizeof(io
));
848 ret
= NtRemoveIoCompletion(port
, &key
, &value
, &io
, &zero
);
849 if (!params
->pending
)
851 /* Completion is skipped on non-pending NT_ERROR regardless of file
852 * options. Windows < 8 interprets
853 * FILE_SKIP_COMPLETION_PORT_ON_SUCCESS to mean that !NT_ERROR
854 * should also be skipped. Windows >= 8 restricts this to
855 * NT_SUCCESS, which has the weird effect that non-pending
856 * NT_WARNING does *not* skip completion. It's not clear whether
857 * this is a bug or not—it looks like one, but on the other hand it
858 * arguably follows the letter of the documentation more closely. */
859 ok(ret
== STATUS_TIMEOUT
|| (NT_WARNING(params
->iosb_status
) && !ret
), "got %#x\n", ret
);
863 ok(!ret
, "got %#x\n", ret
);
867 ok(key
== 123, "got key %Iu\n", key
);
868 ok(value
== 456, "got value %Iu\n", value
);
869 ok(io
.Status
== params
->iosb_status
, "got iosb status %#lx\n", io
.Status
);
870 ok(io
.Information
== 3, "got information %Iu\n", io
.Information
);
874 ret
= CloseHandle(file
);
875 ok(ret
, "failed to close file, error %lu\n", GetLastError());
876 ret
= CloseHandle(port
);
877 ok(ret
, "failed to close port, error %lu\n", GetLastError());
879 /* Test with an APC. */
881 got_return_status_apc
= 0;
883 file
= CreateFileA("\\\\.\\WineTestDriver", FILE_ALL_ACCESS
,
884 0, NULL
, OPEN_EXISTING
, FILE_FLAG_OVERLAPPED
, NULL
);
885 ok(file
!= INVALID_HANDLE_VALUE
, "failed to open device, error %lu\n", GetLastError());
887 strcpy(buffer
, "abcdef");
888 io
.Status
= 0xdeadf00d;
889 io
.Information
= 0xdeadf00d;
890 ret
= NtDeviceIoControlFile(file
, NULL
, return_status_apc
, (void *)456, &io
,
891 ioctl
, params
, sizeof(*params
), buffer
, sizeof(buffer
));
892 ok(ret
== params
->ret_status
, "got %#x\n", ret
);
893 if (!params
->pending
&& NT_ERROR(params
->iosb_status
))
895 ok(io
.Status
== 0xdeadf00d, "got %#lx\n", io
.Status
);
896 ok(io
.Information
== 0xdeadf00d, "got size %Iu\n", io
.Information
);
900 ok(io
.Status
== params
->iosb_status
, "got %#lx\n", io
.Status
);
901 ok(io
.Information
== 3, "got size %Iu\n", io
.Information
);
903 ok(!strcmp(buffer
, expect_buffer
), "got buffer %s\n", buffer
);
905 ret
= SleepEx(0, TRUE
);
906 if (!params
->pending
&& NT_ERROR(params
->iosb_status
))
908 ok(!ret
, "got %d\n", ret
);
909 ok(!got_return_status_apc
, "got %u APC calls\n", got_return_status_apc
);
913 ok(ret
== WAIT_IO_COMPLETION
, "got %d\n", ret
);
914 ok(got_return_status_apc
== 1, "got %u APC calls\n", got_return_status_apc
);
917 ret
= CloseHandle(file
);
918 ok(ret
, "failed to close file, error %lu\n", GetLastError());
923 static void test_return_status(void)
925 struct return_status_params params
;
926 unsigned int i
, j
, k
;
928 static const ULONG method_tests
[] =
930 IOCTL_WINETEST_RETURN_STATUS_BUFFERED
,
931 IOCTL_WINETEST_RETURN_STATUS_DIRECT
,
932 IOCTL_WINETEST_RETURN_STATUS_NEITHER
,
935 static const NTSTATUS status_tests
[] =
942 STATUS_BUFFER_OVERFLOW
,
944 STATUS_NOT_IMPLEMENTED
,
948 for (i
= 0; i
< ARRAY_SIZE(status_tests
); ++i
)
950 for (j
= 0; j
< ARRAY_SIZE(status_tests
); ++j
)
952 for (params
.pending
= 0; params
.pending
<= 1; ++params
.pending
)
954 for (k
= 0; k
< ARRAY_SIZE(method_tests
); ++k
)
956 params
.ret_status
= status_tests
[i
];
957 params
.iosb_status
= status_tests
[j
];
959 winetest_push_context("return 0x%08lx, iosb 0x%08lx, pending %d, method %lu",
960 params
.ret_status
, params
.iosb_status
, params
.pending
, method_tests
[k
] & 3);
962 do_return_status(method_tests
[k
], ¶ms
);
964 winetest_pop_context();
971 static BOOL
compare_unicode_string(const WCHAR
*buffer
, ULONG len
, const WCHAR
*expect
)
973 return len
== wcslen(expect
) * sizeof(WCHAR
) && !memcmp(buffer
, expect
, len
);
976 static void test_object_info(void)
979 OBJECT_NAME_INFORMATION
*name_info
= (OBJECT_NAME_INFORMATION
*)buffer
;
980 OBJECT_TYPE_INFORMATION
*type_info
= (OBJECT_TYPE_INFORMATION
*)buffer
;
981 FILE_FS_VOLUME_INFORMATION
*volume_info
= (FILE_FS_VOLUME_INFORMATION
*)buffer
;
982 FILE_NAME_INFORMATION
*file_info
= (FILE_NAME_INFORMATION
*)buffer
;
988 status
= NtQueryObject(device
, ObjectNameInformation
, buffer
, sizeof(buffer
), NULL
);
989 ok(!status
, "got %#lx\n", status
);
990 ok(compare_unicode_string(name_info
->Name
.Buffer
, name_info
->Name
.Length
, L
"\\Device\\WineTestDriver"),
991 "wrong name %s\n", debugstr_w(name_info
->Name
.Buffer
));
993 status
= NtQueryObject(device
, ObjectTypeInformation
, buffer
, sizeof(buffer
), NULL
);
994 ok(!status
, "got %#lx\n", status
);
995 ok(compare_unicode_string(type_info
->TypeName
.Buffer
, type_info
->TypeName
.Length
, L
"File"),
996 "wrong name %s\n", debugstr_wn(type_info
->TypeName
.Buffer
, type_info
->TypeName
.Length
/ sizeof(WCHAR
)));
998 status
= NtQueryInformationFile(device
, &io
, buffer
, sizeof(buffer
), FileNameInformation
);
999 todo_wine
ok(status
== STATUS_INVALID_DEVICE_REQUEST
, "got %#lx\n", status
);
1001 status
= NtQueryVolumeInformationFile(device
, &io
, buffer
, sizeof(buffer
), FileFsVolumeInformation
);
1002 todo_wine
ok(status
== STATUS_INVALID_DEVICE_REQUEST
, "got %#lx\n", status
);
1004 file
= CreateFileA("\\\\.\\WineTestDriver\\subfile", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1005 todo_wine
ok(file
!= INVALID_HANDLE_VALUE
, "got error %lu\n", GetLastError());
1006 if (file
== INVALID_HANDLE_VALUE
) return;
1008 memset(buffer
, 0xcc, sizeof(buffer
));
1009 status
= NtQueryObject(file
, ObjectNameInformation
, buffer
, sizeof(buffer
), &size
);
1010 ok(!status
, "got %#lx\n", status
);
1011 ok(size
== sizeof(*name_info
) + sizeof(L
"\\Device\\WineTestDriver\\subfile"), "wrong size %lu\n", size
);
1012 ok(compare_unicode_string(name_info
->Name
.Buffer
, name_info
->Name
.Length
, L
"\\Device\\WineTestDriver\\subfile"),
1013 "wrong name %s\n", debugstr_w(name_info
->Name
.Buffer
));
1015 memset(buffer
, 0xcc, sizeof(buffer
));
1016 status
= NtQueryObject(file
, ObjectNameInformation
, buffer
, size
- 2, &size
);
1017 ok(status
== STATUS_BUFFER_OVERFLOW
, "got %#lx\n", status
);
1018 ok(size
== sizeof(*name_info
) + sizeof(L
"\\Device\\WineTestDriver\\subfile"), "wrong size %lu\n", size
);
1019 ok(compare_unicode_string(name_info
->Name
.Buffer
, name_info
->Name
.Length
, L
"\\Device\\WineTestDriver\\subfil"),
1020 "wrong name %s\n", debugstr_w(name_info
->Name
.Buffer
));
1022 memset(buffer
, 0xcc, sizeof(buffer
));
1023 status
= NtQueryObject(file
, ObjectNameInformation
, buffer
, sizeof(*name_info
), &size
);
1024 ok(status
== STATUS_BUFFER_OVERFLOW
, "got %#lx\n", status
);
1025 ok(size
== sizeof(*name_info
) + sizeof(L
"\\Device\\WineTestDriver\\subfile"), "wrong size %lu\n", size
);
1027 status
= NtQueryObject(file
, ObjectTypeInformation
, buffer
, sizeof(buffer
), NULL
);
1028 ok(!status
, "got %#lx\n", status
);
1029 ok(compare_unicode_string(type_info
->TypeName
.Buffer
, type_info
->TypeName
.Length
, L
"File"),
1030 "wrong name %s\n", debugstr_wn(type_info
->TypeName
.Buffer
, type_info
->TypeName
.Length
/ sizeof(WCHAR
)));
1032 status
= NtQueryInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileNameInformation
);
1033 ok(!status
, "got %#lx\n", status
);
1034 ok(compare_unicode_string(file_info
->FileName
, file_info
->FileNameLength
, L
"\\subfile"),
1035 "wrong name %s\n", debugstr_wn(file_info
->FileName
, file_info
->FileNameLength
/ sizeof(WCHAR
)));
1037 io
.Status
= 0xdeadf00d;
1038 io
.Information
= 0xdeadf00d;
1039 status
= NtQueryVolumeInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileFsVolumeInformation
);
1040 ok(!status
, "got %#lx\n", status
);
1041 ok(!io
.Status
, "got status %#lx\n", io
.Status
);
1042 size
= offsetof(FILE_FS_VOLUME_INFORMATION
, VolumeLabel
) + volume_info
->VolumeLabelLength
;
1043 ok(io
.Information
== size
, "expected information %lu, got %Iu\n", size
, io
.Information
);
1044 ok(volume_info
->VolumeSerialNumber
== 0xdeadbeef,
1045 "wrong serial number 0x%08lx\n", volume_info
->VolumeSerialNumber
);
1046 ok(compare_unicode_string(volume_info
->VolumeLabel
, volume_info
->VolumeLabelLength
, L
"WineTestDriver"),
1047 "wrong name %s\n", debugstr_wn(volume_info
->VolumeLabel
, volume_info
->VolumeLabelLength
/ sizeof(WCHAR
)));
1049 io
.Status
= 0xdeadf00d;
1050 io
.Information
= 0xdeadf00d;
1051 status
= NtQueryVolumeInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileFsAttributeInformation
);
1052 ok(status
== STATUS_NOT_IMPLEMENTED
, "got %#lx\n", status
);
1053 ok(io
.Status
== 0xdeadf00d, "got status %#lx\n", io
.Status
);
1054 ok(io
.Information
== 0xdeadf00d, "got information %Iu\n", io
.Information
);
1058 file
= CreateFileA("\\\\.\\WineTestDriver\\notimpl", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1059 ok(file
!= INVALID_HANDLE_VALUE
, "got error %lu\n", GetLastError());
1061 status
= NtQueryObject(file
, ObjectNameInformation
, buffer
, sizeof(buffer
), NULL
);
1062 ok(!status
, "got %#lx\n", status
);
1063 ok(compare_unicode_string(name_info
->Name
.Buffer
, name_info
->Name
.Length
, L
"\\Device\\WineTestDriver"),
1064 "wrong name %s\n", debugstr_w(name_info
->Name
.Buffer
));
1066 status
= NtQueryInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileNameInformation
);
1067 ok(status
== STATUS_NOT_IMPLEMENTED
, "got %#lx\n", status
);
1071 file
= CreateFileA("\\\\.\\WineTestDriver\\badparam", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1072 ok(file
!= INVALID_HANDLE_VALUE
, "got error %lu\n", GetLastError());
1074 status
= NtQueryObject(file
, ObjectNameInformation
, buffer
, sizeof(buffer
), NULL
);
1075 ok(!status
, "got %#lx\n", status
);
1076 ok(compare_unicode_string(name_info
->Name
.Buffer
, name_info
->Name
.Length
, L
"\\Device\\WineTestDriver"),
1077 "wrong name %s\n", debugstr_w(name_info
->Name
.Buffer
));
1079 status
= NtQueryInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileNameInformation
);
1080 ok(status
== STATUS_INVALID_PARAMETER
, "got %#lx\n", status
);
1084 file
= CreateFileA("\\\\.\\WineTestDriver\\genfail", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1085 ok(file
!= INVALID_HANDLE_VALUE
, "got error %lu\n", GetLastError());
1087 status
= NtQueryObject(file
, ObjectNameInformation
, buffer
, sizeof(buffer
), NULL
);
1088 ok(status
== STATUS_UNSUCCESSFUL
, "got %#lx\n", status
);
1090 status
= NtQueryInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileNameInformation
);
1091 ok(status
== STATUS_UNSUCCESSFUL
, "got %#lx\n", status
);
1095 file
= CreateFileA("\\\\.\\WineTestDriver\\badtype", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1096 ok(file
!= INVALID_HANDLE_VALUE
, "got error %lu\n", GetLastError());
1098 status
= NtQueryObject(file
, ObjectNameInformation
, buffer
, sizeof(buffer
), NULL
);
1099 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
, "got %#lx\n", status
);
1101 status
= NtQueryInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileNameInformation
);
1102 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
, "got %#lx\n", status
);
1107 static void test_blocking_irp(void)
1114 file
= CreateFileA("\\\\.\\WineTestDriver\\", FILE_ALL_ACCESS
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1115 ok(file
!= INVALID_HANDLE_VALUE
, "failed to open device: %lu\n", GetLastError());
1117 memset(&io
, 0xcc, sizeof(io
));
1118 status
= NtQueryVolumeInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileFsSizeInformation
);
1119 ok(!status
, "got %#lx\n", status
);
1120 ok(!io
.Status
, "got iosb status %#lx\n", io
.Status
);
1121 ok(!io
.Information
, "got information %#Ix\n", io
.Information
);
1123 io
.Status
= 0xdeadf00d;
1124 io
.Information
= 0xdeadf00d;
1125 status
= NtQueryVolumeInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileFsFullSizeInformation
);
1126 ok(status
== STATUS_DEVICE_NOT_READY
, "got %#lx\n", status
);
1127 ok(io
.Status
== 0xdeadf00d, "got iosb status %#lx\n", io
.Status
);
1128 ok(io
.Information
== 0xdeadf00d, "got information %#Ix\n", io
.Information
);
1132 file
= CreateFileA("\\\\.\\WineTestDriver\\", FILE_ALL_ACCESS
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_OVERLAPPED
, NULL
);
1133 ok(file
!= INVALID_HANDLE_VALUE
, "failed to open device: %lu\n", GetLastError());
1135 memset(&io
, 0xcc, sizeof(io
));
1136 status
= NtQueryVolumeInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileFsSizeInformation
);
1137 ok(!status
, "got %#lx\n", status
);
1138 ok(!io
.Status
, "got iosb status %#lx\n", io
.Status
);
1139 ok(!io
.Information
, "got information %#Ix\n", io
.Information
);
1141 memset(&io
, 0xcc, sizeof(io
));
1142 status
= NtQueryVolumeInformationFile(file
, &io
, buffer
, sizeof(buffer
), FileFsFullSizeInformation
);
1143 ok(status
== STATUS_DEVICE_NOT_READY
, "got %#lx\n", status
);
1144 ok(io
.Status
== STATUS_DEVICE_NOT_READY
, "got iosb status %#lx\n", io
.Status
);
1145 ok(!io
.Information
, "got information %#Ix\n", io
.Information
);
1150 static void test_driver3(struct testsign_context
*ctx
)
1152 WCHAR filename
[MAX_PATH
];
1156 service
= load_driver(ctx
, filename
, L
"driver3.dll", L
"WineTestDriver3");
1157 ok(service
!= NULL
, "driver3 failed to load\n");
1159 ret
= StartServiceA(service
, 0, NULL
);
1160 ok(!ret
, "driver3 should fail to start\n");
1161 ok(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
||
1162 GetLastError() == ERROR_INVALID_FUNCTION
||
1163 GetLastError() == ERROR_PROC_NOT_FOUND
/* XP */ ||
1164 GetLastError() == ERROR_FILE_NOT_FOUND
/* Win7 */, "got %lu\n", GetLastError());
1166 DeleteService(service
);
1167 CloseServiceHandle(service
);
1168 DeleteFileW(filename
);
1171 static DWORD WINAPI
wsk_test_thread(void *parameter
)
1173 static const char test_send_string
[] = "Client test string 1.";
1174 static const WORD version
= MAKEWORD(2, 2);
1175 SOCKET s_listen
, s_accept
, s_connect
;
1176 struct sockaddr_in addr
;
1182 ret
= WSAStartup(version
, &data
);
1183 ok(!ret
, "WSAStartup() failed, ret %u.\n", ret
);
1185 s_connect
= socket(AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
1186 ok(s_connect
!= INVALID_SOCKET
, "Error creating socket, WSAGetLastError() %u.\n", WSAGetLastError());
1188 s_listen
= socket(AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
1189 ok(s_listen
!= INVALID_SOCKET
, "Error creating socket, WSAGetLastError() %u.\n", WSAGetLastError());
1192 setsockopt(s_listen
, SOL_SOCKET
, SO_REUSEADDR
, (const char *)&opt_val
, sizeof(opt_val
));
1194 memset(&addr
, 0, sizeof(addr
));
1195 addr
.sin_family
= AF_INET
;
1196 addr
.sin_port
= htons(CLIENT_LISTEN_PORT
);
1197 addr
.sin_addr
.s_addr
= htonl(0x7f000001);
1198 ret
= bind(s_listen
, (struct sockaddr
*)&addr
, sizeof(addr
));
1199 ok(!ret
, "Got unexpected ret %d, WSAGetLastError() %u.\n", ret
, WSAGetLastError());
1201 ret
= listen(s_listen
, SOMAXCONN
);
1202 ok(!ret
, "Got unexpected ret %d, WSAGetLastError() %u.\n", ret
, WSAGetLastError());
1204 addr
.sin_port
= htons(SERVER_LISTEN_PORT
);
1206 ret
= connect(s_connect
, (struct sockaddr
*)&addr
, sizeof(addr
));
1207 while (ret
&& ((err
= WSAGetLastError()) == WSAECONNREFUSED
|| err
== WSAECONNABORTED
))
1210 ret
= connect(s_connect
, (struct sockaddr
*)&addr
, sizeof(addr
));
1212 ok(!ret
, "Error connecting, WSAGetLastError() %u.\n", WSAGetLastError());
1214 ret
= send(s_connect
, test_send_string
, sizeof(test_send_string
), 0);
1215 ok(ret
== sizeof(test_send_string
), "Got unexpected ret %d.\n", ret
);
1217 ret
= recv(s_connect
, buffer
, sizeof(buffer
), 0);
1218 ok(ret
== sizeof(buffer
), "Got unexpected ret %d.\n", ret
);
1219 ok(!strcmp(buffer
, "Server test string 1."), "Received unexpected data.\n");
1221 s_accept
= accept(s_listen
, NULL
, NULL
);
1222 ok(s_accept
!= INVALID_SOCKET
, "Error creating socket, WSAGetLastError() %u.\n", WSAGetLastError());
1224 closesocket(s_accept
);
1225 closesocket(s_connect
);
1226 closesocket(s_listen
);
1230 static void test_driver_netio(struct testsign_context
*ctx
)
1232 WCHAR filename
[MAX_PATH
];
1237 if (!(service
= load_driver(ctx
, filename
, L
"driver_netio.dll", L
"winetest_netio")))
1240 if (!start_driver(service
, TRUE
))
1242 DeleteFileW(filename
);
1246 device
= CreateFileA("\\\\.\\winetest_netio", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1247 ok(device
!= INVALID_HANDLE_VALUE
, "failed to open device: %lu\n", GetLastError());
1249 hthread
= CreateThread(NULL
, 0, wsk_test_thread
, NULL
, 0, NULL
);
1251 WaitForSingleObject(hthread
, INFINITE
);
1253 CloseHandle(device
);
1255 unload_driver(service
);
1256 ret
= DeleteFileW(filename
);
1257 ok(ret
, "DeleteFile failed: %lu\n", GetLastError());
1264 #elif defined(__x86_64__)
1266 #elif defined(__arm__)
1268 #elif defined(__aarch64__)
1274 static const char inf_text
[] =
1276 "Signature=$Chicago$\n"
1277 "ClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318}\n"
1278 "CatalogFile=winetest.cat\n"
1279 "DriverVer=09/21/2006,6.0.5736.1\n"
1282 "Wine=mfg_section,NT" EXT
"\n"
1284 "[mfg_section.NT" EXT
"]\n"
1285 "Wine test root driver=device_section,test_hardware_id\n"
1287 "[device_section.NT" EXT
"]\n"
1288 "CopyFiles=file_section\n"
1290 "[device_section.NT" EXT
".Services]\n"
1291 "AddService=winetest,0x2,svc_section\n"
1296 "[SourceDisksFiles]\n"
1299 "[SourceDisksNames]\n"
1302 "[DestinationDirs]\n"
1303 "DefaultDestDir=12\n"
1306 "ServiceBinary=%12%\\winetest.sys\n"
1310 "LoadOrderGroup=Extended Base\n"
1311 "DisplayName=\"winetest bus driver\"\n"
1312 "; they don't sleep anymore, on the beach\n";
1314 static void add_file_to_catalog(HANDLE catalog
, const WCHAR
*file
)
1316 SIP_SUBJECTINFO subject_info
= {sizeof(SIP_SUBJECTINFO
)};
1317 SIP_INDIRECT_DATA
*indirect_data
;
1318 const WCHAR
*filepart
= file
;
1319 CRYPTCATMEMBER
*member
;
1320 WCHAR hash_buffer
[100];
1326 ret
= CryptSIPRetrieveSubjectGuidForCatalogFile(file
, NULL
, &subject_guid
);
1327 todo_wine
ok(ret
, "Failed to get subject guid, error %lu\n", GetLastError());
1330 subject_info
.pgSubjectType
= &subject_guid
;
1331 subject_info
.pwsFileName
= file
;
1332 subject_info
.DigestAlgorithm
.pszObjId
= (char *)szOID_OIWSEC_sha1
;
1333 subject_info
.dwFlags
= SPC_INC_PE_RESOURCES_FLAG
| SPC_INC_PE_IMPORT_ADDR_TABLE_FLAG
| SPC_EXC_PE_PAGE_HASHES_FLAG
| 0x10000;
1334 ret
= CryptSIPCreateIndirectData(&subject_info
, &size
, NULL
);
1335 todo_wine
ok(ret
, "Failed to get indirect data size, error %lu\n", GetLastError());
1337 indirect_data
= malloc(size
);
1338 ret
= CryptSIPCreateIndirectData(&subject_info
, &size
, indirect_data
);
1339 todo_wine
ok(ret
, "Failed to get indirect data, error %lu\n", GetLastError());
1342 memset(hash_buffer
, 0, sizeof(hash_buffer
));
1343 for (i
= 0; i
< indirect_data
->Digest
.cbData
; ++i
)
1344 swprintf(&hash_buffer
[i
* 2], 2, L
"%02X", indirect_data
->Digest
.pbData
[i
]);
1346 member
= CryptCATPutMemberInfo(catalog
, (WCHAR
*)file
,
1347 hash_buffer
, &subject_guid
, 0, size
, (BYTE
*)indirect_data
);
1348 ok(!!member
, "Failed to write member, error %lu\n", GetLastError());
1350 if (wcsrchr(file
, '\\'))
1351 filepart
= wcsrchr(file
, '\\') + 1;
1353 ret
= !!CryptCATPutAttrInfo(catalog
, member
, (WCHAR
*)L
"File",
1354 CRYPTCAT_ATTR_NAMEASCII
| CRYPTCAT_ATTR_DATAASCII
| CRYPTCAT_ATTR_AUTHENTICATED
,
1355 (wcslen(filepart
) + 1) * 2, (BYTE
*)filepart
);
1356 ok(ret
, "Failed to write attr, error %lu\n", GetLastError());
1358 ret
= !!CryptCATPutAttrInfo(catalog
, member
, (WCHAR
*)L
"OSAttr",
1359 CRYPTCAT_ATTR_NAMEASCII
| CRYPTCAT_ATTR_DATAASCII
| CRYPTCAT_ATTR_AUTHENTICATED
,
1360 sizeof(L
"2:6.0"), (BYTE
*)L
"2:6.0");
1361 ok(ret
, "Failed to write attr, error %lu\n", GetLastError());
1364 free(indirect_data
);
1367 static const GUID bus_class
= {0xdeadbeef, 0x29ef, 0x4538, {0xa5, 0xfd, 0xb6, 0x95, 0x73, 0xa3, 0x62, 0xc1}};
1368 static const GUID child_class
= {0xdeadbeef, 0x29ef, 0x4538, {0xa5, 0xfd, 0xb6, 0x95, 0x73, 0xa3, 0x62, 0xc2}};
1370 static unsigned int got_bus_arrival
, got_bus_removal
, got_child_arrival
, got_child_removal
;
1372 static LRESULT WINAPI
device_notify_proc(HWND window
, UINT message
, WPARAM wparam
, LPARAM lparam
)
1374 if (message
!= WM_DEVICECHANGE
)
1375 return DefWindowProcA(window
, message
, wparam
, lparam
);
1379 case DBT_DEVNODES_CHANGED
:
1380 if (winetest_debug
> 1) trace("device nodes changed\n");
1382 ok(InSendMessageEx(NULL
) == ISMEX_NOTIFY
, "got message flags %#lx\n", InSendMessageEx(NULL
));
1383 ok(!lparam
, "got lparam %#Ix\n", lparam
);
1386 case DBT_DEVICEARRIVAL
:
1388 const DEV_BROADCAST_DEVICEINTERFACE_A
*iface
= (const DEV_BROADCAST_DEVICEINTERFACE_A
*)lparam
;
1389 DWORD expect_size
= offsetof(DEV_BROADCAST_DEVICEINTERFACE_A
, dbcc_name
[strlen(iface
->dbcc_name
)]);
1391 if (winetest_debug
> 1) trace("device arrival %s\n", iface
->dbcc_name
);
1393 ok(InSendMessageEx(NULL
) == ISMEX_SEND
, "got message flags %#lx\n", InSendMessageEx(NULL
));
1395 ok(iface
->dbcc_devicetype
== DBT_DEVTYP_DEVICEINTERFACE
,
1396 "got unexpected notification type %#lx\n", iface
->dbcc_devicetype
);
1397 ok(iface
->dbcc_size
>= expect_size
, "expected size at least %lu, got %lu\n", expect_size
, iface
->dbcc_size
);
1398 ok(!iface
->dbcc_reserved
, "got reserved %#lx\n", iface
->dbcc_reserved
);
1399 if (IsEqualGUID(&iface
->dbcc_classguid
, &bus_class
))
1402 todo_wine
ok(!strcmp(iface
->dbcc_name
, "\\\\?\\ROOT#WINETEST#0#{deadbeef-29ef-4538-a5fd-b69573a362c1}"),
1403 "got name %s\n", debugstr_a(iface
->dbcc_name
));
1405 else if (IsEqualGUID(&iface
->dbcc_classguid
, &child_class
))
1407 ++got_child_arrival
;
1408 todo_wine
ok(!strcmp(iface
->dbcc_name
, "\\\\?\\wine#test#1#{deadbeef-29ef-4538-a5fd-b69573a362c2}"),
1409 "got name %s\n", debugstr_a(iface
->dbcc_name
));
1414 case DBT_DEVICEREMOVECOMPLETE
:
1416 const DEV_BROADCAST_DEVICEINTERFACE_A
*iface
= (const DEV_BROADCAST_DEVICEINTERFACE_A
*)lparam
;
1417 DWORD expect_size
= offsetof(DEV_BROADCAST_DEVICEINTERFACE_A
, dbcc_name
[strlen(iface
->dbcc_name
)]);
1419 if (winetest_debug
> 1) trace("device removal %s\n", iface
->dbcc_name
);
1421 ok(InSendMessageEx(NULL
) == ISMEX_SEND
, "got message flags %#lx\n", InSendMessageEx(NULL
));
1423 ok(iface
->dbcc_devicetype
== DBT_DEVTYP_DEVICEINTERFACE
,
1424 "got unexpected notification type %#lx\n", iface
->dbcc_devicetype
);
1425 ok(iface
->dbcc_size
>= expect_size
, "expected size at least %lu, got %lu\n", expect_size
, iface
->dbcc_size
);
1426 ok(!iface
->dbcc_reserved
, "got reserved %#lx\n", iface
->dbcc_reserved
);
1427 if (IsEqualGUID(&iface
->dbcc_classguid
, &bus_class
))
1430 todo_wine
ok(!strcmp(iface
->dbcc_name
, "\\\\?\\ROOT#WINETEST#0#{deadbeef-29ef-4538-a5fd-b69573a362c1}"),
1431 "got name %s\n", debugstr_a(iface
->dbcc_name
));
1433 else if (IsEqualGUID(&iface
->dbcc_classguid
, &child_class
))
1435 ++got_child_removal
;
1436 todo_wine
ok(!strcmp(iface
->dbcc_name
, "\\\\?\\wine#test#1#{deadbeef-29ef-4538-a5fd-b69573a362c2}"),
1437 "got name %s\n", debugstr_a(iface
->dbcc_name
));
1442 return DefWindowProcA(window
, message
, wparam
, lparam
);
1445 static void pump_messages(void)
1449 if (!MsgWaitForMultipleObjects(0, NULL
, FALSE
, 200, QS_ALLINPUT
))
1451 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
1453 TranslateMessage(&msg
);
1454 DispatchMessageA(&msg
);
1459 static void test_pnp_devices(void)
1461 static const char expect_hardware_id
[] = "winetest_hardware\0winetest_hardware_1\0";
1462 static const char expect_compat_id
[] = "winetest_compat\0winetest_compat_1\0";
1463 static const WCHAR expect_container_id_w
[] = L
"{12345678-1234-1234-1234-123456789123}";
1466 WCHAR buffer_w
[200];
1467 SP_DEVICE_INTERFACE_DETAIL_DATA_A
*iface_detail
= (void *)buffer
;
1468 SP_DEVICE_INTERFACE_DATA iface
= {sizeof(iface
)};
1469 SP_DEVINFO_DATA device
= {sizeof(device
)};
1470 DEV_BROADCAST_DEVICEINTERFACE_A filter
=
1472 .dbcc_size
= sizeof(filter
),
1473 .dbcc_devicetype
= DBT_DEVTYP_DEVICEINTERFACE
,
1475 static const WNDCLASSA
class =
1477 .lpszClassName
= "ntoskrnl_test_wc",
1478 .lpfnWndProc
= device_notify_proc
,
1480 HDEVNOTIFY notify_handle
;
1481 DWORD size
, type
, dword
;
1482 HANDLE bus
, child
, tmp
;
1483 OBJECT_ATTRIBUTES attr
;
1484 UNICODE_STRING string
;
1485 OVERLAPPED ovl
= {0};
1492 ret
= RegisterClassA(&class);
1493 ok(ret
, "failed to register class\n");
1494 window
= CreateWindowA("ntoskrnl_test_wc", NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, NULL
, NULL
, NULL
);
1495 ok(!!window
, "failed to create window\n");
1496 notify_handle
= RegisterDeviceNotificationA(window
, &filter
, DEVICE_NOTIFY_ALL_INTERFACE_CLASSES
);
1497 ok(!!notify_handle
, "failed to register window, error %lu\n", GetLastError());
1499 set
= SetupDiGetClassDevsA(&control_class
, NULL
, NULL
, DIGCF_PRESENT
| DIGCF_DEVICEINTERFACE
);
1500 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1502 ret
= SetupDiEnumDeviceInfo(set
, 0, &device
);
1503 ok(ret
, "failed to get device, error %#lx\n", GetLastError());
1504 ok(IsEqualGUID(&device
.ClassGuid
, &GUID_DEVCLASS_SYSTEM
), "wrong class %s\n", debugstr_guid(&device
.ClassGuid
));
1506 ret
= SetupDiGetDeviceInstanceIdA(set
, &device
, buffer
, sizeof(buffer
), NULL
);
1507 ok(ret
, "failed to get device ID, error %#lx\n", GetLastError());
1508 ok(!strcasecmp(buffer
, "root\\winetest\\0"), "got ID %s\n", debugstr_a(buffer
));
1510 ret
= SetupDiEnumDeviceInterfaces(set
, NULL
, &control_class
, 0, &iface
);
1511 ok(ret
, "failed to get interface, error %#lx\n", GetLastError());
1512 ok(IsEqualGUID(&iface
.InterfaceClassGuid
, &control_class
),
1513 "wrong class %s\n", debugstr_guid(&iface
.InterfaceClassGuid
));
1514 ok(iface
.Flags
== SPINT_ACTIVE
, "got flags %#lx\n", iface
.Flags
);
1516 iface_detail
->cbSize
= sizeof(*iface_detail
);
1517 ret
= SetupDiGetDeviceInterfaceDetailA(set
, &iface
, iface_detail
, sizeof(buffer
), NULL
, NULL
);
1518 ok(ret
, "failed to get interface path, error %#lx\n", GetLastError());
1519 ok(!strcasecmp(iface_detail
->DevicePath
, "\\\\?\\root#winetest#0#{deadbeef-29ef-4538-a5fd-b69573a362c0}"),
1520 "wrong path %s\n", debugstr_a(iface_detail
->DevicePath
));
1522 SetupDiDestroyDeviceInfoList(set
);
1524 bus
= CreateFileA(iface_detail
->DevicePath
, 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1525 ok(bus
!= INVALID_HANDLE_VALUE
, "got error %lu\n", GetLastError());
1527 ret
= DeviceIoControl(bus
, IOCTL_WINETEST_BUS_MAIN
, NULL
, 0, NULL
, 0, &size
, NULL
);
1528 ok(ret
, "got error %lu\n", GetLastError());
1530 /* Test IoRegisterDeviceInterface() and IoSetDeviceInterfaceState(). */
1532 set
= SetupDiGetClassDevsA(&bus_class
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
);
1533 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1534 ret
= SetupDiEnumDeviceInterfaces(set
, NULL
, &bus_class
, 0, &iface
);
1535 ok(!ret
, "expected failure\n");
1536 ok(GetLastError() == ERROR_NO_MORE_ITEMS
, "got error %#lx\n", GetLastError());
1537 SetupDiDestroyDeviceInfoList(set
);
1539 ret
= DeviceIoControl(bus
, IOCTL_WINETEST_BUS_REGISTER_IFACE
, NULL
, 0, NULL
, 0, &size
, NULL
);
1540 ok(ret
, "got error %lu\n", GetLastError());
1542 set
= SetupDiGetClassDevsA(&bus_class
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
);
1543 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1544 ret
= SetupDiEnumDeviceInterfaces(set
, NULL
, &bus_class
, 0, &iface
);
1545 ok(ret
, "failed to get interface, error %#lx\n", GetLastError());
1546 ok(IsEqualGUID(&iface
.InterfaceClassGuid
, &bus_class
),
1547 "wrong class %s\n", debugstr_guid(&iface
.InterfaceClassGuid
));
1548 ok(!iface
.Flags
, "got flags %#lx\n", iface
.Flags
);
1549 SetupDiDestroyDeviceInfoList(set
);
1551 set
= SetupDiGetClassDevsA(&bus_class
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
| DIGCF_PRESENT
);
1552 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1553 ret
= SetupDiEnumDeviceInterfaces(set
, NULL
, &bus_class
, 0, &iface
);
1554 ok(!ret
, "expected failure\n");
1555 ok(GetLastError() == ERROR_NO_MORE_ITEMS
, "got error %#lx\n", GetLastError());
1556 SetupDiDestroyDeviceInfoList(set
);
1558 ret
= DeviceIoControl(bus
, IOCTL_WINETEST_BUS_ENABLE_IFACE
, NULL
, 0, NULL
, 0, &size
, NULL
);
1559 ok(ret
, "got error %lu\n", GetLastError());
1562 ok(got_bus_arrival
== 1, "got %u bus arrival messages\n", got_bus_arrival
);
1563 ok(!got_bus_removal
, "got %u bus removal messages\n", got_bus_removal
);
1565 set
= SetupDiGetClassDevsA(&bus_class
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
| DIGCF_PRESENT
);
1566 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1567 ret
= SetupDiEnumDeviceInterfaces(set
, NULL
, &bus_class
, 0, &iface
);
1568 ok(ret
, "failed to get interface, error %#lx\n", GetLastError());
1569 ok(IsEqualGUID(&iface
.InterfaceClassGuid
, &bus_class
),
1570 "wrong class %s\n", debugstr_guid(&iface
.InterfaceClassGuid
));
1571 ok(iface
.Flags
== SPINT_ACTIVE
, "got flags %#lx\n", iface
.Flags
);
1572 SetupDiDestroyDeviceInfoList(set
);
1574 ret
= DeviceIoControl(bus
, IOCTL_WINETEST_BUS_DISABLE_IFACE
, NULL
, 0, NULL
, 0, &size
, NULL
);
1575 ok(ret
, "got error %lu\n", GetLastError());
1578 ok(got_bus_arrival
== 1, "got %u bus arrival messages\n", got_bus_arrival
);
1579 ok(got_bus_removal
== 1, "got %u bus removal messages\n", got_bus_removal
);
1581 set
= SetupDiGetClassDevsA(&bus_class
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
);
1582 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1583 ret
= SetupDiEnumDeviceInterfaces(set
, NULL
, &bus_class
, 0, &iface
);
1584 ok(ret
, "failed to get interface, error %#lx\n", GetLastError());
1585 ok(IsEqualGUID(&iface
.InterfaceClassGuid
, &bus_class
),
1586 "wrong class %s\n", debugstr_guid(&iface
.InterfaceClassGuid
));
1587 ok(!iface
.Flags
, "got flags %#lx\n", iface
.Flags
);
1588 SetupDiDestroyDeviceInfoList(set
);
1590 set
= SetupDiGetClassDevsA(&bus_class
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
| DIGCF_PRESENT
);
1591 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1592 ret
= SetupDiEnumDeviceInterfaces(set
, NULL
, &bus_class
, 0, &iface
);
1593 ok(!ret
, "expected failure\n");
1594 ok(GetLastError() == ERROR_NO_MORE_ITEMS
, "got error %#lx\n", GetLastError());
1595 SetupDiDestroyDeviceInfoList(set
);
1597 /* Test exposing a child device. */
1600 ret
= DeviceIoControl(bus
, IOCTL_WINETEST_BUS_ADD_CHILD
, &id
, sizeof(id
), NULL
, 0, &size
, NULL
);
1601 ok(ret
, "got error %lu\n", GetLastError());
1604 ok(got_child_arrival
== 1, "got %u child arrival messages\n", got_child_arrival
);
1605 ok(!got_child_removal
, "got %u child removal messages\n", got_child_removal
);
1607 set
= SetupDiGetClassDevsA(&child_class
, NULL
, NULL
, DIGCF_DEVICEINTERFACE
| DIGCF_PRESENT
);
1608 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1610 ret
= SetupDiEnumDeviceInfo(set
, 0, &device
);
1611 ok(ret
, "failed to get device, error %#lx\n", GetLastError());
1612 ok(IsEqualGUID(&device
.ClassGuid
, &GUID_NULL
), "wrong class %s\n", debugstr_guid(&device
.ClassGuid
));
1614 ret
= SetupDiGetDeviceInstanceIdA(set
, &device
, buffer
, sizeof(buffer
), NULL
);
1615 ok(ret
, "failed to get device ID, error %#lx\n", GetLastError());
1616 ok(!strcasecmp(buffer
, "wine\\test\\1"), "got ID %s\n", debugstr_a(buffer
));
1618 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_CAPABILITIES
,
1619 &type
, (BYTE
*)&dword
, sizeof(dword
), NULL
);
1620 todo_wine
ok(ret
, "got error %#lx\n", GetLastError());
1623 ok(dword
== (CM_DEVCAP_EJECTSUPPORTED
| CM_DEVCAP_UNIQUEID
1624 | CM_DEVCAP_RAWDEVICEOK
| CM_DEVCAP_SURPRISEREMOVALOK
), "got flags %#lx\n", dword
);
1625 ok(type
== REG_DWORD
, "got type %lu\n", type
);
1628 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_CLASSGUID
,
1629 &type
, (BYTE
*)buffer
, sizeof(buffer
), NULL
);
1630 todo_wine
ok(!ret
, "expected failure\n");
1632 ok(GetLastError() == ERROR_INVALID_DATA
, "got error %#lx\n", GetLastError());
1634 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_CONFIGFLAGS
,
1635 &type
, (BYTE
*)&dword
, sizeof(dword
), NULL
);
1636 todo_wine
ok(ret
, "got error %#lx\n", GetLastError());
1639 ok(!dword
, "got flags %#lx\n", dword
);
1640 ok(type
== REG_DWORD
, "got type %lu\n", type
);
1643 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_DEVTYPE
,
1644 &type
, (BYTE
*)&dword
, sizeof(dword
), NULL
);
1645 ok(!ret
, "expected failure\n");
1646 ok(GetLastError() == ERROR_INVALID_DATA
, "got error %#lx\n", GetLastError());
1648 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_DRIVER
,
1649 &type
, (BYTE
*)buffer
, sizeof(buffer
), NULL
);
1650 ok(!ret
, "expected failure\n");
1651 ok(GetLastError() == ERROR_INVALID_DATA
, "got error %#lx\n", GetLastError());
1653 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_HARDWAREID
,
1654 &type
, (BYTE
*)buffer
, sizeof(buffer
), &size
);
1655 ok(ret
, "got error %#lx\n", GetLastError());
1656 ok(type
== REG_MULTI_SZ
, "got type %lu\n", type
);
1657 ok(size
== sizeof(expect_hardware_id
), "got size %lu\n", size
);
1658 ok(!memcmp(buffer
, expect_hardware_id
, size
), "got hardware IDs %s\n", debugstr_an(buffer
, size
));
1660 /* Using the WCHAR variant because Windows returns a WCHAR for this property even when using SetupDiGetDeviceRegistryPropertyA */
1661 ret
= SetupDiGetDeviceRegistryPropertyW(set
, &device
, SPDRP_BASE_CONTAINERID
,
1662 &type
, (BYTE
*)buffer_w
, sizeof(buffer_w
), &size
);
1663 ok(ret
, "got error %#lx\n", GetLastError());
1664 ok(type
== REG_SZ
, "got type %lu\n", type
);
1665 ok(size
== sizeof(expect_container_id_w
), "got size %lu\n", size
);
1666 ok(!memcmp(buffer_w
, expect_container_id_w
, size
), "got container ID %s\n", debugstr_w(buffer_w
));
1668 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_COMPATIBLEIDS
,
1669 &type
, (BYTE
*)buffer
, sizeof(buffer
), &size
);
1670 ok(ret
, "got error %#lx\n", GetLastError());
1671 ok(type
== REG_MULTI_SZ
, "got type %lu\n", type
);
1672 ok(size
== sizeof(expect_compat_id
), "got size %lu\n", size
);
1673 ok(!memcmp(buffer
, expect_compat_id
, size
), "got compatible IDs %s\n", debugstr_an(buffer
, size
));
1675 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
,
1676 &type
, (BYTE
*)buffer
, sizeof(buffer
), NULL
);
1677 todo_wine
ok(ret
, "got error %#lx\n", GetLastError());
1680 ok(type
== REG_SZ
, "got type %lu\n", type
);
1681 ok(!strcmp(buffer
, "\\Device\\winetest_pnp_1"), "got PDO name %s\n", debugstr_a(buffer
));
1684 SetupDiDestroyDeviceInfoList(set
);
1686 RtlInitUnicodeString(&string
, L
"\\Device\\winetest_pnp_1");
1687 InitializeObjectAttributes(&attr
, &string
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
1688 ret
= NtOpenFile(&child
, SYNCHRONIZE
, &attr
, &io
, 0, FILE_SYNCHRONOUS_IO_NONALERT
);
1689 ok(!ret
, "failed to open child: %#x\n", ret
);
1692 ret
= DeviceIoControl(child
, IOCTL_WINETEST_CHILD_GET_ID
, NULL
, 0, &id
, sizeof(id
), &size
, NULL
);
1693 ok(ret
, "got error %lu\n", GetLastError());
1694 ok(id
== 1, "got id %d\n", id
);
1695 ok(size
== sizeof(id
), "got size %lu\n", size
);
1699 ret
= NtOpenFile(&child
, SYNCHRONIZE
, &attr
, &io
, 0, 0);
1700 ok(!ret
, "failed to open child: %#x\n", ret
);
1702 ret
= DeviceIoControl(child
, IOCTL_WINETEST_CHILD_MARK_PENDING
, NULL
, 0, NULL
, 0, &size
, &ovl
);
1703 ok(!ret
, "DeviceIoControl succeeded\n");
1704 ok(GetLastError() == ERROR_IO_PENDING
, "got error %lu\n", GetLastError());
1705 ok(size
== 0, "got size %lu\n", size
);
1708 ret
= DeviceIoControl(bus
, IOCTL_WINETEST_BUS_REMOVE_CHILD
, &id
, sizeof(id
), NULL
, 0, &size
, NULL
);
1709 ok(ret
, "got error %lu\n", GetLastError());
1712 ok(got_child_arrival
== 1, "got %u child arrival messages\n", got_child_arrival
);
1713 ok(got_child_removal
== 1, "got %u child removal messages\n", got_child_removal
);
1715 ret
= DeviceIoControl(child
, IOCTL_WINETEST_CHILD_CHECK_REMOVED
, NULL
, 0, NULL
, 0, &size
, NULL
);
1716 todo_wine
ok(ret
, "got error %lu\n", GetLastError());
1718 ret
= NtOpenFile(&tmp
, SYNCHRONIZE
, &attr
, &io
, 0, FILE_SYNCHRONOUS_IO_NONALERT
);
1719 todo_wine
ok(ret
== STATUS_NO_SUCH_DEVICE
, "got %#x\n", ret
);
1721 ret
= GetOverlappedResult(child
, &ovl
, &size
, TRUE
);
1722 ok(!ret
, "unexpected success.\n");
1723 ok(GetLastError() == ERROR_ACCESS_DENIED
, "got error %lu\n", GetLastError());
1724 ok(size
== 0, "got size %lu\n", size
);
1729 ok(got_child_arrival
== 1, "got %u child arrival messages\n", got_child_arrival
);
1730 ok(got_child_removal
== 1, "got %u child removal messages\n", got_child_removal
);
1732 ret
= NtOpenFile(&tmp
, SYNCHRONIZE
, &attr
, &io
, 0, FILE_SYNCHRONOUS_IO_NONALERT
);
1733 ok(ret
== STATUS_OBJECT_NAME_NOT_FOUND
, "got %#x\n", ret
);
1737 UnregisterDeviceNotification(notify_handle
);
1738 DestroyWindow(window
);
1739 UnregisterClassA("ntoskrnl_test_wc", GetModuleHandleA(NULL
));
1742 static void test_pnp_driver(struct testsign_context
*ctx
)
1744 static const char hardware_id
[] = "test_hardware_id\0";
1745 char path
[MAX_PATH
], dest
[MAX_PATH
], *filepart
;
1746 SP_DEVINFO_DATA device
= {sizeof(device
)};
1747 char cwd
[MAX_PATH
], tempdir
[MAX_PATH
];
1748 WCHAR driver_filename
[MAX_PATH
];
1749 SC_HANDLE manager
, service
;
1750 BOOL ret
, need_reboot
;
1751 HANDLE catalog
, file
;
1757 GetCurrentDirectoryA(ARRAY_SIZE(cwd
), cwd
);
1758 GetTempPathA(ARRAY_SIZE(tempdir
), tempdir
);
1759 SetCurrentDirectoryA(tempdir
);
1761 load_resource(L
"driver_pnp.dll", driver_filename
);
1762 ret
= MoveFileExW(driver_filename
, L
"winetest.sys", MOVEFILE_COPY_ALLOWED
| MOVEFILE_REPLACE_EXISTING
);
1763 ok(ret
, "failed to move file, error %lu\n", GetLastError());
1765 f
= fopen("winetest.inf", "w");
1766 ok(!!f
, "failed to open winetest.inf: %s\n", strerror(errno
));
1770 /* Create the catalog file. */
1772 catalog
= CryptCATOpen((WCHAR
*)L
"winetest.cat", CRYPTCAT_OPEN_CREATENEW
, 0, CRYPTCAT_VERSION_1
, 0);
1773 ok(catalog
!= INVALID_HANDLE_VALUE
, "Failed to create catalog, error %#lx\n", GetLastError());
1775 ret
= !!CryptCATPutCatAttrInfo(catalog
, (WCHAR
*)L
"HWID1",
1776 CRYPTCAT_ATTR_NAMEASCII
| CRYPTCAT_ATTR_DATAASCII
| CRYPTCAT_ATTR_AUTHENTICATED
,
1777 sizeof(L
"test_hardware_id"), (BYTE
*)L
"test_hardware_id");
1778 todo_wine
ok(ret
, "failed to add attribute, error %#lx\n", GetLastError());
1780 ret
= !!CryptCATPutCatAttrInfo(catalog
, (WCHAR
*)L
"OS",
1781 CRYPTCAT_ATTR_NAMEASCII
| CRYPTCAT_ATTR_DATAASCII
| CRYPTCAT_ATTR_AUTHENTICATED
,
1782 sizeof(L
"VistaX64"), (BYTE
*)L
"VistaX64");
1783 todo_wine
ok(ret
, "failed to add attribute, error %#lx\n", GetLastError());
1785 add_file_to_catalog(catalog
, L
"winetest.sys");
1786 add_file_to_catalog(catalog
, L
"winetest.inf");
1788 ret
= CryptCATPersistStore(catalog
);
1789 todo_wine
ok(ret
, "Failed to write catalog, error %lu\n", GetLastError());
1791 ret
= CryptCATClose(catalog
);
1792 ok(ret
, "Failed to close catalog, error %lu\n", GetLastError());
1794 testsign_sign(ctx
, L
"winetest.cat");
1796 /* Install the driver. */
1798 set
= SetupDiCreateDeviceInfoList(NULL
, NULL
);
1799 ok(set
!= INVALID_HANDLE_VALUE
, "failed to create device list, error %#lx\n", GetLastError());
1801 ret
= SetupDiCreateDeviceInfoA(set
, "root\\winetest\\0", &GUID_NULL
, NULL
, NULL
, 0, &device
);
1802 ok(ret
, "failed to create device, error %#lx\n", GetLastError());
1804 ret
= SetupDiSetDeviceRegistryPropertyA( set
, &device
, SPDRP_HARDWAREID
,
1805 (const BYTE
*)hardware_id
, sizeof(hardware_id
) );
1806 ok(ret
, "failed to create set hardware ID, error %#lx\n", GetLastError());
1808 ret
= SetupDiCallClassInstaller(DIF_REGISTERDEVICE
, set
, &device
);
1809 ok(ret
, "failed to register device, error %#lx\n", GetLastError());
1811 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_CONFIGFLAGS
,
1812 &type
, (BYTE
*)&dword
, sizeof(dword
), NULL
);
1813 ok(!ret
, "expected failure\n");
1814 ok(GetLastError() == ERROR_INVALID_DATA
, "got error %#lx\n", GetLastError());
1816 GetFullPathNameA("winetest.inf", sizeof(path
), path
, NULL
);
1817 ret
= UpdateDriverForPlugAndPlayDevicesA(NULL
, hardware_id
, path
, INSTALLFLAG_FORCE
, &need_reboot
);
1818 ok(ret
, "failed to install device, error %#lx\n", GetLastError());
1819 ok(!need_reboot
, "expected no reboot necessary\n");
1821 ret
= SetupDiGetDeviceRegistryPropertyA(set
, &device
, SPDRP_CONFIGFLAGS
,
1822 &type
, (BYTE
*)&dword
, sizeof(dword
), NULL
);
1823 todo_wine
ok(ret
, "got error %#lx\n", GetLastError());
1826 ok(!dword
, "got flags %#lx\n", dword
);
1827 ok(type
== REG_DWORD
, "got type %lu\n", type
);
1836 ret
= SetupDiCallClassInstaller(DIF_REMOVE
, set
, &device
);
1837 ok(ret
, "failed to remove device, error %#lx\n", GetLastError());
1839 file
= CreateFileA("\\\\?\\root#winetest#0#{deadbeef-29ef-4538-a5fd-b69573a362c0}", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1840 ok(file
== INVALID_HANDLE_VALUE
, "expected failure\n");
1841 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "got error %lu\n", GetLastError());
1843 ret
= SetupDiDestroyDeviceInfoList(set
);
1844 ok(ret
, "failed to destroy set, error %#lx\n", GetLastError());
1846 set
= SetupDiGetClassDevsA(NULL
, "wine", NULL
, DIGCF_ALLCLASSES
);
1847 ok(set
!= INVALID_HANDLE_VALUE
, "failed to get device list, error %#lx\n", GetLastError());
1849 for (i
= 0; SetupDiEnumDeviceInfo(set
, i
, &device
); ++i
)
1851 ret
= SetupDiCallClassInstaller(DIF_REMOVE
, set
, &device
);
1852 ok(ret
, "failed to remove device, error %#lx\n", GetLastError());
1855 SetupDiDestroyDeviceInfoList(set
);
1857 /* Windows stops the service but does not delete it. */
1858 manager
= OpenSCManagerA(NULL
, NULL
, SC_MANAGER_CONNECT
);
1859 ok(!!manager
, "failed to open service manager, error %lu\n", GetLastError());
1860 service
= OpenServiceA(manager
, "winetest", SERVICE_STOP
| DELETE
);
1861 ok(!!service
, "failed to open service, error %lu\n", GetLastError());
1862 unload_driver(service
);
1863 CloseServiceHandle(manager
);
1867 GetFullPathNameA("winetest.inf", sizeof(path
), path
, NULL
);
1868 ret
= SetupCopyOEMInfA(path
, NULL
, 0, 0, dest
, sizeof(dest
), NULL
, &filepart
);
1869 ok(ret
, "Failed to copy INF, error %#lx\n", GetLastError());
1870 ret
= SetupUninstallOEMInfA(filepart
, 0, NULL
);
1871 ok(ret
, "Failed to uninstall INF, error %lu\n", GetLastError());
1873 ret
= DeleteFileA("winetest.cat");
1874 ok(ret
, "Failed to delete file, error %lu\n", GetLastError());
1875 ret
= DeleteFileA("winetest.inf");
1876 ok(ret
, "Failed to delete file, error %lu\n", GetLastError());
1877 ret
= DeleteFileA("winetest.sys");
1878 ok(ret
, "Failed to delete file, error %lu\n", GetLastError());
1879 /* Windows 10 apparently deletes the image in SetupUninstallOEMInf(). */
1880 ret
= DeleteFileA("C:/windows/system32/drivers/winetest.sys");
1881 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
, "Failed to delete file, error %lu\n", GetLastError());
1883 SetCurrentDirectoryA(cwd
);
1886 START_TEST(ntoskrnl
)
1888 WCHAR filename
[MAX_PATH
], filename2
[MAX_PATH
];
1889 struct testsign_context ctx
;
1890 SC_HANDLE service
, service2
;
1895 pRtlDosPathNameToNtPathName_U
= (void *)GetProcAddress(GetModuleHandleA("ntdll"), "RtlDosPathNameToNtPathName_U");
1896 pRtlFreeUnicodeString
= (void *)GetProcAddress(GetModuleHandleA("ntdll"), "RtlFreeUnicodeString");
1897 pCancelIoEx
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "CancelIoEx");
1898 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsWow64Process");
1899 pSetFileCompletionNotificationModes
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),
1900 "SetFileCompletionNotificationModes");
1901 pSignerSign
= (void *)GetProcAddress(LoadLibraryA("mssign32"), "SignerSign");
1903 if (IsWow64Process(GetCurrentProcess(), &is_wow64
) && is_wow64
)
1905 skip("Running in WoW64.\n");
1909 if (!testsign_create_cert(&ctx
))
1912 mapping
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
,
1913 0, sizeof(*test_data
), "Global\\winetest_ntoskrnl_section");
1914 ok(!!mapping
, "got error %lu\n", GetLastError());
1915 test_data
= MapViewOfFile(mapping
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 1024);
1916 test_data
->running_under_wine
= !strcmp(winetest_platform
, "wine");
1917 test_data
->winetest_report_success
= winetest_report_success
;
1918 test_data
->winetest_debug
= winetest_debug
;
1920 okfile
= CreateFileA("C:\\windows\\winetest_ntoskrnl_okfile", GENERIC_READ
| GENERIC_WRITE
,
1921 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, CREATE_ALWAYS
, 0, NULL
);
1922 ok(okfile
!= INVALID_HANDLE_VALUE
, "failed to create file, error %lu\n", GetLastError());
1925 if (!(service
= load_driver(&ctx
, filename
, L
"driver.dll", L
"WineTestDriver")))
1928 if (!start_driver(service
, FALSE
))
1930 DeleteFileW(filename
);
1933 service2
= load_driver(&ctx
, filename2
, L
"driver2.dll", L
"WineTestDriver2");
1935 device
= CreateFileA("\\\\.\\WineTestDriver", 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1936 ok(device
!= INVALID_HANDLE_VALUE
, "failed to open device: %lu\n", GetLastError());
1941 todo_wine
ok(modified_value
== 0xdeadbeeffeedcafe, "Got unexpected value %#I64x.\n", modified_value
);
1944 test_load_driver(service2
);
1945 test_file_handles();
1946 test_return_status();
1948 test_blocking_irp();
1950 /* We need a separate ioctl to call IoDetachDevice(); calling it in the
1951 * driver unload routine causes a live-lock. */
1952 ret
= DeviceIoControl(device
, IOCTL_WINETEST_DETACH
, NULL
, 0, NULL
, 0, &written
, NULL
);
1953 ok(ret
, "DeviceIoControl failed: %lu\n", GetLastError());
1955 CloseHandle(device
);
1957 unload_driver(service2
);
1958 unload_driver(service
);
1959 ret
= DeleteFileW(filename
);
1960 ok(ret
, "DeleteFile failed: %lu\n", GetLastError());
1961 ret
= DeleteFileW(filename2
);
1962 ok(ret
, "DeleteFile failed: %lu\n", GetLastError());
1967 subtest("driver_netio");
1968 test_driver_netio(&ctx
);
1970 subtest("driver_pnp");
1971 test_pnp_driver(&ctx
);
1974 testsign_cleanup(&ctx
);
1975 UnmapViewOfFile(test_data
);
1976 CloseHandle(mapping
);
1977 CloseHandle(okfile
);
1978 DeleteFileA("C:\\windows\\winetest_ntoskrnl_okfile");