Skip to content

Commit 86de7f0

Browse files
committed
Log failures from MPI workers
1 parent 60271ff commit 86de7f0

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

Diff for: tasks/mpi/runner.cpp

+38-8
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,54 @@
22

33
#include <boost/mpi/communicator.hpp>
44
#include <boost/mpi/environment.hpp>
5+
#include <memory>
56

67
class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {
78
public:
8-
UnreadMessagesDetector(boost::mpi::communicator world) : world_(std::move(world)) {}
9+
UnreadMessagesDetector(boost::mpi::communicator com) : com_(std::move(com)) {}
910

1011
void OnTestEnd(const ::testing::TestInfo& test_info) override {
11-
world_.barrier();
12-
if (const auto msg = world_.iprobe(boost::mpi::any_source, boost::mpi::any_tag)) {
12+
com_.barrier();
13+
if (const auto msg = com_.iprobe(boost::mpi::any_source, boost::mpi::any_tag)) {
1314
fprintf(
1415
stderr,
1516
"[ PROCESS %d ] [ FAILED ] %s.%s: MPI message queue has an unread message from process %d with tag %d\n",
16-
world_.rank(), test_info.test_suite_name(), test_info.name(), msg->source(), msg->tag());
17+
com_.rank(), test_info.test_suite_name(), test_info.name(), msg->source(), msg->tag());
1718
exit(2);
1819
}
19-
world_.barrier();
20+
com_.barrier();
2021
}
2122

2223
private:
23-
boost::mpi::communicator world_;
24+
boost::mpi::communicator com_;
25+
};
26+
27+
class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
28+
public:
29+
WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener> base, boost::mpi::communicator com)
30+
: base_(std::move(base)), com_(std::move(com)) {}
31+
32+
void OnTestEnd(const ::testing::TestInfo& test_info) override {
33+
if (test_info.result()->Passed()) {
34+
return;
35+
}
36+
PrintProcessRank();
37+
base_->OnTestEnd(test_info);
38+
}
39+
40+
void OnTestPartResult(const ::testing::TestPartResult& test_part_result) override {
41+
if (test_part_result.passed() || test_part_result.skipped()) {
42+
return;
43+
}
44+
PrintProcessRank();
45+
base_->OnTestPartResult(test_part_result);
46+
}
47+
48+
private:
49+
void PrintProcessRank() const { printf(" [ PROCESS %d ] ", com_.rank()); }
50+
51+
std::shared_ptr<::testing::TestEventListener> base_;
52+
boost::mpi::communicator com_;
2453
};
2554

2655
int main(int argc, char** argv) {
@@ -29,8 +58,9 @@ int main(int argc, char** argv) {
2958

3059
::testing::InitGoogleTest(&argc, argv);
3160
auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
32-
if (world.rank() != 0) {
33-
delete listeners.Release(listeners.default_result_printer());
61+
if (world.rank() != 0 && (argc < 2 || argv[1] != std::string("--print-workers"))) {
62+
auto* listener = listeners.Release(listeners.default_result_printer());
63+
listeners.Append(new WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener>(listener), world));
3464
}
3565
listeners.Append(new UnreadMessagesDetector(world));
3666
return RUN_ALL_TESTS();

0 commit comments

Comments
 (0)