2 * PROJECT: ReactOS kernel
3 * FILE: regtests/kmregtests/driver.c
4 * PURPOSE: Kernel-mode regression testing driver
5 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * 06-07-2003 CSH Created
9 #define NTOS_MODE_KERNEL
12 #include "kmregtests.h"
17 extern void AddTest(TestRoutine Routine
);
20 AllocateMemory(ULONG Size
)
22 return ExAllocatePool(NonPagedPool
, Size
);
27 FreeMemory(PVOID Base
)
29 ExFreePool(NonPagedPool
);
35 /* Shutdown bochs programmatically */
36 WRITE_PORT_BUFFER_UCHAR((PUCHAR
) 0x8900,
45 PIO_STACK_LOCATION IrpSp
)
47 TestRoutine
*pTestRoutine
;
49 pTestRoutine
= (TestRoutine
*)Irp
->AssociatedIrp
.SystemBuffer
;
50 AddTest(*pTestRoutine
);
52 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
53 Irp
->IoStatus
.Information
= 0;
54 return STATUS_SUCCESS
;
61 PIO_STACK_LOCATION IrpSp
)
63 PerformTests(NULL
, NULL
);
66 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
67 Irp
->IoStatus
.Information
= 0;
68 return STATUS_SUCCESS
;
74 PDEVICE_OBJECT DeviceObject
,
77 * FUNCTION: IOCTL dispatch routine
79 * DeviceObject = Pointer to a device object for this driver
80 * Irp = Pointer to a I/O request packet
82 * Status of the operation
86 PIO_STACK_LOCATION IrpSp
;
88 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
90 DPRINT("Called. DeviceObject is at (0x%X), IRP is at (0x%X), IrpSp->FileObject (0x%X).\n",
91 DeviceObject
, Irp
, IrpSp
->FileObject
);
93 Irp
->IoStatus
.Information
= 0;
95 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
) {
96 case IOCTL_KMREGTESTS_REGISTER
:
97 Status
= KMRegTestsRegister(Irp
, IrpSp
);
100 case IOCTL_KMREGTESTS_RUN
:
101 Status
= KMRegTestsRun(Irp
, IrpSp
);
105 DPRINT("Unknown IOCTL (0x%X).\n",
106 IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
);
107 Status
= STATUS_NOT_IMPLEMENTED
;
111 if (Status
!= STATUS_PENDING
) {
112 Irp
->IoStatus
.Status
= Status
;
113 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
116 DPRINT("Leaving. Status (0x%X).\n", Status
);
122 KMRegTestsOpenClose(IN PDEVICE_OBJECT DeviceObject
, IN PIRP Irp
)
124 PIO_STACK_LOCATION IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
127 DPRINT("Called. DeviceObject is at (0x%X), IRP is at (0x%X), IrpSp->FileObject (0x%X).\n",
128 DeviceObject
, Irp
, IrpSp
->FileObject
);
130 Status
= STATUS_SUCCESS
;
132 switch (IrpSp
->MajorFunction
)
134 /* Opening and closing handles to the device */
142 Irp
->IoStatus
.Information
= 0;
148 Irp
->IoStatus
.Information
= 0;
149 Status
= STATUS_END_OF_FILE
;
152 /* Unsupported operations */
154 Status
= STATUS_NOT_IMPLEMENTED
;
157 Irp
->IoStatus
.Status
= Status
;
158 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
164 KMRegTestsUnload(PDRIVER_OBJECT DriverObject
)
166 return STATUS_SUCCESS
;
170 DriverEntry(PDRIVER_OBJECT DriverObject
,
171 PUNICODE_STRING RegistryPath
)
173 PDEVICE_OBJECT DeviceObject
;
174 UNICODE_STRING DeviceName
;
177 /* Register driver routines */
178 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = (PDRIVER_DISPATCH
) KMRegTestsOpenClose
;
179 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = (PDRIVER_DISPATCH
) KMRegTestsOpenClose
;
180 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = (PDRIVER_DISPATCH
) KMRegTestsOpenClose
;
181 DriverObject
->MajorFunction
[IRP_MJ_READ
] = (PDRIVER_DISPATCH
) KMRegTestsOpenClose
;
182 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = (PDRIVER_DISPATCH
) KMRegTestsDispatch
;
183 DriverObject
->DriverUnload
= (PDRIVER_UNLOAD
) KMRegTestsUnload
;
186 RtlInitUnicodeString(&DeviceName
,
187 L
"\\Device\\KMRegTests");
189 Status
= IoCreateDevice(DriverObject
,
196 if (!NT_SUCCESS(Status
))
201 DeviceObject
->Flags
|= DO_BUFFERED_IO
;