ReactOS 0.4.16-dev-250-g3ecd236
Example_drv.c File Reference
#include <kmt_test.h>
#include <debug.h>
#include "Example.h"
Include dependency graph for Example_drv.c:

Go to the source code of this file.

Functions

TestEntry

Test entry point. This is called by DriverEntry as early as possible, but with ResultBuffer initialized, so that test macros work correctly

Parameters
DriverObjectDriver Object. This is guaranteed not to have been touched by DriverEntry before the call to TestEntry
RegistryPathDriver Registry Path This is guaranteed not to have been touched by DriverEntry before the call to TestEntry
DeviceNamePointer to receive a test-specific name for the device to create
FlagsPointer to a flags variable instructing DriverEntry how to proceed. See the KMT_TESTENTRY_FLAGS enumeration for possible values Initialized to zero on entry
Returns
Status. DriverEntry will fail if this is a failure status
NTSTATUS TestEntry (IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath, OUT PCWSTR *DeviceName, IN OUT INT *Flags)
 
TestUnload

Test unload routine. This is called by the driver's Unload routine as early as possible, with ResultBuffer and the test device object still valid, so that test macros work correctly

Parameters
DriverObjectDriver Object. This is guaranteed not to have been touched by Unload before the call to TestEntry
Returns
Status
VOID TestUnload (IN PDRIVER_OBJECT DriverObject)
 
TestMessageHandler

Test message handler routine

Parameters
DeviceObjectDevice Object. This is guaranteed not to have been touched by the dispatch function before the call to the IRP handler
IrpDevice Object. This is guaranteed not to have been touched by the dispatch function before the call to the IRP handler, except for passing it to IoGetCurrentStackLocation
IoStackLocationDevice Object. This is guaranteed not to have been touched by the dispatch function before the call to the IRP handler
Returns
Status
static NTSTATUS TestMessageHandler (IN PDEVICE_OBJECT DeviceObject, IN ULONG ControlCode, IN PVOID Buffer OPTIONAL, IN SIZE_T InLength, IN OUT PSIZE_T OutLength)
 
TestIrpHandler

Test IRP handler routine

Parameters
DeviceObjectDevice Object. This is guaranteed not to have been touched by the dispatch function before the call to the IRP handler
IrpDevice Object. This is guaranteed not to have been touched by the dispatch function before the call to the IRP handler, except for passing it to IoGetCurrentStackLocation
IoStackLocationDevice Object. This is guaranteed not to have been touched by the dispatch function before the call to the IRP handler
Returns
Status
static NTSTATUS TestIrpHandler (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 

Variables

static KMT_MESSAGE_HANDLER TestMessageHandler
 
static KMT_IRP_HANDLER TestIrpHandler
 
static PDRIVER_OBJECT TestDriverObject
 

Function Documentation

◆ TestEntry()

NTSTATUS TestEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PCUNICODE_STRING  RegistryPath,
OUT PCWSTR DeviceName,
IN OUT INT Flags 
)

Definition at line 48 of file Example_drv.c.

53{
55
56 PAGED_CODE();
57
60
61 DPRINT("Entry!\n");
62
63 ok_irql(PASSIVE_LEVEL);
65
66 *DeviceName = L"Example";
67
68 trace("Hi, this is the example driver\n");
69
73
74 return Status;
75}
#define PAGED_CODE()
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: Example_drv.c:16
static PDRIVER_OBJECT TestDriverObject
Definition: Example_drv.c:20
static KMT_IRP_HANDLER TestIrpHandler
Definition: Example_drv.c:17
#define trace
Definition: atltest.h:70
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:25
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define L(x)
Definition: ntvdm.h:50
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ TestIrpHandler()

static NTSTATUS TestIrpHandler ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)
static

Definition at line 220 of file Example_drv.c.

224{
226
227 DPRINT("IRP!\n");
228
229 ok_irql(PASSIVE_LEVEL);
231
232 if (IoStackLocation->MajorFunction == IRP_MJ_CREATE)
233 trace("Got IRP_MJ_CREATE!\n");
234 else if (IoStackLocation->MajorFunction == IRP_MJ_CLOSE)
235 trace("Got IRP_MJ_CLOSE!\n");
236 else
237 trace("Got an IRP!\n");
238
239 Irp->IoStatus.Status = Status;
240 Irp->IoStatus.Information = 0;
241
243
244 return Status;
245}
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ TestMessageHandler()

static NTSTATUS TestMessageHandler ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  ControlCode,
IN PVOID Buffer  OPTIONAL,
IN SIZE_T  InLength,
IN OUT PSIZE_T  OutLength 
)
static

