ReactOS  0.4.14-dev-614-gbfd8a84
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 IRP_MJ_CREATE
Definition: rdpdr.c:44
static KMT_IRP_HANDLER TestIrpHandler
Definition: Example_drv.c:17
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: Example_drv.c:16
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define PAGED_CODE()
Definition: video.h:57
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
static PDRIVER_OBJECT TestDriverObject
Definition: Example_drv.c:20
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
#define trace
Definition: atltest.h:70
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ 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 IRP_MJ_CREATE
Definition: rdpdr.c:44
_In_ PIRP Irp
Definition: csq.h:116
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
static PDRIVER_OBJECT TestDriverObject
Definition: Example_drv.c:20
#define trace
Definition: atltest.h:70
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ 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  }
151  case IOCTL_SEND_STRING:
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  }
167  case IOCTL_SEND_MYSTRUCT:
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 }
signed char * PCHAR
Definition: retypes.h:7
#define ok_eq_ulong(value, expected)
#define IOCTL_SEND_STRING
Definition: Example.h:18
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
NTSYSAPI LONG NTAPI RtlCompareString(PSTRING String1, PSTRING String2, BOOLEAN CaseInSensitive)
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_SEND_MYSTRUCT
Definition: Example.h:19
#define IOCTL_NOTIFY
Definition: Example.h:17
smooth NULL
Definition: ftsmooth.c:416
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
Definition: bufpool.h:45
USHORT MaximumLength
Definition: env_spec_w32.h:377
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
unsigned short USHORT
Definition: pedump.c:61
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ 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 }
#define ok_eq_pointer(value, expected)
#define PAGED_CODE()
Definition: video.h:57
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
static PDRIVER_OBJECT TestDriverObject
Definition: Example_drv.c:20
#define trace
Definition: atltest.h:70
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693

Referenced by DriverUnload().

Variable Documentation

◆ TestDriverObject

PDRIVER_OBJECT TestDriverObject
static

Definition at line 20 of file Example_drv.c.

Referenced by 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().