ReactOS 0.4.15-dev-6054-gbddd8b0
IoDeviceInterface.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Device Interface functions test
5 * PROGRAMMER: Filip Navara <xnavara@volny.cz>
6 */
7
8/* TODO: what's with the prototypes at the top, what's with the if-ed out part? Doesn't process most results */
9
10#include <kmt_test.h>
11#include <poclass.h>
12
13#define NDEBUG
14#include <debug.h>
15
16#if 0
18(NTAPI *IoGetDeviceInterfaces_Func)(
23
25ReactOS_IoGetDeviceInterfaces(
30#endif /* 0 */
31
33{
36 PWSTR SymbolicLinkListPtr;
37 GUID Guid = {0x378de44c, 0x56ef, 0x11d1, {0xbc, 0x8c, 0x00, 0xa0, 0xc9, 0x14, 0x05, 0xdd}};
38
40 &Guid,
41 NULL,
42 0,
44
46 "IoGetDeviceInterfaces failed with status 0x%X\n",
47 (unsigned int)Status);
48 if (!NT_SUCCESS(Status))
49 {
50 return;
51 }
52
53 DPRINT("IoGetDeviceInterfaces results:\n");
54 for (SymbolicLinkListPtr = SymbolicLinkList;
55 SymbolicLinkListPtr[0] != 0 && SymbolicLinkListPtr[1] != 0;
56 SymbolicLinkListPtr += wcslen(SymbolicLinkListPtr) + 1)
57 {
58 DPRINT1("Symbolic Link: %S\n", SymbolicLinkListPtr);
59 }
60
61#if 0
62 DPRINT("[PnP Test] Trying to get aliases\n");
63
64 for (SymbolicLinkListPtr = SymbolicLinkList;
65 SymbolicLinkListPtr[0] != 0 && SymbolicLinkListPtr[1] != 0;
66 SymbolicLinkListPtr += wcslen(SymbolicLinkListPtr) + 1)
67 {
69 UNICODE_STRING AliasSymbolicLink;
70
71 SymbolicLink.Buffer = SymbolicLinkListPtr;
72 SymbolicLink.Length = SymbolicLink.MaximumLength = wcslen(SymbolicLinkListPtr);
73 RtlInitUnicodeString(&AliasSymbolicLink, NULL);
76 &AliasGuid,
77 &AliasSymbolicLink);
78 if (AliasSymbolicLink.Buffer != NULL)
79 {
80 DPRINT("[PnP Test] Original: %S\n", SymbolicLinkListPtr);
81 DPRINT("[PnP Test] Alias: %S\n", AliasSymbolicLink.Buffer);
82 }
83 }
84#endif
85
87}
88
89static
90VOID
92{
93 GUID Guid = {0x378de44c, 0x56ef, 0x11d1, {0xbc, 0x8c, 0x00, 0xa0, 0xc9, 0x14, 0x05, 0xdd}};
95 EXTENDED_DEVOBJ_EXTENSION DeviceObjectExtension;
99
101
102 // Prepare our surrogate of a Device Object
103 DeviceObject.DeviceObjectExtension = (PDEVOBJ_EXTENSION)&DeviceObjectExtension;
104
105 // 1. DeviceNode = NULL
106 DeviceObjectExtension.DeviceNode = NULL;
109
111 "IoRegisterDeviceInterface returned 0x%08lX\n", Status);
112
113 // 2. DeviceNode->InstancePath is of a null length
114 DeviceObjectExtension.DeviceNode = &DeviceNode;
115 DeviceNode.InstancePath.Length = 0;
118
120 "IoRegisterDeviceInterface returned 0x%08lX\n", Status);
121
123}
124
126
127static DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback;
128static
130NTAPI
134{
139
140 ok_irql(PASSIVE_LEVEL);
142 ok_eq_uint(Notification->Version, 1);
143 ok_eq_uint(Notification->Size, sizeof(*Notification));
144
145 /* symbolic link must exist */
146 trace("Interface change: %wZ\n", Notification->SymbolicLinkName);
148 Notification->SymbolicLinkName,
150 NULL,
151 NULL);
154 if (!skip(NT_SUCCESS(Status), "No symbolic link\n"))
155 {
158 }
159 return STATUS_SUCCESS;
160}
161
162static
163VOID
165{
168
171 (PVOID)&GUID_DEVICE_SYS_BUTTON,
172 KmtDriverObject,
177 if (!skip(NT_SUCCESS(Status), "PlugPlayNotification not registered\n"))
178 {
181 }
182}
183
184static
185VOID
187{
192
193 /* Invalid prefix or GUID */
198
199 RtlInitEmptyUnicodeString(&SymbolicLinkName, NULL, 0);
204
210
216
222
223 RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
228
229 /* Valid prefix & GUID, invalid device node */
230 RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
235
236 RtlInitUnicodeString(&SymbolicLinkName, L"\\\\?\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
241
242 RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\X{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}\\");
247
248 RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
253
254 /* Must not read past the buffer */
255 RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
258 if (!skip(Buffer != NULL, "Failed to allocate %lu bytes\n", BufferSize))
259 {
261 SymbolicLinkName.Buffer = Buffer;
262 SymbolicLinkName.MaximumLength = BufferSize;
268 }
269
270 RtlInitUnicodeString(&SymbolicLinkName, L"\\??\\#aaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}");
273 if (!skip(Buffer != NULL, "Failed to allocate %lu bytes\n", BufferSize))
274 {
276 SymbolicLinkName.Buffer = Buffer;
277 SymbolicLinkName.MaximumLength = BufferSize;
283 }
284}
285
286START_TEST(IoDeviceInterface)
287{
288 // FIXME: This test crashes in Windows
292}
static VOID DeviceInterfaceTest_Func()
static DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback
static VOID Test_IoRegisterPlugPlayNotification(VOID)
static VOID Test_IoRegisterDeviceInterface(VOID)
static VOID Test_IoSetDeviceInterface(VOID)
static UCHAR NotificationContext
@ DeviceNode
Definition: Node.h:9
#define ok_eq_hex(value, expected)
Definition: NtContinue.c:18
#define ok_eq_pointer(value, expected)
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define BufferSize
Definition: mmc.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NTSTATUS
Definition: precomp.h:20
#define GENERIC_READ
Definition: compat.h:135
static const WCHAR SymbolicLink[]
Definition: interface.c:31
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define KmtStartSeh()
Definition: kmt_test.h:279
VOID KmtFreeGuarded(PVOID Pointer)
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:241
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:285
BOOLEAN BOOLEAN VOID VOID BOOLEAN BOOLEAN PVOID KmtAllocateGuarded(SIZE_T SizeRequested)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define _Inout_opt_
Definition: ms_sal.h:379
#define _In_
Definition: ms_sal.h:308
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
NTSTATUS NTAPI IoGetDeviceInterfaceAlias(IN PUNICODE_STRING SymbolicLinkName, IN CONST GUID *AliasInterfaceClassGuid, OUT PUNICODE_STRING AliasSymbolicLinkName)
Definition: deviface.c:303
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
#define CONST
Definition: pedump.c:81
NTSTATUS NTAPI IoRegisterPlugPlayNotification(_In_ IO_NOTIFICATION_EVENT_CATEGORY EventCategory, _In_ ULONG EventCategoryFlags, _In_opt_ PVOID EventCategoryData, _In_ PDRIVER_OBJECT DriverObject, _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, _Inout_opt_ PVOID Context, _Out_ PVOID *NotificationEntry)
Definition: pnpnotify.c:345
NTSTATUS NTAPI IoUnregisterPlugPlayNotification(_In_ PVOID NotificationEntry)
Definition: pnpnotify.c:479
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
struct _DEVICE_NODE * DeviceNode
Definition: iotypes.h:935
uint16_t * PWSTR
Definition: typedefs.h:56
#define OPTIONAL
Definition: typedefs.h:41
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_DEVICE_SHUTDOWN_NOTIFICATION Notification
Definition: wdfcontrol.h:115
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING SymbolicLinkName
Definition: wdfdevice.h:3739
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList
_In_ CONST GUID * InterfaceClassGuid
Definition: iofuncs.h:1136
_In_ ULONG _In_opt_ PVOID _In_ PDRIVER_OBJECT _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE _Inout_opt_ __drv_aliasesMem PVOID _Outptr_result_nullonfailure_ _At_ * NotificationEntry(return==0, __drv_allocatesMem(Mem))) PVOID *NotificationEntry
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
struct _DEVOBJ_EXTENSION * PDEVOBJ_EXTENSION
@ EventCategoryDeviceInterfaceChange
Definition: iotypes.h:1226
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1239
unsigned char UCHAR
Definition: xmlstorage.h:181