GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* Copyright 2019, LAAS-CNRS |
||
2 |
* |
||
3 |
* Olivier Stasse |
||
4 |
* |
||
5 |
* See LICENSE file |
||
6 |
* |
||
7 |
*/ |
||
8 |
#include <dynamic-graph/entity.h> |
||
9 |
#include <dynamic-graph/exception-factory.h> |
||
10 |
|||
11 |
#include <iostream> |
||
12 |
#include <sstream> |
||
13 |
|||
14 |
#include "dynamic-graph/factory.h" |
||
15 |
#include "dynamic-graph/pool.h" |
||
16 |
|||
17 |
#define ENABLE_RT_LOG |
||
18 |
#include <dynamic-graph/logger.h> |
||
19 |
#include <dynamic-graph/real-time-logger.h> |
||
20 |
|||
21 |
#define BOOST_TEST_MODULE debug - logger |
||
22 |
|||
23 |
#if BOOST_VERSION >= 105900 |
||
24 |
#include <boost/test/tools/output_test_stream.hpp> |
||
25 |
#else |
||
26 |
#include <boost/test/output_test_stream.hpp> |
||
27 |
#endif |
||
28 |
#include <boost/test/unit_test.hpp> |
||
29 |
|||
30 |
using boost::test_tools::output_test_stream; |
||
31 |
|||
32 |
namespace dynamicgraph { |
||
33 |
class CustomEntity : public Entity { |
||
34 |
public: |
||
35 |
static const std::string CLASS_NAME; |
||
36 |
virtual const std::string &getClassName() const { return CLASS_NAME; } |
||
37 |
1 |
explicit CustomEntity(const std::string &n) : Entity(n) { |
|
38 |
✓✗ | 1 |
logger_.setTimeSample(0.001); |
39 |
✓✗ | 1 |
logger_.setStreamPrintPeriod(0.005); |
40 |
|||
41 |
✓✗ | 1 |
logger_.setVerbosity(VERBOSITY_NONE); |
42 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_NONE); |
43 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_DEBUG).isNull()); |
44 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_INFO).isNull()); |
45 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_WARNING).isNull()); |
46 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_ERROR).isNull()); |
47 |
|||
48 |
✓✗ | 1 |
logger_.setVerbosity(VERBOSITY_ERROR); |
49 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_ERROR); |
50 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_DEBUG).isNull()); |
51 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_INFO).isNull()); |
52 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_WARNING).isNull()); |
53 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR).isNull()); |
54 |
|||
55 |
✓✗ | 1 |
logger_.setVerbosity(VERBOSITY_WARNING_ERROR); |
56 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_WARNING_ERROR); |
57 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_DEBUG).isNull()); |
58 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_INFO).isNull()); |
59 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_WARNING).isNull()); |
60 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR).isNull()); |
61 |
|||
62 |
✓✗ | 1 |
logger_.setVerbosity(VERBOSITY_INFO_WARNING_ERROR); |
63 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_INFO_WARNING_ERROR); |
64 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(logger_.stream(MSG_TYPE_DEBUG).isNull()); |
65 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_INFO).isNull()); |
66 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_WARNING).isNull()); |
67 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR).isNull()); |
68 |
|||
69 |
✓✗ | 1 |
logger_.setVerbosity(VERBOSITY_ALL); |
70 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_ALL); |
71 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_DEBUG).isNull()); |
72 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_INFO).isNull()); |
73 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_WARNING).isNull()); |
74 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR).isNull()); |
75 |
1 |
} |
|
76 |
|||
77 |
~CustomEntity() {} |
||
78 |
10000 |
void testDebugTrace() { |
|
79 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_DEBUG) |
80 |
✓✗ | 10000 |
<< "This is a message of level MSG_TYPE_DEBUG\n"; |
81 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
82 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_INFO) |
83 |
✓✗ | 10000 |
<< "This is a message of level MSG_TYPE_INFO\n"; |
84 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
85 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_WARNING) |
86 |
✓✗ | 10000 |
<< "This is a message of level MSG_TYPE_WARNING\n"; |
87 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
88 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_ERROR) |
89 |
✓✗ | 10000 |
<< "This is a message of level MSG_TYPE_ERROR\n"; |
90 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
91 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_DEBUG_STREAM) |
92 |
✓✗ | 10000 |
<< "This is a message of level MSG_TYPE_DEBUG_STREAM\n"; |
93 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
94 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_INFO_STREAM) |
95 |
✓✗ | 10000 |
<< "This is a message of level MSG_TYPE_INFO_STREAM\n"; |
96 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
97 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_WARNING_STREAM) |
98 |
✓✗ | 10000 |
<< "This is a message of level MSG_TYPE_WARNING_STREAM\n"; |
99 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
100 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_ERROR_STREAM) |
101 |
✓✗ | 10000 |
<< "This is a message of level MSG_TYPE_ERROR_STREAM\n"; |
102 |
/* Add test toString */ |
||
103 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
104 |
10000 |
double q = 1.0; |
|
105 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
10000 |
logger_.stream() << "Value to display: " + toString(q) << '\n'; |
106 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
107 |
20000 |
std::vector<double> vq; |
|
108 |
✓✗ | 10000 |
vq.resize(3); |
109 |
10000 |
vq[0] = 1.0; |
|
110 |
10000 |
vq[1] = 2.0; |
|
111 |
10000 |
vq[2] = 3.0; |
|
112 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_INFO) |
113 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
10000 |
<< "Value to display: " << toString(vq) << '\n'; |
114 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
115 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_INFO) |
116 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
10000 |
<< "Value to display: " << toString(vq, 3, 10) << '\n'; |
117 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
118 |
✓✗ | 10000 |
Eigen::Matrix<double, 3, 3> an_eig_m; |
119 |
✓✗ | 10000 |
an_eig_m.setOnes(); |
120 |
✓✗✓✗ |
20000 |
logger_.stream(MSG_TYPE_INFO) |
121 |
✓✗✓✗ ✓✗✓✗ |
10000 |
<< "Value to display: " << toString(an_eig_m) << '\n'; |
122 |
✓✗✓✗ |
10000 |
dynamicgraph::RealTimeLogger::instance().spinOnce(); |
123 |
✓✗ | 10000 |
logger_.countdown(); |
124 |
10000 |
} |
|
125 |
}; |
||
126 |
✓✗ | 1 |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity"); |
127 |
} // namespace dynamicgraph |
||
128 |
|||
129 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(debug_logger) { |
130 |
✓✗ | 4 |
std::ofstream of; |
131 |
✓✗ | 2 |
dynamicgraph::RealTimeLogger::instance(); |
132 |
✓✗ | 2 |
of.open("/tmp/dg-LOGS.txt", std::ofstream::out | std::ofstream::app); |
133 |
✓✗✓✗ ✓✗✓✗ |
2 |
dgADD_OSTREAM_TO_RTLOG(of); |
134 |
|||
135 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity"); |
136 |
|||
137 |
dynamicgraph::CustomEntity &entity = |
||
138 |
*(dynamic_cast<dynamicgraph::CustomEntity *>( |
||
139 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity", |
140 |
2 |
"my-entity"))); |
|
141 |
|||
142 |
✓✗ | 2 |
entity.setTimeSample(0.002); |
143 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(entity.getTimeSample(), 0.002); |
144 |
✓✗ | 2 |
entity.setStreamPrintPeriod(0.002); |
145 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(entity.getStreamPrintPeriod(), 0.002); |
146 |
|||
147 |
✓✓ | 20002 |
for (unsigned int i = 0; i < 10000; i++) { |
148 |
✓✗ | 20000 |
entity.testDebugTrace(); |
149 |
} |
||
150 |
|||
151 |
✓✗ | 2 |
dynamicgraph::RealTimeLogger::destroy(); |
152 |
2 |
} |
Generated by: GCOVR (Version 4.2) |