2 * PROJECT: ReactOS kernel-mode tests - Filter Manager
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Tests for checking filter registration
5 * PROGRAMMER: Ged Murphy <gedmurphy@reactos.org>
8 // This tests needs to be run via a standalone driver because FltRegisterFilter
9 // uses the DriverObject in its internal structures, and we don't want it to be
10 // linked to a device object from the test suite itself.
13 #include <fltkernel.h>
14 #include <fltmgrint.h>
19 #define RESET_REGISTRATION(basic) \
21 RtlZeroMemory(&FilterRegistration, sizeof(FLT_REGISTRATION)); \
23 FilterRegistration.Size = sizeof(FLT_REGISTRATION); \
24 FilterRegistration.Version = FLT_REGISTRATION_VERSION; \
28 #define RESET_UNLOAD(DO) DO->DriverUnload = NULL;
34 _In_ FLT_FILTER_UNLOAD_FLAGS Flags
38 static PDRIVER_OBJECT TestDriverObject
;
39 static FLT_REGISTRATION FilterRegistration
;
40 static PFLT_FILTER TestFilter
= NULL
;
46 TestFltRegisterFilter(_In_ PDRIVER_OBJECT DriverObject
)
48 UNICODE_STRING Altitude
;
50 PFLT_FILTER Filter
= NULL
;
51 PFLT_FILTER Temp
= NULL
;
54 RESET_REGISTRATION(FALSE
);
57 Status
= FltRegisterFilter(NULL
, &FilterRegistration
, &Filter
);
58 KmtEndSeh(STATUS_INVALID_PARAMETER
);
61 Status
= FltRegisterFilter(DriverObject
, NULL
, &Filter
);
62 KmtEndSeh(STATUS_INVALID_PARAMETER
);
65 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, NULL
);
66 KmtEndSeh(STATUS_INVALID_PARAMETER
)
69 RESET_REGISTRATION(TRUE
);
70 FilterRegistration
.Version
= 0x0100;
71 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, &Filter
);
72 ok_eq_hex(Status
, STATUS_INVALID_PARAMETER
);
74 RESET_REGISTRATION(TRUE
);
75 FilterRegistration
.Version
= 0x0300;
76 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, &Filter
);
77 ok_eq_hex(Status
, STATUS_INVALID_PARAMETER
);
79 RESET_REGISTRATION(TRUE
);
80 FilterRegistration
.Version
= 0x0200;
81 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, &Filter
);
82 ok_eq_hex(Status
, STATUS_SUCCESS
);
83 FltUnregisterFilter(Filter
);
86 /* Test invalid sizes. MSDN says this is required, but it doesn't appear to be */
87 RESET_REGISTRATION(TRUE
);
88 FilterRegistration
.Size
= 0;
89 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, &Filter
);
90 ok_eq_hex(Status
, STATUS_SUCCESS
);
91 FltUnregisterFilter(Filter
);
93 RESET_REGISTRATION(TRUE
);
94 FilterRegistration
.Size
= 0xFFFF;
95 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, &Filter
);
96 ok_eq_hex(Status
, STATUS_SUCCESS
);
97 FltUnregisterFilter(Filter
);
100 /* Now make a valid registration */
101 RESET_REGISTRATION(TRUE
);
102 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, &Filter
);
103 ok_eq_hex(Status
, STATUS_SUCCESS
);
105 /* Try to register again */
106 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, &Temp
);
107 ok_eq_hex(Status
, STATUS_FLT_INSTANCE_ALTITUDE_COLLISION
);
110 ok_eq_hex(Filter
->Base
.Flags
, FLT_OBFL_TYPE_FILTER
);
112 /* Check we have the right filter name */
113 RtlInitUnicodeString(&Name
, L
"Kmtest-FltMgrReg");
114 ok_eq_long(RtlCompareUnicodeString(&Filter
->Name
, &Name
, FALSE
), 0);
116 /* And the altitude is corect */
117 RtlInitUnicodeString(&Altitude
, L
"123456");
118 ok_eq_long(RtlCompareUnicodeString(&Filter
->DefaultAltitude
, &Altitude
, FALSE
), 0);
121 // FIXME: More checks
124 /* Cleanup the valid registration */
125 FltUnregisterFilter(Filter
);
128 * The last thing we'll do before we exit is to properly register with the filter manager
129 * and set an unload routine. This'll let us test the FltUnregisterFilter routine
131 RESET_REGISTRATION(TRUE
);
133 /* Set a fake unload routine we'll use to test */
134 DriverObject
->DriverUnload
= (PDRIVER_UNLOAD
)0x1234FFFF;
136 FilterRegistration
.FilterUnloadCallback
= TestRegFilterUnload
;
137 Status
= FltRegisterFilter(DriverObject
, &FilterRegistration
, &TestFilter
);
138 ok_eq_hex(Status
, STATUS_SUCCESS
);
140 /* Test all the unlod routines */
141 ok_eq_pointer(TestFilter
->FilterUnload
, TestRegFilterUnload
);
142 ok_eq_pointer(TestFilter
->OldDriverUnload
, (PFLT_FILTER_UNLOAD_CALLBACK
)0x1234FFFF);
144 // This should equal the fltmgr's private unload routine, but there's no easy way of testing it...
145 //ok_eq_pointer(DriverObject->DriverUnload, FltpMiniFilterDriverUnload);
147 /* Make sure our test address is never actually called */
148 TestFilter
->OldDriverUnload
= (PFLT_FILTER_UNLOAD_CALLBACK
)NULL
;
157 _In_ FLT_FILTER_UNLOAD_FLAGS Flags
)
161 ok_irql(PASSIVE_LEVEL
);
162 ok(TestFilter
!= NULL
, "Buffer is NULL\n");
168 FltUnregisterFilter(TestFilter
);
174 return STATUS_SUCCESS
;
187 * KMT Callback routines
192 IN PDRIVER_OBJECT DriverObject
,
193 IN PCUNICODE_STRING RegistryPath
,
194 OUT PCWSTR
*DeviceName
,
197 NTSTATUS Status
= STATUS_SUCCESS
;
201 UNREFERENCED_PARAMETER(RegistryPath
);
203 DPRINT("FltMgrReg Entry!\n");
204 trace("Entered FltMgrReg tests\n");
206 /* We'll do the work ourselves in this test */
207 *Flags
= TESTENTRY_NO_ALL
;
209 ok_irql(PASSIVE_LEVEL
);
210 TestDriverObject
= DriverObject
;
214 (VOID
)TestFltRegisterFilter(DriverObject
);
224 ok_irql(PASSIVE_LEVEL
);
229 _In_ PCFLT_RELATED_OBJECTS FltObjects
,
230 _In_ FLT_INSTANCE_SETUP_FLAGS Flags
,
231 _In_ DEVICE_TYPE VolumeDeviceType
,
232 _In_ FLT_FILESYSTEM_TYPE VolumeFilesystemType
,
233 _In_ PUNICODE_STRING VolumeName
,
234 _In_ ULONG SectorSize
,
235 _In_ ULONG ReportedSectorSize
238 return STATUS_FLT_DO_NOT_ATTACH
;
243 _In_ PCFLT_RELATED_OBJECTS FltObjects
,
244 _In_ FLT_INSTANCE_QUERY_TEARDOWN_FLAGS Flags
)
246 UNREFERENCED_PARAMETER(FltObjects
);
247 UNREFERENCED_PARAMETER(Flags
);