Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

955 Clear out uses of addAction in tests #979

Merged
merged 4 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions tests/unit/pipe/test_callback_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ TEST_F(TestCallbackFunc, test_callback_func_2) {

called = 0;

if (this_node == 0) {
auto cb = theCB()->makeFunc([]{ called = 400; });
auto msg = makeMessage<CallbackMsg>(cb);
theMsg()->sendMsg<CallbackMsg, test_handler>(1, msg.get());
runInEpochCollective([this_node]{
if (this_node == 0) {
auto cb = theCB()->makeFunc([]{ called = 400; });
auto msg = makeMessage<CallbackMsg>(cb);
theMsg()->sendMsg<CallbackMsg, test_handler>(1, msg.get());
}
});

theTerm()->addAction([=]{
EXPECT_EQ(called, 400);
});
if (this_node == 0) {
EXPECT_EQ(called, 400);
}
}

Expand Down
41 changes: 20 additions & 21 deletions tests/unit/pipe/test_callback_func_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,27 @@ TEST_F(TestCallbackFuncCtx, test_callback_func_ctx_2) {
return;
}

ctx = std::make_unique<Context>();
ctx->val = this_node;

auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeFunc<DataMsg,Context>(
ctx.get(), [next](DataMsg* msg, Context* my_ctx){
called = 500;
EXPECT_EQ(my_ctx->val, theContext()->getNode());
//fmt::print("{}: a={},b={},c={}\n",n,msg->a,msg->b,msg->c);
EXPECT_EQ(msg->a, next+1);
EXPECT_EQ(msg->b, next+2);
EXPECT_EQ(msg->c, next+3);
}
);
//fmt::print("{}: next={}\n", this_node, next);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, test_handler>(next, msg.get());

theTerm()->addAction([=]{
//fmt::print("{}: called={}\n", this_node, called);
EXPECT_EQ(called, 500);
runInEpochCollective([this_node, num_nodes]{
ctx = std::make_unique<Context>();
ctx->val = this_node;

auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeFunc<DataMsg, Context>(
ctx.get(), [next](DataMsg* msg, Context* my_ctx) {
called = 500;
EXPECT_EQ(my_ctx->val, theContext()->getNode());
// fmt::print("{}: a={},b={},c={}\n",n,msg->a,msg->b,msg->c);
EXPECT_EQ(msg->a, next + 1);
EXPECT_EQ(msg->b, next + 2);
EXPECT_EQ(msg->c, next + 3);
});
// fmt::print("{}: next={}\n", this_node, next);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, test_handler>(next, msg.get());
});

// fmt::print("{}: called={}\n", this_node, called);
EXPECT_EQ(called, 500);
}

}}} // end namespace vt::tests::unit
70 changes: 38 additions & 32 deletions tests/unit/pipe/test_callback_send.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,81 +114,87 @@ TEST_F(TestCallbackSend, test_callback_send_1) {
auto const& this_node = theContext()->getNode();

called = 0;
auto cb = theCB()->makeSend<DataMsg,callbackFn>(this_node);
auto nmsg = makeMessage<DataMsg>(1,2,3);
cb.send(nmsg.get());

theTerm()->addAction([=]{
EXPECT_EQ(called, 100);
runInEpochCollective([this_node]{
auto cb = theCB()->makeSend<DataMsg, callbackFn>(this_node);
auto nmsg = makeMessage<DataMsg>(1, 2, 3);
cb.send(nmsg.get());
});

EXPECT_EQ(called, 100);
}

TEST_F(TestCallbackSend, test_callback_send_2) {
auto const& this_node = theContext()->getNode();
called = 0;
auto cb = theCB()->makeSend<CallbackFunctor>(this_node);
auto nmsg = makeMessage<DataMsg>(1,2,3);
cb.send(nmsg.get());

theTerm()->addAction([=]{
EXPECT_EQ(called, 200);
runInEpochCollective([this_node]{
auto cb = theCB()->makeSend<CallbackFunctor>(this_node);
auto nmsg = makeMessage<DataMsg>(1, 2, 3);
cb.send(nmsg.get());
});

EXPECT_EQ(called, 200);
}

TEST_F(TestCallbackSend, test_callback_send_3) {
auto const& this_node = theContext()->getNode();
called = 0;
auto cb = theCB()->makeSend<CallbackFunctorEmpty>(this_node);
cb.send();

theTerm()->addAction([=]{
EXPECT_EQ(called, 300);
runInEpochCollective([this_node]{
auto cb = theCB()->makeSend<CallbackFunctorEmpty>(this_node);
cb.send();
});

EXPECT_EQ(called, 300);
}

TEST_F(TestCallbackSend, test_callback_send_remote_1) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();

called = 0;
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<DataMsg,callbackFn>(this_node);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());

theTerm()->addAction([=]{
EXPECT_EQ(called, 100);
runInEpochCollective([this_node, num_nodes]{
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<DataMsg, callbackFn>(this_node);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
});

EXPECT_EQ(called, 100);
}

TEST_F(TestCallbackSend, test_callback_send_remote_2) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();

called = 0;
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<CallbackFunctor>(this_node);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());

theTerm()->addAction([=]{
EXPECT_EQ(called, 200);
runInEpochCollective([this_node, num_nodes]{
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<CallbackFunctor>(this_node);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
});

EXPECT_EQ(called, 200);
}

TEST_F(TestCallbackSend, test_callback_send_remote_3) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();

called = 0;
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<CallbackFunctorEmpty>(this_node);
auto msg = makeMessage<CallbackMsg>(cb);
theMsg()->sendMsg<CallbackMsg, testHandlerEmpty>(next, msg.get());

theTerm()->addAction([=]{
EXPECT_EQ(called, 300);
runInEpochCollective([this_node, num_nodes]{
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<CallbackFunctorEmpty>(this_node);
auto msg = makeMessage<CallbackMsg>(cb);
theMsg()->sendMsg<CallbackMsg, testHandlerEmpty>(next, msg.get());
});

EXPECT_EQ(called, 300);
}


Expand Down
137 changes: 78 additions & 59 deletions tests/unit/pipe/test_callback_send_collection.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ namespace vt { namespace tests { namespace unit {
using namespace vt;
using namespace vt::tests::unit;

struct TestColMsg;

struct CallbackMsg : vt::Message {
CallbackMsg() = default;
explicit CallbackMsg(Callback<> in_cb) : cb_(in_cb) { }
Expand Down Expand Up @@ -88,11 +90,9 @@ struct TestCallbackSendCollection : TestParallelHarness {

struct TestCol : vt::Collection<TestCol, vt::Index1D> {
TestCol() = default;
virtual ~TestCol() = default;

virtual ~TestCol() {
// fmt::print(
// "{}: destroying {}\n", theContext()->getNode(), this->getIndex()
// );
void check(TestColMsg* msg) {
if (this->getIndex().x() % 2 == 0) {
EXPECT_EQ(val, 29);
} else {
Expand Down Expand Up @@ -125,29 +125,37 @@ static void cb3(DataMsg* msg, TestCol* col) {
col->val = 13;
}

struct TestColMsg : ::vt::CollectionMessage<TestCol> {};

TEST_F(TestCallbackSendCollection, test_callback_send_collection_1) {
auto const& this_node = theContext()->getNode();

if (this_node == 0) {
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(range);

for (auto i = 0; i < 32; i++) {
if (i % 2 == 0) {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb1>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8,9,10);
cb.send(nmsg.get());
} else {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb2>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8,9,10);
cb.send(nmsg.get());
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(range);

runInEpochCollective([this_node, proxy]{
if (this_node == 0) {
for (auto i = 0; i < 32; i++) {
if (i % 2 == 0) {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb1>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8, 9, 10);
cb.send(nmsg.get());
} else {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb2>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8, 9, 10);
cb.send(nmsg.get());
}
}
}
});

theTerm()->addAction([=]{
proxy.destroy();
});
}
runInEpochCollective([this_node, proxy]{
if (this_node == 0) {
auto msg = makeMessage<TestColMsg>();
proxy.broadcast<TestColMsg, &TestCol::check>(msg.get());
}
});
}

TEST_F(TestCallbackSendCollection, test_callback_send_collection_2) {
Expand All @@ -158,53 +166,64 @@ TEST_F(TestCallbackSendCollection, test_callback_send_collection_2) {
return;
}

if (this_node == 0) {
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(range);

for (auto i = 0; i < 32; i++) {
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
if (i % 2 == 0) {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb1>(proxy(i));
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
} else {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb2>(proxy(i));
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(range);

runInEpochCollective([this_node, num_nodes, proxy]{
if (this_node == 0) {
for (auto i = 0; i < 32; i++) {
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
if (i % 2 == 0) {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb1>(proxy(i));
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
} else {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb2>(proxy(i));
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
}
}
}
});

theTerm()->addAction([=]{
proxy.destroy();
});
}

runInEpochCollective([this_node, proxy]{
if (this_node == 0) {
auto msg = makeMessage<TestColMsg>();
proxy.broadcast<TestColMsg, &TestCol::check>(msg.get());
}
});
}

TEST_F(TestCallbackSendCollection, test_callback_send_collection_3) {
auto const& this_node = theContext()->getNode();

if (this_node == 0) {
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(range);

for (auto i = 0; i < 32; i++) {
if (i % 2 == 0) {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb1>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8,9,10);
cb.send(nmsg.get());
} else {
auto cb = theCB()->makeSend<TestCol,DataMsg,cb3>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8,9,10);
cb.send(nmsg.get());
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(range);

runInEpochCollective([this_node, proxy]{
if (this_node == 0) {
for (auto i = 0; i < 32; i++) {
if (i % 2 == 0) {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb1>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8, 9, 10);
cb.send(nmsg.get());
} else {
auto cb = theCB()->makeSend<TestCol, DataMsg, cb3>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8, 9, 10);
cb.send(nmsg.get());
}
}
}
});

theTerm()->addAction([=]{
proxy.destroy();
});
}
runInEpochCollective([this_node, proxy]{
if (this_node == 0) {
auto msg = makeMessage<TestColMsg>();
proxy.broadcast<TestColMsg, &TestCol::check>(msg.get());
}
});
}


Expand Down
Loading