Skip to content

Commit a6bc279

Browse files
committed
Log failures from MPI workers
1 parent 32d76a7 commit a6bc279

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

Diff for: tasks/mpi/runner.cpp

+34-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,45 @@
22

33
#include <boost/mpi/communicator.hpp>
44
#include <boost/mpi/environment.hpp>
5+
#include <memory>
6+
7+
class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
8+
public:
9+
WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener> base, boost::mpi::communicator world)
10+
: base_(std::move(base)), world_(std::move(world)) {}
11+
12+
void OnTestEnd(const ::testing::TestInfo& test_info) override {
13+
if (test_info.result()->Passed()) {
14+
return;
15+
}
16+
PrintProcessRank();
17+
base_->OnTestEnd(test_info);
18+
}
19+
20+
void OnTestPartResult(const ::testing::TestPartResult& test_part_result) override {
21+
if (test_part_result.passed() || test_part_result.skipped()) {
22+
return;
23+
}
24+
PrintProcessRank();
25+
base_->OnTestPartResult(test_part_result);
26+
}
27+
28+
private:
29+
void PrintProcessRank() const { printf(" [ PROCESS %d ] ", world_.rank()); }
30+
31+
std::shared_ptr<TestEventListener> base_;
32+
boost::mpi::communicator world_;
33+
};
534

635
int main(int argc, char** argv) {
736
boost::mpi::environment env(argc, argv);
837
boost::mpi::communicator world;
38+
939
::testing::InitGoogleTest(&argc, argv);
10-
::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
11-
if (world.rank() != 0) {
12-
delete listeners.Release(listeners.default_result_printer());
40+
auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
41+
if (world.rank() != 0 && (argc < 2 || argv[1] != std::string("--print-workers"))) {
42+
auto* listener = listeners.Release(listeners.default_result_printer());
43+
listeners.Append(new WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener>(listener), world));
1344
}
1445
return RUN_ALL_TESTS();
1546
}

0 commit comments

Comments
 (0)