[KMTESTS\NTOS_KE] - Add KeTimer test stub which tests only KeInitializeTimerEx (Note...
authorRafal Harabien <rafalh@reactos.org>
Fri, 7 Oct 2011 16:13:03 +0000 (16:13 +0000)
committerRafal Harabien <rafalh@reactos.org>
Fri, 7 Oct 2011 16:13:03 +0000 (16:13 +0000)
svn path=/trunk/; revision=54047

rostests/kmtests/CMakeLists.txt
rostests/kmtests/kmtest_drv.rbuild
rostests/kmtests/kmtest_drv/testlist.c
rostests/kmtests/ntos_ke/KeTimer.c [new file with mode: 0644]

index 310d342..8011065 100644 (file)
@@ -43,6 +43,7 @@ list(APPEND KMTEST_DRV_SOURCE
     ntos_ke/KeIrql.c
     ntos_ke/KeProcessor.c
     ntos_ke/KeSpinLock.c
+    ntos_ke/KeTimer.c
     ntos_mm/MmSection.c
     ntos_ob/ObReference.c
     ntos_ob/ObType.c
index d9789a2..624b1b5 100644 (file)
@@ -43,6 +43,7 @@
                <file>KeIrql.c</file>
                <file>KeProcessor.c</file>
                <file>KeSpinLock.c</file>
+               <file>KeTimer.c</file>
        </directory>
        <directory name="ntos_mm">
                <file>MmSection.c</file>
index 4fffe48..2cf3727 100644 (file)
@@ -29,6 +29,7 @@ KMT_TESTFUNC Test_KeEvent;
 KMT_TESTFUNC Test_KeGuardedMutex;
 KMT_TESTFUNC Test_KeIrql;
 KMT_TESTFUNC Test_KeProcessor;
+KMT_TESTFUNC Test_KeTimer;
 KMT_TESTFUNC Test_KernelType;
 KMT_TESTFUNC Test_MmSection;
 KMT_TESTFUNC Test_ObReference;
@@ -63,6 +64,7 @@ const KMT_TEST TestList[] =
     { "KeGuardedMutex",                     Test_KeGuardedMutex },
     { "KeIrql",                             Test_KeIrql },
     { "-KeProcessor",                       Test_KeProcessor },
+    { "KeTimer",                            Test_KeTimer },
     { "-KernelType",                        Test_KernelType },
     { "MmSection",                          Test_MmSection },
     { "ObReference",                        Test_ObReference },
diff --git a/rostests/kmtests/ntos_ke/KeTimer.c b/rostests/kmtests/ntos_ke/KeTimer.c
new file mode 100644 (file)
index 0000000..69cb48f
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * PROJECT:         ReactOS kernel-mode tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Kernel-Mode Test Suite Timer test
+ * PROGRAMMER:      Rafal Harabien <rafalh@reactos.org>
+ */
+
+#include <kmt_test.h>
+
+#define CheckTimer(Timer, ExpectedType, State, ExpectedWaitNext,                \
+                            Irql, ThreadList, ThreadCount) do                   \
+{                                                                               \
+    INT TheIndex;                                                               \
+    PLIST_ENTRY TheEntry;                                                       \
+    PKTHREAD TheThread;                                                         \
+    ok_eq_uint((Timer)->Header.Type, ExpectedType);                             \
+    ok_eq_uint((Timer)->Header.Hand, sizeof *(Timer) / sizeof(ULONG));          \
+    ok_eq_hex((Timer)->Header.Lock & 0xFF00FF00L, 0x00005500L);                 \
+    ok_eq_long((Timer)->Header.SignalState, State);                             \
+    TheEntry = (Timer)->Header.WaitListHead.Flink;                              \
+    for (TheIndex = 0; TheIndex < (ThreadCount); ++TheIndex)                    \
+    {                                                                           \
+        TheThread = CONTAINING_RECORD(TheEntry, KTHREAD,                        \
+                                        WaitBlock[0].WaitListEntry);            \
+        ok_eq_pointer(TheThread, (ThreadList)[TheIndex]);                       \
+        ok_eq_pointer(TheEntry->Flink->Blink, TheEntry);                        \
+        TheEntry = TheEntry->Flink;                                             \
+    }                                                                           \
+    ok_eq_pointer(TheEntry, &(Timer)->Header.WaitListHead);                     \
+    ok_eq_pointer(TheEntry->Flink->Blink, TheEntry);                            \
+    ok_eq_long(KeReadStateTimer(Timer), State);                                 \
+    ok_eq_bool(Thread->WaitNext, ExpectedWaitNext);                             \
+    ok_irql(Irql);                                                              \
+} while (0)
+
+static
+VOID
+TestTimerFunctional(
+    IN PKTIMER Timer,
+    IN TIMER_TYPE Type,
+    IN KIRQL OriginalIrql)
+{
+    PKTHREAD Thread = KeGetCurrentThread();
+
+    memset(Timer, 0x55, sizeof *Timer);
+    KeInitializeTimerEx(Timer, Type);
+    CheckTimer(Timer, TimerNotificationObject + Type, 0L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
+}
+
+START_TEST(KeTimer)
+{
+    KTIMER Timer;
+    KIRQL Irql;
+    KIRQL Irqls[] = { PASSIVE_LEVEL, APC_LEVEL, DISPATCH_LEVEL, HIGH_LEVEL };
+    INT i;
+
+    for (i = 0; i < sizeof Irqls / sizeof Irqls[0]; ++i)
+    {
+        /* DRIVER_IRQL_NOT_LESS_OR_EQUAL (TODO: on MP only?) */
+        if (Irqls[i] > DISPATCH_LEVEL && KmtIsCheckedBuild)
+            return;
+        KeRaiseIrql(Irqls[i], &Irql);
+        TestTimerFunctional(&Timer, NotificationTimer, Irqls[i]);
+        TestTimerFunctional(&Timer, SynchronizationTimer, Irqls[i]);
+        KeLowerIrql(Irql);
+    }
+
+    ok_irql(PASSIVE_LEVEL);
+    KmtSetIrql(PASSIVE_LEVEL);
+}