[KMTESTS/IO]
authorThomas Faber <thomas.faber@reactos.org>
Wed, 24 Aug 2011 14:09:53 +0000 (14:09 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Wed, 24 Aug 2011 14:09:53 +0000 (14:09 +0000)
- Add IoInterrupt test with a simple test for KeSynchronizeExecution

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

kmtests/CMakeLists.txt
kmtests/kmtest_drv.rbuild
kmtests/kmtest_drv/testlist.c
kmtests/ntos_io/IoInterrupt.c [new file with mode: 0644]

index ca5c0d1..864d202 100644 (file)
@@ -27,6 +27,7 @@ list(APPEND KMTEST_DRV_SOURCE
     ntos_ex/ExTimer.c
     ntos_fsrtl/FsRtlExpression.c
     ntos_io/IoDeviceInterface.c
+    ntos_io/IoInterrupt.c
     ntos_io/IoIrp.c
     ntos_io/IoMdl.c
     ntos_ke/KeApc.c
index 2226807..f77b3cd 100644 (file)
@@ -30,6 +30,7 @@
        </directory>
        <directory name="ntos_io">
                <file>IoDeviceInterface.c</file>
+               <file>IoInterrupt.c</file>
                <file>IoIrp.c</file>
                <file>IoMdl.c</file>
        </directory>
index 6562c0e..c57cad9 100644 (file)
@@ -20,6 +20,7 @@ KMT_TESTFUNC Test_ExSingleList;
 KMT_TESTFUNC Test_ExTimer;
 KMT_TESTFUNC Test_FsRtlExpression;
 KMT_TESTFUNC Test_IoDeviceInterface;
+KMT_TESTFUNC Test_IoInterrupt;
 KMT_TESTFUNC Test_IoIrp;
 KMT_TESTFUNC Test_IoMdl;
 KMT_TESTFUNC Test_KeApc;
@@ -51,6 +52,7 @@ const KMT_TEST TestList[] =
     { "Example",                            Test_Example },
     { "FsRtlExpression",                    Test_FsRtlExpression },
     { "IoDeviceInterface",                  Test_IoDeviceInterface },
+    { "IoInterrupt",                        Test_IoInterrupt },
     { "IoIrp",                              Test_IoIrp },
     { "IoMdl",                              Test_IoMdl },
     { "KeApc",                              Test_KeApc },
diff --git a/kmtests/ntos_io/IoInterrupt.c b/kmtests/ntos_io/IoInterrupt.c
new file mode 100644 (file)
index 0000000..0f4d8de
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * PROJECT:         ReactOS kernel-mode tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Kernel-Mode Test Suite Interrupt test
+ * PROGRAMMER:      Thomas Faber <thfabba@gmx.de>
+ */
+
+#include <kmt_test.h>
+
+#define NDEBUG
+#include <debug.h>
+
+#define CheckSpinLock(Lock, Locked) do                  \
+{                                                       \
+    if (KmtIsMultiProcessorBuild)                       \
+        ok_eq_ulongptr(*(Lock), (Locked) != 0);         \
+    else                                                \
+        ok_eq_ulongptr(*(Lock), 0);                     \
+} while (0)
+
+typedef struct
+{
+    BOOLEAN ReturnValue;
+    KIRQL ExpectedIrql;
+    PKINTERRUPT Interrupt;
+} TEST_CONTEXT, *PTEST_CONTEXT;
+
+static KSYNCHRONIZE_ROUTINE SynchronizeRoutine;
+
+static
+BOOLEAN
+NTAPI
+SynchronizeRoutine(
+    IN PVOID Context)
+{
+    PTEST_CONTEXT TestContext = Context;
+
+    ok_irql(TestContext->ExpectedIrql);
+
+    CheckSpinLock(TestContext->Interrupt->ActualLock, TRUE);
+
+    return TestContext->ReturnValue;
+}
+
+static
+VOID
+TestSynchronizeExecution(VOID)
+{
+    KINTERRUPT Interrupt;
+    TEST_CONTEXT TestContext;
+    KIRQL SynchIrql;
+    KIRQL OriginalIrql;
+    KIRQL Irql;
+    KSPIN_LOCK ActualLock;
+    BOOLEAN Ret;
+
+    RtlFillMemory(&Interrupt, sizeof Interrupt, 0x55);
+    Interrupt.ActualLock = &ActualLock;
+    KeInitializeSpinLock(Interrupt.ActualLock);
+    CheckSpinLock(Interrupt.ActualLock, FALSE);
+
+    TestContext.Interrupt = &Interrupt;
+    TestContext.ReturnValue = TRUE;
+
+    for (TestContext.ReturnValue = 0; TestContext.ReturnValue <= 2; ++TestContext.ReturnValue)
+    {
+        for (OriginalIrql = PASSIVE_LEVEL; OriginalIrql <= HIGH_LEVEL; ++OriginalIrql)
+        {
+            /* TODO: don't hardcode this :| */
+            if (OriginalIrql == 3 || (OriginalIrql >= 11 && OriginalIrql <= 26) || OriginalIrql == 30)
+                continue;
+            KeRaiseIrql(OriginalIrql, &Irql);
+            for (SynchIrql = max(DISPATCH_LEVEL, OriginalIrql); SynchIrql <= HIGH_LEVEL; ++SynchIrql)
+            {
+                if (SynchIrql == 3 || (SynchIrql >= 11 && SynchIrql <= 26) || SynchIrql == 30)
+                    continue;
+                Interrupt.SynchronizeIrql = SynchIrql;
+                ok_irql(OriginalIrql);
+                CheckSpinLock(Interrupt.ActualLock, FALSE);
+                TestContext.ExpectedIrql = SynchIrql;
+                Ret = KeSynchronizeExecution(&Interrupt, SynchronizeRoutine, &TestContext);
+                ok_eq_int(Ret, TestContext.ReturnValue);
+                ok_irql(OriginalIrql);
+                CheckSpinLock(Interrupt.ActualLock, FALSE);
+                /* TODO: Check that all other fields of the interrupt are untouched */
+            }
+            KeLowerIrql(Irql);
+        }
+    }
+}
+
+START_TEST(IoInterrupt)
+{
+    TestSynchronizeExecution();
+}