1fad7614fddddaf264171de75adcc1031e2bdcbf
[reactos.git] / rostests / kmtests / ntos_ex / ExSequencedList.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite sequenced singly-linked list test
5 * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
6 */
7
8 struct _SINGLE_LIST_ENTRY;
9 union _SLIST_HEADER;
10 struct _SINGLE_LIST_ENTRY *__fastcall ExInterlockedPushEntrySList(union _SLIST_HEADER *, struct _SINGLE_LIST_ENTRY *, unsigned long *);
11 struct _SINGLE_LIST_ENTRY *__fastcall ExInterlockedPopEntrySList(union _SLIST_HEADER *, unsigned long *);
12
13 #include <kmt_test.h>
14
15 /* TODO: SLIST_HEADER is a lot different for x64 */
16
17 #define CheckSListHeader(ListHead, ExpectedPointer, ExpectedDepth) do \
18 { \
19 ok_eq_pointer((ListHead)->Next.Next, ExpectedPointer); \
20 /*ok_eq_pointer(FirstEntrySList(ListHead), ExpectedPointer);*/ \
21 ok_eq_uint((ListHead)->Depth, ExpectedDepth); \
22 ok_eq_uint((ListHead)->Sequence, ExpectedSequence); \
23 ok_eq_uint(ExQueryDepthSList(ListHead), ExpectedDepth); \
24 ok_irql(HIGH_LEVEL); \
25 ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:"); \
26 } while (0)
27
28 #define PXLIST_HEADER PSLIST_HEADER
29 #define PXLIST_ENTRY PSLIST_ENTRY
30 #define PushXList ExInterlockedPushEntrySList
31 #define PopXList ExInterlockedPopEntrySList
32 #define FlushXList ExInterlockedFlushSList
33 #define ok_free_xlist ok_eq_pointer
34 #define CheckXListHeader CheckSListHeader
35 #define TestXListFunctional TestSListFunctional
36 #include "ExXList.h"
37
38 #undef ExInterlockedPushEntrySList
39 #undef ExInterlockedPopEntrySList
40 #define TestXListFunctional TestSListFunctionalExports
41 #include "ExXList.h"
42
43 START_TEST(ExSequencedList)
44 {
45 PSLIST_HEADER ListHead;
46 KSPIN_LOCK SpinLock;
47 USHORT ExpectedSequence = 0;
48 PKSPIN_LOCK pSpinLock = &SpinLock;
49 PCHAR Buffer;
50 PSLIST_ENTRY Entries;
51 SIZE_T EntriesSize = 5 * sizeof *Entries;
52 KIRQL Irql;
53
54 KeInitializeSpinLock(&SpinLock);
55 #ifdef _M_IX86
56 pSpinLock = NULL;
57 #endif
58
59 /* make sure stuff is as un-aligned as possible ;) */
60 Buffer = ExAllocatePoolWithTag(NonPagedPool, sizeof *ListHead + EntriesSize + 1, 'TLqS');
61 ListHead = (PVOID)&Buffer[1];
62 Entries = (PVOID)&ListHead[1];
63 KeRaiseIrql(HIGH_LEVEL, &Irql);
64
65 RtlFillMemory(Entries, EntriesSize, 0x55);
66 RtlFillMemory(ListHead, sizeof *ListHead, 0x55);
67 InitializeSListHead(ListHead);
68 CheckSListHeader(ListHead, NULL, 0);
69 TestSListFunctional(ListHead, Entries, pSpinLock);
70
71 RtlFillMemory(Entries, EntriesSize, 0x55);
72 RtlFillMemory(ListHead, sizeof *ListHead, 0x55);
73 ExInitializeSListHead(ListHead);
74 CheckSListHeader(ListHead, NULL, 0);
75 TestSListFunctionalExports(ListHead, Entries, pSpinLock);
76
77 KeLowerIrql(Irql);
78 ExFreePoolWithTag(Buffer, 'TLqS');
79 }