From 3738485072d7bfd1add449c3c15b49f0300fab67 Mon Sep 17 00:00:00 2001 From: Jakub Domagala Date: Fri, 25 Sep 2020 00:21:19 +0200 Subject: [PATCH] #1024: Update collective bcast unittests after API changes --- .../test_collection_group.extended.cc | 81 ++++++++++++++----- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/tests/unit/collection/test_collection_group.extended.cc b/tests/unit/collection/test_collection_group.extended.cc index 78709b68c3..d03b6b5d9c 100644 --- a/tests/unit/collection/test_collection_group.extended.cc +++ b/tests/unit/collection/test_collection_group.extended.cc @@ -55,6 +55,7 @@ namespace vt { namespace tests { namespace unit { static int32_t elem_counter = 0; +static bool handler_executed = false; struct MyReduceMsg : collective::ReduceTMsg { explicit MyReduceMsg(int const in_num) @@ -87,6 +88,7 @@ struct ColA : Collection { void memberHanlder(TestDataMsg* msg) { EXPECT_EQ(msg->value_, theContext()->getNode()); --elem_counter; + handler_executed = true; } virtual ~ColA() { @@ -103,10 +105,20 @@ struct ColA : Collection { void colHanlder( ColA::TestDataMsg* msg, typename ColA::TestDataMsg::CollectionType* type) { --elem_counter; + handler_executed = true; } -struct TestCollectionGroup : TestParallelHarness { }; +template +void runBcastTestHelper(f&& func) +{ + handler_executed = false; + func(); + + // spin the scheduler until the handler is called + theSched()->runSchedulerWhile([]{ return not handler_executed; }); +} +struct TestCollectionGroup : TestParallelHarness { }; TEST_F(TestCollectionGroup, test_collection_group_1) { auto const my_node = theContext()->getNode(); @@ -118,52 +130,83 @@ TEST_F(TestCollectionGroup, test_collection_group_1) { } } -TEST_F(TestCollectionGroup, test_collection_group_2){ +TEST_F(TestCollectionGroup, test_collection_group_2) { auto const my_node = theContext()->getNode(); auto const range = Index1D(8); auto const proxy = - theCollection()->constructCollective(range, [](vt::Index1D idx) { + theCollection()->constructCollective(range, [](vt::Index1D idx){ ++elem_counter; return std::make_unique(); - }); + } + ); + + auto const numElems = elem_counter; - const auto numElems = elem_counter; - auto msg = ::vt::makeMessage(my_node); + // raw msg pointer case + runBcastTestHelper([proxy, my_node]{ + auto msg = ::vt::makeMessage(my_node); + proxy.broadcastCollectiveMsg( + msg.get() + ); + }); - proxy.broadcastCollective(msg.get()); EXPECT_EQ(elem_counter, 0); - proxy.broadcastCollective(msg); + // smart msg pointer case + runBcastTestHelper([proxy, my_node]{ + auto msg = ::vt::makeMessage(my_node); + proxy.broadcastCollectiveMsg(msg); + }); + EXPECT_EQ(elem_counter, -numElems); - proxy.broadcastCollective< - ColA::TestDataMsg, &ColA::memberHanlder, ColA::TestDataMsg>(my_node); + // msg constructed on the fly case + runBcastTestHelper([proxy, my_node] { + proxy.broadcastCollective< + ColA::TestDataMsg, &ColA::memberHanlder, ColA::TestDataMsg>(my_node); + }); + EXPECT_EQ(elem_counter, -2 * numElems); } -TEST_F(TestCollectionGroup, test_collection_group_3){ +TEST_F(TestCollectionGroup, test_collection_group_3) { elem_counter = 0; auto const my_node = theContext()->getNode(); auto const range = Index1D(8); auto const proxy = - theCollection()->constructCollective(range, [](vt::Index1D idx) { + theCollection()->constructCollective(range, [](vt::Index1D idx){ ++elem_counter; return std::make_unique(); - }); + } + ); - const auto numElems = elem_counter; - auto msg = ::vt::makeMessage(my_node); + auto const numElems = elem_counter; + + // raw msg pointer case + runBcastTestHelper([proxy, my_node]{ + auto msg = ::vt::makeMessage(my_node); + proxy.broadcastCollectiveMsg(msg.get()); + }); - proxy.broadcastCollective(msg.get()); EXPECT_EQ(elem_counter, 0); - proxy.broadcastCollective(msg); + // smart msg pointer case + runBcastTestHelper([proxy, my_node]{ + auto msg = ::vt::makeMessage(my_node); + proxy.broadcastCollectiveMsg(msg); + }); + EXPECT_EQ(elem_counter, -numElems); - proxy.broadcastCollective< - ColA::TestDataMsg, colHanlder, ColA::TestDataMsg>(my_node); + // msg constructed on the fly case + runBcastTestHelper([proxy, my_node]{ + proxy.broadcastCollective( + my_node + ); + }); + EXPECT_EQ(elem_counter, -2 * numElems); }