[KMTESTS]
authorThomas Faber <thomas.faber@reactos.org>
Wed, 3 Aug 2011 12:48:22 +0000 (12:48 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Wed, 3 Aug 2011 12:48:22 +0000 (12:48 +0000)
- add IoDriverObject test, partly ported from old kmtests. Should possibly be merged with another test
- ExDoubleList: add another small testcase

svn path=/branches/GSoC_2011/KMTestSuite/; revision=53047

kmtests/CMakeLists.txt
kmtests/directory.rbuild
kmtests/kmtest.rbuild
kmtests/kmtest/testlist.c
kmtests/ntos_ex/ExDoubleList.c
kmtests/ntos_io/CMakeLists.txt [new file with mode: 0644]
kmtests/ntos_io/IoDriverObject_drv.c [new file with mode: 0644]
kmtests/ntos_io/IoDriverObject_user.c [new file with mode: 0644]
kmtests/ntos_io/iodriverobject_drv.rbuild [new file with mode: 0644]

index f024f5d..9c634a1 100644 (file)
@@ -5,6 +5,7 @@ include_directories(
 # subdirectories containing special-purpose drivers
 #
 add_subdirectory(example)
+add_subdirectory(ntos_io)
 
 #
 # kmtest_drv.sys driver
@@ -65,6 +66,7 @@ list(APPEND KMTEST_SOURCE
     kmtest/testlist.c
 
     example/Example_user.c
+    ntos_io/IoDriverObject_user.c
     rtl/RtlAvlTree.c
     rtl/RtlMemory.c
     rtl/RtlSplayTree.c
@@ -82,7 +84,7 @@ add_cd_file(TARGET kmtest DESTINATION reactos/bin FOR all)
 # Group targets
 #
 add_custom_target(kmtest_drivers)
-add_dependencies(kmtest_drivers kmtest_drv example_drv)
+add_dependencies(kmtest_drivers kmtest_drv example_drv iodriverobject_drv)
 
 add_custom_target(kmtest_all)
 add_dependencies(kmtest_all kmtest_drivers kmtest)
index 3c42f83..5815892 100644 (file)
@@ -4,6 +4,9 @@
        <directory name="example">
                <xi:include href="example/example_drv.rbuild" />
        </directory>
+       <directory name="ntos_io">
+               <xi:include href="ntos_io/iodriverobject_drv.rbuild" />
+       </directory>
        <xi:include href="kmtest.rbuild" />
        <xi:include href="kmtest_drv.rbuild" />
 </group>
index 16fbd77..d169d9f 100644 (file)
@@ -12,6 +12,9 @@
        <directory name="example">
                <file>Example_user.c</file>
        </directory>
+       <directory name="ntos_io">
+               <file>IoDriverObject_user.c</file>
+       </directory>
        <directory name="rtl">
                <file>RtlAvlTree.c</file>
                <file>RtlMemory.c</file>
index d634ac9..f6e8ce5 100644 (file)
@@ -8,6 +8,7 @@
 #include <kmt_test.h>
 
 KMT_TESTFUNC Test_Example;
+KMT_TESTFUNC Test_IoDriverObject;
 KMT_TESTFUNC Test_RtlAvlTree;
 KMT_TESTFUNC Test_RtlMemory;
 KMT_TESTFUNC Test_RtlSplayTree;
@@ -16,6 +17,7 @@ KMT_TESTFUNC Test_RtlSplayTree;
 const KMT_TEST TestList[] =
 {
     { "Example",            Test_Example },
+    { "IoDriverObject",     Test_IoDriverObject },
     { "RtlAvlTree",         Test_RtlAvlTree },
     { "RtlMemory",          Test_RtlMemory },
     { "RtlSplayTree",       Test_RtlSplayTree },
index fb9251b..d27993f 100644 (file)
@@ -35,16 +35,16 @@ START_TEST(ExDoubleList)
     KSPIN_LOCK SpinLock;
     LIST_ENTRY ListHead;
     PLIST_ENTRY Ret;
-    
+
     KeInitializeSpinLock(&SpinLock);
-    
+
     memset(&ListHead, 0x55, sizeof ListHead);
     InitializeListHead(&ListHead);
     ok_eq_pointer(ListHead.Flink, &ListHead);
     ok_eq_pointer(ListHead.Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedInsertHeadList(&ListHead, &Entries[0], &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &Entries[0]);
@@ -53,7 +53,7 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedRemoveHeadList(&ListHead, &SpinLock);
     ok_eq_pointer(Ret, &Entries[0]);
     ok_eq_pointer(ListHead.Flink, &ListHead);
@@ -62,7 +62,7 @@ START_TEST(ExDoubleList)
     ok_eq_free(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedRemoveHeadList(&ListHead, &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &ListHead);
@@ -71,7 +71,7 @@ START_TEST(ExDoubleList)
     ok_eq_free(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedInsertTailList(&ListHead, &Entries[0], &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &Entries[0]);
@@ -80,7 +80,7 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedRemoveHeadList(&ListHead, &SpinLock);
     ok_eq_pointer(Ret, &Entries[0]);
     ok_eq_pointer(ListHead.Flink, &ListHead);
@@ -89,7 +89,7 @@ START_TEST(ExDoubleList)
     ok_eq_free(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedRemoveHeadList(&ListHead, &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &ListHead);
@@ -98,7 +98,7 @@ START_TEST(ExDoubleList)
     ok_eq_free(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedInsertTailList(&ListHead, &Entries[0], &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &Entries[0]);
@@ -107,7 +107,7 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedInsertHeadList(&ListHead, &Entries[1], &SpinLock);
     ok_eq_pointer(Ret, &Entries[0]);
     ok_eq_pointer(ListHead.Flink, &Entries[1]);
@@ -118,7 +118,20 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(Entries[1].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
+    Ret = ExInterlockedInsertTailList(&ListHead, &Entries[2], &SpinLock);
+    ok_eq_pointer(Ret, &Entries[0]);
+    ok_eq_pointer(ListHead.Flink, &Entries[1]);
+    ok_eq_pointer(ListHead.Blink, &Entries[2]);
+    ok_eq_pointer(Entries[0].Flink, &Entries[2]);
+    ok_eq_pointer(Entries[0].Blink, &Entries[1]);
+    ok_eq_pointer(Entries[1].Flink, &Entries[0]);
+    ok_eq_pointer(Entries[1].Blink, &ListHead);
+    ok_eq_pointer(Entries[2].Flink, &ListHead);
+    ok_eq_pointer(Entries[2].Blink, &Entries[0]);
+    ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
+    ok_irql(PASSIVE_LEVEL);
+
     memset(Entries, 0x55, sizeof Entries);
 #undef ExInterlockedInsertHeadList
 #undef ExInterlockedInsertTailList
@@ -130,7 +143,7 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(ListHead.Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedInsertHeadList(&ListHead, &Entries[0], &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &Entries[0]);
@@ -139,7 +152,7 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedRemoveHeadList(&ListHead, &SpinLock);
     ok_eq_pointer(Ret, &Entries[0]);
     ok_eq_pointer(ListHead.Flink, &ListHead);
@@ -148,7 +161,7 @@ START_TEST(ExDoubleList)
     ok_eq_free2(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedRemoveHeadList(&ListHead, &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &ListHead);
@@ -157,7 +170,7 @@ START_TEST(ExDoubleList)
     ok_eq_free2(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedInsertTailList(&ListHead, &Entries[0], &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &Entries[0]);
@@ -166,7 +179,7 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedRemoveHeadList(&ListHead, &SpinLock);
     ok_eq_pointer(Ret, &Entries[0]);
     ok_eq_pointer(ListHead.Flink, &ListHead);
@@ -175,7 +188,7 @@ START_TEST(ExDoubleList)
     ok_eq_free2(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedRemoveHeadList(&ListHead, &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &ListHead);
@@ -184,7 +197,7 @@ START_TEST(ExDoubleList)
     ok_eq_free2(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedInsertTailList(&ListHead, &Entries[0], &SpinLock);
     ok_eq_pointer(Ret, NULL);
     ok_eq_pointer(ListHead.Flink, &Entries[0]);
@@ -193,7 +206,7 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(Entries[0].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
     Ret = ExInterlockedInsertHeadList(&ListHead, &Entries[1], &SpinLock);
     ok_eq_pointer(Ret, &Entries[0]);
     ok_eq_pointer(ListHead.Flink, &Entries[1]);
@@ -204,6 +217,19 @@ START_TEST(ExDoubleList)
     ok_eq_pointer(Entries[1].Blink, &ListHead);
     ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
     ok_irql(PASSIVE_LEVEL);
-    
+
+    Ret = ExInterlockedInsertTailList(&ListHead, &Entries[2], &SpinLock);
+    ok_eq_pointer(Ret, &Entries[0]);
+    ok_eq_pointer(ListHead.Flink, &Entries[1]);
+    ok_eq_pointer(ListHead.Blink, &Entries[2]);
+    ok_eq_pointer(Entries[0].Flink, &Entries[2]);
+    ok_eq_pointer(Entries[0].Blink, &Entries[1]);
+    ok_eq_pointer(Entries[1].Flink, &Entries[0]);
+    ok_eq_pointer(Entries[1].Blink, &ListHead);
+    ok_eq_pointer(Entries[2].Flink, &ListHead);
+    ok_eq_pointer(Entries[2].Blink, &Entries[0]);
+    ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:");
+    ok_irql(PASSIVE_LEVEL);
+
     KmtSetIrql(PASSIVE_LEVEL);
 }
diff --git a/kmtests/ntos_io/CMakeLists.txt b/kmtests/ntos_io/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8559c43
--- /dev/null
@@ -0,0 +1,15 @@
+include_directories(
+    ../include)
+
+list(APPEND EXAMPLE_DRV_SOURCE
+    ../kmtest_drv/kmtest_standalone.c
+    IoDriverObject_drv.c)
+
+add_library(iodriverobject_drv SHARED ${EXAMPLE_DRV_SOURCE})
+
+set_module_type(iodriverobject_drv kernelmodedriver)
+target_link_libraries(iodriverobject_drv kmtest_printf ${PSEH_LIB})
+add_importlibs(iodriverobject_drv ntoskrnl hal)
+set_property(TARGET iodriverobject_drv PROPERTY COMPILE_DEFINITIONS KMT_STANDALONE_DRIVER)
+
+add_cd_file(TARGET iodriverobject_drv DESTINATION reactos/bin FOR all)
diff --git a/kmtests/ntos_io/IoDriverObject_drv.c b/kmtests/ntos_io/IoDriverObject_drv.c
new file mode 100644 (file)
index 0000000..5c34eb7
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * PROJECT:         ReactOS kernel-mode tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Kernel-Mode Test Suite Driver Object Test Driver
+ * PROGRAMMER:      Michael Martin <martinmnet@hotmail.com>
+ *                  Thomas Faber <thfabba@gmx.de>
+ */
+
+#include <kmt_test.h>
+
+//#define NDEBUG
+#include <debug.h>
+
+typedef enum
+{
+    DriverEntry,
+    DriverIrp,
+    DriverUnload
+} DRIVER_STATUS;
+
+static KMT_IRP_HANDLER TestIrpHandler;
+static VOID TestDriverObject(IN PDRIVER_OBJECT DriverObject, IN DRIVER_STATUS DriverStatus);
+
+NTSTATUS
+TestEntry(
+    IN PDRIVER_OBJECT DriverObject,
+    IN PCUNICODE_STRING RegistryPath,
+    OUT PCWSTR *DeviceName,
+    OUT INT *Flags)
+{
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    PAGED_CODE();
+
+    UNREFERENCED_PARAMETER(RegistryPath);
+
+    *DeviceName = L"IoDriverObject";
+
+    KmtRegisterIrpHandler(IRP_MJ_CREATE, NULL, TestIrpHandler);
+    KmtRegisterIrpHandler(IRP_MJ_CLOSE, NULL, TestIrpHandler);
+
+    TestDriverObject(DriverObject, DriverEntry);
+
+    return Status;
+}
+
+VOID
+TestUnload(
+    IN PDRIVER_OBJECT DriverObject)
+{
+    PAGED_CODE();
+
+    TestDriverObject(DriverObject, DriverUnload);
+}
+
+static
+NTSTATUS
+TestIrpHandler(
+    IN PDEVICE_OBJECT DeviceObject,
+    IN PIRP Irp,
+    IN PIO_STACK_LOCATION IoStackLocation)
+{
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    TestDriverObject(DeviceObject->DriverObject, DriverIrp);
+
+    Irp->IoStatus.Status = Status;
+    Irp->IoStatus.Information = 0;
+
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+    return Status;
+}
+
+static
+VOID
+TestDriverObject(
+    IN PDRIVER_OBJECT DriverObject,
+    IN DRIVER_STATUS DriverStatus)
+{
+    BOOLEAN CheckThisDispatchRoutine;
+    PVOID FirstMajorFunc;
+    int i;
+
+    ok(DriverObject->Size == sizeof(DRIVER_OBJECT), "Size does not match, got %x",DriverObject->Size);
+    ok(DriverObject->Type == 4, "Type does not match 4. got %d",DriverObject->Type);
+
+    if (DriverStatus == DriverEntry)
+    {
+        ok(DriverObject->DeviceObject == NULL, "Expected DeviceObject pointer to be 0, got %p",
+            DriverObject->DeviceObject);
+        ok (DriverObject->Flags == DRVO_LEGACY_DRIVER,
+            "Expected Flags to be DRVO_LEGACY_DRIVER, got %lu",
+            DriverObject->Flags);
+    }
+    else if (DriverStatus == DriverIrp)
+    {
+        ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null");
+        ok (DriverObject->Flags == (DRVO_LEGACY_DRIVER | DRVO_INITIALIZED),
+            "Expected Flags to be DRVO_LEGACY_DRIVER | DRVO_INITIALIZED, got %lu",
+            DriverObject->Flags);
+    }
+    else if (DriverStatus == DriverUnload)
+    {
+        ok(DriverObject->DeviceObject != NULL, "Expected DeviceObject pointer to non null");
+        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",
+            DriverObject->Flags);
+    }
+    else
+        ASSERT(FALSE);
+
+    /* Select a routine that was not changed */
+    FirstMajorFunc = DriverObject->MajorFunction[1];
+    ok(FirstMajorFunc != 0, "Expected MajorFunction[1] to be non NULL");
+
+    if (!skip(FirstMajorFunc != NULL, "First major function not set!\n"))
+    {
+        for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
+        {
+            if (DriverStatus > 0) CheckThisDispatchRoutine = (i > 3) && (i != 14);
+            else CheckThisDispatchRoutine = TRUE;
+
+            if (CheckThisDispatchRoutine)
+            {
+                ok(DriverObject->MajorFunction[i] == FirstMajorFunc, "Expected MajorFunction[%d] to match %p",
+                    i, FirstMajorFunc);
+            }
+        }
+    }
+}
diff --git a/kmtests/ntos_io/IoDriverObject_user.c b/kmtests/ntos_io/IoDriverObject_user.c
new file mode 100644 (file)
index 0000000..87f9bd0
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * PROJECT:         ReactOS kernel-mode tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Kernel-Mode Test Suite Driver Object test user-mode part
+ * PROGRAMMER:      Thomas Faber <thfabba@gmx.de>
+ */
+
+#include <kmt_test.h>
+
+START_TEST(IoDriverObject)
+{
+    KmtLoadDriver(L"IoDriverObject", FALSE);
+    KmtOpenDriver();
+    KmtCloseDriver();
+    KmtUnloadDriver();
+}
diff --git a/kmtests/ntos_io/iodriverobject_drv.rbuild b/kmtests/ntos_io/iodriverobject_drv.rbuild
new file mode 100644 (file)
index 0000000..d8fb06c
--- /dev/null
@@ -0,0 +1,14 @@
+<module name="iodriverobject_drv" type="kernelmodedriver" installbase="bin" installname="iodriverobject_drv.sys">
+       <include base="kmtest_drv">include</include>
+       <library>ntoskrnl</library>
+       <library>hal</library>
+       <library>pseh</library>
+       <library>kmtest_printf</library>
+       <define name="KMT_STANDALONE_DRIVER" />
+       <file>IoDriverObject_drv.c</file>
+       <directory name="..">
+               <directory name="kmtest_drv">
+                       <file>kmtest_standalone.c</file>
+               </directory>
+       </directory>
+</module>