summaryrefslogtreecommitdiffstats
path: root/vespamalloc/src/tests/test1/new_test.cpp
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-02-09 11:16:12 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-02-09 11:16:12 +0000
commitf702453ad7df68f68149f32edfa53f2bb9899e4f (patch)
tree924d2bae527c369babdbcd5aec0a3bf20d8334fd /vespamalloc/src/tests/test1/new_test.cpp
parent38620108085ba82cd7c43fbabb02aee848e5ff26 (diff)
Wire in mallopt(in param, int value) interface in vespamalloc and verify simple wiring.
Diffstat (limited to 'vespamalloc/src/tests/test1/new_test.cpp')
-rw-r--r--vespamalloc/src/tests/test1/new_test.cpp27
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(); }