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>
28 VOID
DriverObjectTest(PDRIVER_OBJECT DriverObject
, int DriverStatus
)
30 BOOLEAN CheckThisDispatchRoutine
;
34 ok(DriverObject
->Size
== sizeof(DRIVER_OBJECT
), "Size does not match, got %x",DriverObject
->Size
);
35 ok(DriverObject
->Type
== 4, "Type does not match 4. got %d",DriverObject
->Type
);
37 if (DriverStatus
== 0)
39 ok(DriverObject
->DeviceObject
== NULL
, "Expected DeviceObject pointer to be 0, got %p",
40 DriverObject
->DeviceObject
);
41 ok (DriverObject
->Flags
== DRVO_LEGACY_DRIVER
,
42 "Expected Flags to be DRVO_LEGACY_DRIVER, got %lu",
45 else if (DriverStatus
== 1)
47 ok(DriverObject
->DeviceObject
!= NULL
, "Expected DeviceObject pointer to non null");
48 ok (DriverObject
->Flags
== (DRVO_LEGACY_DRIVER
| DRVO_INITIALIZED
),
49 "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED, got %lu",
54 ok(DriverObject
->DeviceObject
!= NULL
, "Expected DeviceObject pointer to non null");
55 ok (DriverObject
->Flags
== (DRVO_LEGACY_DRIVER
| DRVO_INITIALIZED
| DRVO_UNLOAD_INVOKED
),
56 "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED | DRVO_UNLOAD_INVOKED, got %lu",
60 /* Select a routine that was not changed */
61 FirstMajorFunc
= DriverObject
->MajorFunction
[1];
62 ok(FirstMajorFunc
!= 0, "Expected MajorFunction[1] to be non NULL");
66 for (i
= 0; i
<= IRP_MJ_MAXIMUM_FUNCTION
; i
++)
68 if (DriverStatus
> 0) CheckThisDispatchRoutine
= (i
> 3) && (i
!= 14);
69 else CheckThisDispatchRoutine
= TRUE
;
71 if (CheckThisDispatchRoutine
)
73 ok(DriverObject
->MajorFunction
[i
] == FirstMajorFunc
, "Expected MajorFunction[%d] to match %p",
80 ok(TRUE
, "Skipped testing for all MajorFunction");
84 BOOLEAN
ZwLoadTest(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING DriverRegistryPath
, PWCHAR NewDriverRegPath
)
86 UNICODE_STRING RegPath
;
89 /* Try to load ourself */
90 Status
= ZwLoadDriver(DriverRegistryPath
);
91 ok (Status
== STATUS_IMAGE_ALREADY_LOADED
, "Expected NTSTATUS STATUS_IMAGE_ALREADY_LOADED, got 0x%lX", Status
);
93 if (Status
!= STATUS_IMAGE_ALREADY_LOADED
)
95 DbgPrint("WARNING: Loading this a second time will cause BUGCHECK!\n");
98 /* Try to load with a Registry Path that doesnt exist */
99 RtlInitUnicodeString(&RegPath
, L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef");
100 Status
= ZwLoadDriver(&RegPath
);
101 ok (Status
== STATUS_OBJECT_NAME_NOT_FOUND
, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX", Status
);
103 /* Load the driver */
104 RtlInitUnicodeString(&RegPath
, NewDriverRegPath
);
105 Status
= ZwLoadDriver(&RegPath
);
106 ok(Status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got 0x%lX", Status
);
108 if (!NT_SUCCESS(Status
))
116 BOOLEAN
ZwUnloadTest(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING DriverRegistryPath
, PWCHAR NewDriverRegPath
)
118 UNICODE_STRING RegPath
;
121 /* Try to unload ourself, which should fail as our Unload routine hasnt been set yet. */
122 Status
= ZwUnloadDriver(DriverRegistryPath
);
123 ok (Status
== STATUS_INVALID_DEVICE_REQUEST
, "Expected NTSTATUS STATUS_INVALID_DEVICE_REQUEST, got 0x%lX", Status
);
125 /* Try to unload with a Registry Path that doesnt exist */
126 RtlInitUnicodeString(&RegPath
, L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef");
127 Status
= ZwUnloadDriver(&RegPath
);
128 ok (Status
== STATUS_OBJECT_NAME_NOT_FOUND
, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX", Status
);
130 /* Unload the driver */
131 RtlInitUnicodeString(&RegPath
, NewDriverRegPath
);
132 Status
= ZwUnloadDriver(&RegPath
);
133 ok(Status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got 0x%lX", Status
);
135 if (!NT_SUCCESS(Status
))