preCICE v3.1.1
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Setup boost test
2// Disable the auto generation of main()
3#define BOOST_TEST_NO_MAIN
4// Specify the overall name of test framework
5#define BOOST_TEST_MODULE "preCICE Tests"
6
7#include <boost/test/tools/fpc_tolerance.hpp>
8#include <boost/test/tree/test_case_counter.hpp>
9#include <boost/test/tree/traverse.hpp>
10#include <boost/test/unit_test.hpp>
11
12#include <filesystem>
13#include <iostream>
14#include <string>
15
16#include "com/SharedPointer.hpp"
18#include "utils/IntraComm.hpp"
19#include "utils/Parallel.hpp"
20
21namespace precice {
22extern bool syncMode;
23} // namespace precice
24
26{
27 using namespace boost::unit_test;
28 test_case_counter tcc;
29 traverse_test_tree(framework::master_test_suite(), tcc, true);
30 return tcc.p_count;
31}
32
33class test_case_printer : public boost::unit_test::test_tree_visitor {
34private:
36
37 bool test_suite_start(boost::unit_test::test_suite const &ts) override
38 {
39 if (ts.p_type_name == "suite") {
40 prefix.push_back(ts.p_name);
41 }
42 return test_tree_visitor::visit((boost::unit_test::test_unit const &) ts);
43 }
44
45 void test_suite_finish(boost::unit_test::test_suite const &ts) override
46 {
47 if (ts.p_type_name == "suite") {
49 }
50 }
51
52 void visit(boost::unit_test::test_case const &tc) override
53 {
54 for (const auto &p : prefix) {
55 std::cout << p << '/';
56 }
57 std::cout << tc.p_name << '\n';
58 }
59};
60
62{
63 using namespace boost::unit_test;
65 traverse_test_tree(framework::master_test_suite(), tcp, true);
66}
67
69{
70 static constexpr double tolerance = 1e-9;
71
72 boost::test_tools::fpc_tolerance<double>() = tolerance;
73 boost::test_tools::fpc_tolerance<float>() = tolerance;
74}
75
77{
78 namespace fs = std::filesystem;
79 fs::path runDir("precice-run");
80 if (fs::exists(runDir) && fs::is_directory(runDir) && !fs::is_empty(runDir)) {
81 std::cout << "Removing a non-empty precice-run directory from a previously failing test.\n";
82 fs::remove_all(runDir);
83 }
84}
85
87int main(int argc, char *argv[])
88{
89 using namespace precice;
90
91 precice::syncMode = false;
92 utils::Parallel::initializeTestingMPI(&argc, &argv);
93 const auto rank = utils::Parallel::current()->rank();
94 const auto size = utils::Parallel::current()->size();
95 logging::setMPIRank(rank);
96
97 // Handle custom printing
98 if (argc == 2 && std::string(argv[1]) == "--list_units") {
99 if (rank == 0) {
101 }
102 utils::Parallel::finalizeTestingMPI();
103 return 0;
104 }
105
106 // Handle not enough MPI ranks
107 if (size < 4 && argc < 2) {
108 if (rank == 0) {
109 std::cerr << "ERROR: The tests require at least 4 MPI processes. Please use \"mpirun -np 4 ./testprecice\" or \"ctest\" to run the full testsuite. \n";
110 }
111 utils::Parallel::finalizeTestingMPI();
112 return 2;
113 }
114
115 std::cout << "This test suite runs on rank " << rank << " of " << size << '\n';
116
117 if (rank == 0) {
119 }
120
122 int retCode = boost::unit_test::unit_test_main(&init_unit_test, argc, argv);
123 const int testsRan = countEnabledTests();
124
125 // Override the return code if the secondary ranks have nothing to test
126 if ((testsRan == 0) && (rank != 0)) {
127 retCode = EXIT_SUCCESS;
128 }
129
130 utils::IntraComm::getCommunication() = nullptr;
131 utils::Parallel::finalizeTestingMPI();
132 return retCode;
133}
Eigen::Vector2d ts
void test_suite_finish(boost::unit_test::test_suite const &ts) override
Definition main.cpp:45
bool test_suite_start(boost::unit_test::test_suite const &ts) override
Definition main.cpp:37
void visit(boost::unit_test::test_case const &tc) override
Definition main.cpp:52
std::vector< std::string > prefix
Definition main.cpp:35
int main(int argc, char **argv)
Definition main.cpp:17
T exists(T... args)
T is_directory(T... args)
T is_empty(T... args)
Main namespace of the precice library.
bool syncMode
Enabled further inter- and intra-solver synchronisation.
T pop_back(T... args)
T push_back(T... args)
T remove_all(T... args)
void printTestList()
Definition main.cpp:61
void removeStaleRunDirectory()
Definition main.cpp:76
int countEnabledTests()
Definition main.cpp:25
void setupTolerance()
Definition main.cpp:68