summaryrefslogtreecommitdiffstats
path: root/vespamalloc/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-06-09 08:01:03 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-06-09 08:01:03 +0000
commit6ef440733ef899251be945a1b3c985e76e4a6312 (patch)
tree28f2ae3d4d0c2de8ce06fc549212e9d540ea88b2 /vespamalloc/src/tests
parentc6120d5e864cabf282495889398621d2fc047f90 (diff)
Add support for new/delete with alignment that came along in c++17 with gcc 9
Diffstat (limited to 'vespamalloc/src/tests')
-rw-r--r--vespamalloc/src/tests/test1/CMakeLists.txt22
-rw-r--r--vespamalloc/src/tests/test1/new_test.cpp91
2 files changed, 113 insertions, 0 deletions
diff --git a/vespamalloc/src/tests/test1/CMakeLists.txt b/vespamalloc/src/tests/test1/CMakeLists.txt
index cade2e092b4..15680f22595 100644
--- a/vespamalloc/src/tests/test1/CMakeLists.txt
+++ b/vespamalloc/src/tests/test1/CMakeLists.txt
@@ -6,3 +6,25 @@ vespa_add_executable(vespamalloc_testatomic_app TEST
${VESPA_ATOMIC_LIB}
)
vespa_add_test(NAME vespamalloc_testatomic_app NO_VALGRIND COMMAND vespamalloc_testatomic_app)
+
+vespa_add_executable(vespamalloc_new_test_app TEST
+ SOURCES
+ new_test.cpp
+)
+vespa_add_test(NAME vespamalloc_new_test_app NO_VALGRIND COMMAND vespamalloc_new_test_app)
+
+vespa_add_executable(vespamalloc_new_test_with_vespamalloc_app TEST
+ SOURCES
+ new_test.cpp
+ DEPENDS
+ vespamalloc
+)
+vespa_add_test(NAME vespamalloc_new_test_with_vespamalloc_app NO_VALGRIND COMMAND vespamalloc_new_test_with_vespamalloc_app)
+
+vespa_add_executable(vespamalloc_new_test_with_vespamallocd_app TEST
+ SOURCES
+ new_test.cpp
+ DEPENDS
+ vespamallocd
+)
+vespa_add_test(NAME vespamalloc_new_test_with_vespamallocd_app NO_VALGRIND COMMAND vespamalloc_new_test_with_vespamallocd_app)
diff --git a/vespamalloc/src/tests/test1/new_test.cpp b/vespamalloc/src/tests/test1/new_test.cpp
new file mode 100644
index 00000000000..784ae16f7ad
--- /dev/null
+++ b/vespamalloc/src/tests/test1/new_test.cpp
@@ -0,0 +1,91 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/log/log.h>
+
+LOG_SETUP("new_test");
+
+void cmp(const void *a, const void *b) {
+ EXPECT_EQUAL(a, b);
+}
+void cmp(const void *base, size_t offset, const void *p) {
+ cmp((static_cast<const char *>(base) + offset), p);
+}
+
+TEST("verify new with normal alignment") {
+ struct S {
+ int a;
+ long b;
+ int c;
+ };
+ static_assert(sizeof(S) == 24, "sizeof(S) == 16");
+ auto s = std::make_unique<S>();
+ cmp(s.get(), &s->a);
+ cmp(s.get(), 8, &s->b);
+ cmp(s.get(), 16, &s->c);
+ LOG(info, "&s=%p &s.b=%p &s.c=%p", s.get(), &s->b, &s->c);
+}
+
+TEST("verify new with alignment = 16") {
+ struct S {
+ int a;
+ alignas(16) long b;
+ int c;
+ };
+ static_assert(sizeof(S) == 32, "sizeof(S) == 32");
+ auto s = std::make_unique<S>();
+ cmp(s.get(), &s->a);
+ cmp(s.get(), 16, &s->b);
+ cmp(s.get(), 24, &s->c);
+ LOG(info, "&s=%p &s.b=%p &s.c=%p", s.get(), &s->b, &s->c);
+}
+
+TEST("verify new with alignment = 32") {
+ struct S {
+ int a;
+ alignas(32) long b;
+ int c;
+ };
+ static_assert(sizeof(S) == 64, "sizeof(S) == 64");
+ auto s = std::make_unique<S>();
+ cmp(s.get(), &s->a);
+ cmp(s.get(), 32, &s->b);
+ cmp(s.get(), 40, &s->c);
+ LOG(info, "&s=%p &s.b=%p &s.c=%p", s.get(), &s->b, &s->c);
+}
+
+TEST("verify new with alignment = 64") {
+ struct S {
+ int a;
+ alignas(64) long b;
+ int c;
+ };
+ static_assert(sizeof(S) == 128, "sizeof(S) == 128");
+ auto s = std::make_unique<S>();
+ cmp(s.get(), &s->a);
+ cmp(s.get(), 64, &s->b);
+ cmp(s.get(), 72, &s->c);
+ LOG(info, "&s=%p &s.b=%p &s.c=%p", s.get(), &s->b, &s->c);
+}
+
+TEST("verify new with alignment = 64 with single element") {
+ struct S {
+ alignas(64) long a;
+ };
+ static_assert(sizeof(S) == 64, "sizeof(S) == 64");
+ auto s = std::make_unique<S>();
+ cmp(s.get(), &s->a);
+ LOG(info, "&s=%p", s.get());
+}
+
+TEST("verify new with alignment = 64 with single element") {
+ struct alignas(64) S {
+ long a;
+ };
+ static_assert(sizeof(S) == 64, "sizeof(S) == 64");
+ auto s = std::make_unique<S>();
+ cmp(s.get(), &s->a);
+ LOG(info, "&s=%p", s.get());
+}
+
+
+TEST_MAIN() { TEST_RUN_ALL(); }