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>
8 /* TODO: PoolsCorruption tests fail because accessing invalid memory doesn't necessarily cause an access violation */
15 #define TAG_POOLTEST 'tstP'
17 static VOID
PoolsTest(VOID
)
20 ULONG AllocSize
, i
, AllocNumber
;
23 // Stress-test nonpaged pool
24 for (i
=1; i
<10000; i
++)
26 // make up some increasing, a bit irregular size
35 // start with non-paged pool
36 Ptr
= ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
38 // it may fail due to no-memory condition
41 // try to fully fill it
42 RtlFillMemory(Ptr
, AllocSize
, 0xAB);
45 ExFreePoolWithTag(Ptr
, TAG_POOLTEST
);
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(PagedPool
, 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
);
73 // test super-big allocations
74 /*AllocSize = 2UL * 1024 * 1024 * 1024;
75 Ptr = ExAllocatePoolWithTag(NonPagedPool, AllocSize, TAG_POOLTEST);
76 ok(Ptr == NULL, "Allocating 2Gb of nonpaged pool should fail\n");
78 Ptr = ExAllocatePoolWithTag(PagedPool, AllocSize, TAG_POOLTEST);
79 ok(Ptr == NULL, "Allocating 2Gb of paged pool should fail\n");*/
81 // now test allocating lots of small/medium blocks
83 Allocs
= ExAllocatePoolWithTag(PagedPool
, sizeof(Allocs
) * AllocNumber
, TAG_POOLTEST
);
86 for (i
=0; i
<AllocNumber
; i
++)
89 Allocs
[i
] = ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
93 for (i
=0; i
<AllocNumber
; i
++)
95 ExFreePoolWithTag(Allocs
[i
], TAG_POOLTEST
);
99 ExFreePoolWithTag(Allocs
, TAG_POOLTEST
);
102 static VOID
PoolsCorruption(VOID
)
106 NTSTATUS Status
= STATUS_SUCCESS
;
108 // start with non-paged pool
109 AllocSize
= 4096 + 0x10;
110 Ptr
= ExAllocatePoolWithTag(NonPagedPool
, AllocSize
, TAG_POOLTEST
);
112 // touch all bytes, it shouldn't cause an exception
113 RtlZeroMemory(Ptr
, AllocSize
);
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
);
144 ExFreePoolWithTag(Ptr
, TAG_POOLTEST
);