summaryrefslogtreecommitdiffstats
path: root/vespamalloc/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-06-28 11:21:20 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-06-28 11:21:20 +0000
commit78153ab3b636f1b0642590cfd296ed8e19415c88 (patch)
treea2f69801527086e04b3d4b4eada7f7c64671853c /vespamalloc/src/tests
parent21f1ed5bceb790564918ccb010d60fd85a87497c (diff)
Expose a way to access vespamalloc internals.
Diffstat (limited to 'vespamalloc/src/tests')
-rw-r--r--vespamalloc/src/tests/stacktrace/stacktrace.cpp18
-rw-r--r--vespamalloc/src/tests/test1/new_test.cpp14
2 files changed, 20 insertions, 12 deletions
diff --git a/vespamalloc/src/tests/stacktrace/stacktrace.cpp b/vespamalloc/src/tests/stacktrace/stacktrace.cpp
index d13fb6bb59b..e7c53fa5c3f 100644
--- a/vespamalloc/src/tests/stacktrace/stacktrace.cpp
+++ b/vespamalloc/src/tests/stacktrace/stacktrace.cpp
@@ -1,7 +1,9 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <stdlib.h>
-#include <stdio.h>
+#include <cstdlib>
+#include <cstdio>
#include <pthread.h>
+#include <dlfcn.h>
+#include <cassert>
void * run(void * arg)
{
@@ -10,7 +12,11 @@ void * run(void * arg)
char * b = new char [1]; // but b should as it not deleted.
(void) b;
delete [] a;
- return NULL;
+ return nullptr;
+}
+
+void verify_that_vespamalloc_datasegment_size_exists() {
+ assert(dlsym(RTLD_NEXT, "vespamalloc_datasegment_size") != nullptr);
}
int main(int argc, char *argv[])
@@ -22,14 +28,16 @@ int main(int argc, char *argv[])
(void) b;
delete [] a;
pthread_t tid;
- int retval = pthread_create(&tid, NULL, run, NULL);
+ int retval = pthread_create(&tid, nullptr, run, nullptr);
if (retval != 0) {
perror("pthread_create failed");
abort();
}
- retval = pthread_join(tid, NULL);
+ retval = pthread_join(tid, nullptr);
if (retval != 0) {
perror("pthread_join failed");
abort();
}
+
+ verify_that_vespamalloc_datasegment_size_exists();
}
diff --git a/vespamalloc/src/tests/test1/new_test.cpp b/vespamalloc/src/tests/test1/new_test.cpp
index 2400e41a1d9..a8392363f6f 100644
--- a/vespamalloc/src/tests/test1/new_test.cpp
+++ b/vespamalloc/src/tests/test1/new_test.cpp
@@ -12,7 +12,7 @@ void cmp(const void *base, size_t offset, const void *p) {
}
template <typename S>
-void veryfy_aligned(S * p) {
+void verify_aligned(S * p) {
EXPECT_TRUE((uintptr_t(p) % alignof(S)) == 0);
memset(p, 0, sizeof(S));
}
@@ -26,7 +26,7 @@ TEST("verify new with normal alignment") {
static_assert(sizeof(S) == 24);
static_assert(alignof(S) == 8);
auto s = std::make_unique<S>();
- veryfy_aligned(s.get());
+ verify_aligned(s.get());
cmp(s.get(), &s->a);
cmp(s.get(), 8, &s->b);
cmp(s.get(), 16, &s->c);
@@ -42,7 +42,7 @@ TEST("verify new with alignment = 16") {
static_assert(sizeof(S) == 32);
static_assert(alignof(S) == 16);
auto s = std::make_unique<S>();
- veryfy_aligned(s.get());
+ verify_aligned(s.get());
cmp(s.get(), &s->a);
cmp(s.get(), 16, &s->b);
cmp(s.get(), 24, &s->c);
@@ -58,7 +58,7 @@ TEST("verify new with alignment = 32") {
static_assert(sizeof(S) == 64);
static_assert(alignof(S) == 32);
auto s = std::make_unique<S>();
- veryfy_aligned(s.get());
+ verify_aligned(s.get());
cmp(s.get(), &s->a);
cmp(s.get(), 32, &s->b);
cmp(s.get(), 40, &s->c);
@@ -74,7 +74,7 @@ TEST("verify new with alignment = 64") {
static_assert(sizeof(S) == 128);
static_assert(alignof(S) == 64);
auto s = std::make_unique<S>();
- veryfy_aligned(s.get());
+ verify_aligned(s.get());
cmp(s.get(), &s->a);
cmp(s.get(), 64, &s->b);
cmp(s.get(), 72, &s->c);
@@ -88,7 +88,7 @@ TEST("verify new with alignment = 64 with single element") {
static_assert(sizeof(S) == 64);
static_assert(alignof(S) == 64);
auto s = std::make_unique<S>();
- veryfy_aligned(s.get());
+ verify_aligned(s.get());
cmp(s.get(), &s->a);
LOG(info, "&s=%p", s.get());
}
@@ -100,7 +100,7 @@ TEST("verify new with alignment = 64 with single element") {
static_assert(sizeof(S) == 64);
static_assert(alignof(S) == 64);
auto s = std::make_unique<S>();
- veryfy_aligned(s.get());
+ verify_aligned(s.get());
cmp(s.get(), &s->a);
LOG(info, "&s=%p", s.get());
}