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> 15 #include <boost/test/included/unit_test.hpp> 37 asotei_lib_file_ = LIB_PLUGIN_ABSTRACT_PATH;
38 good_python_script_ = TEST_GOOD_PYTHON_SCRIPT;
39 bad_python_script_ = TEST_BAD_PYTHON_SCRIPT;
49 std::map<std::string, SensorValues>
sensors;
54 BOOST_AUTO_TEST_SUITE(sot_loader_test_suite)
57 std::ifstream file(asotei_lib_file_);
58 bool file_exists =
false;
62 BOOST_CHECK(file_exists);
63 BOOST_CHECK(asotei_lib_file_ !=
"");
86 char argv0[] =
"test_sot_loader";
87 char argv1[] =
"--input-file";
88 char argv2[] = LIB_PLUGIN_ABSTRACT_PATH;
89 char *argv[] = {argv0, argv1, argv2, NULL};
98 char argv0[] =
"test_sot_loader";
99 char argv1[] =
"--sot-dynamic-library";
100 char argv2[] = LIB_PLUGIN_ABSTRACT_PATH;
101 char *argv[] = {argv0, argv1, argv2, NULL};
113 std::vector<double> controls_values;
119 BOOST_CHECK(controls.find(
"ctrl_map_name") == controls.end());
122 std::cout <<
"running the graph" << std::endl;
124 std::cout <<
"running the graph ... done" << std::endl;
125 controls_values = controls[
"ctrl_map_name"].getValues();
126 BOOST_CHECK_EQUAL(controls_values.size(), 5);
127 for (
auto value : controls_values) {
128 BOOST_CHECK_EQUAL(
value, 3.1415);
148 std::string
res, out,
err;
150 BOOST_CHECK_EQUAL(res,
"2");
151 BOOST_CHECK_EQUAL(out,
"");
152 BOOST_CHECK_EQUAL(err,
"");
159 std::string
res, out,
err;
161 std::cout << std::quoted(err) << std::endl;
162 BOOST_CHECK_EQUAL(res,
"");
163 BOOST_CHECK_EQUAL(out,
"");
164 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");
176 BOOST_CHECK_EQUAL(err,
"");
185 BOOST_CHECK_EQUAL(err,
186 "Traceback (most recent call last):\n" 189 "\", line 2, in <module>\n" 191 "NameError: name 'b' is not defined\n");
198 Device device(
"device_name");
200 std::string
res, out,
err;
201 sot_loader.
runPythonCommand(
"print(device_cpp_object.name)", res, out, err);
202 BOOST_CHECK_EQUAL(res,
"None");
203 BOOST_CHECK_EQUAL(out,
"device_name\n");
204 BOOST_CHECK_EQUAL(err,
"");
void loadDeviceInPython(const std::string &device_name)
Load the Device entity in the python global scope.
bool initialization()
Prepare the SoT framework.
This class is loading the control part of the Stack-Of-Tasks.
std::string good_python_script_
Path to a python srcipt to parse without error.
void startDG()
Get Status of dg.
std::string bad_python_script_
Path to a python srcipt to parse with error.
bool isDynamicGraphStopped()
Get Status of dg.
void oneIteration(std::map< std::string, SensorValues > &sensors_in, std::map< std::string, ControlValues > &control_values, const double &period)
Compute one iteration of control. Basically executes fillSensors, the SoT and the readControl...
void cleanUp()
Unload the library which handles the robot device.
void stopDG()
Get Status of dg.
std::string asotei_lib_file_
Path to the AbstractSotExternalInterface test library.
TestDevice(const std::string &RobotName)
std::map< std::string, SensorValues > sensors
Sensor values container.
BOOST_FIXTURE_TEST_CASE(test_plugin_existance, TestFixture)
const std::string & getName() const
BOOST_AUTO_TEST_SUITE_END() MatrixHomogeneous randomM()
void runPythonCommand(const std::string &command, std::string &result, std::string &out, std::string &err)
Run a python command inside the embeded python interpreter.
std::map< std::string, ControlValues > controls
Control values container.
void setDynamicLibraryName(std::string &afilename)
Specify the name of the dynamic library.
int parseOptions(int argc, char *argv[])
Read user input to extract the path of the SoT dynamic library.
void runPythonFile(std::string ifilename, std::string &err)
Run a python script inside the embeded python interpreter.