mirror of
https://github.com/gperftools/gperftools
synced 2025-02-14 10:27:00 +00:00
clean up and gtest-ify large_heap_fragmentation_unittest
This commit is contained in:
parent
27a57a1b30
commit
159c9e5c53
@ -574,7 +574,7 @@ if(BUILD_TESTING)
|
||||
add_executable(tcmalloc_minimal_large_heap_fragmentation_unittest
|
||||
src/tests/large_heap_fragmentation_unittest.cc)
|
||||
target_link_libraries(
|
||||
tcmalloc_minimal_large_heap_fragmentation_unittest tcmalloc_minimal)
|
||||
tcmalloc_minimal_large_heap_fragmentation_unittest tcmalloc_minimal gtest)
|
||||
add_test(tcmalloc_minimal_large_heap_fragmentation_unittest tcmalloc_minimal_large_heap_fragmentation_unittest)
|
||||
|
||||
add_executable(addressmap_unittest
|
||||
@ -802,7 +802,7 @@ if(GPERFTOOLS_BUILD_HEAP_CHECKER OR GPERFTOOLS_BUILD_HEAP_PROFILER)
|
||||
add_test(tcmalloc_large_unittest tcmalloc_large_unittest)
|
||||
|
||||
add_executable(tcmalloc_large_heap_fragmentation_unittest src/tests/large_heap_fragmentation_unittest.cc)
|
||||
target_link_libraries(tcmalloc_large_heap_fragmentation_unittest tcmalloc)
|
||||
target_link_libraries(tcmalloc_large_heap_fragmentation_unittest tcmalloc gtest)
|
||||
add_test(tcmalloc_large_heap_fragmentation_unittest tcmalloc_large_heap_fragmentation_unittest)
|
||||
|
||||
# sampler_test and sampling_test both require sampling to be turned
|
||||
|
@ -404,7 +404,8 @@ tcmalloc_minimal_large_unittest_LDADD = libtcmalloc_minimal.la
|
||||
TESTS += tcmalloc_minimal_large_heap_fragmentation_unittest
|
||||
tcmalloc_minimal_large_heap_fragmentation_unittest_SOURCES = src/tests/large_heap_fragmentation_unittest.cc
|
||||
tcmalloc_minimal_large_heap_fragmentation_unittest_LDFLAGS = $(TCMALLOC_FLAGS) $(AM_LDFLAGS)
|
||||
tcmalloc_minimal_large_heap_fragmentation_unittest_LDADD = libtcmalloc_minimal.la
|
||||
tcmalloc_minimal_large_heap_fragmentation_unittest_CPPFLAGS = $(gtest_CPPFLAGS)
|
||||
tcmalloc_minimal_large_heap_fragmentation_unittest_LDADD = libtcmalloc_minimal.la libgtest.la
|
||||
|
||||
if !MINGW
|
||||
TESTS += system_alloc_unittest
|
||||
@ -710,7 +711,8 @@ tcmalloc_large_unittest_LDADD = libtcmalloc.la $(PTHREAD_LIBS)
|
||||
TESTS += tcmalloc_large_heap_fragmentation_unittest
|
||||
tcmalloc_large_heap_fragmentation_unittest_SOURCES = src/tests/large_heap_fragmentation_unittest.cc
|
||||
tcmalloc_large_heap_fragmentation_unittest_LDFLAGS = $(TCMALLOC_FLAGS) $(AM_LDFLAGS)
|
||||
tcmalloc_large_heap_fragmentation_unittest_LDADD = libtcmalloc.la
|
||||
tcmalloc_large_heap_fragmentation_unittest_CPPFLAGS = $(gtest_CPPFLAGS)
|
||||
tcmalloc_large_heap_fragmentation_unittest_LDADD = libtcmalloc.la libgtest.la
|
||||
|
||||
# These unittests often need to run binaries. They're in the current dir
|
||||
TESTS_ENVIRONMENT += BINDIR=.
|
||||
|
@ -29,19 +29,25 @@
|
||||
// meg) page spans. It makes sure that allocations/releases of
|
||||
// increasing memory chunks do not blowup memory
|
||||
// usage. See also https://github.com/gperftools/gperftools/issues/371
|
||||
#include "config.h"
|
||||
|
||||
#include <gperftools/malloc_extension.h>
|
||||
#include <gperftools/tcmalloc.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "common.h"
|
||||
#include <gperftools/malloc_extension.h>
|
||||
#include <gperftools/tcmalloc.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(LargeHeapFragmentationTest, Basic) {
|
||||
// First grow heap by single large amount, to ensure that we do have
|
||||
// a big chunk of consecutive memory. Otherwise details of
|
||||
// sys-allocator behavior may trigger fragmentation regardless of
|
||||
// our mitigations.
|
||||
tc_free(tc_malloc(550 << 20));
|
||||
MallocExtension::instance()->ReleaseFreeMemory();
|
||||
|
||||
int main (int argc, char** argv) {
|
||||
for (int pass = 1; pass <= 3; pass++) {
|
||||
size_t size = 100*1024*1024;
|
||||
while (size < 500*1024*1024) {
|
||||
@ -50,14 +56,11 @@ int main (int argc, char** argv) {
|
||||
size += 20000;
|
||||
|
||||
size_t heap_size = static_cast<size_t>(-1);
|
||||
MallocExtension::instance()->GetNumericProperty("generic.heap_size",
|
||||
&heap_size);
|
||||
ASSERT_TRUE(MallocExtension::instance()->GetNumericProperty(
|
||||
"generic.heap_size",
|
||||
&heap_size));
|
||||
|
||||
|
||||
CHECK_LT(heap_size, 1*1024*1024*1024);
|
||||
ASSERT_LT(heap_size, 1 << 30);
|
||||
}
|
||||
}
|
||||
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user