diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespalib/src/tests/alignedmemory |
Publish
Diffstat (limited to 'vespalib/src/tests/alignedmemory')
-rw-r--r-- | vespalib/src/tests/alignedmemory/.cvsignore | 3 | ||||
-rw-r--r-- | vespalib/src/tests/alignedmemory/.gitignore | 4 | ||||
-rw-r--r-- | vespalib/src/tests/alignedmemory/CMakeLists.txt | 8 | ||||
-rw-r--r-- | vespalib/src/tests/alignedmemory/DESC | 1 | ||||
-rw-r--r-- | vespalib/src/tests/alignedmemory/FILES | 1 | ||||
-rw-r--r-- | vespalib/src/tests/alignedmemory/alignedmemory_test.cpp | 69 |
6 files changed, 86 insertions, 0 deletions
diff --git a/vespalib/src/tests/alignedmemory/.cvsignore b/vespalib/src/tests/alignedmemory/.cvsignore new file mode 100644 index 00000000000..0cc06a2789a --- /dev/null +++ b/vespalib/src/tests/alignedmemory/.cvsignore @@ -0,0 +1,3 @@ +.depend +Makefile +alignedmemory_test diff --git a/vespalib/src/tests/alignedmemory/.gitignore b/vespalib/src/tests/alignedmemory/.gitignore new file mode 100644 index 00000000000..8777f6e4632 --- /dev/null +++ b/vespalib/src/tests/alignedmemory/.gitignore @@ -0,0 +1,4 @@ +.depend +Makefile +alignedmemory_test +vespalib_alignedmemory_test_app diff --git a/vespalib/src/tests/alignedmemory/CMakeLists.txt b/vespalib/src/tests/alignedmemory/CMakeLists.txt new file mode 100644 index 00000000000..685705b0761 --- /dev/null +++ b/vespalib/src/tests/alignedmemory/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vespalib_alignedmemory_test_app + SOURCES + alignedmemory_test.cpp + DEPENDS + vespalib +) +vespa_add_test(NAME vespalib_alignedmemory_test_app COMMAND vespalib_alignedmemory_test_app) diff --git a/vespalib/src/tests/alignedmemory/DESC b/vespalib/src/tests/alignedmemory/DESC new file mode 100644 index 00000000000..4f3b4f32604 --- /dev/null +++ b/vespalib/src/tests/alignedmemory/DESC @@ -0,0 +1 @@ +alignedmemory test. Take a look at alignedmemory.cpp for details. diff --git a/vespalib/src/tests/alignedmemory/FILES b/vespalib/src/tests/alignedmemory/FILES new file mode 100644 index 00000000000..d0363c78367 --- /dev/null +++ b/vespalib/src/tests/alignedmemory/FILES @@ -0,0 +1 @@ +alignedmemory.cpp diff --git a/vespalib/src/tests/alignedmemory/alignedmemory_test.cpp b/vespalib/src/tests/alignedmemory/alignedmemory_test.cpp new file mode 100644 index 00000000000..73814d3284e --- /dev/null +++ b/vespalib/src/tests/alignedmemory/alignedmemory_test.cpp @@ -0,0 +1,69 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +LOG_SETUP("alignedmemory_test"); +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/util/alignedmemory.h> + +using namespace vespalib; + +TEST_SETUP(Test); + +int +Test::Main() +{ + TEST_INIT("alignedmemory_test"); + { // aligned alloc + AlignedMemory mem8(32, 8); + AlignedMemory mem16(32, 16); + AlignedMemory mem512(32, 512); + AlignedMemory mem7(32, 7); + + EXPECT_EQUAL(0u, ((uintptr_t)mem8.get()) % 8); + EXPECT_EQUAL(0u, ((uintptr_t)mem16.get()) % 16); + EXPECT_EQUAL(0u, ((uintptr_t)mem512.get()) % 512); + EXPECT_EQUAL(0u, ((uintptr_t)mem7.get()) % 7); + } + { // swap + AlignedMemory a(32, 8); + AlignedMemory b(32, 8); + char *pa = a.get(); + char *pb = b.get(); + + EXPECT_EQUAL(pa, a.get()); + EXPECT_EQUAL(pb, b.get()); + a.swap(b); + EXPECT_EQUAL(pb, a.get()); + EXPECT_EQUAL(pa, b.get()); + b.swap(a); + EXPECT_EQUAL(pa, a.get()); + EXPECT_EQUAL(pb, b.get()); + } + { // std::swap + AlignedMemory a(32, 8); + AlignedMemory b(32, 8); + char *pa = a.get(); + char *pb = b.get(); + + EXPECT_EQUAL(pa, a.get()); + EXPECT_EQUAL(pb, b.get()); + std::swap(a, b); + EXPECT_EQUAL(pb, a.get()); + EXPECT_EQUAL(pa, b.get()); + std::swap(a, b); + EXPECT_EQUAL(pa, a.get()); + EXPECT_EQUAL(pb, b.get()); + } + { // construct with zero size + AlignedMemory null(0, 0); + char *expect = 0; + EXPECT_EQUAL(expect, null.get()); + } + { // const get() + const AlignedMemory null(0, 0); + const char *expect = 0; + const char *got = null.get(); + EXPECT_EQUAL(expect, got); + } + TEST_DONE(); +} |