From da015907b5eb3be7429abe28cd9c63b32aa482cd Mon Sep 17 00:00:00 2001 From: Martin Killenberg <martin.killenberg@desy.de> Date: Fri, 15 Sep 2017 19:11:55 +0200 Subject: [PATCH] added test that is sensitive on scalars and arrays (here spectra) really being read and written in a server. Currently failing because the syncutil is not worling with the new DoocsSpectrum implementation. The adapter currently really is broken --- tests/serverTestReadWrite.conf | 57 ++++++++++++++++ tests/src/serverTestReadWrite.cpp | 110 ++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 tests/serverTestReadWrite.conf create mode 100644 tests/src/serverTestReadWrite.cpp diff --git a/tests/serverTestReadWrite.conf b/tests/serverTestReadWrite.conf new file mode 100644 index 0000000..eed12e2 --- /dev/null +++ b/tests/serverTestReadWrite.conf @@ -0,0 +1,57 @@ +eq_conf: + +oper_uid: -1 +oper_gid: 405 +xpert_uid: 1000 +xpert_gid: 1000 +ring_buffer: 10000 +memory_buffer: 500 + +eq_fct_name: "PLAIN_VARIABLE_CREATION_TEST._SVR" +eq_fct_type: 1 +{ +SVR.RPC_NUMBER: 610498009 +SVR.NAME: "PLAIN_VARIABLE_CREATION_TEST._SVR" +SVR.RATE: 57005 48879 0 0 +SVR.BPN: 6000 +} +eq_fct_name: "INT" +eq_fct_type: 10 +{ +NAME: "INT" +} +eq_fct_name: "SHORT" +eq_fct_type: 10 +{ +NAME: "SHORT" +} +eq_fct_name: "FLOAT" +eq_fct_type: 10 +{ +NAME: "FLOAT" +} +eq_fct_name: "DOUBLE" +eq_fct_type: 10 +{ +NAME: "DOUBLE" +} +eq_fct_name: "UINT" +eq_fct_type: 10 +{ +NAME: "UINT" +} +eq_fct_name: "USHORT" +eq_fct_type: 10 +{ +NAME: "USHORT" +} +eq_fct_name: "CHAR" +eq_fct_type: 10 +{ +NAME: "CHAR" +} +eq_fct_name: "UCHAR" +eq_fct_type: 10 +{ +NAME: "UCHAR" +} diff --git a/tests/src/serverTestReadWrite.cpp b/tests/src/serverTestReadWrite.cpp new file mode 100644 index 0000000..eb3f803 --- /dev/null +++ b/tests/src/serverTestReadWrite.cpp @@ -0,0 +1,110 @@ +#include <boost/test/included/unit_test.hpp> + +//#include <boost/test/test_case_template.hpp> +//#include <boost/mpl/list.hpp> + +#include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> +#include <doocs-server-test-helper/doocsServerTestHelper.h> +#include <thread> + +ReferenceTestApplication referenceTestApplication("serverTestReadWrite"); + +// declare that we have some thing like a doocs server. is is linked from the doocs lib, but there is no header. +extern int eq_server(int, char **); + +//#include <limits> +//#include <sstream> + +using namespace boost::unit_test_framework; +using namespace ChimeraTK; + +// use boost meta-programming to use test case templates +// The list of types is an mpl type +//typedef boost::mpl::list<int32_t, uint32_t, +// int16_t, uint16_t, +// int8_t, uint8_t, +// float, double> simple_test_types; + +/// Check that all expected variables are there. +void testReadWrite(){ + // halt the test application tread + referenceTestApplication.initialiseManualLoopControl(); + std::cout << "got the application main lock" << std::endl; + // run update once to make sure the server is up and running + std::cout << "running update once " << std::endl; + DoocsServerTestHelper::runUpdate(); + std::cout << "ran update once, let's test " << std::endl; + + // just a few tests before we start + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//INT/DATA_TYPE_CONSTANT") == -4 ); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//CHAR/DATA_TYPE_CONSTANT") == -1 ); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//INT/FROM_DEVICE_SCALAR") == 0 ); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//CHAR/FROM_DEVICE_SCALAR") == 0 ); + + DoocsServerTestHelper::doocsSet<int>("//INT/TO_DEVICE_SCALAR", 42 ); + DoocsServerTestHelper::doocsSet<int>("//CHAR/TO_DEVICE_SCALAR", 44 ); + DoocsServerTestHelper::doocsSet<int>("//INT/TO_DEVICE_ARRAY", {140, 141, 142, 143, 144, 145, 146, 147, 148, 149} ); + + // running update now does not change anything, the application has not acted yet + DoocsServerTestHelper::runUpdate(); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//INT/FROM_DEVICE_SCALAR") == 0 ); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//CHAR/FROM_DEVICE_SCALAR") == 0 ); + + // run the application loop. Still no changes until we run the doocs server update + referenceTestApplication.runMainLoopOnce(); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//INT/FROM_DEVICE_SCALAR") == 0 ); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//CHAR/FROM_DEVICE_SCALAR") == 0 ); + + // now finally after the next update we should see the new data in doocs + DoocsServerTestHelper::runUpdate(); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//INT/FROM_DEVICE_SCALAR") == 42 ); + BOOST_CHECK( DoocsServerTestHelper::doocsGet<int>("//CHAR/FROM_DEVICE_SCALAR") == 44 ); + + // we have to get stuff as float in order to work with spectra + auto intArray = DoocsServerTestHelper::doocsGetArray<float>("//INT/FROM_DEVICE_ARRAY"); + int testVal = 410; + for (auto val : intArray){ + BOOST_CHECK( (val - testVal++) < 0.001); + } + + auto constArray = DoocsServerTestHelper::doocsGetArray<float>("//INT/CONSTANT_ARRAY"); + for (int i =0; i < int(constArray.size()); ++i){ + std::cout << "constArray["<<i<<"] " << constArray[i] << std::endl; + BOOST_CHECK( constArray[i] - (-4*i*i) < 0.001); // float check to compensate binary roundings errors + } + + for (auto const location : { "CHAR", "DOUBLE", "FLOAT", "INT", "SHORT", "UCHAR", "UINT", "USHORT"} ){ + for (auto const property : { "CONSTANT_ARRAY", "FROM_DEVICE_ARRAY", "TO_DEVICE_ARRAY "} ){ + // if this throws the property does not exist. we should always be able to read" + BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGetArray<int>( (std::string("//")+location+"/"+ property).c_str() )); + } + for (auto const property : { "DATA_TYPE_CONSTANT", "FROM_DEVICE_SCALAR", "TO_DEVICE_SCALAR"} ){ + // if this throws the property does not exist. we should always be able to read" + BOOST_CHECK_NO_THROW( DoocsServerTestHelper::doocsGet<int>( (std::string("//")+location+"/"+ property).c_str() )); + } + } +} + +// due to the doocs server thread you can only have one test suite +class DoocsServerTestSuite : public test_suite { +public: + DoocsServerTestSuite(int argc, char* argv[]) + : test_suite("Read write test suite") , + doocsServerThread(eq_server, argc, argv) + { + doocsServerThread.detach(); + add( BOOST_TEST_CASE( &testReadWrite ) ); + } + virtual ~DoocsServerTestSuite(){ + referenceTestApplication.releaseManualLoopControl(); + } +protected: + std::thread doocsServerThread; +}; + +test_suite* +init_unit_test_suite( int argc, char* argv[] ) +{ + framework::master_test_suite().p_name.value = "Read write server test suite"; + return new DoocsServerTestSuite(argc, argv); +} -- GitLab