/* * PROJECT: ReactOS kernel-mode tests * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory * PURPOSE: Kernel-Mode Test Suite Pools test routines KM-Test * PROGRAMMER: Aleksey Bragin */ #include #define NDEBUG #include #define TAG_POOLTEST 'tstP' #define BASE_POOL_TYPE_MASK 1 #define QUOTA_POOL_MASK 8 static LONG GetRefCount( _In_ PVOID Object) { POBJECT_HEADER Header = OBJECT_TO_OBJECT_HEADER(Object); return Header->PointerCount; } static VOID PoolsTest(VOID) { PVOID Ptr; ULONG AllocSize, i, AllocNumber; PVOID *Allocs; // Stress-test nonpaged pool for (i=1; i<10000; i++) { // make up some increasing, a bit irregular size AllocSize = i*10; if (i % 10) AllocSize++; if (i % 25) AllocSize += 13; // start with non-paged pool Ptr = ExAllocatePoolWithTag(NonPagedPool, AllocSize, TAG_POOLTEST); // it may fail due to no-memory condition if (!Ptr) break; // try to fully fill it RtlFillMemory(Ptr, AllocSize, 0xAB); // free it ExFreePoolWithTag(Ptr, TAG_POOLTEST); } // now paged one for (i=1; i<10000; i++) { // make up some increasing, a bit irregular size AllocSize = i*50; if (i % 10) AllocSize++; if (i % 25) AllocSize += 13; // start with non-paged pool Ptr = ExAllocatePoolWithTag(PagedPool, AllocSize, TAG_POOLTEST); // it may fail due to no-memory condition if (!Ptr) break; // try to fully fill it RtlFillMemory(Ptr, AllocSize, 0xAB); // free it ExFreePoolWithTag(Ptr, TAG_POOLTEST); } // test super-big allocations /*AllocSize = 2UL * 1024 * 1024 * 1024; Ptr = ExAllocatePoolWithTag(NonPagedPool, AllocSize, TAG_POOLTEST); ok(Ptr == NULL, "Allocating 2Gb of nonpaged pool should fail\n"); Ptr = ExAllocatePoolWithTag(PagedPool, AllocSize, TAG_POOLTEST); ok(Ptr == NULL, "Allocating 2Gb of paged pool should fail\n");*/ // now test allocating lots of small/medium blocks AllocNumber = 100000; Allocs = ExAllocatePoolWithTag(PagedPool, sizeof(*Allocs) * AllocNumber, TAG_POOLTEST); // alloc blocks for (i=0; i