Skip to content

Commit

Permalink
Add test of copy constructor/assignment operator for DualView.
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenarnst committed Oct 3, 2023
1 parent 82044c6 commit 39316fa
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions containers/unit_tests/TestDualView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,48 @@ struct test_dualview_alloc {
}
};

template <typename Scalar, class Device>
struct test_dualview_copy_construction_and_assignment {
using scalar_type = Scalar;
using execution_space = Device;

template <typename ViewType>
void run_me() {
const unsigned int n = 10;
const unsigned int m = 5;

ViewType a("A", n, m);

// Copy construction
ViewType b(a);

// Copy assignment
ViewType c = a;

// Check equality (shallow) of the host and device views
ASSERT_EQ(a.view_host(), b.view_host());
ASSERT_EQ(a.view_device(), b.view_device());

ASSERT_EQ(a.view_host(), c.view_host());
ASSERT_EQ(a.view_device(), c.view_device());

// We can't test shallow equality of modified_flags because it's protected.
// So we test it indirectly through sync state behavior.
if (!std::decay_t<ViewType>::impl_dualview_is_single_device::value) {
a.clear_sync_state();
a.modify_host();
ASSERT_TRUE(a.need_sync_device());
ASSERT_TRUE(b.need_sync_device());
ASSERT_TRUE(c.need_sync_device());
a.clear_sync_state();
}
}

test_dualview_copy_construction_and_assignment() {
run_me<Kokkos::DualView<Scalar**, Kokkos::LayoutLeft, Device> >();
}
};

template <typename Scalar, class Device>
struct test_dualview_combinations {
using self_type = test_dualview_combinations<Scalar, Device>;
Expand Down Expand Up @@ -379,6 +421,11 @@ void test_dualview_alloc(unsigned int size) {
ASSERT_TRUE(test.result);
}

template <typename Scalar, typename Device>
void test_dualview_copy_construction_and_assignment() {
Impl::test_dualview_copy_construction_and_assignment<Scalar, Device>();
}

template <typename Scalar, typename Device>
void test_dualview_deep_copy() {
Impl::test_dual_view_deep_copy<Scalar, Device>();
Expand All @@ -404,6 +451,10 @@ TEST(TEST_CATEGORY, dualview_alloc) {
test_dualview_alloc<int, TEST_EXECSPACE>(10);
}

TEST(TEST_CATEGORY, test_dualview_copy_construction_and_assignment) {
test_dualview_copy_construction_and_assignment<int, TEST_EXECSPACE>();
}

TEST(TEST_CATEGORY, dualview_combinations_without_init) {
test_dualview_combinations<int, TEST_EXECSPACE>(10, false);
}
Expand Down

0 comments on commit 39316fa

Please sign in to comment.