Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Add test for array modifiers and modify pmreorder test.
Browse files Browse the repository at this point in the history
  • Loading branch information
igchor committed Jan 24, 2019
1 parent 047a58e commit 770b634
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 8 deletions.
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Expand Up @@ -292,4 +292,8 @@ add_test_generic(vector_iterators_access none)
add_test_generic(vector_iterators_access memcheck)
add_test_generic(vector_iterators_access pmemcheck)

build_test(array_modifiers array_modifiers/array_modifiers.cpp)
add_test_generic(array_modifiers none)
add_test_generic(array_modifiers pmemcheck)

add_subdirectory(external)
175 changes: 175 additions & 0 deletions tests/array_modifiers/array_modifiers.cpp
@@ -0,0 +1,175 @@
/*
* Copyright 2019, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "unittest.hpp"

#include <algorithm>
#include <iterator>

#include <libpmemobj++/experimental/array.hpp>
#include <libpmemobj++/make_persistent.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>

namespace pmemobj_exp = pmem::obj::experimental;

using array_type = pmemobj_exp::array<double, 5>;

struct root {
pmem::obj::persistent_ptr<array_type> ptr_a;
pmem::obj::persistent_ptr<array_type> ptr_b;
};

void
test_modifiers(pmem::obj::pool<struct root> &pop)
{
auto r = pop.root();

try {
pmem::obj::transaction::run(pop, [&] {
r->ptr_a = pmem::obj::make_persistent<array_type>();
r->ptr_b = pmem::obj::make_persistent<array_type>();
});
} catch (std::exception &e) {
UT_FATALexc(e);
}

r->ptr_a->fill(2.4);
r->ptr_b->fill(1.0);

r->ptr_a->swap(*(r->ptr_b));

*(r->ptr_a) = *(r->ptr_b);
*(r->ptr_b) = std::move(*(r->ptr_a));

*(r->ptr_a) = *(r->ptr_b);

*(r->ptr_b) = *(r->ptr_b);
UT_ASSERT(*(r->ptr_a) == *(r->ptr_b));

*(r->ptr_b) = std::move(*(r->ptr_b));
UT_ASSERT(*(r->ptr_a) == *(r->ptr_b));

r->ptr_b->swap(*(r->ptr_b));
UT_ASSERT(*(r->ptr_a) == *(r->ptr_b));

array_type stack_array;

try {
stack_array.fill(1.0);
UT_ASSERT(0);
} catch (pmem::pool_error &) {
} catch (std::exception &e) {
UT_FATALexc(e);
}

try {
stack_array.swap(*(r->ptr_a));
UT_ASSERT(0);
} catch (pmem::pool_error &) {
} catch (std::exception &e) {
UT_FATALexc(e);
}

try {
stack_array = *(r->ptr_a);
UT_ASSERT(0);
} catch (pmem::pool_error &) {
} catch (std::exception &e) {
UT_FATALexc(e);
}

try {
stack_array = std::move(*(r->ptr_a));
UT_ASSERT(0);
} catch (pmem::pool_error &) {
} catch (std::exception &e) {
UT_FATALexc(e);
}

try {
stack_array.swap(stack_array);
UT_ASSERT(0);
} catch (pmem::pool_error &) {
} catch (std::exception &e) {
UT_FATALexc(e);
}

try {
stack_array = stack_array;
UT_ASSERT(0);
} catch (pmem::pool_error &) {
} catch (std::exception &e) {
UT_FATALexc(e);
}

try {
array_type &ref = stack_array;

stack_array = std::move(ref);
UT_ASSERT(0);
} catch (pmem::pool_error &) {
} catch (std::exception &e) {
UT_FATALexc(e);
}

try {
pmem::obj::transaction::run(pop, [&] {
pmem::obj::delete_persistent<array_type>(r->ptr_a);
pmem::obj::delete_persistent<array_type>(r->ptr_b);
});
} catch (std::exception &e) {
UT_FATALexc(e);
}
}

int
main(int argc, char *argv[])
{
START();

if (argc < 2) {
std::cerr << "usage: " << argv[0] << " file-name" << std::endl;
return 1;
}

auto path = argv[1];

auto pop = pmem::obj::pool<root>::create(
path, "ArrayTest", PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR);

test_modifiers(pop);

pop.close();

return 0;
}
38 changes: 38 additions & 0 deletions tests/array_modifiers/array_modifiers_0.cmake
@@ -0,0 +1,38 @@
#
# Copyright 2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include(${SRC_DIR}/../helpers.cmake)

setup()

execute(${TEST_EXECUTABLE} ${DIR}/testfile)

finish()
18 changes: 10 additions & 8 deletions tests/array_slice_pmreorder/array_slice_pmreorder.cpp
@@ -1,5 +1,5 @@
/*
* Copyright 2018, Intel Corporation
* Copyright 2018-2019, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -109,13 +109,15 @@ check_consistency(nvobj::pool<root> &pop)
{
auto r = pop.root();

nvobj::experimental::array<int, 5> expected;
if (r->ptr->array[0] == 1)
expected = {{1, 2, 3, 4, 5}};
else
expected = {{2, 3, 4, 5, 6}};

UT_ASSERT(r->ptr->array == expected);
if (r->ptr->array[0] == 1) {
auto it = 1;
for (const auto &e : r->ptr->array)
UT_ASSERT(e == it++);
} else {
auto it = 2;
for (const auto &e : r->ptr->array)
UT_ASSERT(e == it++);
}
}

int
Expand Down

0 comments on commit 770b634

Please sign in to comment.