diff --git a/tests/include/serverBasedTestTools.h b/tests/include/serverBasedTestTools.h index 38236d7417bcb4c5b86c1f1556c350811c7fa2d3..53e1f8faa857523e0df72974d8cfd51989356ed6 100644 --- a/tests/include/serverBasedTestTools.h +++ b/tests/include/serverBasedTestTools.h @@ -14,29 +14,37 @@ static const int ACCESS_RW = 1; // read/write GlobalFixture() { ChimeraTK::DoocsAdapter::waitUntilInitialised(); } \ \ ReferenceTestApplication referenceTestApplication{framework::master_test_suite().p_name.value}; \ - ThreadedDoocsServer server{framework::master_test_suite().p_name.value + ".conf", \ - framework::master_test_suite().argc, framework::master_test_suite().argv}; \ + ThreadedDoocsServer server{framework::master_test_suite().p_name.value, \ + framework::master_test_suite().p_name.value + ".conf", framework::master_test_suite().argc, \ + framework::master_test_suite().argv}; \ }; \ \ BOOST_GLOBAL_FIXTURE(GlobalFixture); -#define DOOCS_ADAPTER_DEFAULT_FIXTURE_STATIC_APPLICATION \ +#define DOOCS_ADAPTER_DEFAULT_FIXTURE_STATIC_APPLICATION_WITH_CODE(codeBlockStartUp) \ struct GlobalFixture { \ GlobalFixture() { \ + rpcNo = server.rpcNo(); \ ChimeraTK::DoocsAdapter::waitUntilInitialised(); \ GlobalFixture::referenceTestApplication.initialiseManualLoopControl(); \ + codeBlockStartUp \ } \ \ ~GlobalFixture() { GlobalFixture::referenceTestApplication.releaseManualLoopControl(); } \ \ static ReferenceTestApplication referenceTestApplication; \ - ThreadedDoocsServer server{framework::master_test_suite().p_name.value + ".conf", \ - framework::master_test_suite().argc, framework::master_test_suite().argv}; \ + static std::string rpcNo; \ + ThreadedDoocsServer server{framework::master_test_suite().p_name.value, \ + framework::master_test_suite().p_name.value + ".conf", framework::master_test_suite().argc, \ + framework::master_test_suite().argv}; \ }; \ \ ReferenceTestApplication GlobalFixture::referenceTestApplication{BOOST_STRINGIZE(BOOST_TEST_MODULE)}; \ + std::string GlobalFixture::rpcNo; \ BOOST_GLOBAL_FIXTURE(GlobalFixture); +#define DOOCS_ADAPTER_DEFAULT_FIXTURE_STATIC_APPLICATION DOOCS_ADAPTER_DEFAULT_FIXTURE_STATIC_APPLICATION_WITH_CODE({}) + template<class DOOCS_T> void checkHistory(DOOCS_T* property, bool expected_has_history) { bool has_history = property->get_histPointer(); diff --git a/tests/src/serverTestAutoCreateLocations.cpp b/tests/src/serverTestAutoCreateLocations.cpp index 347c644d5998df8b631b11ec7fafe7f0e347f899..9880979ed4778ceec92c4e3a28ff8d249c6d48f8 100644 --- a/tests/src/serverTestAutoCreateLocations.cpp +++ b/tests/src/serverTestAutoCreateLocations.cpp @@ -10,6 +10,8 @@ #include "DoocsAdapter.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> #include <thread> @@ -26,7 +28,7 @@ struct GlobalFixture { } ReferenceTestApplication referenceTestApplication{framework::master_test_suite().p_name.value}; - ThreadedDoocsServer server{{}, 0, nullptr, false}; + ThreadedDoocsServer server{BOOST_STRINGIZE(BOOST_TEST_MODULE), {}, 0, nullptr, false}; }; BOOST_GLOBAL_FIXTURE(GlobalFixture); diff --git a/tests/src/serverTestDataMatching.cpp b/tests/src/serverTestDataMatching.cpp index 8df1947e5cc7ac9604b9880c05b7a785d1a540d7..bbf67c2e6f4447a4c4c8f7be44c4343c44a7ab98 100644 --- a/tests/src/serverTestDataMatching.cpp +++ b/tests/src/serverTestDataMatching.cpp @@ -6,6 +6,8 @@ #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> //#include <doocs-server-test-helper/ThreadedDoocsServer.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> diff --git a/tests/src/serverTestErrorFlag.cpp b/tests/src/serverTestErrorFlag.cpp index 1f17041df9b886596781ec2a725c246c4d988192..b4317571c724c0626dfa9518998b056872d9841a 100644 --- a/tests/src/serverTestErrorFlag.cpp +++ b/tests/src/serverTestErrorFlag.cpp @@ -3,6 +3,8 @@ #include <boost/test/included/unit_test.hpp> #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> diff --git a/tests/src/serverTestGlobalTurnOnOffHistory.cpp b/tests/src/serverTestGlobalTurnOnOffHistory.cpp index b577bb4113a5f2b4fceeb065683bac652df21504..3af0655b062cd4251437addcd1bed7699b3c3726 100644 --- a/tests/src/serverTestGlobalTurnOnOffHistory.cpp +++ b/tests/src/serverTestGlobalTurnOnOffHistory.cpp @@ -5,6 +5,8 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; diff --git a/tests/src/serverTestGlobalTurnOnOffWriteable.cpp b/tests/src/serverTestGlobalTurnOnOffWriteable.cpp index 94924579bcf136a15a2b2cde05c0f274d7fa250a..61a3e52e76ec54f56ff7d04b2f312b8e6d9284d2 100644 --- a/tests/src/serverTestGlobalTurnOnOffWriteable.cpp +++ b/tests/src/serverTestGlobalTurnOnOffWriteable.cpp @@ -6,6 +6,8 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; diff --git a/tests/src/serverTestIfff.cpp b/tests/src/serverTestIfff.cpp index 390d5b7df9dddbf8b691e0f4f7c8543efee99c08..09b1740d6467d82a89329b4b5ebaa52b855dde8f 100644 --- a/tests/src/serverTestIfff.cpp +++ b/tests/src/serverTestIfff.cpp @@ -1,8 +1,11 @@ -#define BOOST_TEST_MODULE serverTestXy +#define BOOST_TEST_MODULE serverTestIfff #include <boost/test/included/unit_test.hpp> #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; +#include <doocs-server-test-helper/ThreadedDoocsServer.h> #include <eq_client.h> #include <random> #include <thread> @@ -14,61 +17,9 @@ using namespace boost::unit_test_framework; using namespace ChimeraTK; -static ReferenceTestApplication referenceTestApplication("serverTestIfff"); - const std::string PROPERTY_NAME{"//CUSTOM/IFFF"}; -/**********************************************************************************************************************/ - -extern int eq_server(int, char**); - -struct DoocsLauncher { - DoocsLauncher() { - // choose random RPC number - std::random_device rd; - std::uniform_int_distribution<int> dist(620000000, 999999999); - rpc_no = std::to_string(dist(rd)); - // update config file with the RPC number - std::string command = "sed -i serverTestIfff.conf -e " - "'s/^SVR.RPC_NUMBER:.*$/SVR.RPC_NUMBER: " + - rpc_no + "/'"; - auto rc = std::system(command.c_str()); - (void)rc; - - // start the server - doocsServerThread = std::thread(eq_server, boost::unit_test::framework::master_test_suite().argc, - boost::unit_test::framework::master_test_suite().argv); - // wait until server has started (both the update thread and the rpc thread) - EqCall eq; - EqAdr ea; - EqData src, dst; - ea.adr("doocs://localhost:" + rpc_no + "/F/D/INT/TO_DEVICE_SCALAR"); - while(eq.get(&ea, &src, &dst)) usleep(100000); - referenceTestApplication.initialiseManualLoopControl(); - } - - /** - * @brief For compatibility with older DOOCS versions declare our own eq_exit - * - * Can be removed once a new doocs server version is released. - */ - void eq_exit() { - auto nativeHandle = doocsServerThread.native_handle(); - if(nativeHandle != 0) pthread_kill(nativeHandle, SIGTERM); - } - - ~DoocsLauncher() { - referenceTestApplication.releaseManualLoopControl(); - eq_exit(); - doocsServerThread.join(); - } - - std::thread doocsServerThread; - static std::string rpc_no; -}; -std::string DoocsLauncher::rpc_no; - -BOOST_GLOBAL_FIXTURE(DoocsLauncher); +DOOCS_ADAPTER_DEFAULT_FIXTURE_STATIC_APPLICATION /**********************************************************************************************************************/ BOOST_AUTO_TEST_CASE(testIfffUpdate) { @@ -89,12 +40,12 @@ BOOST_AUTO_TEST_CASE(testIfffUpdate) { auto writeIfff = [&](IFFF ifff) { // we have to use the names if the correct variables - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); DoocsServerTestHelper::doocsSet<int>("//INT/TO_DEVICE_SCALAR", ifff.i1_data); DoocsServerTestHelper::doocsSet<float>("//FLOAT/TO_DEVICE_SCALAR", ifff.f1_data); DoocsServerTestHelper::doocsSet<double>("//DOUBLE/TO_DEVICE_SCALAR", static_cast<double>(ifff.f2_data)); DoocsServerTestHelper::doocsSet<int>("//SHORT/TO_DEVICE_SCALAR", static_cast<int>(ifff.f3_data)); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); }; // we used SHORT/FROM_DEVICE_SCALAR for the f3_value, so only values that fit in int16_t can be used for it, no franctional numbers @@ -144,9 +95,9 @@ BOOST_AUTO_TEST_CASE(testIfffUpdate) { // check data consistency implementation // send only one variable, then change the version number again - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); DoocsServerTestHelper::doocsSet<int>("//INT/TO_DEVICE_SCALAR", 543); // will never be seen - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); // sleep a bit, we don't except a change sleep(1); resultIfff = extractValue(); @@ -156,11 +107,11 @@ BOOST_AUTO_TEST_CASE(testIfffUpdate) { BOOST_CHECK_CLOSE(resultIfff.f2_data, referenceIfff.f2_data, 0.0001); BOOST_CHECK_CLOSE(resultIfff.f3_data, referenceIfff.f3_data, 0.0001); - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); DoocsServerTestHelper::doocsSet<float>("//FLOAT/TO_DEVICE_SCALAR", newReferenceIfff.f1_data); DoocsServerTestHelper::doocsSet<double>("//DOUBLE/TO_DEVICE_SCALAR", static_cast<double>(newReferenceIfff.f2_data)); DoocsServerTestHelper::doocsSet<int>("//SHORT/TO_DEVICE_SCALAR", static_cast<int>(newReferenceIfff.f3_data)); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); // all variables have been updated, but not in a consistent way. still no change sleep(1); @@ -173,7 +124,7 @@ BOOST_AUTO_TEST_CASE(testIfffUpdate) { // finally upate the missing variable with the same version as the others DoocsServerTestHelper::doocsSet<int>("//INT/TO_DEVICE_SCALAR", newReferenceIfff.i1_data); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); // now we see the new reference checkWithTimeout<int>( diff --git a/tests/src/serverTestImportAllIntoLocation.cpp b/tests/src/serverTestImportAllIntoLocation.cpp index d651d1bf150d02c81fcf1cc2155c092bbe19e031..73b40d8a7c45c63b6f07193e79ec2d712e6c9e24 100644 --- a/tests/src/serverTestImportAllIntoLocation.cpp +++ b/tests/src/serverTestImportAllIntoLocation.cpp @@ -8,6 +8,8 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; diff --git a/tests/src/serverTestPlainVariableCreation.cpp b/tests/src/serverTestPlainVariableCreation.cpp index de0f91eec6707c068be3eddf100742db0378fca6..0e1db700993103cffa766c462a05728ec25edd4c 100644 --- a/tests/src/serverTestPlainVariableCreation.cpp +++ b/tests/src/serverTestPlainVariableCreation.cpp @@ -5,6 +5,8 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; diff --git a/tests/src/serverTestReadWrite.cpp b/tests/src/serverTestReadWrite.cpp index 50223897619bb433a9998a71c970cac4a33c67ee..d001b53be22930e1f6fde2109ff9aba7eef16e1f 100644 --- a/tests/src/serverTestReadWrite.cpp +++ b/tests/src/serverTestReadWrite.cpp @@ -5,6 +5,8 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; diff --git a/tests/src/serverTestRenameImport.cpp b/tests/src/serverTestRenameImport.cpp index 3cec5b02b349c75346ddfd8b9e19edc5869af4c1..ce4e9cc185b2ac57cf453c814ae975b49c371918 100644 --- a/tests/src/serverTestRenameImport.cpp +++ b/tests/src/serverTestRenameImport.cpp @@ -5,6 +5,8 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; diff --git a/tests/src/serverTestRetypeProperties.cpp b/tests/src/serverTestRetypeProperties.cpp index e6524794db18510b48a3acde4a1181acf2f9c241..64e4a2da96833d2a1162735d99187875a218b9e3 100644 --- a/tests/src/serverTestRetypeProperties.cpp +++ b/tests/src/serverTestRetypeProperties.cpp @@ -5,6 +5,8 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; diff --git a/tests/src/serverTestSpectrumArray.cpp b/tests/src/serverTestSpectrumArray.cpp index 68c65d5f626a6161467c3f982f20b8b15ce8a7e4..16924b7ae3c18165ea45ae26e8d9e67f944cc40c 100644 --- a/tests/src/serverTestSpectrumArray.cpp +++ b/tests/src/serverTestSpectrumArray.cpp @@ -5,6 +5,8 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; @@ -17,8 +19,8 @@ struct GlobalFixture { ~GlobalFixture() { referenceTestApplication.releaseManualLoopControl(); } static ReferenceTestApplication referenceTestApplication; - ThreadedDoocsServer server{BOOST_STRINGIZE(BOOST_TEST_MODULE) ".conf", framework::master_test_suite().argc, - framework::master_test_suite().argv}; + ThreadedDoocsServer server{BOOST_STRINGIZE(BOOST_TEST_MODULE), BOOST_STRINGIZE(BOOST_TEST_MODULE) ".conf", + framework::master_test_suite().argc, framework::master_test_suite().argv}; }; ReferenceTestApplication GlobalFixture::referenceTestApplication{BOOST_STRINGIZE(BOOST_TEST_MODULE)}; diff --git a/tests/src/serverTestSpectrumBuffer-exception.cpp b/tests/src/serverTestSpectrumBuffer-exception.cpp index a90a954a825d9e927c0cd461b3f8650322cb904f..eb0ab080692c8df5e24c35732c74b43f4df5b55c 100644 --- a/tests/src/serverTestSpectrumBuffer-exception.cpp +++ b/tests/src/serverTestSpectrumBuffer-exception.cpp @@ -1,8 +1,10 @@ -#define BOOST_TEST_MODULE serverTestSpectrumBuffer +#define BOOST_TEST_MODULE serverTestSpectrumBuffer - exception #include <boost/test/included/unit_test.hpp> #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> +extern const char* object_name; + #include <eq_client.h> #include <random> #include <thread> @@ -35,6 +37,7 @@ BOOST_AUTO_TEST_CASE(testSpectrum) { // staring the server should cause the exception try { + object_name = "serverTestSpectrumBuffer-exception"; eq_server( boost::unit_test::framework::master_test_suite().argc, boost::unit_test::framework::master_test_suite().argv); BOOST_ERROR("Exception expected"); diff --git a/tests/src/serverTestSpectrumBuffer.cpp b/tests/src/serverTestSpectrumBuffer.cpp index e9b8140d1864731f0efac8e792f5366c95138d4f..700598c0a8b36fe2c6defd7b48cebc47fb5e789a 100644 --- a/tests/src/serverTestSpectrumBuffer.cpp +++ b/tests/src/serverTestSpectrumBuffer.cpp @@ -5,36 +5,15 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> + +extern const char* object_name; #include <doocs-server-test-helper/ThreadedDoocsServer.h> using namespace boost::unit_test_framework; using namespace boost::unit_test; using namespace ChimeraTK; -struct GlobalFixture { - GlobalFixture() { - rpcNo = server.rpcNo(); - // wait until server has started (both the update thread and the rpc thread) - EqCall eq; - EqAdr ea; - EqData src, dst; - ea.adr("doocs://localhost:" + server.rpcNo() + "/F/D/INT/TO_DEVICE_SCALAR"); - std::cout << "doocs://localhost:" + server.rpcNo() + "/F/D/INT/TO_DEVICE_SCALAR" << std::endl; - while(eq.get(&ea, &src, &dst)) usleep(100000); - referenceTestApplication.initialiseManualLoopControl(); - } - - ~GlobalFixture() { referenceTestApplication.releaseManualLoopControl(); } - - static ReferenceTestApplication referenceTestApplication; - static std::string rpcNo; - ThreadedDoocsServer server{BOOST_STRINGIZE(BOOST_TEST_MODULE) ".conf", framework::master_test_suite().argc, - framework::master_test_suite().argv}; -}; -ReferenceTestApplication GlobalFixture::referenceTestApplication{BOOST_STRINGIZE(BOOST_TEST_MODULE)}; -std::string GlobalFixture::rpcNo; - -BOOST_GLOBAL_FIXTURE(GlobalFixture); +DOOCS_ADAPTER_DEFAULT_FIXTURE_STATIC_APPLICATION /**********************************************************************************************************************/ diff --git a/tests/src/serverTestVariableMapperWithLocationAndCode.cpp b/tests/src/serverTestVariableMapperWithLocationAndCode.cpp index 3073a329992dfc0827888133ba8b4a4381507d0c..12baa6568fb2d9b817bd0fde4a41e6e90cd59cb0 100644 --- a/tests/src/serverTestVariableMapperWithLocationAndCode.cpp +++ b/tests/src/serverTestVariableMapperWithLocationAndCode.cpp @@ -1,3 +1,4 @@ +#define BOOST_TEST_MODULE serverTestVariableMapperWithLocationAndCode #include <boost/test/included/unit_test.hpp> #include <boost/filesystem.hpp> @@ -8,18 +9,17 @@ #include "serverBasedTestTools.h" #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> -#include <thread> - -ReferenceTestApplication referenceTestApplication("serverTestVariableMapperWithLocationAndCode"); -// 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**); +extern const char* object_name; +#include <doocs-server-test-helper/ThreadedDoocsServer.h> +#include <thread> using namespace boost::unit_test_framework; using namespace ChimeraTK; -void testCodeIsSetCorrectly() { +DOOCS_ADAPTER_DEFAULT_FIXTURE + +BOOST_AUTO_TEST_CASE(testCodeIsSetCorrectly) { EqFct* eq = find_device("CREATED"); BOOST_CHECK_EQUAL(eq->fct_code(), 10); @@ -32,38 +32,3 @@ void testCodeIsSetCorrectly() { eq = find_device("FLOAT"); BOOST_CHECK_EQUAL(eq->fct_code(), 11); } - -// due to the doocs server thread you can only have one test suite -class serverTestVariableMapperWithLocationAndCodeTestSuite : public test_suite { - public: - serverTestVariableMapperWithLocationAndCodeTestSuite(int argc, char* argv[]) - : test_suite("serverTestVariableMapperWithLocationAndCode test suite") { - // create DOOCS thread - doocsServerThread = std::thread(eq_server, argc, argv); - // wait for doocs to start up before detaching the thread and continuing - ChimeraTK::DoocsAdapter::waitUntilInitialised(); - add(BOOST_TEST_CASE(&testCodeIsSetCorrectly)); - } - /** - * @brief For compatibility with older DOOCS versions declare our own eq_exit - * - * Can be removed once a new doocs server version is released. - */ - void eq_exit() { - auto nativeHandle = doocsServerThread.native_handle(); - if(nativeHandle != 0) pthread_kill(nativeHandle, SIGTERM); - } - - ~serverTestVariableMapperWithLocationAndCodeTestSuite() { - eq_exit(); - doocsServerThread.join(); - } - - protected: - std::thread doocsServerThread; -}; - -test_suite* init_unit_test_suite(int argc, char* argv[]) { - framework::master_test_suite().p_name.value = "serverTestVariableMapperWithLocationAndCode server test suite"; - return new serverTestVariableMapperWithLocationAndCodeTestSuite(argc, argv); -} diff --git a/tests/src/serverTestXy.cpp b/tests/src/serverTestXy.cpp index c08322dcb439a33102e55ff15e98f0f96c20b794..d5296c037e92ac5f8b81edb61d02e44436b8e737 100644 --- a/tests/src/serverTestXy.cpp +++ b/tests/src/serverTestXy.cpp @@ -3,6 +3,9 @@ #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> +extern const char* object_name; +#include <doocs-server-test-helper/ThreadedDoocsServer.h> + #include <eq_client.h> #include <random> #include <thread> @@ -14,64 +17,12 @@ using namespace boost::unit_test_framework; using namespace ChimeraTK; -static ReferenceTestApplication referenceTestApplication("serverTestXy"); +DOOCS_ADAPTER_DEFAULT_FIXTURE_STATIC_APPLICATION const std::string PROPERTY_NAME{"//FLOAT/TEST_XY"}; /**********************************************************************************************************************/ -extern int eq_server(int, char**); - -struct DoocsLauncher { - DoocsLauncher() { - // choose random RPC number - std::random_device rd; - std::uniform_int_distribution<int> dist(620000000, 999999999); - rpc_no = std::to_string(dist(rd)); - // update config file with the RPC number - std::string command = "sed -i serverTestXy.conf -e " - "'s/^SVR.RPC_NUMBER:.*$/SVR.RPC_NUMBER: " + - rpc_no + "/'"; - auto rc = std::system(command.c_str()); - (void)rc; - - // start the server - doocsServerThread = std::thread(eq_server, boost::unit_test::framework::master_test_suite().argc, - boost::unit_test::framework::master_test_suite().argv); - // wait until server has started (both the update thread and the rpc thread) - EqCall eq; - EqAdr ea; - EqData src, dst; - ea.adr("doocs://localhost:" + rpc_no + "/F/D/INT/TO_DEVICE_SCALAR"); - while(eq.get(&ea, &src, &dst)) usleep(100000); - referenceTestApplication.initialiseManualLoopControl(); - } - - /** - * @brief For compatibility with older DOOCS versions declare our own eq_exit - * - * Can be removed once a new doocs server version is released. - */ - void eq_exit() { - auto nativeHandle = doocsServerThread.native_handle(); - if(nativeHandle != 0) pthread_kill(nativeHandle, SIGTERM); - } - - ~DoocsLauncher() { - referenceTestApplication.releaseManualLoopControl(); - eq_exit(); - doocsServerThread.join(); - } - - std::thread doocsServerThread; - static std::string rpc_no; -}; -std::string DoocsLauncher::rpc_no; - -BOOST_GLOBAL_FIXTURE(DoocsLauncher); - -/**********************************************************************************************************************/ - BOOST_AUTO_TEST_CASE(testXyMetadata) { std::cout << "testXyMetadata" << std::endl; @@ -112,7 +63,7 @@ BOOST_AUTO_TEST_CASE(testXyUpdates) { std::vector<double> yArrayValues = {-10.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0f}; DoocsServerTestHelper::doocsSet<double>("//DOUBLE/TO_DEVICE_ARRAY", yArrayValues); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); // Wait a bit usleep(2000000); @@ -127,10 +78,10 @@ BOOST_AUTO_TEST_CASE(testXyUpdates) { } } - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); DoocsServerTestHelper::doocsSet<float>("//FLOAT/TO_DEVICE_ARRAY", xArrayValues); DoocsServerTestHelper::doocsSet<double>("//DOUBLE/TO_DEVICE_ARRAY", yArrayValues); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); checkWithTimeout<double>(check, -10.0); @@ -147,7 +98,7 @@ BOOST_AUTO_TEST_CASE(testXyUpdates) { /* Just updating Y values with matching version */ std::transform(yArrayValues.begin(), yArrayValues.end(), yArrayValues.begin(), [](double v) { return v * 10.0; }); DoocsServerTestHelper::doocsSet<double>("//DOUBLE/TO_DEVICE_ARRAY", yArrayValues); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); checkWithTimeout<double>(check, -10.0 * 10.0); // Nothing should have happened @@ -162,9 +113,9 @@ BOOST_AUTO_TEST_CASE(testXyUpdates) { std::transform(yArrayValues.begin(), yArrayValues.end(), yArrayValues.begin(), [](double v) { return v * 10.0; }); - referenceTestApplication.versionNumber = boost::none; + GlobalFixture::referenceTestApplication.versionNumber = boost::none; DoocsServerTestHelper::doocsSet<double>("//DOUBLE/TO_DEVICE_ARRAY", yArrayValues); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); // Wait a bit usleep(2000000); diff --git a/tests/src/serverTestZeroMQ.cpp b/tests/src/serverTestZeroMQ.cpp index 9f19328a75d88daedcfc1ea72a0c36d90adc5a51..24748ce83a930a1a0192654e6fff6e8c0f41d6c4 100644 --- a/tests/src/serverTestZeroMQ.cpp +++ b/tests/src/serverTestZeroMQ.cpp @@ -1,8 +1,11 @@ -#define BOOST_TEST_MODULE servertestZeroMQ +#define BOOST_TEST_MODULE serverTestZeroMQ #include <boost/test/included/unit_test.hpp> #include <ChimeraTK/ControlSystemAdapter/Testing/ReferenceTestApplication.h> #include <doocs-server-test-helper/doocsServerTestHelper.h> +extern const char* object_name; +#include <doocs-server-test-helper/ThreadedDoocsServer.h> + #include <eq_client.h> #include <random> #include <thread> @@ -13,74 +16,19 @@ using namespace boost::unit_test_framework; using namespace ChimeraTK; -static ReferenceTestApplication referenceTestApplication("serverTestZeroMQ"); - -/**********************************************************************************************************************/ - -extern int eq_server(int, char**); - -struct DoocsLauncher { - DoocsLauncher() { - // choose random RPC number - std::random_device rd; - std::uniform_int_distribution<int> dist(620000000, 999999999); - rpc_no = std::to_string(dist(rd)); - // update config file with the RPC number - std::string command = "sed -i serverTestZeroMQ.conf -e " - "'s/^SVR.RPC_NUMBER:.*$/SVR.RPC_NUMBER: " + - rpc_no + "/'"; - auto rc = std::system(command.c_str()); - (void)rc; - - // start the server - doocsServerThread = std::thread(eq_server, boost::unit_test::framework::master_test_suite().argc, - boost::unit_test::framework::master_test_suite().argv); - // wait until server has started (both the update thread and the rpc thread) - EqCall eq; - EqAdr ea; - EqData src, dst; - ea.adr("doocs://localhost:" + rpc_no + "/F/D/UINT/FROM_DEVICE_SCALAR"); - while(eq.get(&ea, &src, &dst)) usleep(100000); - dmsg_start(); - referenceTestApplication.initialiseManualLoopControl(); - } - - /** - * @brief For compatibility with older DOOCS versions declare our own eq_exit - * - * Can be removed once a new doocs server version is released. - */ - void eq_exit() { - auto nativeHandle = doocsServerThread.native_handle(); - if(nativeHandle != 0) pthread_kill(nativeHandle, SIGTERM); - } - - ~DoocsLauncher() { - referenceTestApplication.releaseManualLoopControl(); - eq_exit(); - doocsServerThread.join(); - } - - std::thread doocsServerThread; - static std::string rpc_no; -}; -std::string DoocsLauncher::rpc_no; - -/**********************************************************************************************************************/ +DOOCS_ADAPTER_DEFAULT_FIXTURE_STATIC_APPLICATION_WITH_CODE(dmsg_start();) static std::atomic<bool> dataReceived; static EqData received; static dmsg_info_t receivedInfo; static std::mutex mutex; -BOOST_GLOBAL_FIXTURE(DoocsLauncher); - /**********************************************************************************************************************/ BOOST_AUTO_TEST_CASE(testScalar) { std::cout << "testScalar" << std::endl; - auto appPVmanager = referenceTestApplication.getPVManager(); + auto appPVmanager = GlobalFixture::referenceTestApplication.getPVManager(); /// Note: The data is processed by the ReferenceTestApplication in the order /// of the types as listed in the HolderMap of the ReferenceTestApplication. @@ -89,7 +37,7 @@ BOOST_AUTO_TEST_CASE(testScalar) { EqData dst; EqAdr ea; - ea.adr("doocs://localhost:" + DoocsLauncher::rpc_no + "/F/D/UINT/FROM_DEVICE_SCALAR"); + ea.adr("doocs://localhost:" + GlobalFixture::rpcNo + "/F/D/UINT/FROM_DEVICE_SCALAR"); dmsg_t tag; int err = dmsg_attach(&ea, &dst, nullptr, [](void*, EqData* data, dmsg_info_t* info) { @@ -108,7 +56,7 @@ BOOST_AUTO_TEST_CASE(testScalar) { // Everything from now on will get the same version number, until we manually set a new one. //ChimeraTK::VersionNumber unusedVersion; //std::cout << "unusedVersion " << std::string(unusedVersion) << std::endl; - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); //std::cout << "version number now is " << std::string(referenceTestApplication.versionNumber.value_or(unusedVersion)) << std::endl; int macroPulseNumber = 12345; @@ -125,7 +73,7 @@ BOOST_AUTO_TEST_CASE(testScalar) { while(!dataReceived) { // First send, then wait. We assume that after 10 ms the event has been received once the ZMQ mechanism is up and running DoocsServerTestHelper::doocsSet<uint32_t>("//UINT/TO_DEVICE_SCALAR", expectedValue); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); // FIXME: This timeout is essential so everything has been received and the next // dataReceived really is false. It is a potential source of timing problems / // race conditions in this test. @@ -143,7 +91,7 @@ BOOST_AUTO_TEST_CASE(testScalar) { // Make sure consistent receiving is happening whether the macro pulse number is send first or second. std::array<bool, 10> sendMacroPulseFirst = {true, true, true, false, false, false, true, false, true, false}; for(size_t i = 0; i < 10; ++i) { - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); ++macroPulseNumber; expectedValue = 100 + i; if(sendMacroPulseFirst[i]) { @@ -155,7 +103,7 @@ BOOST_AUTO_TEST_CASE(testScalar) { // nothing must be received, no consistent set yet dataReceived = false; - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); usleep(10000); BOOST_CHECK(dataReceived == false); @@ -166,7 +114,7 @@ BOOST_AUTO_TEST_CASE(testScalar) { else { DoocsServerTestHelper::doocsSet<int32_t>("//INT/TO_DEVICE_SCALAR", macroPulseNumber); } - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); CHECK_WITH_TIMEOUT(dataReceived == true); { @@ -190,11 +138,11 @@ BOOST_AUTO_TEST_CASE(testScalar) { BOOST_AUTO_TEST_CASE(testArray) { std::cout << "testArray" << std::endl; - auto appPVmanager = referenceTestApplication.getPVManager(); + auto appPVmanager = GlobalFixture::referenceTestApplication.getPVManager(); EqData dst; EqAdr ea; - ea.adr("doocs://localhost:" + DoocsLauncher::rpc_no + "/F/D/UINT/FROM_DEVICE_ARRAY"); + ea.adr("doocs://localhost:" + GlobalFixture::rpcNo + "/F/D/UINT/FROM_DEVICE_ARRAY"); dmsg_t tag; int err = dmsg_attach(&ea, &dst, nullptr, [](void*, EqData* data, dmsg_info_t* info) { @@ -209,7 +157,7 @@ BOOST_AUTO_TEST_CASE(testArray) { // Add additional delay for the ZMQ system to come up usleep(2000000); - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); int macroPulseNumber = 99999; DoocsServerTestHelper::doocsSet<int>("//INT/TO_DEVICE_SCALAR", macroPulseNumber); @@ -222,7 +170,7 @@ BOOST_AUTO_TEST_CASE(testArray) { dataReceived = false; while(!dataReceived) { DoocsServerTestHelper::doocsSet<int32_t>("//UINT/TO_DEVICE_ARRAY", expectedArrayValue); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); // FIXME: This timeout is essential so everything has been received and the next // dataReceived really is false. It is a potential source of timing problems / // race conditions in this test. @@ -241,7 +189,7 @@ BOOST_AUTO_TEST_CASE(testArray) { // Make sure consistent receiving is happening whether the macro pulse number is send first or second. std::array<bool, 10> sendMacroPulseFirst = {true, true, true, false, false, false, true, false, true, false}; for(size_t i = 0; i < 10; ++i) { - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); --macroPulseNumber; expectedArrayValue[1] = 100 + i; if(sendMacroPulseFirst[i]) { @@ -253,7 +201,7 @@ BOOST_AUTO_TEST_CASE(testArray) { // nothing must be received, no consistent set yet dataReceived = false; - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); usleep(10000); BOOST_CHECK(dataReceived == false); @@ -264,7 +212,7 @@ BOOST_AUTO_TEST_CASE(testArray) { else { DoocsServerTestHelper::doocsSet<int32_t>("//INT/TO_DEVICE_SCALAR", macroPulseNumber); } - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); CHECK_WITH_TIMEOUT(dataReceived == true); { std::lock_guard<std::mutex> lock(mutex); @@ -288,11 +236,11 @@ BOOST_AUTO_TEST_CASE(testArray) { BOOST_AUTO_TEST_CASE(testSpectrum) { std::cout << "testSpectrum" << std::endl; - auto appPVmanager = referenceTestApplication.getPVManager(); + auto appPVmanager = GlobalFixture::referenceTestApplication.getPVManager(); EqData dst; EqAdr ea; - ea.adr("doocs://localhost:" + DoocsLauncher::rpc_no + "/F/D/FLOAT/FROM_DEVICE_ARRAY"); + ea.adr("doocs://localhost:" + GlobalFixture::rpcNo + "/F/D/FLOAT/FROM_DEVICE_ARRAY"); dmsg_t tag; int err = dmsg_attach(&ea, &dst, nullptr, [](void*, EqData* data, dmsg_info_t* info) { @@ -307,7 +255,7 @@ BOOST_AUTO_TEST_CASE(testSpectrum) { // Add additional delay for the ZMQ system to come up usleep(2000000); - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); int macroPulseNumber = -100; DoocsServerTestHelper::doocsSet<int>("//INT/TO_DEVICE_SCALAR", macroPulseNumber); @@ -320,7 +268,7 @@ BOOST_AUTO_TEST_CASE(testSpectrum) { dataReceived = false; while(!dataReceived) { DoocsServerTestHelper::doocsSet<int>("//INT/TO_DEVICE_SCALAR", macroPulseNumber); - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); // FIXME: This timeout is essential so everything has been received and the next // dataReceived really is false. It is a potential source of timing problems / // race conditions in this test. @@ -338,7 +286,7 @@ BOOST_AUTO_TEST_CASE(testSpectrum) { // Make sure consistent receiving is happening whether the macro pulse number is send first or second. std::array<bool, 10> sendMacroPulseFirst = {true, true, true, false, false, false, true, false, true, false}; for(size_t i = 0; i < 10; ++i) { - referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); + GlobalFixture::referenceTestApplication.versionNumber = ChimeraTK::VersionNumber(); macroPulseNumber *= -2; expectedFloatArrayValue[1] = 100 + i; if(sendMacroPulseFirst[i]) { @@ -350,7 +298,7 @@ BOOST_AUTO_TEST_CASE(testSpectrum) { // nothing must be received, no consistent set yet dataReceived = false; - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); usleep(10000); BOOST_CHECK(dataReceived == false); @@ -361,7 +309,7 @@ BOOST_AUTO_TEST_CASE(testSpectrum) { else { DoocsServerTestHelper::doocsSet<int32_t>("//INT/TO_DEVICE_SCALAR", macroPulseNumber); } - referenceTestApplication.runMainLoopOnce(); + GlobalFixture::referenceTestApplication.runMainLoopOnce(); CHECK_WITH_TIMEOUT(dataReceived == true); { std::lock_guard<std::mutex> lock(mutex);