From df73bd6e1cb4e27ac1190f4774dc7b1d55f4bfa9 Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Mon, 31 Oct 2022 18:07:05 +0100 Subject: [PATCH] #2001: Add UTs to replicate defect --- tests/unit/collection/test_list_insert.cc | 177 ++++++++++++++++++++++ 1 file changed, 177 insertions(+) diff --git a/tests/unit/collection/test_list_insert.cc b/tests/unit/collection/test_list_insert.cc index 694bf1bd73..6ffed1d6ad 100644 --- a/tests/unit/collection/test_list_insert.cc +++ b/tests/unit/collection/test_list_insert.cc @@ -58,6 +58,7 @@ using namespace vt::collective; using namespace vt::tests::unit; struct WorkMsg; +struct WorkMsgNDC; static int32_t num_inserted = 0; static int32_t num_deleted = 0; @@ -83,6 +84,38 @@ void ListInsertTest::work(WorkMsg* msg) { struct WorkMsg : CollectionMessage {}; using ColProxyType = CollectionIndexProxy; +struct NonDefaultConstructibleStruct : Collection { + using ConstructFnType = vt::vrt::collection::param::ConstructParams< + NonDefaultConstructibleStruct>::ConstructFnType; + + NonDefaultConstructibleStruct(int) { + num_inserted++; + } + + virtual ~NonDefaultConstructibleStruct() { + num_deleted++; + } + + void work(WorkMsgNDC* msg); + + static ConstructFnType getConstructor() { + return [](vt::Index1D) { + return std::make_unique(0); + }; + } +}; + +struct WorkMsgNDC : CollectionMessage {}; +using ColProxyTypeNDC = CollectionIndexProxy; + +void reconstruct(NonDefaultConstructibleStruct*&, void*) { +} + +void NonDefaultConstructibleStruct::work(WorkMsgNDC* msg) { + vt_print(gen, "num_work={}, idx={}\n", num_work, getIndex()); + num_work++; +} + struct TestListInsert : TestParallelHarness { }; static constexpr int32_t const num_elms_per_node = 8; @@ -114,6 +147,34 @@ TEST_F(TestListInsert, test_bounded_list_insert_1) { EXPECT_EQ(num_work, num_elms_per_node * num_nodes); } +TEST_F(TestListInsert, test_bounded_list_insert_no_default_constructor) { + num_inserted = 0; + num_work = 0; + + auto const num_nodes = theContext()->getNumNodes(); + + auto const range = Index1D(num_nodes * num_elms_per_node); + std::vector list_insert; + for (int i = 0; i < range.x(); i++) { + list_insert.emplace_back(Index1D{i}); + } + + auto proxy = vt::makeCollection("test_bounded_list_insert_no_default_constructor") + .collective(true) + .bounds(range) + .listInsert(list_insert) + .elementConstructor(NonDefaultConstructibleStruct::getConstructor()) + .wait(); + + EXPECT_EQ(num_inserted, num_elms_per_node); + num_inserted = 0; + + runInEpochCollective([&]{ + proxy.broadcast(); + }); + EXPECT_EQ(num_work, num_elms_per_node * num_nodes); +} + template struct MyMapper : vt::mapping::BaseMapper { static vt::ObjGroupProxyType construct() { @@ -154,6 +215,34 @@ TEST_F(TestListInsert, test_unbounded_list_insert_2) { EXPECT_EQ(num_work, num_elms_per_node * num_nodes); } +TEST_F(TestListInsert, test_unbounded_list_insert_no_default_constructor) { + num_inserted = 0; + num_work = 0; + + auto const num_nodes = theContext()->getNumNodes(); + + auto const range = Index1D(num_nodes * num_elms_per_node); + std::vector list_insert; + for (int i = 0; i < range.x(); i++) { + list_insert.emplace_back(Index1D{i}); + } + + auto proxy = vt::makeCollection("test_unbounded_list_insert_no_default_constructor") + .collective(true) + .listInsert(list_insert) + .elementConstructor(NonDefaultConstructibleStruct::getConstructor()) + .template mapperObjGroupConstruct>() + .wait(); + + EXPECT_EQ(num_inserted, num_elms_per_node); + num_inserted = 0; + + runInEpochCollective([&]{ + proxy.broadcast(); + }); + EXPECT_EQ(num_work, num_elms_per_node * num_nodes); +} + TEST_F(TestListInsert, test_bounded_list_insert_here_3) { num_inserted = 0; num_work = 0; @@ -188,6 +277,38 @@ TEST_F(TestListInsert, test_bounded_list_insert_here_3) { EXPECT_EQ(num_work, num_elms_per_node * num_nodes); } +TEST_F(TestListInsert, test_bounded_list_insert_here_no_default_constructor) { + num_inserted = 0; + num_work = 0; + + auto const num_nodes = theContext()->getNumNodes(); + auto const range = Index1D(num_nodes * num_elms_per_node); + + std::vector>> elms; + for (int i = 0; i < range.x(); i++) { + if (i % num_nodes == 0) { + Index1D ix{i}; + elms.emplace_back( + std::make_tuple(ix, std::make_unique(0)) + ); + } + } + + auto proxy = vt::makeCollection("test_bounded_list_insert_here_no_default_constructor") + .collective(true) + .bounds(range) + .listInsertHere(std::move(elms)) + .wait(); + + EXPECT_EQ(num_inserted, num_elms_per_node); + num_inserted = 0; + + runInEpochCollective([&]{ + proxy.broadcast(); + }); + EXPECT_EQ(num_work, num_elms_per_node * num_nodes); +} + TEST_F(TestListInsert, test_unbounded_list_insert_here_4) { num_inserted = 0; num_work = 0; @@ -222,4 +343,60 @@ TEST_F(TestListInsert, test_unbounded_list_insert_here_4) { EXPECT_EQ(num_work, num_elms_per_node * num_nodes); } +TEST_F(TestListInsert, test_unbounded_list_insert_here_no_default_constructor) { + num_inserted = 0; + num_work = 0; + + auto const num_nodes = theContext()->getNumNodes(); + auto const range = Index1D(num_nodes * num_elms_per_node); + + std::vector>> elms; + for (int i = 0; i < range.x(); i++) { + if (i % num_nodes == 0) { + Index1D ix{i}; + elms.emplace_back( + std::make_tuple(ix, std::make_unique(0)) + ); + } + } + + auto proxy = vt::makeCollection("test_unbounded_list_insert_here_no_default_constructor") + .collective(true) + .listInsertHere(std::move(elms)) + .template mapperObjGroupConstruct>() + .wait(); + + EXPECT_EQ(num_inserted, num_elms_per_node); + num_inserted = 0; + + runInEpochCollective([&]{ + proxy.broadcast(); + }); + EXPECT_EQ(num_work, num_elms_per_node * num_nodes); +} + +TEST_F(TestListInsert, test_bounded_bulk_insert_no_default_constructor) { + num_inserted = 0; + num_work = 0; + + auto const num_nodes = theContext()->getNumNodes(); + auto const range = Index1D(num_nodes * num_elms_per_node); + + auto proxy = vt::makeCollection("test_bounded_bulk_insert_no_default_constructor") + .collective(true) + .bounds(range) + .bulkInsert() + .elementConstructor(NonDefaultConstructibleStruct::getConstructor()) + .template mapperObjGroupConstruct>() + .wait(); + + EXPECT_EQ(num_inserted, num_elms_per_node); + num_inserted = 0; + + runInEpochCollective([&]{ + proxy.broadcast(); + }); + EXPECT_EQ(num_work, num_elms_per_node * num_nodes); +} + }}}} // end namespace vt::tests::unit::list_insert