[KMTESTS/IO]

- Fix and enable all of IoDeviceObject

svn path=/branches/GSoC_2011/KMTestSuite/; revision=53294
This commit is contained in:
Thomas Faber 2011-08-18 07:53:37 +00:00
parent b9b5b6762d
commit 39c506a4aa
2 changed files with 198 additions and 134 deletions

View file

@ -18,8 +18,16 @@ typedef enum
DriverUnload DriverUnload
} DRIVER_STATUS; } DRIVER_STATUS;
static KMT_IRP_HANDLER TestIrpHandler; static DRIVER_DISPATCH TestDispatch;
static VOID TestDriverObject(IN PDRIVER_OBJECT DriverObject, IN DRIVER_STATUS DriverStatus); static VOID TestDriverObject(IN PDRIVER_OBJECT DriverObject, IN DRIVER_STATUS DriverStatus);
static BOOLEAN TestZwLoad(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING DriverRegistryPath, IN PWCHAR NewDriverRegPath);
static BOOLEAN TestZwUnload(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING DriverRegistryPath, IN PWCHAR NewDriverRegPath);
static VOID TestLowerDeviceKernelAPI(IN PDEVICE_OBJECT DeviceObject);
static VOID TestDeviceCreated(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ExclusiveAccess);
static VOID TestDeviceDeletion(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Lower, IN BOOLEAN Attached);
static VOID TestDeviceCreateDelete(IN PDRIVER_OBJECT DriverObject);
static VOID TestAttachDevice(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR NewDriverRegPath);
static VOID TestDetachDevice(IN PDEVICE_OBJECT AttachedDevice);
static PDEVICE_OBJECT MainDeviceObject; static PDEVICE_OBJECT MainDeviceObject;
static PDEVICE_OBJECT AttachDeviceObject; static PDEVICE_OBJECT AttachDeviceObject;
@ -33,19 +41,47 @@ TestEntry(
IN OUT INT *Flags) IN OUT INT *Flags)
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
BOOLEAN Ret;
INT i;
PAGED_CODE(); PAGED_CODE();
UNREFERENCED_PARAMETER(RegistryPath); UNREFERENCED_PARAMETER(DeviceName);
UNREFERENCED_PARAMETER(Flags);
*DeviceName = L"IoDeviceObject"; *Flags = TESTENTRY_NO_CREATE_DEVICE | TESTENTRY_NO_REGISTER_DISPATCH;
KmtRegisterIrpHandler(IRP_MJ_CREATE, NULL, TestIrpHandler); ThisDriverObject = DriverObject;
KmtRegisterIrpHandler(IRP_MJ_CLOSE, NULL, TestIrpHandler);
TestDriverObject(DriverObject, DriverEntry); TestDriverObject(DriverObject, DriverEntry);
/* Create and delete device, on return MainDeviceObject has been created */
TestDeviceCreateDelete(DriverObject);
/* Make sure a device object was created */
if (!skip(MainDeviceObject != NULL, "Device object creation failed\n"))
{
PWCHAR LowerDriverRegPath = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Kmtest-IoHelper";
/* Load driver test and load the lower driver */
Ret = TestZwLoad(DriverObject, RegistryPath, LowerDriverRegPath);
if (!skip(Ret, "Failed to load helper driver\n"))
{
TestAttachDevice(MainDeviceObject, L"\\Device\\Kmtest-IoHelper");
if (!skip(AttachDeviceObject != NULL, "No attached device object\n"))
TestLowerDeviceKernelAPI(MainDeviceObject);
/* Unload lower driver without detaching from its device */
TestZwUnload(DriverObject, RegistryPath, LowerDriverRegPath);
TestLowerDeviceKernelAPI(MainDeviceObject);
}
}
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; ++i)
DriverObject->MajorFunction[i] = NULL;
DriverObject->MajorFunction[IRP_MJ_CREATE] = TestDispatch;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = TestDispatch;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TestDispatch;
return Status; return Status;
} }
@ -55,19 +91,45 @@ TestUnload(
{ {
PAGED_CODE(); PAGED_CODE();
if (!skip(AttachDeviceObject != NULL, "no attached device object\n"))
{
TestDeviceDeletion(MainDeviceObject, FALSE, TRUE);
TestDeviceDeletion(AttachDeviceObject, TRUE, FALSE);
TestDetachDevice(AttachDeviceObject);
}
TestDeviceDeletion(MainDeviceObject, FALSE, FALSE);
TestDriverObject(DriverObject, DriverUnload); TestDriverObject(DriverObject, DriverUnload);
if (MainDeviceObject)
IoDeleteDevice(MainDeviceObject);
} }
static static
NTSTATUS NTSTATUS
TestIrpHandler( NTAPI
TestDispatch(
IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp, IN PIRP Irp)
IN PIO_STACK_LOCATION IoStackLocation)
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
PIO_STACK_LOCATION IoStackLocation;
UNREFERENCED_PARAMETER(IoStackLocation); PAGED_CODE();
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
DPRINT("TestIrpHandler. Function=%s, DeviceObject=%p, AttachDeviceObject=%p\n",
KmtMajorFunctionNames[IoStackLocation->MajorFunction],
DeviceObject,
AttachDeviceObject);
if (AttachDeviceObject)
{
IoSkipCurrentIrpStackLocation(Irp);
Status = IoCallDriver(AttachDeviceObject, Irp);
return Status;
}
TestDriverObject(DeviceObject->DriverObject, DriverIrp); TestDriverObject(DeviceObject->DriverObject, DriverIrp);
@ -89,29 +151,29 @@ TestDriverObject(
PVOID FirstMajorFunc; PVOID FirstMajorFunc;
int i; int i;
ok(DriverObject->Size == sizeof(DRIVER_OBJECT), "Size does not match, got %x",DriverObject->Size); ok(DriverObject->Size == sizeof(DRIVER_OBJECT), "Size does not match, got %x\n",DriverObject->Size);
ok(DriverObject->Type == 4, "Type does not match 4. got %d",DriverObject->Type); ok(DriverObject->Type == 4, "Type does not match 4. got %d\n", DriverObject->Type);
if (DriverStatus == DriverEntry) if (DriverStatus == DriverEntry)
{ {
ok(DriverObject->DeviceObject == NULL, "Expected DeviceObject pointer to be 0, got %p", ok(DriverObject->DeviceObject == NULL, "Expected DeviceObject pointer to be 0, got %p\n",
DriverObject->DeviceObject); DriverObject->DeviceObject);
ok (DriverObject->Flags == DRVO_LEGACY_DRIVER, ok (DriverObject->Flags == DRVO_LEGACY_DRIVER,
"Expected Flags to be DRVO_LEGACY_DRIVER, got %lu", "Expected Flags to be DRVO_LEGACY_DRIVER, got %lu\n",
DriverObject->Flags); DriverObject->Flags);
} }
else if (DriverStatus == DriverIrp) else if (DriverStatus == DriverIrp)
{ {
ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null"); ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null\n");
ok (DriverObject->Flags == (DRVO_LEGACY_DRIVER | DRVO_INITIALIZED), ok (DriverObject->Flags == (DRVO_LEGACY_DRIVER | DRVO_INITIALIZED),
"Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED, got %lu", "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED, got %lu\n",
DriverObject->Flags); DriverObject->Flags);
} }
else if (DriverStatus == DriverUnload) else if (DriverStatus == DriverUnload)
{ {
ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null"); ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null\n");
ok (DriverObject->Flags == (DRVO_LEGACY_DRIVER | DRVO_INITIALIZED | DRVO_UNLOAD_INVOKED), ok (DriverObject->Flags == (DRVO_LEGACY_DRIVER | DRVO_INITIALIZED | DRVO_UNLOAD_INVOKED),
"Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED | DRVO_UNLOAD_INVOKED, got %lu", "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED | DRVO_UNLOAD_INVOKED, got %lu\n",
DriverObject->Flags); DriverObject->Flags);
} }
else else
@ -119,7 +181,7 @@ TestDriverObject(
/* Select a routine that was not changed */ /* Select a routine that was not changed */
FirstMajorFunc = DriverObject->MajorFunction[1]; FirstMajorFunc = DriverObject->MajorFunction[1];
ok(FirstMajorFunc != 0, "Expected MajorFunction[1] to be non NULL"); ok(FirstMajorFunc != 0, "Expected MajorFunction[1] to be non NULL\n");
if (!skip(FirstMajorFunc != NULL, "First major function not set!\n")) if (!skip(FirstMajorFunc != NULL, "First major function not set!\n"))
{ {
@ -130,21 +192,26 @@ TestDriverObject(
if (CheckThisDispatchRoutine) if (CheckThisDispatchRoutine)
{ {
ok(DriverObject->MajorFunction[i] == FirstMajorFunc, "Expected MajorFunction[%d] to match %p", ok(DriverObject->MajorFunction[i] == FirstMajorFunc, "Expected MajorFunction[%d] to match %p\n",
i, FirstMajorFunc); i, FirstMajorFunc);
} }
} }
} }
} }
BOOLEAN ZwLoadTest(PDRIVER_OBJECT DriverObject, PUNICODE_STRING DriverRegistryPath, PWCHAR NewDriverRegPath) static
BOOLEAN
TestZwLoad(
IN PDRIVER_OBJECT DriverObject,
IN PCUNICODE_STRING DriverRegistryPath,
IN PWCHAR NewDriverRegPath)
{ {
UNICODE_STRING RegPath; UNICODE_STRING RegPath;
NTSTATUS Status; NTSTATUS Status;
/* Try to load ourself */ /* Try to load ourself */
Status = ZwLoadDriver(DriverRegistryPath); Status = ZwLoadDriver((PUNICODE_STRING)DriverRegistryPath);
ok (Status == STATUS_IMAGE_ALREADY_LOADED, "Expected NTSTATUS STATUS_IMAGE_ALREADY_LOADED, got 0x%lX", Status); ok (Status == STATUS_IMAGE_ALREADY_LOADED, "Expected NTSTATUS STATUS_IMAGE_ALREADY_LOADED, got 0x%lX\n", Status);
if (Status != STATUS_IMAGE_ALREADY_LOADED) if (Status != STATUS_IMAGE_ALREADY_LOADED)
{ {
@ -154,64 +221,54 @@ BOOLEAN ZwLoadTest(PDRIVER_OBJECT DriverObject, PUNICODE_STRING DriverRegistryPa
/* Try to load with a Registry Path that doesnt exist */ /* Try to load with a Registry Path that doesnt exist */
RtlInitUnicodeString(&RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef"); RtlInitUnicodeString(&RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef");
Status = ZwLoadDriver(&RegPath); Status = ZwLoadDriver(&RegPath);
ok (Status == STATUS_OBJECT_NAME_NOT_FOUND, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX", Status); ok (Status == STATUS_OBJECT_NAME_NOT_FOUND, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX\n", Status);
/* Load the driver */ /* Load the driver */
RtlInitUnicodeString(&RegPath, NewDriverRegPath); RtlInitUnicodeString(&RegPath, NewDriverRegPath);
Status = ZwLoadDriver(&RegPath); Status = ZwLoadDriver(&RegPath);
ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX", Status); ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
if (!NT_SUCCESS(Status)) return NT_SUCCESS(Status);
{
return FALSE;
}
return TRUE;
} }
BOOLEAN ZwUnloadTest(PDRIVER_OBJECT DriverObject, PUNICODE_STRING DriverRegistryPath, PWCHAR NewDriverRegPath) static
BOOLEAN
TestZwUnload(
IN PDRIVER_OBJECT DriverObject,
IN PCUNICODE_STRING DriverRegistryPath,
IN PWCHAR NewDriverRegPath)
{ {
UNICODE_STRING RegPath; UNICODE_STRING RegPath;
NTSTATUS Status; NTSTATUS Status;
/* Try to unload ourself, which should fail as our Unload routine hasnt been set yet. */ /* Try to unload ourself, which should fail as our Unload routine hasnt been set yet. */
Status = ZwUnloadDriver(DriverRegistryPath); Status = ZwUnloadDriver((PUNICODE_STRING)DriverRegistryPath);
ok (Status == STATUS_INVALID_DEVICE_REQUEST, "Expected NTSTATUS STATUS_INVALID_DEVICE_REQUEST, got 0x%lX", Status); ok (Status == STATUS_INVALID_DEVICE_REQUEST, "Expected NTSTATUS STATUS_INVALID_DEVICE_REQUEST, got 0x%lX\n", Status);
/* Try to unload with a Registry Path that doesnt exist */ /* Try to unload with a Registry Path that doesnt exist */
RtlInitUnicodeString(&RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef"); RtlInitUnicodeString(&RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\deadbeef");
Status = ZwUnloadDriver(&RegPath); Status = ZwUnloadDriver(&RegPath);
ok (Status == STATUS_OBJECT_NAME_NOT_FOUND, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX", Status); ok (Status == STATUS_OBJECT_NAME_NOT_FOUND, "Expected NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND, got 0x%lX\n", Status);
/* Unload the driver */ /* Unload the driver */
RtlInitUnicodeString(&RegPath, NewDriverRegPath); RtlInitUnicodeString(&RegPath, NewDriverRegPath);
Status = ZwUnloadDriver(&RegPath); Status = ZwUnloadDriver(&RegPath);
ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX", Status); ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
if (!NT_SUCCESS(Status)) return NT_SUCCESS(Status);
{
return FALSE;
}
return TRUE;
} }
VOID LowerDeviceKernelAPITest(PDEVICE_OBJECT DeviceObject, BOOLEAN UnLoading) static
VOID
TestLowerDeviceKernelAPI(
IN PDEVICE_OBJECT DeviceObject)
{ {
PDEVICE_OBJECT RetObject; PDEVICE_OBJECT RetObject;
RetObject = IoGetLowerDeviceObject(DeviceObject); RetObject = IoGetLowerDeviceObject(DeviceObject);
if (UnLoading) ok(RetObject == AttachDeviceObject,
{ "Expected an Attached DeviceObject %p, got %p\n", AttachDeviceObject, RetObject);
ok(RetObject == 0,
"Expected no Lower DeviceObject, got %p", RetObject);
}
else
{
ok(RetObject == AttachDeviceObject,
"Expected an Attached DeviceObject %p, got %p", AttachDeviceObject, RetObject);
}
if (RetObject) if (RetObject)
{ {
@ -219,8 +276,8 @@ VOID LowerDeviceKernelAPITest(PDEVICE_OBJECT DeviceObject, BOOLEAN UnLoading)
} }
RetObject = IoGetDeviceAttachmentBaseRef(DeviceObject); RetObject = IoGetDeviceAttachmentBaseRef(DeviceObject);
ok(RetObject == DeviceObject, ok(RetObject == AttachDeviceObject,
"Expected an Attached DeviceObject %p, got %p", DeviceObject, RetObject); "Expected an Attached DeviceObject %p, got %p\n", AttachDeviceObject, RetObject);
if (RetObject) if (RetObject)
{ {
@ -228,114 +285,125 @@ VOID LowerDeviceKernelAPITest(PDEVICE_OBJECT DeviceObject, BOOLEAN UnLoading)
} }
} }
VOID DeviceCreatedTest(PDEVICE_OBJECT DeviceObject, BOOLEAN ExclusiveAccess)
static
VOID
TestDeviceCreated(
IN PDEVICE_OBJECT DeviceObject,
IN BOOLEAN ExclusiveAccess)
{ {
PEXTENDED_DEVOBJ_EXTENSION extdev; PEXTENDED_DEVOBJ_EXTENSION extdev;
/*Check the device object members */ /* Check the device object members */
ok(DeviceObject->Type==3, "Expected Type = 3, got %x", DeviceObject->Type); ok(DeviceObject->Type == 3, "Expected Type = 3, got %x\n", DeviceObject->Type);
ok(DeviceObject->Size = 0xb8, "Expected Size = 0xba, got %x", DeviceObject->Size); ok(DeviceObject->Size == 0xb8, "Expected Size = 0xb8, got %x\n", DeviceObject->Size);
ok(DeviceObject->ReferenceCount == 0, "Expected ReferenceCount = 0, got %lu", ok(DeviceObject->ReferenceCount == 0, "Expected ReferenceCount = 0, got %lu\n",
DeviceObject->ReferenceCount); DeviceObject->ReferenceCount);
ok(DeviceObject->DriverObject == ThisDriverObject, ok(DeviceObject->DriverObject == ThisDriverObject,
"Expected DriverObject member to match this DriverObject %p, got %p", "Expected DriverObject member to match this DriverObject %p, got %p\n",
ThisDriverObject, DeviceObject->DriverObject); ThisDriverObject, DeviceObject->DriverObject);
ok(DeviceObject->NextDevice == NULL, "Expected NextDevice to be NULL, got %p", DeviceObject->NextDevice); ok(DeviceObject->NextDevice == NULL, "Expected NextDevice to be NULL, got %p\n", DeviceObject->NextDevice);
ok(DeviceObject->AttachedDevice == NULL, "Expected AttachDevice to be NULL, got %p", DeviceObject->AttachedDevice); ok(DeviceObject->AttachedDevice == NULL, "Expected AttachDevice to be NULL, got %p\n", DeviceObject->AttachedDevice);
ok(DeviceObject->Characteristics == 0, "Expected Characteristics to be 0"); ok(DeviceObject->Characteristics == 0, "Expected Characteristics to be 0\n");
if (ExclusiveAccess) if (ExclusiveAccess)
{ {
ok((DeviceObject->Flags == (DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING | DO_EXCLUSIVE)), ok((DeviceObject->Flags == (DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING | DO_EXCLUSIVE)),
"Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING | DO_EXCLUSIVE, got %lu", DeviceObject->Flags); "Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING | DO_EXCLUSIVE, got %lu\n", DeviceObject->Flags);
} }
else else
{ {
ok((DeviceObject->Flags == (DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING)), ok((DeviceObject->Flags == (DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING)),
"Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING, got %lu", DeviceObject->Flags); "Expected Flags DO_DEVICE_HAS_NAME | DO_DEVICE_INITIALIZING, got %lu\n", DeviceObject->Flags);
} }
ok(DeviceObject->DeviceType == FILE_DEVICE_UNKNOWN, ok(DeviceObject->DeviceType == FILE_DEVICE_UNKNOWN,
"Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu", "Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu\n",
DeviceObject->DeviceType); DeviceObject->DeviceType);
ok(DeviceObject->ActiveThreadCount == 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject->ActiveThreadCount); ok(DeviceObject->ActiveThreadCount == 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject->ActiveThreadCount);
/*Check the extended extension */ /* Check the extended extension */
extdev = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension; extdev = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension;
ok(extdev->ExtensionFlags == 0, "Expected Extended ExtensionFlags to be 0, got %lu", extdev->ExtensionFlags); ok(extdev->ExtensionFlags == 0, "Expected Extended ExtensionFlags to be 0, got %lu\n", extdev->ExtensionFlags);
ok (extdev->Type == 13, "Expected Type of 13, got %d", extdev->Type); ok (extdev->Type == 13, "Expected Type of 13, got %d\n", extdev->Type);
ok (extdev->Size == 0, "Expected Size of 0, got %d", extdev->Size); ok (extdev->Size == 0, "Expected Size of 0, got %d\n", extdev->Size);
ok (extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p", ok (extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p\n",
DeviceObject, extdev->DeviceObject); DeviceObject, extdev->DeviceObject);
ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p", extdev->AttachedTo); ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p\n", extdev->AttachedTo);
ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu", extdev->StartIoCount); ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu\n", extdev->StartIoCount);
ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu", extdev->StartIoKey); ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu\n", extdev->StartIoKey);
ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu", extdev->StartIoFlags); ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu\n", extdev->StartIoFlags);
} }
VOID DeviceDeletionTest(PDEVICE_OBJECT DeviceObject, BOOLEAN Lower) static
VOID
TestDeviceDeletion(
IN PDEVICE_OBJECT DeviceObject,
IN BOOLEAN Lower,
IN BOOLEAN Attached)
{ {
PEXTENDED_DEVOBJ_EXTENSION extdev; PEXTENDED_DEVOBJ_EXTENSION extdev;
/*Check the device object members */ /* Check the device object members */
ok(DeviceObject->Type==3, "Expected Type = 3, got %d", DeviceObject->Type); ok(DeviceObject->Type == 3, "Expected Type = 3, got %d\n", DeviceObject->Type);
ok(DeviceObject->Size = 0xb8, "Expected Size = 0xba, got %d", DeviceObject->Size); ok(DeviceObject->Size == 0xb8, "Expected Size = 0xb8, got %d\n", DeviceObject->Size);
ok(DeviceObject->ReferenceCount == 0, "Expected ReferenceCount = 0, got %lu", ok(DeviceObject->ReferenceCount == 0, "Expected ReferenceCount = 0, got %lu\n",
DeviceObject->ReferenceCount); DeviceObject->ReferenceCount);
if (!Lower) if (!Lower)
{ {
ok(DeviceObject->DriverObject == ThisDriverObject, ok(DeviceObject->DriverObject == ThisDriverObject,
"Expected DriverObject member to match this DriverObject %p, got %p", "Expected DriverObject member to match this DriverObject %p, got %p\n",
ThisDriverObject, DeviceObject->DriverObject); ThisDriverObject, DeviceObject->DriverObject);
} }
ok(DeviceObject->NextDevice == NULL, "Expected NextDevice to be NULL, got %p", DeviceObject->NextDevice); ok(DeviceObject->NextDevice == NULL, "Expected NextDevice to be NULL, got %p\n", DeviceObject->NextDevice);
if (Lower) if (Lower)
{ {
ok(DeviceObject->AttachedDevice == MainDeviceObject, ok(DeviceObject->AttachedDevice == MainDeviceObject,
"Expected AttachDevice to be %p, got %p", MainDeviceObject, DeviceObject->AttachedDevice); "Expected AttachDevice to be %p, got %p\n", MainDeviceObject, DeviceObject->AttachedDevice);
} }
else else
{ {
ok(DeviceObject->AttachedDevice == NULL, "Expected AttachDevice to be NULL, got %p", DeviceObject->AttachedDevice); ok(DeviceObject->AttachedDevice == NULL, "Expected AttachDevice to be NULL, got %p\n", DeviceObject->AttachedDevice);
} }
ok(DeviceObject->Flags ==FILE_VIRTUAL_VOLUME, ok(DeviceObject->Flags == (DO_DEVICE_HAS_NAME | (Lower ? DO_EXCLUSIVE : 0)),
"Expected Flags FILE_VIRTUAL_VOLUME, got %lu", DeviceObject->Flags); "Expected Flags DO_DEVICE_HAS_NAME, got %lu\n", DeviceObject->Flags);
ok(DeviceObject->DeviceType == FILE_DEVICE_UNKNOWN, ok(DeviceObject->DeviceType == FILE_DEVICE_UNKNOWN,
"Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu", "Expected DeviceType to match creation parameter FILE_DEVICE_UNKNWOWN, got %lu\n",
DeviceObject->DeviceType); DeviceObject->DeviceType);
ok(DeviceObject->ActiveThreadCount == 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject->ActiveThreadCount); ok(DeviceObject->ActiveThreadCount == 0, "Expected ActiveThreadCount = 0, got %lu\n", DeviceObject->ActiveThreadCount);
/*Check the extended extension */ /*Check the extended extension */
extdev = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension; extdev = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension;
ok(extdev->ExtensionFlags == DOE_UNLOAD_PENDING, ok(extdev->ExtensionFlags == DOE_UNLOAD_PENDING,
"Expected Extended ExtensionFlags to be DOE_UNLOAD_PENDING, got %lu", extdev->ExtensionFlags); "Expected Extended ExtensionFlags to be DOE_UNLOAD_PENDING, got %lu\n", extdev->ExtensionFlags);
ok (extdev->Type == 13, "Expected Type of 13, got %d", extdev->Type); ok (extdev->Type == 13, "Expected Type of 13, got %d\n", extdev->Type);
ok (extdev->Size == 0, "Expected Size of 0, got %d", extdev->Size); ok (extdev->Size == 0, "Expected Size of 0, got %d\n", extdev->Size);
ok (extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p", ok (extdev->DeviceObject == DeviceObject, "Expected DeviceOject to match newly created device %p, got %p\n",
DeviceObject, extdev->DeviceObject); DeviceObject, extdev->DeviceObject);
if (Lower) if (Lower || !Attached)
{ {
/* Skip this for now */ ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p\n", extdev->AttachedTo);
//ok(extdev->AttachedTo == MainDeviceObject, "Expected AttachTo to %p, got %p", MainDeviceObject, extdev->AttachedTo);
} }
else else
{ {
ok(extdev->AttachedTo == NULL, "Expected AttachTo to be NULL, got %p", extdev->AttachedTo); ok(extdev->AttachedTo == AttachDeviceObject, "Expected AttachTo to %p, got %p\n", AttachDeviceObject, extdev->AttachedTo);
} }
ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu", extdev->StartIoCount); ok(extdev->StartIoCount == 0, "Expected StartIoCount = 0, got %lu\n", extdev->StartIoCount);
ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu", extdev->StartIoKey); ok(extdev->StartIoKey == 0, "Expected StartIoKey = 0, got %lu\n", extdev->StartIoKey);
ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu", extdev->StartIoFlags); ok(extdev->StartIoFlags == 0, "Expected StartIoFlags = 0, got %lu\n", extdev->StartIoFlags);
} }
VOID DeviceCreateDeleteTest(PDRIVER_OBJECT DriverObject) static
VOID
TestDeviceCreateDelete(
IN PDRIVER_OBJECT DriverObject)
{ {
NTSTATUS Status; NTSTATUS Status;
UNICODE_STRING DeviceString; UNICODE_STRING DeviceString;
UNICODE_STRING DosDeviceString;
PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT DeviceObject;
/* Create using wrong directory */ /* Create using wrong directory */
RtlInitUnicodeString(&DeviceString, L"\\Device1\\Kmtest"); RtlInitUnicodeString(&DeviceString, L"\\Device1\\Kmtest-IoDeviceObject");
Status = IoCreateDevice(DriverObject, Status = IoCreateDevice(DriverObject,
0, 0,
&DeviceString, &DeviceString,
@ -343,10 +411,10 @@ VOID DeviceCreateDeleteTest(PDRIVER_OBJECT DriverObject)
0, 0,
FALSE, FALSE,
&DeviceObject); &DeviceObject);
ok(Status == STATUS_OBJECT_PATH_NOT_FOUND, "Expected STATUS_OBJECT_PATH_NOT_FOUND, got 0x%lX", Status); ok(Status == STATUS_OBJECT_PATH_NOT_FOUND, "Expected STATUS_OBJECT_PATH_NOT_FOUND, got 0x%lX\n", Status);
/* Create using correct params with exlusice access */ /* Create using correct params with exclusice access */
RtlInitUnicodeString(&DeviceString, L"\\Device\\Kmtest"); RtlInitUnicodeString(&DeviceString, L"\\Device\\Kmtest-IoDeviceObject");
Status = IoCreateDevice(DriverObject, Status = IoCreateDevice(DriverObject,
0, 0,
&DeviceString, &DeviceString,
@ -354,19 +422,19 @@ VOID DeviceCreateDeleteTest(PDRIVER_OBJECT DriverObject)
0, 0,
TRUE, TRUE,
&DeviceObject); &DeviceObject);
ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX", Status); ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
DeviceCreatedTest(DeviceObject, TRUE); TestDeviceCreated(DeviceObject, TRUE);
/* Delete the device */ /* Delete the device */
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
IoDeleteDevice(DeviceObject); IoDeleteDevice(DeviceObject);
ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p", ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p\n",
DriverObject->DeviceObject); DriverObject->DeviceObject);
} }
/* Create using correct params with exlusice access */ /* Create using correct params without exclusice access */
Status = IoCreateDevice(DriverObject, Status = IoCreateDevice(DriverObject,
0, 0,
&DeviceString, &DeviceString,
@ -374,15 +442,15 @@ VOID DeviceCreateDeleteTest(PDRIVER_OBJECT DriverObject)
0, 0,
FALSE, FALSE,
&DeviceObject); &DeviceObject);
ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX", Status); ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
DeviceCreatedTest(DeviceObject, FALSE); TestDeviceCreated(DeviceObject, FALSE);
/* Delete the device */ /* Delete the device */
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
IoDeleteDevice(DeviceObject); IoDeleteDevice(DeviceObject);
ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p", ok(DriverObject->DeviceObject == 0, "Expected DriverObject->DeviceObject to be NULL, got %p\n",
DriverObject->DeviceObject); DriverObject->DeviceObject);
} }
@ -394,42 +462,34 @@ VOID DeviceCreateDeleteTest(PDRIVER_OBJECT DriverObject)
0, 0,
FALSE, FALSE,
&DeviceObject); &DeviceObject);
ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX", Status); ok(Status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%lX\n", Status);
RtlInitUnicodeString(&DosDeviceString, L"\\DosDevices\\kmtest"); if (NT_SUCCESS(Status))
Status = IoCreateSymbolicLink(&DosDeviceString, &DeviceString); MainDeviceObject = DeviceObject;
if (!NT_SUCCESS(Status))
{
/* Delete device object if not successful */
IoDeleteDevice(DeviceObject);
return;
}
MainDeviceObject = DeviceObject;
return;
} }
BOOLEAN AttachDeviceTest(PDEVICE_OBJECT DeviceObject, PWCHAR NewDriverRegPath) static
VOID
TestAttachDevice(
IN PDEVICE_OBJECT DeviceObject,
IN PWCHAR NewDriverRegPath)
{ {
NTSTATUS Status; NTSTATUS Status;
UNICODE_STRING LowerDeviceName; UNICODE_STRING LowerDeviceName;
RtlInitUnicodeString(&LowerDeviceName, NewDriverRegPath); RtlInitUnicodeString(&LowerDeviceName, NewDriverRegPath);
Status = IoAttachDevice(DeviceObject, &LowerDeviceName, &AttachDeviceObject); Status = IoAttachDevice(DeviceObject, &LowerDeviceName, &AttachDeviceObject);
ok_eq_hex(Status, STATUS_SUCCESS);
/* TODO: Add more tests */ /* TODO: Add more tests */
return TRUE;
} }
BOOLEAN DetachDeviceTest(PDEVICE_OBJECT AttachedDevice) static
VOID
TestDetachDevice(
IN PDEVICE_OBJECT AttachedDevice)
{ {
IoDetachDevice(AttachedDevice); IoDetachDevice(AttachedDevice);
/* TODO: Add more tests */ /* TODO: Add more tests */
return TRUE;
} }

View file

@ -9,7 +9,11 @@
START_TEST(IoDeviceObject) START_TEST(IoDeviceObject)
{ {
KmtLoadDriver(L"IoDeviceObject", FALSE); /* make sure IoHelper has an existing service key, but is not started */
KmtLoadDriver(L"IoHelper", FALSE);
KmtUnloadDriver();
KmtLoadDriver(L"IoDeviceObject", TRUE);
KmtOpenDriver(); KmtOpenDriver();
KmtCloseDriver(); KmtCloseDriver();
KmtUnloadDriver(); KmtUnloadDriver();