Definition at line 129 of file Example_drv.c.

135{
137
138 switch (ControlCode)
139 {
140 case IOCTL_NOTIFY:
141 {
142 static int TimesReceived = 0;
143
144 ++TimesReceived;
145 ok(TimesReceived == 1, "Received control code 1 %d times\n", TimesReceived);
147 ok_eq_ulong((ULONG)InLength, 0LU);
148 ok_eq_ulong((ULONG)*OutLength, 0LU);
149 break;
150 }
152 {
153 static int TimesReceived = 0;
154 ANSI_STRING ExpectedString = RTL_CONSTANT_STRING("yay");
155 ANSI_STRING ReceivedString;
156
157 ++TimesReceived;
158 ok(TimesReceived == 1, "Received control code 2 %d times\n", TimesReceived);
159 ok(Buffer != NULL, "Buffer is NULL\n");
160 ok_eq_ulong((ULONG)InLength, (ULONG)ExpectedString.Length);
161 ok_eq_ulong((ULONG)*OutLength, 0LU);
162 ReceivedString.MaximumLength = ReceivedString.Length = (USHORT)InLength;
163 ReceivedString.Buffer = Buffer;
164 ok(RtlCompareString(&ExpectedString, &ReceivedString, FALSE) == 0, "Received string: %Z\n", &ReceivedString);
165 break;
166 }
168 {
169 static int TimesReceived = 0;
170 MY_STRUCT ExpectedStruct = { 123, ":D" };
171 MY_STRUCT ResultStruct = { 456, "!!!" };
172
173 ++TimesReceived;
174 ok(TimesReceived == 1, "Received control code 3 %d times\n", TimesReceived);
175 ok(Buffer != NULL, "Buffer is NULL\n");
176 ok_eq_ulong((ULONG)InLength, (ULONG)sizeof ExpectedStruct);
177 ok_eq_ulong((ULONG)*OutLength, 2LU * sizeof ExpectedStruct);
178 if (!skip(Buffer && InLength >= sizeof ExpectedStruct, "Cannot read from buffer!\n"))
179 ok(RtlCompareMemory(&ExpectedStruct, Buffer, sizeof ExpectedStruct) == sizeof ExpectedStruct, "Buffer does not contain expected values\n");
180
181 if (!skip(Buffer && *OutLength >= 2 * sizeof ExpectedStruct, "Cannot write to buffer!\n"))
182 {
183 RtlCopyMemory((PCHAR)Buffer + sizeof ExpectedStruct, &ResultStruct, sizeof ResultStruct);
184 *OutLength = 2 * sizeof ExpectedStruct;
185 }
186 break;
187 }
188 default:
189 ok(0, "Got an unknown message! DeviceObject=%p, ControlCode=%lu, Buffer=%p, In=%lu, Out=%lu bytes\n",
190 DeviceObject, ControlCode, Buffer, InLength, *OutLength);
191 break;
192 }
193
194 return Status;
195}
#define IOCTL_NOTIFY
Definition: Example.h:17
#define IOCTL_SEND_MYSTRUCT
Definition: Example.h:19
#define IOCTL_SEND_STRING
Definition: Example.h:18
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define U(x)
Definition: wordpad.c:45
Definition: bufpool.h:45
#define FALSE
Definition: types.h:117
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
NTSYSAPI LONG NTAPI RtlCompareString(PSTRING String1, PSTRING String2, BOOLEAN CaseInSensitive)
unsigned short USHORT
Definition: pedump.c:61
USHORT MaximumLength
Definition: env_spec_w32.h:377
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

◆ TestUnload()

VOID TestUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 93 of file Example_drv.c.

95{
96 PAGED_CODE();
97
98 DPRINT("Unload!\n");
99
100 ok_irql(PASSIVE_LEVEL);
102
103 trace("Unloading example driver\n");
104}

Referenced by DriverUnload().

Variable Documentation

◆ TestDriverObject

PDRIVER_OBJECT TestDriverObject
static

Definition at line 20 of file Example_drv.c.

Referenced by TestDispatch(), TestEntry(), TestIrpHandler(), and TestUnload().

◆ TestIrpHandler

KMT_IRP_HANDLER TestIrpHandler
static

Definition at line 17 of file Example_drv.c.

Referenced by TestEntry().

◆ TestMessageHandler

KMT_MESSAGE_HANDLER TestMessageHandler
static

Definition at line 16 of file Example_drv.c.

Referenced by TestEntry().