ReactOS 0.4.15-dev-7674-gc0b4db1
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
12static KMT_MESSAGE_HANDLER TestMessageHandler;
13
17
18static
22{
24 PDEVICE_OBJECT AttachedDevice;
25
27 if (!NT_SUCCESS(Status))
28 return Status;
29
30 DeviceObject1->Flags &= ~DO_DEVICE_INITIALIZING;
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 {
46 }
47
48 DeviceObject2->Flags &= ~DO_DEVICE_INITIALIZING;
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 {
68 }
69
70 DeviceObject3->Flags &= ~DO_DEVICE_INITIALIZING;
71
72 return Status;
73}
74
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
98VOID
101{
103
104 PAGED_CODE();
105}
106
107//
108// PoRequestPowerIrp test
109//
113
114static
115VOID
116NTAPI
123{
124 PIRP Irp;
125 PIO_STACK_LOCATION IoStackLocation;
126
129 ok_eq_uint(PowerState.DeviceState, PowerDeviceD0);
133 ok_eq_ulongptr(IoStatus->Information, 7);
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
151static
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");
202 }
203}
204
205static
206VOID
208{
211
213
215
216 PowerState.DeviceState = PowerDeviceD0;
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//
235static
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:
269 }
270
271 return Status;
272}
#define PAGED_CODE()
#define IOCTL_RUN_TEST
Definition: PoIrp.h:11
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
static PDEVICE_OBJECT DeviceObject1
Definition: PoIrp_drv.c:14
static NTSTATUS RequestedPowerIrpHandler(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStackLocation)
Definition: PoIrp_drv.c:153
static PIRP RequestedPowerIrpReturned
Definition: PoIrp_drv.c:112
static PIRP RequestedPowerIrp
Definition: PoIrp_drv.c:111
static PDEVICE_OBJECT DeviceObject3
Definition: PoIrp_drv.c:16
static KEVENT TestDoneEvent
Definition: PoIrp_drv.c:110
static PDEVICE_OBJECT DeviceObject2
Definition: PoIrp_drv.c:15
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: PoIrp_drv.c:12
VOID TestUnload(IN PDRIVER_OBJECT DriverObject)
Definition: PoIrp_drv.c:99
static NTSTATUS CreateTestDevices(_In_ PDRIVER_OBJECT DriverObject)
Definition: PoIrp_drv.c:20
static PDRIVER_OBJECT TestDriverObject
Definition: PoIrp_drv.c:11
NTSTATUS TestEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PCUNICODE_STRING RegistryPath, _Out_ PCWSTR *DeviceName, _Inout_ INT *Flags)
Definition: PoIrp_drv.c:76
static VOID TestPoRequestPowerIrp(VOID)
Definition: PoIrp_drv.c:207
#define ok_eq_pointer(value, expected)
Definition: apitest.h:58
#define ok_eq_hex(value, expected)
Definition: apitest.h:76
#define ok_eq_uint(value, expected)
Definition: apitest.h:60
#define ok_eq_ulongptr(value, expected)
Definition: apitest.h:70
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
Status
Definition: gdiplustypes.h:25
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
NTSTATUS KmtUnregisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
#define _Inout_
Definition: ms_sal.h:378
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ NotificationEvent
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
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
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
NTSTATUS NTAPI PoRequestPowerIrp(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction, _In_opt_ __drv_aliasesMem PVOID Context, _Outptr_opt_ PIRP *pIrp)
Definition: power.c:659
@ DevicePowerState
Definition: ntpoapi.h:63
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_WAIT_3
Definition: ntstatus.h:73
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:140
#define STATUS_SUCCESS
Definition: shellext.h:65
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:3314
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
_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
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_SET_POWER
#define IRP_MJ_POWER
@ Executive
Definition: ketypes.h:415
unsigned char UCHAR
Definition: xmlstorage.h:181