diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-09 14:03:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-09 14:03:42 +0100 |
commit | c051534e3e17f945634dac5691da50771f6126ed (patch) | |
tree | 7694073f36f7da7dc73e5f967a28c2911636663c /vespamalloc/src/tests/test1/new_test.cpp | |
parent | 234adeffe4f1e4f1275a834f42293722a2ce6829 (diff) |
Revert "Revert "Wire in mallopt(in param, int value) interface in vespamalloc and ver…""
Diffstat (limited to 'vespamalloc/src/tests/test1/new_test.cpp')
-rw-r--r-- | vespamalloc/src/tests/test1/new_test.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/vespamalloc/src/tests/test1/new_test.cpp b/vespamalloc/src/tests/test1/new_test.cpp index 5230869145d..6f84f7c0f63 100644 --- a/vespamalloc/src/tests/test1/new_test.cpp +++ b/vespamalloc/src/tests/test1/new_test.cpp @@ -3,7 +3,6 @@ #include <vespa/log/log.h> #include <malloc.h> #include <dlfcn.h> -#include <functional> LOG_SETUP("new_test"); @@ -134,14 +133,28 @@ void verify_vespamalloc_usable_size() { } } +enum class MallocLibrary { UNKNOWN, VESPA_MALLOC, VESPA_MALLOC_D}; + +MallocLibrary +detectLibrary() { + if (dlsym(RTLD_NEXT, "is_vespamallocd") != nullptr) { + // Debug variants will never have more memory available as there is pre/postamble for error detection. + return MallocLibrary::VESPA_MALLOC_D; + } else if (dlsym(RTLD_NEXT, "is_vespamalloc") != nullptr) { + return MallocLibrary::VESPA_MALLOC; + } + return MallocLibrary::UNKNOWN; +} + TEST("verify malloc_usable_size is sane") { constexpr size_t SZ = 33; std::unique_ptr<char[]> buf = std::make_unique<char[]>(SZ); size_t usable_size = malloc_usable_size(buf.get()); - if (dlsym(RTLD_NEXT, "is_vespamallocd") != nullptr) { + MallocLibrary env = detectLibrary(); + if (env == MallocLibrary::VESPA_MALLOC_D) { // Debug variants will never have more memory available as there is pre/postamble for error detection. EXPECT_EQUAL(SZ, usable_size); - } else if (dlsym(RTLD_NEXT, "is_vespamalloc") != nullptr) { + } else if (env == MallocLibrary::VESPA_MALLOC) { // Normal production vespamalloc will round up EXPECT_EQUAL(64u, usable_size); verify_vespamalloc_usable_size(); @@ -151,5 +164,13 @@ TEST("verify malloc_usable_size is sane") { } } +TEST("verify mallopt") { + MallocLibrary env = detectLibrary(); + if (env == MallocLibrary::UNKNOWN) return; + EXPECT_EQUAL(0, mallopt(M_MMAP_MAX, 0x1000000)); + EXPECT_EQUAL(1, mallopt(M_MMAP_THRESHOLD, 0x1000000)); + EXPECT_EQUAL(1, mallopt(M_MMAP_THRESHOLD, -1)); +} + TEST_MAIN() { TEST_RUN_ALL(); } |