preCICE v3.1.1
Loading...
Searching...
No Matches
GlobalFixtures.cpp
Go to the documentation of this file.
1#include <boost/test/detail/log_level.hpp>
2#include <boost/test/tools/fpc_tolerance.hpp>
3#include <boost/test/tree/test_unit.hpp>
4#include <boost/test/unit_test.hpp>
5#include <boost/test/unit_test_parameters.hpp>
6#include <boost/test/unit_test_suite.hpp>
7#include <iostream>
8
11
12namespace precice::testing {
13
15
34boost::unit_test::log_level getBoostTestLogLevel()
35{
36 namespace bu = boost::unit_test;
37#if BOOST_VERSION == 106900 || __APPLE__ && __MACH__
38 std::cerr << "Boost 1.69 and macOS get log_level is broken, preCICE log level set to debug.\n";
39 return bu::log_successful_tests;
40#else
41 return bu::runtime_config::get<bu::log_level>(bu::runtime_config::btrt_log_level);
42#endif
43}
44
45std::string filterFromLogLevel(boost::unit_test::log_level logLevel)
46{
47 namespace bu = boost::unit_test;
48
49 if (logLevel == bu::log_successful_tests || logLevel == bu::log_test_units) {
50 return "%Severity% >= debug";
51 }
52 if (logLevel == bu::log_messages) {
53 return "%Severity% >= info";
54 }
55 if (logLevel == bu::log_warnings) {
56 return "%Severity% >= warning";
57 }
58 // log warnings in any case
59 return "%Severity% >= warning";
60}
61
63{
64 // See if there is a manual override using a log.conf file.
65 auto logConfigs = logging::readLogConfFile("log.conf");
66
67 if (logConfigs.empty()) {
68 // Nothing has been read from log.conf
69 // We configure the log level based on the test framework log level
70
73
74 const std::string prefix{"%TimeStamp(format=\"%H:%M:%S.%f\")%|%Participant%|%Rank%|%Module%|l%Line%|%Function%|"};
75
76 // Console output
77 config.format = prefix + "%ColorizedSeverity%%Message%";
78 config.type = "stream";
79 config.output = "stdout";
80 logConfigs.push_back(config);
81
82 // File Outputs
83 config.format = prefix + "%Severity%%Message%";
84 config.type = "file";
85 config.output = "test.log";
86 logConfigs.push_back(config);
87
88 // The full debug log
89 config.output = "test.debug.log";
90 config.filter = "%Severity% >= debug";
91 logConfigs.push_back(config);
92 }
93
94 logging::setupLogging(logConfigs);
95 // Lock the logging configuration to prevent systemtests from changing them
97}
98
99} // namespace precice::testing
100
101// Fixtures need to be defined in the global scope
102
104 static void setup()
105 {
106 std::cerr << "Setup up logging\n";
108 }
109};
110
std::string prefix
BOOST_TEST_GLOBAL_FIXTURE(PreciceTestLoggingFixture)
void setupLogging(LoggingConfiguration configs, bool enabled)
Configures the logging from a LoggingConfiguration.
LoggingConfiguration readLogConfFile(std::string const &filename)
Reads a log file, returns a logging configuration.
contains the testing framework.
Definition helper.hpp:9
boost::unit_test::log_level getBoostTestLogLevel()
Boost test Initialization function.
std::string filterFromLogLevel(boost::unit_test::log_level logLevel)
T push_back(T... args)
Holds the configuration for one logging backend (sink) and takes care of default values.