void TestMallocExtension(void) { int blocks; size_t total; int hist[64]; char buffer[200]; char* x = (char*)malloc(10); MallocExtension_VerifyAllMemory(); MallocExtension_VerifyMallocMemory(x); MallocExtension_MallocMemoryStats(&blocks, &total, hist); MallocExtension_GetStats(buffer, sizeof(buffer)); if (!MallocExtension_GetNumericProperty("generic.current_allocated_bytes", &total)) { FAIL("GetNumericProperty failed for generic.current_allocated_bytes"); } if (total < 10) { FAIL("GetNumericProperty had bad return for generic.current_allocated_bytes"); } if (!MallocExtension_GetNumericProperty("generic.current_allocated_bytes", &total)) { FAIL("GetNumericProperty failed for generic.current_allocated_bytes"); } MallocExtension_MarkThreadIdle(); MallocExtension_MarkThreadBusy(); MallocExtension_ReleaseToSystem(1); MallocExtension_ReleaseFreeMemory(); if (MallocExtension_GetEstimatedAllocatedSize(10) < 10) { FAIL("GetEstimatedAllocatedSize returned a bad value (too small)"); } if (MallocExtension_GetAllocatedSize(x) < 10) { FAIL("GetEstimatedAllocatedSize returned a bad value (too small)"); } free(x); }
void TestMallocExtension(void) { int blocks; size_t total; int hist[64]; char buffer[200]; char* x = (char*)malloc(10); MallocExtension_VerifyAllMemory(); MallocExtension_VerifyMallocMemory(x); MallocExtension_MallocMemoryStats(&blocks, &total, hist); MallocExtension_GetStats(buffer, sizeof(buffer)); if (!MallocExtension_GetNumericProperty("generic.current_allocated_bytes", &total)) { FAIL("GetNumericProperty failed for generic.current_allocated_bytes"); } if (total < 10) { FAIL("GetNumericProperty had bad return for generic.current_allocated_bytes"); } if (!MallocExtension_GetNumericProperty("generic.current_allocated_bytes", &total)) { FAIL("GetNumericProperty failed for generic.current_allocated_bytes"); } MallocExtension_MarkThreadIdle(); MallocExtension_MarkThreadBusy(); MallocExtension_ReleaseToSystem(1); MallocExtension_ReleaseFreeMemory(); if (MallocExtension_GetEstimatedAllocatedSize(10) < 10) { FAIL("GetEstimatedAllocatedSize returned a bad value (too small)"); } if (MallocExtension_GetAllocatedSize(x) < 10) { FAIL("GetEstimatedAllocatedSize returned a bad value (too small)"); } if (MallocExtension_GetOwnership(x) != MallocExtension_kOwned) { FAIL("DidAllocatePtr returned a bad value (kNotOwned)"); } /* TODO(csilvers): this relies on undocumented behavior that GetOwnership works on stack-allocated variables. Use a better test. */ if (MallocExtension_GetOwnership(hist) != MallocExtension_kNotOwned) { FAIL("DidAllocatePtr returned a bad value (kOwned)"); } free(x); }