From 4ec8c9dbb25e2844f98f7acc848aa3b190349d70 Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Sun, 10 Sep 2023 22:18:51 -0400 Subject: [PATCH] reduce set of nallocx size testing points Testing every 7th size is a bit slow on slower machines. No need to be as thorough. We now bump by about 1/128th each step which is still more steps than size classes we have. --- src/tests/tcmalloc_unittest.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/tests/tcmalloc_unittest.cc b/src/tests/tcmalloc_unittest.cc index 9a61bd7..707840a 100644 --- a/src/tests/tcmalloc_unittest.cc +++ b/src/tests/tcmalloc_unittest.cc @@ -1118,8 +1118,23 @@ static void check_global_nallocx() { CHECK_GT(nallocx(99, 0), 99); } #endif // __GNUC__ +static size_t GrowNallocxTestSize(size_t sz) { + if (sz < 1024) { + return sz + 7; + } + + size_t divided = sz >> 7; + divided |= (divided >> 1); + divided |= (divided >> 2); + divided |= (divided >> 4); + divided |= (divided >> 8); + divided |= (divided >> 16); + divided += 1; + return sz + divided; +} + static void TestNAllocX() { - for (size_t size = 0; size <= (1 << 20); size += 7) { + for (size_t size = 0; size <= (1 << 20); size = GrowNallocxTestSize(size)) { size_t rounded = nallocx(size, 0); ASSERT_GE(rounded, size); void* ptr = malloc(size); @@ -1129,7 +1144,7 @@ static void TestNAllocX() { } static void TestNAllocXAlignment() { - for (size_t size = 0; size <= (1 << 20); size += 7) { + for (size_t size = 0; size <= (1 << 20); size = GrowNallocxTestSize(size)) { for (size_t align = 0; align < 10; align++) { size_t rounded = nallocx(size, MALLOCX_LG_ALIGN(align)); ASSERT_GE(rounded, size);