[FLTMGR] Latest from my branch (#135)
[reactos.git] / modules / rostests / kmtests / fltmgr / fltmgr_register / fltmgr_register.c
1 /*
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>
6 */
7
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.
11
12 #include <kmt_test.h>
13 #include <fltkernel.h>
14 #include <fltmgrint.h>
15
16 //#define NDEBUG
17 #include <debug.h>
18
19 #define RESET_REGISTRATION(basic) \
20 do { \
21 RtlZeroMemory(&FilterRegistration, sizeof(FLT_REGISTRATION)); \
22 if (basic) { \
23 FilterRegistration.Size = sizeof(FLT_REGISTRATION); \
24 FilterRegistration.Version = FLT_REGISTRATION_VERSION; \
25 } \
26 } while (0)
27
28 #define RESET_UNLOAD(DO) DO->DriverUnload = NULL;
29
30
31 NTSTATUS
32 FLTAPI
33 TestRegFilterUnload(
34 _In_ FLT_FILTER_UNLOAD_FLAGS Flags
35 );
36
37 /* Globals */
38 static PDRIVER_OBJECT TestDriverObject;
39 static FLT_REGISTRATION FilterRegistration;
40 static PFLT_FILTER TestFilter = NULL;
41
42
43
44
45 BOOLEAN
46 TestFltRegisterFilter(_In_ PDRIVER_OBJECT DriverObject)
47 {
48 UNICODE_STRING Altitude;
49 UNICODE_STRING Name;
50 PFLT_FILTER Filter = NULL;
51 PFLT_FILTER Temp = NULL;
52 NTSTATUS Status;
53
54 RESET_REGISTRATION(FALSE);
55 #if 0
56 KmtStartSeh()
57 Status = FltRegisterFilter(NULL, &FilterRegistration, &Filter);
58 KmtEndSeh(STATUS_INVALID_PARAMETER);
59
60 KmtStartSeh()
61 Status = FltRegisterFilter(DriverObject, NULL, &Filter);
62 KmtEndSeh(STATUS_INVALID_PARAMETER);
63
64 KmtStartSeh()
65 Status = FltRegisterFilter(DriverObject, &FilterRegistration, NULL);
66 KmtEndSeh(STATUS_INVALID_PARAMETER)
67 #endif
68
69 RESET_REGISTRATION(TRUE);
70 FilterRegistration.Version = 0x0100;
71 Status = FltRegisterFilter(DriverObject, &FilterRegistration, &Filter);
72 ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
73
74 RESET_REGISTRATION(TRUE);
75 FilterRegistration.Version = 0x0300;
76 Status = FltRegisterFilter(DriverObject, &FilterRegistration, &Filter);
77 ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
78
79 RESET_REGISTRATION(TRUE);
80 FilterRegistration.Version = 0x0200;
81 Status = FltRegisterFilter(DriverObject, &FilterRegistration, &Filter);
82 ok_eq_hex(Status, STATUS_SUCCESS);
83 FltUnregisterFilter(Filter);
84
85
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);
92
93 RESET_REGISTRATION(TRUE);
94 FilterRegistration.Size = 0xFFFF;
95 Status = FltRegisterFilter(DriverObject, &FilterRegistration, &Filter);
96 ok_eq_hex(Status, STATUS_SUCCESS);
97 FltUnregisterFilter(Filter);
98
99
100 /* Now make a valid registration */
101 RESET_REGISTRATION(TRUE);
102 Status = FltRegisterFilter(DriverObject, &FilterRegistration, &Filter);
103 ok_eq_hex(Status, STATUS_SUCCESS);
104
105 /* Try to register again */
106 Status = FltRegisterFilter(DriverObject, &FilterRegistration, &Temp);
107 ok_eq_hex(Status, STATUS_FLT_INSTANCE_ALTITUDE_COLLISION);
108
109
110 ok_eq_hex(Filter->Base.Flags, FLT_OBFL_TYPE_FILTER);
111
112 /* Check we have the right filter name */
113 RtlInitUnicodeString(&Name, L"Kmtest-FltMgrReg");
114 ok_eq_long(RtlCompareUnicodeString(&Filter->Name, &Name, FALSE), 0);
115
116 /* And the altitude is corect */
117 RtlInitUnicodeString(&Altitude, L"123456");
118 ok_eq_long(RtlCompareUnicodeString(&Filter->DefaultAltitude, &Altitude, FALSE), 0);
119
120 //
121 // FIXME: More checks
122 //
123
124 /* Cleanup the valid registration */
125 FltUnregisterFilter(Filter);
126
127 /*
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
130 */
131 RESET_REGISTRATION(TRUE);
132
133 /* Set a fake unload routine we'll use to test */
134 DriverObject->DriverUnload = (PDRIVER_UNLOAD)0x1234FFFF;
135
136 FilterRegistration.FilterUnloadCallback = TestRegFilterUnload;
137 Status = FltRegisterFilter(DriverObject, &FilterRegistration, &TestFilter);
138 ok_eq_hex(Status, STATUS_SUCCESS);
139
140 /* Test all the unlod routines */
141 ok_eq_pointer(TestFilter->FilterUnload, TestRegFilterUnload);
142 ok_eq_pointer(TestFilter->OldDriverUnload, (PFLT_FILTER_UNLOAD_CALLBACK)0x1234FFFF);
143
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);
146
147 /* Make sure our test address is never actually called */
148 TestFilter->OldDriverUnload = (PFLT_FILTER_UNLOAD_CALLBACK)NULL;
149
150 return TRUE;
151 }
152
153
154 NTSTATUS
155 FLTAPI
156 TestRegFilterUnload(
157 _In_ FLT_FILTER_UNLOAD_FLAGS Flags)
158 {
159 //__debugbreak();
160
161 ok_irql(PASSIVE_LEVEL);
162 ok(TestFilter != NULL, "Buffer is NULL\n");
163
164 //
165 // FIXME: Add tests
166 //
167
168 FltUnregisterFilter(TestFilter);
169
170 //
171 // FIXME: Add tests
172 //
173
174 return STATUS_SUCCESS;
175 }
176
177
178
179
180
181
182
183
184
185
186 /*
187 * KMT Callback routines
188 */
189
190 NTSTATUS
191 TestEntry(
192 IN PDRIVER_OBJECT DriverObject,
193 IN PCUNICODE_STRING RegistryPath,
194 OUT PCWSTR *DeviceName,
195 IN OUT INT *Flags)
196 {
197 NTSTATUS Status = STATUS_SUCCESS;
198
199 PAGED_CODE();
200
201 UNREFERENCED_PARAMETER(RegistryPath);
202
203 DPRINT("FltMgrReg Entry!\n");
204 trace("Entered FltMgrReg tests\n");
205
206 /* We'll do the work ourselves in this test */
207 *Flags = TESTENTRY_NO_ALL;
208
209 ok_irql(PASSIVE_LEVEL);
210 TestDriverObject = DriverObject;
211
212
213 /* Run the tests */
214 (VOID)TestFltRegisterFilter(DriverObject);
215
216 return Status;
217 }
218
219 VOID
220 TestFilterUnload(
221 IN ULONG Flags)
222 {
223 PAGED_CODE();
224 ok_irql(PASSIVE_LEVEL);
225 }
226
227 NTSTATUS
228 TestInstanceSetup(
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
236 )
237 {
238 return STATUS_FLT_DO_NOT_ATTACH;
239 }
240
241 VOID
242 TestQueryTeardown(
243 _In_ PCFLT_RELATED_OBJECTS FltObjects,
244 _In_ FLT_INSTANCE_QUERY_TEARDOWN_FLAGS Flags)
245 {
246 UNREFERENCED_PARAMETER(FltObjects);
247 UNREFERENCED_PARAMETER(Flags);
248 }