ReactOS  0.4.15-dev-1070-ge1a01de
PoIrp_drv.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite Power IRP management test
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 #include "PoIrp.h"
10 
12 static KMT_MESSAGE_HANDLER TestMessageHandler;
13 
17 
18 static
22 {
24  PDEVICE_OBJECT AttachedDevice;
25 
27  if (!NT_SUCCESS(Status))
28  return Status;
29 
31 
33  if (!NT_SUCCESS(Status))
34  {
36  return Status;
37  }
38 
40  ok(AttachedDevice == DeviceObject1, "Device attached to %p is %p, expected %p\n", DeviceObject2, AttachedDevice, DeviceObject1);
41  if (AttachedDevice == NULL)
42  {
45  return STATUS_UNSUCCESSFUL;
46  }
47 
49 
51  if (!NT_SUCCESS(Status))
52  {
56  return Status;
57  }
58 
60  ok(AttachedDevice == DeviceObject2, "Device attached to %p is %p, expected %p\n", DeviceObject2, AttachedDevice, DeviceObject2);
61  if (AttachedDevice == NULL)
62  {
67  return STATUS_UNSUCCESSFUL;
68  }
69 
71 
72  return Status;
73 }
74 
80  _Inout_ INT *Flags)
81 {
83 
84  PAGED_CODE();
85 
87 
89 
90  *DeviceName = L"PoIrp";
91  *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE;
92 
94 
95  return Status;
96 }
97 
98 VOID
101 {
103 
104  PAGED_CODE();
105 }
106 
107 //
108 // PoRequestPowerIrp test
109 //
113 
114 static
115 VOID
116 NTAPI
123 {
124  PIRP Irp;
125  PIO_STACK_LOCATION IoStackLocation;
126 
133  ok_eq_ulongptr(IoStatus->Information, 7);
134  ok_eq_hex(IoStatus->Status, STATUS_WAIT_3);
136 
137  ok_eq_uint(Irp->StackCount, 5);
138  ok_eq_uint(Irp->CurrentLocation, 4);
139  ok_eq_pointer(Irp->Tail.Overlay.Thread, NULL);
140  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
141  ok_eq_uint(IoStackLocation->MajorFunction, 0);
142  ok_eq_uint(IoStackLocation->MinorFunction, 0);
143  ok_eq_pointer(IoStackLocation->CompletionRoutine, NULL);
144  ok_eq_pointer(IoStackLocation->Context, NULL);
145  ok_eq_pointer(IoStackLocation->Parameters.Others.Argument1, DeviceObject);
146  ok_eq_pointer(IoStackLocation->Parameters.Others.Argument2, (PVOID)(ULONG_PTR)MinorFunction);
147  ok_eq_pointer(IoStackLocation->Parameters.Others.Argument3, (PVOID)(ULONG_PTR)PowerState.SystemState);
148  ok_eq_pointer(IoStackLocation->Parameters.Others.Argument4, Context);
149 }
150 
151 static
152 NTSTATUS
155  _In_ PIRP Irp,
156  _In_ PIO_STACK_LOCATION IoStackLocation)
157 {
158  if (RequestedPowerIrp == NULL)
160  else
162 
163  ok_eq_uint(Irp->StackCount, 5);
164  ok_eq_ulongptr(Irp->IoStatus.Information, 0);
165  ok_eq_hex(Irp->IoStatus.Status, STATUS_NOT_SUPPORTED);
166  ok_eq_pointer(Irp->Tail.Overlay.Thread, NULL);
167  ok_eq_uint(IoStackLocation->MajorFunction, IRP_MJ_POWER);
168  ok_eq_uint(IoStackLocation->MinorFunction, IRP_MN_SET_POWER);
169  ok_eq_pointer(IoStackLocation->Context, RequestedPowerCompletion);
170  ok_eq_uint(IoStackLocation->Parameters.Power.Type, DevicePowerState);
171  ok_eq_uint(IoStackLocation->Parameters.Power.State.DeviceState, PowerDeviceD0);
172 
174  {
175  ok_eq_uint(Irp->CurrentLocation, 3);
176  Irp->IoStatus.Information = 7;
177  Irp->IoStatus.Status = STATUS_WAIT_3;
180  return STATUS_SUCCESS;
181  }
182  else if (DeviceObject == DeviceObject2)
183  {
184  ok_eq_uint(Irp->CurrentLocation, 3);
187  return PoCallDriver(DeviceObject1, Irp);
188  }
189  else if (DeviceObject == DeviceObject3)
190  {
191  ok_eq_uint(Irp->CurrentLocation, 3);
194  return PoCallDriver(DeviceObject2, Irp);
195  }
196  else
197  {
198  ok(0, "\n");
201  return STATUS_NOT_SUPPORTED;
202  }
203 }
204 
205 static
206 VOID
208 {
211 
213 
215 
219  PowerState,
223  ok(Status == STATUS_PENDING, "PoRequestPowerIrp returned %lx\n", Status);
225 
227  ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
229 }
230 
231 
232 //
233 // Message handler
234 //
235 static
236 NTSTATUS
241  _In_ SIZE_T InLength,
242  _Inout_ PSIZE_T OutLength)
243 {
245 
246  PAGED_CODE();
247 
248  switch (ControlCode)
249  {
250  case IOCTL_RUN_TEST:
251  {
254  if (!NT_SUCCESS(Status))
255  return Status;
256 
258 
264 
265  break;
266  }
267  default:
268  return STATUS_NOT_SUPPORTED;
269  }
270 
271  return Status;
272 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
static PIRP RequestedPowerIrp
Definition: PoIrp_drv.c:111
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define IN
Definition: typedefs.h:39
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
static VOID NTAPI RequestedPowerCompletion(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PVOID Context, _In_ PIO_STATUS_BLOCK IoStatus)
Definition: PoIrp_drv.c:117
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2659
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS RequestedPowerIrpHandler(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStackLocation)
Definition: PoIrp_drv.c:153
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
static PDRIVER_OBJECT TestDriverObject
Definition: PoIrp_drv.c:11
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
WCHAR DeviceName[]
Definition: adapter.cpp:21
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
int32_t INT
Definition: typedefs.h:58
#define _In_opt_
Definition: no_sal2.h:213
NTSTATUS KmtUnregisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
uint32_t ULONG_PTR
Definition: typedefs.h:65
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
static PDEVICE_OBJECT DeviceObject2
Definition: PoIrp_drv.c:15
#define IOCTL_RUN_TEST
Definition: PoIrp.h:11
NTSTATUS TestEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PCUNICODE_STRING RegistryPath, _Out_ PCWSTR *DeviceName, _Inout_ INT *Flags)
Definition: PoIrp_drv.c:76
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
static VOID TestPoRequestPowerIrp(VOID)
Definition: PoIrp_drv.c:207
Definition: bufpool.h:45
static KEVENT TestDoneEvent
Definition: PoIrp_drv.c:110
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:3293
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define _Inout_
Definition: no_sal2.h:244
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MJ_POWER
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
static PDEVICE_OBJECT DeviceObject3
Definition: PoIrp_drv.c:16
#define IRP_MN_SET_POWER
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
#define _In_
Definition: no_sal2.h:204
ULONG_PTR SIZE_T
Definition: typedefs.h:80
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static PIRP RequestedPowerIrpReturned
Definition: PoIrp_drv.c:112
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
#define ok(value,...)
Definition: atltest.h:57
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:139
static PDEVICE_OBJECT DeviceObject1
Definition: PoIrp_drv.c:14
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
static NTSTATUS CreateTestDevices(_In_ PDRIVER_OBJECT DriverObject)
Definition: PoIrp_drv.c:20
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: PoIrp_drv.c:12
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define STATUS_WAIT_3
Definition: ntstatus.h:73
VOID TestUnload(IN PDRIVER_OBJECT DriverObject)
Definition: PoIrp_drv.c:99
#define ok_eq_hex(value, expected)
NTSTATUS NTAPI PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PREQUEST_POWER_COMPLETE CompletionFunction, IN PVOID Context, OUT PIRP *pIrp OPTIONAL)
Definition: power.c:639
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:239
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68