GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* Copyright 2019, LAAS-CNRS |
||
2 |
* |
||
3 |
* Olivier Stasse |
||
4 |
* |
||
5 |
*/ |
||
6 |
|||
7 |
#include <dynamic-graph/command.h> |
||
8 |
#include <dynamic-graph/entity.h> |
||
9 |
#include <dynamic-graph/exception-factory.h> |
||
10 |
#include <dynamic-graph/factory.h> |
||
11 |
#include <dynamic-graph/pool.h> |
||
12 |
#include <dynamic-graph/signal-ptr.h> |
||
13 |
#include <dynamic-graph/signal-time-dependent.h> |
||
14 |
#include <dynamic-graph/tracer-real-time.h> |
||
15 |
|||
16 |
#include <iostream> |
||
17 |
#define BOOST_TEST_MODULE debug - tracer |
||
18 |
|||
19 |
#if BOOST_VERSION >= 105900 |
||
20 |
#include <boost/test/tools/output_test_stream.hpp> |
||
21 |
#else |
||
22 |
#include <boost/test/output_test_stream.hpp> |
||
23 |
#endif |
||
24 |
#include <boost/test/unit_test.hpp> |
||
25 |
using boost::test_tools::output_test_stream; |
||
26 |
|||
27 |
namespace dynamicgraph { |
||
28 |
struct MyEntity : public dynamicgraph::Entity { |
||
29 |
static const std::string CLASS_NAME; |
||
30 |
|||
31 |
dynamicgraph::Signal<double, int> m_sigdSIN; |
||
32 |
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT; |
||
33 |
dynamicgraph::SignalTimeDependent<double, int> m_sigdTwoTimeDepSOUT; |
||
34 |
|||
35 |
1 |
explicit MyEntity(const std::string &name) |
|
36 |
1 |
: Entity(name), |
|
37 |
✓✗ | 2 |
m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"), |
38 |
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2), |
||
39 |
m_sigdSIN, |
||
40 |
✓✗ | 2 |
"MyEntity(" + name + ")::input(double)::out_double"), |
41 |
m_sigdTwoTimeDepSOUT( |
||
42 |
boost::bind(&MyEntity::update, this, _1, _2), m_sigdSIN, |
||
43 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
5 |
"MyEntity(" + name + ")::input(double)::out2double") |
44 |
|||
45 |
{ |
||
46 |
✓✗✓✗ ✓✗ |
1 |
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigdTwoTimeDepSOUT); |
47 |
1 |
} |
|
48 |
|||
49 |
2000 |
double &update(double &res, const int &inTime) { |
|
50 |
2000 |
const double &aDouble = m_sigdSIN(inTime); |
|
51 |
2000 |
res = aDouble; |
|
52 |
2000 |
return res; |
|
53 |
} |
||
54 |
}; |
||
55 |
✓✗ | 1 |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MyEntity, "MyEntity"); |
56 |
} // namespace dynamicgraph |
||
57 |
|||
58 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(test_tracer) { |
59 |
using namespace dynamicgraph; |
||
60 |
|||
61 |
// Creates a tracer. |
||
62 |
TracerRealTime &atracer = *dynamic_cast<TracerRealTime *>( |
||
63 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
2 |
FactoryStorage::getInstance()->newEntity("TracerRealTime", "my-tracer")); |
64 |
|||
65 |
MyEntity &entity = *dynamic_cast<MyEntity *>( |
||
66 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
2 |
FactoryStorage::getInstance()->newEntity("MyEntity", "my-entity")); |
67 |
|||
68 |
✓✗ | 4 |
std::string rootdir("/tmp"); |
69 |
✓✗ | 4 |
std::string basename("my-tracer"); |
70 |
✓✗ | 4 |
std::string suffix(".dat"); |
71 |
|||
72 |
2 |
atracer.setBufferSize(1 << 14); |
|
73 |
|||
74 |
// Check that an exception is thrown if the filename is invalid. |
||
75 |
✓✗✓✗ |
2 |
atracer.openFiles(rootdir, "invalid/filename", suffix); |
76 |
✓✗✓✗ ✓✗✓✗ ✗✓✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✓ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
14 |
BOOST_CHECK_THROW( |
77 |
atracer.addSignalToTraceByName("my-entity.out_double", "output"), |
||
78 |
ExceptionTraces); |
||
79 |
|||
80 |
// Test openfiles |
||
81 |
✓✗ | 2 |
atracer.openFiles(rootdir, basename, suffix); |
82 |
// Add trace by name |
||
83 |
✓✗✓✗ ✓✗ |
2 |
atracer.addSignalToTraceByName("my-entity.out_double", "output"); |
84 |
|||
85 |
/// Add trace by name |
||
86 |
✓✗✓✗ |
2 |
SignalBase<int> &out_double = entity.getSignal("out_double"); |
87 |
✓✗✓✗ |
2 |
SignalBase<int> &out_double_2 = entity.getSignal("out2double"); |
88 |
|||
89 |
Signal<double, int> &in_double = |
||
90 |
✓✗✓✗ ✓✗ |
2 |
*(dynamic_cast<Signal<double, int> *>(&entity.getSignal("in_double"))); |
91 |
|||
92 |
✓✗ | 2 |
in_double.setConstant(1.5); |
93 |
2 |
atracer.start(); |
|
94 |
|||
95 |
✓✗ | 4 |
std::string emptybuf_cmd_str("empty"); |
96 |
✓✗ | 2 |
command::Command *acmd = atracer.getNewStyleCommand(emptybuf_cmd_str); |
97 |
✓✗ | 2 |
acmd->execute(); |
98 |
✓✓ | 2002 |
for (int i = 0; i < 1000; i++) { |
99 |
✓✗ | 2000 |
in_double.setTime(i); |
100 |
✓✗ | 2000 |
out_double.recompute(i); |
101 |
✓✗ | 2000 |
out_double_2.recompute(i); |
102 |
✓✗ | 2000 |
atracer.recordTrigger(i, i); |
103 |
} |
||
104 |
✓✗✓✗ |
4 |
output_test_stream output; |
105 |
|||
106 |
✓✗ | 2 |
atracer.display(output); |
107 |
|||
108 |
2 |
atracer.stop(); |
|
109 |
✓✗ | 2 |
atracer.trace(); |
110 |
✓✗ | 2 |
atracer.clearSignalToTrace(); |
111 |
✓✗ | 2 |
atracer.closeFiles(); |
112 |
✓✗ | 2 |
acmd->execute(); |
113 |
✓✗ | 2 |
atracer.record(); |
114 |
|||
115 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal( |
116 |
"TracerRealTime my-tracer [mode=play] : \n" |
||
117 |
" - Dep list: \n" |
||
118 |
" -> MyEntity(my-entity)::input(double)::out_double (in output)" |
||
119 |
" [8Ko/16Ko] \n")); |
||
120 |
2 |
} |
Generated by: GCOVR (Version 4.2) |