GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* |
||
2 |
* License BSD3 |
||
3 |
* Copyright 2021, |
||
4 |
* Maximilien Naveau, |
||
5 |
* |
||
6 |
* CNRS |
||
7 |
* |
||
8 |
*/ |
||
9 |
|||
10 |
#define BOOST_TEST_MODULE test_sot_loader |
||
11 |
#include <dynamic-graph/entity.h> |
||
12 |
#include <dynamic-graph/factory.h> |
||
13 |
#include <dynamic-graph/pool.h> |
||
14 |
|||
15 |
#include <boost/test/included/unit_test.hpp> |
||
16 |
#include <fstream> |
||
17 |
#include <iostream> |
||
18 |
|||
19 |
#include "sot/core/debug.hh" |
||
20 |
#include "sot/core/device.hh" |
||
21 |
#include "sot/core/sot-loader.hh" |
||
22 |
|||
23 |
using namespace dynamicgraph; |
||
24 |
using namespace dynamicgraph::sot; |
||
25 |
namespace dg = dynamicgraph; |
||
26 |
|||
27 |
class TestDevice : public dg::sot::Device { |
||
28 |
public: |
||
29 |
TestDevice(const std::string &RobotName) : Device(RobotName) { |
||
30 |
timestep_ = 0.001; |
||
31 |
} |
||
32 |
~TestDevice() {} |
||
33 |
}; |
||
34 |
|||
35 |
struct TestFixture { |
||
36 |
14 |
TestFixture() { |
|
37 |
✓✗ | 14 |
asotei_lib_file_ = LIB_PLUGIN_ABSTRACT_PATH; |
38 |
✓✗ | 14 |
good_python_script_ = TEST_GOOD_PYTHON_SCRIPT; |
39 |
✓✗ | 14 |
bad_python_script_ = TEST_BAD_PYTHON_SCRIPT; |
40 |
14 |
} |
|
41 |
14 |
~TestFixture() {} |
|
42 |
/// @brief Path to the AbstractSotExternalInterface test library. |
||
43 |
std::string asotei_lib_file_; |
||
44 |
/// @brief Path to a python srcipt to parse without error. |
||
45 |
std::string good_python_script_; |
||
46 |
/// @brief Path to a python srcipt to parse with error. |
||
47 |
std::string bad_python_script_; |
||
48 |
/// @brief Sensor values container. |
||
49 |
std::map<std::string, SensorValues> sensors; |
||
50 |
/// @brief Control values container. |
||
51 |
std::map<std::string, ControlValues> controls; |
||
52 |
}; |
||
53 |
|||
54 |
BOOST_AUTO_TEST_SUITE(sot_loader_test_suite) |
||
55 |
|||
56 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_plugin_existance, TestFixture) { |
57 |
✓✗ | 4 |
std::ifstream file(asotei_lib_file_); |
58 |
2 |
bool file_exists = false; |
|
59 |
✓✗✓✗ |
2 |
if (file) { |
60 |
2 |
file_exists = true; |
|
61 |
} |
||
62 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(file_exists); |
63 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(asotei_lib_file_ != ""); |
64 |
2 |
} |
|
65 |
|||
66 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_default_behavior, TestFixture) { |
67 |
✓✗ | 4 |
SotLoader sot_loader; |
68 |
✓✗ | 2 |
sot_loader.initialization(); |
69 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(sot_loader.isDynamicGraphStopped()); |
70 |
2 |
} |
|
71 |
|||
72 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_start_stop_dg, TestFixture) { |
73 |
✓✗ | 4 |
SotLoader sot_loader; |
74 |
✓✗ | 2 |
sot_loader.initialization(); |
75 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(sot_loader.isDynamicGraphStopped()); |
76 |
2 |
sot_loader.startDG(); |
|
77 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(!sot_loader.isDynamicGraphStopped()); |
78 |
2 |
sot_loader.stopDG(); |
|
79 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(sot_loader.isDynamicGraphStopped()); |
80 |
2 |
} |
|
81 |
|||
82 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_option_parsing_input_file, TestFixture) { |
83 |
✓✗ | 4 |
SotLoader sot_loader; |
84 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
85 |
|||
86 |
2 |
char argv0[] = "test_sot_loader"; |
|
87 |
2 |
char argv1[] = "--input-file"; |
|
88 |
2 |
char argv2[] = LIB_PLUGIN_ABSTRACT_PATH; |
|
89 |
2 |
char *argv[] = {argv0, argv1, argv2, NULL}; |
|
90 |
✓✗ | 2 |
sot_loader.parseOptions(3, argv); |
91 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(sot_loader.initialization()); |
92 |
2 |
} |
|
93 |
|||
94 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_option_parsing_sot_dynamic_library, TestFixture) { |
95 |
✓✗ | 4 |
SotLoader sot_loader; |
96 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
97 |
|||
98 |
2 |
char argv0[] = "test_sot_loader"; |
|
99 |
2 |
char argv1[] = "--sot-dynamic-library"; |
|
100 |
2 |
char argv2[] = LIB_PLUGIN_ABSTRACT_PATH; |
|
101 |
2 |
char *argv[] = {argv0, argv1, argv2, NULL}; |
|
102 |
✓✗ | 2 |
sot_loader.parseOptions(3, argv); |
103 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(sot_loader.initialization()); |
104 |
2 |
} |
|
105 |
|||
106 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_sot_loader_set_dynamic_library_name, TestFixture) { |
107 |
✓✗ | 4 |
SotLoader sot_loader; |
108 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
109 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(sot_loader.initialization()); |
110 |
2 |
} |
|
111 |
|||
112 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_sot_loader_one_iteration, TestFixture) { |
113 |
4 |
std::vector<double> controls_values; |
|
114 |
✓✗ | 4 |
SotLoader sot_loader; |
115 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
116 |
✓✗ | 2 |
sot_loader.initialization(); |
117 |
// Without running the graph: |
||
118 |
✓✗ | 2 |
sot_loader.oneIteration(sensors, controls); |
119 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(controls.find("ctrl_map_name") == controls.end()); |
120 |
// With the graph running: |
||
121 |
2 |
sot_loader.startDG(); |
|
122 |
✓✗✓✗ |
2 |
std::cout << "running the graph" << std::endl; |
123 |
✓✗ | 2 |
sot_loader.oneIteration(sensors, controls); |
124 |
✓✗✓✗ |
2 |
std::cout << "running the graph ... done" << std::endl; |
125 |
✓✗✓✗ ✓✗ |
2 |
controls_values = controls["ctrl_map_name"].getValues(); |
126 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(controls_values.size(), 5); |
127 |
✓✓ | 12 |
for (auto value : controls_values) { |
128 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
10 |
BOOST_CHECK_EQUAL(value, 3.1415); |
129 |
} |
||
130 |
2 |
} |
|
131 |
|||
132 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_cleanup_no_init, TestFixture) { |
133 |
✓✗ | 4 |
SotLoader sot_loader; |
134 |
✓✗ | 2 |
sot_loader.cleanUp(); |
135 |
2 |
} |
|
136 |
|||
137 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_cleanup_init, TestFixture) { |
138 |
✓✗ | 4 |
SotLoader sot_loader; |
139 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
140 |
✓✗ | 2 |
sot_loader.initialization(); |
141 |
✓✗ | 2 |
sot_loader.cleanUp(); |
142 |
2 |
} |
|
143 |
|||
144 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_run_python_command, TestFixture) { |
145 |
✓✗ | 4 |
SotLoader sot_loader; |
146 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
147 |
✓✗ | 2 |
sot_loader.initialization(); |
148 |
4 |
std::string res, out, err; |
|
149 |
✓✗✓✗ |
2 |
sot_loader.runPythonCommand("1+1", res, out, err); |
150 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(res, "2"); |
151 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(out, ""); |
152 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(err, ""); |
153 |
2 |
} |
|
154 |
|||
155 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_run_python_command_error, TestFixture) { |
156 |
✓✗ | 4 |
SotLoader sot_loader; |
157 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
158 |
✓✗ | 2 |
sot_loader.initialization(); |
159 |
4 |
std::string res, out, err; |
|
160 |
✓✗✓✗ |
2 |
sot_loader.runPythonCommand("print(a)", res, out, err); |
161 |
✓✗✓✗ ✓✗ |
2 |
std::cout << std::quoted(err) << std::endl; |
162 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(res, ""); |
163 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(out, ""); |
164 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(err, |
165 |
"Traceback (most recent call last):\n" |
||
166 |
" File \"<string>\", line 1, in <module>\n" |
||
167 |
"NameError: name 'a' is not defined\n"); |
||
168 |
2 |
} |
|
169 |
|||
170 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_run_python_scripts, TestFixture) { |
171 |
✓✗ | 4 |
SotLoader sot_loader; |
172 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
173 |
✓✗ | 2 |
sot_loader.initialization(); |
174 |
4 |
std::string err; |
|
175 |
✓✗✓✗ |
2 |
sot_loader.runPythonFile(good_python_script_, err); |
176 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(err, ""); |
177 |
2 |
} |
|
178 |
|||
179 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_run_python_scripts_failure, TestFixture) { |
180 |
✓✗ | 4 |
SotLoader sot_loader; |
181 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
182 |
✓✗ | 2 |
sot_loader.initialization(); |
183 |
4 |
std::string err; |
|
184 |
✓✗✓✗ |
2 |
sot_loader.runPythonFile(bad_python_script_, err); |
185 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(err, |
186 |
"Traceback (most recent call last):\n" |
||
187 |
" File \"" + |
||
188 |
bad_python_script_ + |
||
189 |
"\", line 2, in <module>\n" |
||
190 |
" print(b)\n" |
||
191 |
"NameError: name 'b' is not defined\n"); |
||
192 |
2 |
} |
|
193 |
|||
194 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4 |
BOOST_FIXTURE_TEST_CASE(test_load_device_in_python, TestFixture) { |
195 |
✓✗ | 4 |
SotLoader sot_loader; |
196 |
✓✗ | 2 |
sot_loader.setDynamicLibraryName(asotei_lib_file_); |
197 |
✓✗ | 2 |
sot_loader.initialization(); |
198 |
✓✗✓✗ |
6 |
Device device("device_name"); |
199 |
✓✗ | 2 |
sot_loader.loadDeviceInPython(device.getName()); |
200 |
4 |
std::string res, out, err; |
|
201 |
✓✗✓✗ |
2 |
sot_loader.runPythonCommand("print(device_cpp_object.name)", res, out, err); |
202 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(res, "None"); |
203 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(out, "device_name\n"); |
204 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(err, ""); |
205 |
2 |
} |
|
206 |
|||
207 |
BOOST_AUTO_TEST_SUITE_END() |
Generated by: GCOVR (Version 4.2) |