Skip to content
Merged
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
48 changes: 40 additions & 8 deletions tasks/mpi/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,68 @@

#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>
#include <memory>

class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {
public:
UnreadMessagesDetector(boost::mpi::communicator world) : world_(std::move(world)) {}
UnreadMessagesDetector(boost::mpi::communicator com) : com_(std::move(com)) {}

void OnTestEnd(const ::testing::TestInfo& test_info) override {
world_.barrier();
if (const auto msg = world_.iprobe(boost::mpi::any_source, boost::mpi::any_tag)) {
com_.barrier();
if (const auto msg = com_.iprobe(boost::mpi::any_source, boost::mpi::any_tag)) {
fprintf(
stderr,
"[ PROCESS %d ] [ FAILED ] %s.%s: MPI message queue has an unread message from process %d with tag %d\n",
world_.rank(), test_info.test_suite_name(), test_info.name(), msg->source(), msg->tag());
com_.rank(), test_info.test_suite_name(), test_info.name(), msg->source(), msg->tag());
exit(2);
}
world_.barrier();
com_.barrier();
}

private:
boost::mpi::communicator world_;
boost::mpi::communicator com_;
};

class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
public:
WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener> base, boost::mpi::communicator com)
: base_(std::move(base)), com_(std::move(com)) {}

void OnTestEnd(const ::testing::TestInfo& test_info) override {
if (test_info.result()->Passed()) {
return;
}
PrintProcessRank();
base_->OnTestEnd(test_info);

Check warning on line 37 in tasks/mpi/runner.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/mpi/runner.cpp#L36-L37

Added lines #L36 - L37 were not covered by tests
}

void OnTestPartResult(const ::testing::TestPartResult& test_part_result) override {
if (test_part_result.passed() || test_part_result.skipped()) {
return;
}
PrintProcessRank();
base_->OnTestPartResult(test_part_result);

Check warning on line 45 in tasks/mpi/runner.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/mpi/runner.cpp#L44-L45

Added lines #L44 - L45 were not covered by tests
}

private:
void PrintProcessRank() const { printf(" [ PROCESS %d ] ", com_.rank()); }

Check warning on line 49 in tasks/mpi/runner.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/mpi/runner.cpp#L49

Added line #L49 was not covered by tests

std::shared_ptr<::testing::TestEventListener> base_;
boost::mpi::communicator com_;
};

int main(int argc, char** argv) {
boost::mpi::environment env(argc, argv);
boost::mpi::communicator world;

::testing::InitGoogleTest(&argc, argv);

auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
if (world.rank() != 0) {
delete listeners.Release(listeners.default_result_printer());
if (world.rank() != 0 && (argc < 2 || argv[1] != std::string("--print-workers"))) {
auto* listener = listeners.Release(listeners.default_result_printer());
listeners.Append(new WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener>(listener), world));
}
listeners.Append(new UnreadMessagesDetector(world));

return RUN_ALL_TESTS();
}
Loading