2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Pools test routines KM-Test
5 * PROGRAMMER: Aleksey Bragin <aleksey@reactos.org>
13 #define TAG_POOLTEST 'tstP'
15 static VOID
PoolsTest(VOID
)
18 ULONG AllocSize
, i
, AllocNumber
;
21 // Stress-test nonpaged pool
22 for (i
=1; i
<10000; i
++)
24 // make up some increasing, a bit irregular size
33 // start with non-paged pool
34 Ptr
= ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
36 // it may fail due to no-memory condition
39 // try to fully fill it
40 RtlFillMemory(Ptr
, AllocSize
, 0xAB);
43 ExFreePoolWithTag(Ptr
, TAG_POOLTEST
);
47 for (i
=1; i
<10000; i
++)
49 // make up some increasing, a bit irregular size
58 // start with non-paged pool
59 Ptr
= ExAllocatePoolWithTag(PagedPool
, AllocSize
, TAG_POOLTEST
);
61 // it may fail due to no-memory condition
64 // try to fully fill it
65 RtlFillMemory(Ptr
, AllocSize
, 0xAB);
68 ExFreePoolWithTag(Ptr
, TAG_POOLTEST
);
71 // test super-big allocations
72 /*AllocSize = 2UL * 1024 * 1024 * 1024;
73 Ptr = ExAllocatePoolWithTag(NonPagedPool, AllocSize, TAG_POOLTEST);
74 ok(Ptr == NULL, "Allocating 2Gb of nonpaged pool should fail\n");
76 Ptr = ExAllocatePoolWithTag(PagedPool, AllocSize, TAG_POOLTEST);
77 ok(Ptr == NULL, "Allocating 2Gb of paged pool should fail\n");*/
79 // now test allocating lots of small/medium blocks
81 Allocs
= ExAllocatePoolWithTag(PagedPool
, sizeof(Allocs
) * AllocNumber
, TAG_POOLTEST
);
84 for (i
=0; i
<AllocNumber
; i
++)
87 Allocs
[i
] = ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
91 for (i
=0; i
<AllocNumber
; i
++)
93 ExFreePoolWithTag(Allocs
[i
], TAG_POOLTEST
);
97 ExFreePoolWithTag(Allocs
, TAG_POOLTEST
);
100 static VOID
PoolsCorruption(VOID
)
105 // start with non-paged pool
106 AllocSize
= 4096 + 0x10;
107 Ptr
= ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
109 // touch all bytes, it shouldn't cause an exception
110 RtlZeroMemory(Ptr
, AllocSize
);
112 /* TODO: These fail because accessing invalid memory doesn't necessarily
113 cause an access violation */
114 #ifdef THIS_DOESNT_WORK
115 // test buffer overrun, right after our allocation ends
118 TestPtr
= (PULONG
)((PUCHAR
)Ptr
+ AllocSize
);
119 //Ptr[4] = 0xd33dbeef;
120 *TestPtr
= 0xd33dbeef;
122 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
125 Status
= _SEH2_GetExceptionCode();
128 ok(Status
== STATUS_ACCESS_VIOLATION
, "Exception should occur, but got Status 0x%08lX\n", Status
);
130 // test overrun in a distant byte range, but within 4096KB
133 Ptr
[2020] = 0xdeadb33f;
135 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
138 Status
= _SEH2_GetExceptionCode();
141 ok(Status
== STATUS_ACCESS_VIOLATION
, "Exception should occur, but got Status 0x%08lX\n", Status
);
145 ExFreePoolWithTag(Ptr
, TAG_POOLTEST
);
154 Memory
= ExAllocatePoolWithTag(PagedPool
, 8, 'MyTa');
155 ok_eq_tag(KmtGetPoolTag(Memory
), 'MyTa');
156 ExFreePoolWithTag(Memory
, 'MyTa');
158 Memory
= ExAllocatePoolWithTag(PagedPool
, PAGE_SIZE
, 'MyTa');
159 ok_eq_tag(KmtGetPoolTag(Memory
), 'TooL');
160 ExFreePoolWithTag(Memory
, 'MyTa');
162 Memory
= ExAllocatePoolWithTag(PagedPool
, PAGE_SIZE
- 3 * sizeof(PVOID
), 'MyTa');
163 ok_eq_tag(KmtGetPoolTag(Memory
), 'TooL');
164 ExFreePoolWithTag(Memory
, 'MyTa');
166 Memory
= ExAllocatePoolWithTag(PagedPool
, PAGE_SIZE
- 4 * sizeof(PVOID
) + 1, 'MyTa');
167 ok_eq_tag(KmtGetPoolTag(Memory
), 'TooL');
168 ExFreePoolWithTag(Memory
, 'MyTa');
170 Memory
= ExAllocatePoolWithTag(PagedPool
, PAGE_SIZE
- 4 * sizeof(PVOID
), 'MyTa');
171 ok_eq_tag(KmtGetPoolTag(Memory
), 'MyTa');
172 ExFreePoolWithTag(Memory
, 'MyTa');