2 * Driver Regression Tests
4 * Copyright 2009 Michael Martin <martinmnet@hotmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; see the file COPYING.LIB.
18 * If not, write to the Free Software Foundation,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /* INCLUDES *******************************************************************/
25 #include <ddk/ntddk.h>
26 #include <ddk/ntifs.h>
30 VOID
LowerDeviceKernelAPITest(PDEVICE_OBJECT DeviceObject
, BOOLEAN UnLoading
)
32 PDEVICE_OBJECT RetObject
;
34 RetObject
= IoGetLowerDeviceObject(DeviceObject
);
39 "Expected no Lower DeviceObject, got %p", RetObject
);
43 ok(RetObject
== AttachDeviceObject
,
44 "Expected an Attached DeviceObject %p, got %p", AttachDeviceObject
, RetObject
);
49 ObDereferenceObject(RetObject
);
52 RetObject
= IoGetDeviceAttachmentBaseRef(DeviceObject
);
53 ok(RetObject
== DeviceObject
,
54 "Expected an Attached DeviceObject %p, got %p", DeviceObject
, RetObject
);
58 ObDereferenceObject(RetObject
);
62 VOID
DeviceCreatedTest(PDEVICE_OBJECT DeviceObject
, BOOLEAN ExclusiveAccess
)
64 PEXTENDED_DEVOBJ_EXTENSION extdev
;
66 /*Check the device object members */
67 ok(DeviceObject
->Type
==3, "Expected Type = 3, got %x", DeviceObject
->Type
);
68 ok(DeviceObject
->Size
= 0xb8, "Expected Size = 0xba, got %x", DeviceObject
->Size
);
69 ok(DeviceObject
->ReferenceCount
== 0, "Expected ReferenceCount = 0, got %lu",
70 DeviceObject
->ReferenceCount
);
71 ok(DeviceObject
->DriverObject
== ThisDriverObject
,
72 "Expected DriverObject member to match this DriverObject %p, got %p",
73 ThisDriverObject
, DeviceObject
->DriverObject
);
74 ok(DeviceObject
->NextDevice
== NULL
, "Expected NextDevice to be NULL, got %p", DeviceObject
->NextDevice
);
75 ok(DeviceObject
->AttachedDevice
== NULL
, "Expected AttachDevice to be NULL, got %p", DeviceObject
->AttachedDevice
);
76 ok(DeviceObject
->Characteristics
== 0, "Expected Characteristics to be 0");
79 ok((DeviceObject
->Flags
== (DO_DEVICE_HAS_NAME
| DO_DEVICE_INITIALIZING
| DO_EXCLUSIVE
)),
80 "Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING | DO_EXCLUSIVE, got %lu", DeviceObject
->Flags
);
84 ok((DeviceObject
->Flags
== (DO_DEVICE_HAS_NAME
| DO_DEVICE_INITIALIZING
)),
85 "Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING, got %lu", DeviceObject
->Flags
);
87 ok(DeviceObject
->DeviceType
== FILE_DEVICE_UNKNOWN
,
88 "Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu",
89 DeviceObject
->DeviceType
);
90 ok(DeviceObject
->ActiveThreadCount
== 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject
->ActiveThreadCount
);
92 /*Check the extended extension */
93 extdev
= (PEXTENDED_DEVOBJ_EXTENSION
)DeviceObject
->DeviceObjectExtension
;
94 ok(extdev
->ExtensionFlags
== 0, "Expected Extended ExtensionFlags to be 0, got %lu", extdev
->ExtensionFlags
);
95 ok (extdev
->Type
== 13, "Expected Type of 13, got %d", extdev
->Type
);
96 ok (extdev
->Size
== 0, "Expected Size of 0, got %d", extdev
->Size
);
97 ok (extdev
->DeviceObject
== DeviceObject
, "Expected DeviceOject to match newly created device %p, got %p",
98 DeviceObject
, extdev
->DeviceObject
);
99 ok(extdev
->AttachedTo
== NULL
, "Expected AttachTo to be NULL, got %p", extdev
->AttachedTo
);
100 ok(extdev
->StartIoCount
== 0, "Expected StartIoCount = 0, got %lu", extdev
->StartIoCount
);
101 ok(extdev
->StartIoKey
== 0, "Expected StartIoKey = 0, got %lu", extdev
->StartIoKey
);
102 ok(extdev
->StartIoFlags
== 0, "Expected StartIoFlags = 0, got %lu", extdev
->StartIoFlags
);
105 VOID
DeviceDeletionTest(PDEVICE_OBJECT DeviceObject
, BOOLEAN Lower
)
107 PEXTENDED_DEVOBJ_EXTENSION extdev
;
109 /*Check the device object members */
110 ok(DeviceObject
->Type
==3, "Expected Type = 3, got %d", DeviceObject
->Type
);
111 ok(DeviceObject
->Size
= 0xb8, "Expected Size = 0xba, got %d", DeviceObject
->Size
);
112 ok(DeviceObject
->ReferenceCount
== 0, "Expected ReferenceCount = 0, got %lu",
113 DeviceObject
->ReferenceCount
);
116 ok(DeviceObject
->DriverObject
== ThisDriverObject
,
117 "Expected DriverObject member to match this DriverObject %p, got %p",
118 ThisDriverObject
, DeviceObject
->DriverObject
);
120 ok(DeviceObject
->NextDevice
== NULL
, "Expected NextDevice to be NULL, got %p", DeviceObject
->NextDevice
);
124 ok(DeviceObject
->AttachedDevice
== MainDeviceObject
,
125 "Expected AttachDevice to be %p, got %p", MainDeviceObject
, DeviceObject
->AttachedDevice
);
129 ok(DeviceObject
->AttachedDevice
== NULL
, "Expected AttachDevice to be NULL, got %p", DeviceObject
->AttachedDevice
);
132 ok(DeviceObject
->Flags
==FILE_VIRTUAL_VOLUME
,
133 "Expected Flags FILE_VIRTUAL_VOLUME, got %lu", DeviceObject
->Flags
);
134 ok(DeviceObject
->DeviceType
== FILE_DEVICE_UNKNOWN
,
135 "Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu",
136 DeviceObject
->DeviceType
);
137 ok(DeviceObject
->ActiveThreadCount
== 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject
->ActiveThreadCount
);
139 /*Check the extended extension */
140 extdev
= (PEXTENDED_DEVOBJ_EXTENSION
)DeviceObject
->DeviceObjectExtension
;
141 ok(extdev
->ExtensionFlags
== DOE_UNLOAD_PENDING
,
142 "Expected Extended ExtensionFlags to be DOE_UNLOAD_PENDING, got %lu", extdev
->ExtensionFlags
);
143 ok (extdev
->Type
== 13, "Expected Type of 13, got %d", extdev
->Type
);
144 ok (extdev
->Size
== 0, "Expected Size of 0, got %d", extdev
->Size
);
145 ok (extdev
->DeviceObject
== DeviceObject
, "Expected DeviceOject to match newly created device %p, got %p",
146 DeviceObject
, extdev
->DeviceObject
);
149 /* Skip this for now */
150 //ok(extdev->AttachedTo == MainDeviceObject, "Expected AttachTo to %p, got %p", MainDeviceObject, extdev->AttachedTo);
154 ok(extdev
->AttachedTo
== NULL
, "Expected AttachTo to be NULL, got %p", extdev
->AttachedTo
);
156 ok(extdev
->StartIoCount
== 0, "Expected StartIoCount = 0, got %lu", extdev
->StartIoCount
);
157 ok(extdev
->StartIoKey
== 0, "Expected StartIoKey = 0, got %lu", extdev
->StartIoKey
);
158 ok(extdev
->StartIoFlags
== 0, "Expected StartIoFlags = 0, got %lu", extdev
->StartIoFlags
);
161 VOID
DeviceCreateDeleteTest(PDRIVER_OBJECT DriverObject
)
164 UNICODE_STRING DeviceString
;
165 UNICODE_STRING DosDeviceString
;
166 PDEVICE_OBJECT DeviceObject
;
168 /* Create using wrong directory */
169 RtlInitUnicodeString(&DeviceString
, L
"\\Device1\\Kmtest");
170 Status
= IoCreateDevice(DriverObject
,
177 ok(Status
== STATUS_OBJECT_PATH_NOT_FOUND
, "Expected STATUS_OBJECT_PATH_NOT_FOUND, got 0x%lX", Status
);
179 /* Create using correct params with exlusice access */
180 RtlInitUnicodeString(&DeviceString
, L
"\\Device\\Kmtest");
181 Status
= IoCreateDevice(DriverObject
,
188 ok(Status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got 0x%lX", Status
);
190 DeviceCreatedTest(DeviceObject
, TRUE
);
192 /* Delete the device */
193 if (NT_SUCCESS(Status
))
195 IoDeleteDevice(DeviceObject
);
196 ok(DriverObject
->DeviceObject
== 0, "Expected DriverObject->DeviceObject to be NULL, got %p",
197 DriverObject
->DeviceObject
);
200 /* Create using correct params with exlusice access */
201 Status
= IoCreateDevice(DriverObject
,
208 ok(Status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got 0x%lX", Status
);
210 DeviceCreatedTest(DeviceObject
, FALSE
);
212 /* Delete the device */
213 if (NT_SUCCESS(Status
))
215 IoDeleteDevice(DeviceObject
);
216 ok(DriverObject
->DeviceObject
== 0, "Expected DriverObject->DeviceObject to be NULL, got %p",
217 DriverObject
->DeviceObject
);
220 /* Recreate device */
221 Status
= IoCreateDevice(DriverObject
,
228 ok(Status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got 0x%lX", Status
);
230 RtlInitUnicodeString(&DosDeviceString
, L
"\\DosDevices\\kmtest");
231 Status
= IoCreateSymbolicLink(&DosDeviceString
, &DeviceString
);
233 if (!NT_SUCCESS(Status
))
235 /* Delete device object if not successful */
236 IoDeleteDevice(DeviceObject
);
240 MainDeviceObject
= DeviceObject
;
245 BOOLEAN
AttachDeviceTest(PDEVICE_OBJECT DeviceObject
, PWCHAR NewDriverRegPath
)
248 UNICODE_STRING LowerDeviceName
;
250 RtlInitUnicodeString(&LowerDeviceName
, NewDriverRegPath
);
251 Status
= IoAttachDevice(DeviceObject
, &LowerDeviceName
, &AttachDeviceObject
);
253 /* TODO: Add more tests */
258 BOOLEAN
DetachDeviceTest(PDEVICE_OBJECT AttachedDevice
)
261 IoDetachDevice(AttachedDevice
);
263 /* TODO: Add more tests */