Author: tfaber
Date: Fri Sep 28 07:09:08 2012
New Revision: 57408
URL:
http://svn.reactos.org/svn/reactos?rev=57408&view=rev
Log:
[KMTESTS:KE]
- Add test for KeInitializeMutant vs KeInitializeMutex. Dedicated to Mike.
Added:
trunk/rostests/kmtests/ntos_ke/KeMutex.c (with props)
Modified:
trunk/rostests/kmtests/CMakeLists.txt
trunk/rostests/kmtests/kmtest_drv/testlist.c
Modified: trunk/rostests/kmtests/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/CMakeLists.txt?re…
==============================================================================
--- trunk/rostests/kmtests/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/rostests/kmtests/CMakeLists.txt [iso-8859-1] Fri Sep 28 07:09:08 2012
@@ -45,6 +45,7 @@
ntos_ke/KeEvent.c
ntos_ke/KeGuardedMutex.c
ntos_ke/KeIrql.c
+ ntos_ke/KeMutex.c
ntos_ke/KeProcessor.c
ntos_ke/KeSpinLock.c
ntos_ke/KeTimer.c
Modified: trunk/rostests/kmtests/kmtest_drv/testlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/kmtest_drv/testli…
==============================================================================
--- trunk/rostests/kmtests/kmtest_drv/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/kmtests/kmtest_drv/testlist.c [iso-8859-1] Fri Sep 28 07:09:08 2012
@@ -30,6 +30,7 @@
KMT_TESTFUNC Test_KeEvent;
KMT_TESTFUNC Test_KeGuardedMutex;
KMT_TESTFUNC Test_KeIrql;
+KMT_TESTFUNC Test_KeMutex;
KMT_TESTFUNC Test_KeProcessor;
KMT_TESTFUNC Test_KeTimer;
KMT_TESTFUNC Test_KernelType;
@@ -70,6 +71,7 @@
{ "KeEvent", Test_KeEvent },
{ "KeGuardedMutex", Test_KeGuardedMutex },
{ "KeIrql", Test_KeIrql },
+ { "KeMutex", Test_KeMutex },
{ "-KeProcessor", Test_KeProcessor },
{ "KeTimer", Test_KeTimer },
{ "-KernelType", Test_KernelType },
Added: trunk/rostests/kmtests/ntos_ke/KeMutex.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/ntos_ke/KeMutex.c…
==============================================================================
--- trunk/rostests/kmtests/ntos_ke/KeMutex.c (added)
+++ trunk/rostests/kmtests/ntos_ke/KeMutex.c [iso-8859-1] Fri Sep 28 07:09:08 2012
@@ -1,0 +1,98 @@
+/*
+ * PROJECT: ReactOS kernel-mode tests
+ * LICENSE: GPLv2+ - See COPYING in the top level directory
+ * PURPOSE: Kernel-Mode Test Suite Mutant/Mutex test
+ * PROGRAMMER: Thomas Faber <thfabba(a)gmx.de>
+ */
+
+#include <kmt_test.h>
+
+#define ULONGS_PER_POINTER (sizeof(PVOID) / sizeof(ULONG))
+#define MUTANT_SIZE (2 + 6 * ULONGS_PER_POINTER)
+
+C_ASSERT(sizeof(DISPATCHER_HEADER) == 8 + 2 * sizeof(PVOID));
+C_ASSERT(sizeof(KMUTANT) == sizeof(DISPATCHER_HEADER) + 3 * sizeof(PVOID) +
sizeof(PVOID));
+C_ASSERT(sizeof(KMUTANT) == MUTANT_SIZE * sizeof(ULONG));
+
+#define CheckMutex(Mutex, Held, New, ExpectedApcDisable) do { \
+ PKTHREAD Thread = KeGetCurrentThread(); \
+ ok_eq_uint((Mutex)->Header.Type, MutantObject); \
+ ok_eq_uint((Mutex)->Header.Abandoned, 0x55); \
+ ok_eq_uint((Mutex)->Header.Size, MUTANT_SIZE); \
+ ok_eq_uint((Mutex)->Header.DpcActive, 0x55); \
+ ok_eq_pointer((Mutex)->Header.WaitListHead.Flink, \
+ &(Mutex)->Header.WaitListHead); \
+ ok_eq_pointer((Mutex)->Header.WaitListHead.Blink, \
+ &(Mutex)->Header.WaitListHead); \
+ if (Held) \
+ { \
+ ok_eq_long((Mutex)->Header.SignalState, 0); \
+ ok_eq_pointer((Mutex)->MutantListEntry.Flink, &Thread->MutantListHead);
\
+ ok_eq_pointer((Mutex)->MutantListEntry.Blink, &Thread->MutantListHead);
\
+ ok_eq_pointer(Thread->MutantListHead.Flink, &(Mutex)->MutantListEntry);
\
+ ok_eq_pointer(Thread->MutantListHead.Blink, &(Mutex)->MutantListEntry);
\
+ ok_eq_pointer((Mutex)->OwnerThread, Thread); \
+ } \
+ else \
+ { \
+ ok_eq_long((Mutex)->Header.SignalState, 1); \
+ if (New) \
+ { \
+ ok_eq_pointer((Mutex)->MutantListEntry.Flink, \
+ (PVOID)0x5555555555555555ULL); \
+ ok_eq_pointer((Mutex)->MutantListEntry.Blink, \
+ (PVOID)0x5555555555555555ULL); \
+ } \
+ ok_eq_pointer(Thread->MutantListHead.Flink, &Thread->MutantListHead);
\
+ ok_eq_pointer(Thread->MutantListHead.Blink, &Thread->MutantListHead);
\
+ ok_eq_pointer((Mutex)->OwnerThread, NULL); \
+ } \
+ ok_eq_uint((Mutex)->Abandoned, 0); \
+ ok_eq_uint((Mutex)->ApcDisable, ExpectedApcDisable); \
+} while (0)
+
+static
+VOID
+TestMutant(VOID)
+{
+ KMUTANT Mutant;
+ PKTHREAD Thread = KeGetCurrentThread();
+ LONG State;
+
+ RtlFillMemory(&Mutant, sizeof(Mutant), 0x55);
+ KeInitializeMutant(&Mutant, FALSE);
+ ok_irql(PASSIVE_LEVEL);
+ CheckMutex(&Mutant, FALSE, TRUE, 0);
+
+ RtlFillMemory(&Mutant, sizeof(Mutant), 0x55);
+ KeInitializeMutant(&Mutant, TRUE);
+ ok_irql(PASSIVE_LEVEL);
+ CheckMutex(&Mutant, TRUE, TRUE, 0);
+ State = KeReleaseMutant(&Mutant, 1, FALSE, FALSE);
+ ok_eq_long(State, 0);
+ ok_irql(PASSIVE_LEVEL);
+ CheckMutex(&Mutant, FALSE, FALSE, 0);
+}
+
+static
+VOID
+TestMutex(VOID)
+{
+ KMUTEX Mutex;
+
+ RtlFillMemory(&Mutex, sizeof(Mutex), 0x55);
+ KeInitializeMutex(&Mutex, 0);
+ ok_irql(PASSIVE_LEVEL);
+ CheckMutex(&Mutex, FALSE, TRUE, 1);
+
+ RtlFillMemory(&Mutex, sizeof(Mutex), 0x55);
+ KeInitializeMutex(&Mutex, 123);
+ ok_irql(PASSIVE_LEVEL);
+ CheckMutex(&Mutex, FALSE, TRUE, 1);
+}
+
+START_TEST(KeMutex)
+{
+ TestMutant();
+ TestMutex();
+}
Propchange: trunk/rostests/kmtests/ntos_ke/KeMutex.c
------------------------------------------------------------------------------
svn:eol-style = native