2 * NTOSKRNL Pools test routines KM-Test
3 * ReactOS Kernel Mode Regression Testing framework
5 * Copyright 2008 Aleksey Bragin <aleksey@reactos.org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; see the file COPYING.LIB.
19 * If not, write to the Free Software Foundation,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /* INCLUDES *******************************************************************/
25 #include <ddk/ntddk.h>
27 #include <ndk/ntndk.h>
28 /* SEH support with PSEH */
29 #include <pseh/pseh2.h>
35 #define TAG_POOLTEST 'tstP'
37 /* PUBLIC FUNCTIONS ***********************************************************/
40 PoolsTest(HANDLE KeyHandle
)
43 ULONG AllocSize
, i
, AllocNumber
;
48 // Stress-test nonpaged pool
49 for (i
=1; i
<10000; i
++)
51 // make up some increasing, a bit irregular size
60 // start with non-paged pool
61 Ptr
= ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
63 // it may fail due to no-memory condition
66 // try to fully fill it
67 RtlFillMemory(Ptr
, AllocSize
, 0xAB);
70 ExFreePoolWithTag(Ptr
, TAG_POOLTEST
);
74 for (i
=1; i
<10000; i
++)
76 // make up some increasing, a bit irregular size
85 // start with non-paged pool
86 Ptr
= ExAllocatePoolWithTag(PagedPool
, AllocSize
, TAG_POOLTEST
);
88 // it may fail due to no-memory condition
91 // try to fully fill it
92 RtlFillMemory(Ptr
, AllocSize
, 0xAB);
95 ExFreePoolWithTag(Ptr
, TAG_POOLTEST
);
98 // test super-big allocations
99 /*AllocSize = 2UL * 1024 * 1024 * 1024;
100 Ptr = ExAllocatePoolWithTag(NonPagedPool, AllocSize, TAG_POOLTEST);
101 ok(Ptr == NULL, "Allocating 2Gb of nonpaged pool should fail\n");
103 Ptr = ExAllocatePoolWithTag(PagedPool, AllocSize, TAG_POOLTEST);
104 ok(Ptr == NULL, "Allocating 2Gb of paged pool should fail\n");*/
106 // now test allocating lots of small/medium blocks
107 AllocNumber
= 100000;
108 Allocs
= ExAllocatePoolWithTag(PagedPool
, sizeof(Allocs
) * AllocNumber
, TAG_POOLTEST
);
111 for (i
=0; i
<AllocNumber
; i
++)
114 Allocs
[i
] = ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
118 for (i
=0; i
<AllocNumber
; i
++)
120 ExFreePoolWithTag(Allocs
[i
], TAG_POOLTEST
);
124 ExFreePoolWithTag(Allocs
, TAG_POOLTEST
);
127 FinishTest(KeyHandle
, L
"MmPoolAllocTest");
131 PoolsCorruption(HANDLE KeyHandle
)
135 NTSTATUS Status
= STATUS_SUCCESS
;
139 // start with non-paged pool
140 AllocSize
= 4096 + 0x10;
141 Ptr
= ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
143 // touch all bytes, it shouldn't cause an exception
144 RtlZeroMemory(Ptr
, AllocSize
);
146 // test buffer overrun, right after our allocation ends
149 TestPtr
= (PULONG
)((PUCHAR
)Ptr
+ AllocSize
);
150 //Ptr[4] = 0xd33dbeef;
151 *TestPtr
= 0xd33dbeef;
153 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
156 Status
= _SEH2_GetExceptionCode();
159 ok(Status
== STATUS_ACCESS_VIOLATION
, "Exception should occur, but got Status 0x%08lX\n", Status
);
161 // test overrun in a distant byte range, but within 4096KB
164 Ptr
[2020] = 0xdeadb33f;
166 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
169 Status
= _SEH2_GetExceptionCode();
172 ok(Status
== STATUS_ACCESS_VIOLATION
, "Exception should occur, but got Status 0x%08lX\n", Status
);
175 ExFreePoolWithTag(Ptr
, TAG_POOLTEST
);
177 FinishTest(KeyHandle
, L
"MmPoolCorruptionTest");