Skip to content

Commit

Permalink
#476 add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Strzebonski authored and nlslatt committed May 25, 2022
1 parent 3d97ec0 commit 0ca2089
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/unit/collection/test_lb.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,81 @@ INSTANTIATE_TEST_SUITE_P(
DumpUserdefinedDataExplode, TestDumpUserdefinedData, booleans
);

struct SerdeTestCol : vt::Collection<SerdeTestCol, vt::Index1D> {
template <typename SerializerT> void serialize(SerializerT &s) {
vt::Collection<SerdeTestCol, vt::Index1D>::serialize(s);

if (s.isSizing()) {
s | was_packed | was_unpacked | packed_on_node | unpacked_on_node;
return;
}

was_packed = was_unpacked = false;
packed_on_node = unpacked_on_node = -1;

if (s.isPacking()) {
was_packed = true;
packed_on_node = theContext()->getNode();
}

s | was_packed | was_unpacked | packed_on_node | unpacked_on_node;

if (s.isUnpacking()) {
was_unpacked = true;
unpacked_on_node = theContext()->getNode();
}
}

bool was_packed = false;
bool was_unpacked = false;
int packed_on_node = -1;
int unpacked_on_node = -1;
};

using SerdeTestMsg = vt::CollectionMessage<SerdeTestCol>;

void serdeColHandler(SerdeTestMsg *, SerdeTestCol *col) {
auto const cur_phase = thePhase()->getCurrentPhase();
if (cur_phase < 2) {
return;
}

EXPECT_TRUE(col->was_packed);
EXPECT_TRUE(col->was_unpacked);
EXPECT_EQ(col->packed_on_node, col->unpacked_on_node);
}

void runSerdeTest() {
theConfig()->vt_lb = true;
theConfig()->vt_lb_name = "SerdeTestLB";
if (theContext()->getNode() == 0) {
::fmt::print("Testing LB: SerdeTestLB\n");
}

theCollective()->barrier();

auto range = Index1D{8};
vrt::collection::CollectionProxy<SerdeTestCol> proxy;

runInEpochCollective([&] {
proxy = theCollection()->constructCollective<SerdeTestCol>(range);
});

for (int phase = 0; phase < num_phases; ++phase) {
runInEpochCollective([&] {
proxy.broadcastCollective<SerdeTestMsg, serdeColHandler>();
});
thePhase()->nextPhaseCollective();
}
}

struct TestLoadBalancerSerdeTestLB : TestParallelHarness {};

TEST_F(TestLoadBalancerSerdeTestLB, test_SerdeTestLB_load_balancer) {
theCollective()->barrier();
runSerdeTest();
}

}}}} // end namespace vt::tests::unit::lb

#endif /*vt_check_enabled(lblite)*/

0 comments on commit 0ca2089

Please sign in to comment.