mirror of
https://github.com/reactos/reactos.git
synced 2025-05-06 18:31:26 +00:00
[KMTESTS:KE]
- Add test for KeInitializeMutant vs KeInitializeMutex. Dedicated to Mike. svn path=/trunk/; revision=57408
This commit is contained in:
parent
0ad6bb0b52
commit
f00cc3de89
3 changed files with 101 additions and 0 deletions
|
@ -45,6 +45,7 @@ list(APPEND KMTEST_DRV_SOURCE
|
|||
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
|
||||
|
|
|
@ -30,6 +30,7 @@ KMT_TESTFUNC Test_KeDpc;
|
|||
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 @@ const KMT_TEST TestList[] =
|
|||
{ "KeEvent", Test_KeEvent },
|
||||
{ "KeGuardedMutex", Test_KeGuardedMutex },
|
||||
{ "KeIrql", Test_KeIrql },
|
||||
{ "KeMutex", Test_KeMutex },
|
||||
{ "-KeProcessor", Test_KeProcessor },
|
||||
{ "KeTimer", Test_KeTimer },
|
||||
{ "-KernelType", Test_KernelType },
|
||||
|
|
98
rostests/kmtests/ntos_ke/KeMutex.c
Normal file
98
rostests/kmtests/ntos_ke/KeMutex.c
Normal file
|
@ -0,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@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();
|
||||
}
|
Loading…
Reference in a new issue