From 59ba31edffe49f54ffa405d37d7bcfd74eb8056a Mon Sep 17 00:00:00 2001 From: ingvord Date: Tue, 13 Dec 2016 15:05:59 +0100 Subject: [PATCH 1/6] Progress: --- test/cpp_test_suite/cxxtest/CMakeLists.txt | 12 +- .../cxxtest/bin/kill_server.sh.cmake | 15 +++ .../cxxtest/bin/start_server.sh.cmake | 10 ++ .../cxxtest/include/config.h.cmake | 12 ++ .../new_tests/cxx_test_reconnection.cpp | 126 ++++++++++++++++++ 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 test/cpp_test_suite/cxxtest/bin/kill_server.sh.cmake create mode 100644 test/cpp_test_suite/cxxtest/bin/start_server.sh.cmake create mode 100644 test/cpp_test_suite/cxxtest/include/config.h.cmake create mode 100644 test/cpp_test_suite/new_tests/cxx_test_reconnection.cpp diff --git a/test/cpp_test_suite/cxxtest/CMakeLists.txt b/test/cpp_test_suite/cxxtest/CMakeLists.txt index 76280f439..c4275ff1b 100644 --- a/test/cpp_test_suite/cxxtest/CMakeLists.txt +++ b/test/cpp_test_suite/cxxtest/CMakeLists.txt @@ -11,7 +11,7 @@ macro(CXX_GENERATE_TEST name) endif() add_executable(${name} $ ${name}.cpp) - target_include_directories(${name} PRIVATE include) + target_include_directories(${name} PRIVATE include ${CMAKE_CURRENT_BINARY_DIR}/include) target_link_libraries(${name} PRIVATE tango) target_compile_definitions(${name} PRIVATE "-DVALGRIND -D_PTHREADS -D_REENTRANT") @@ -71,4 +71,12 @@ CXX_GENERATE_TEST(cxx_fwd_att) CXX_GENERATE_TEST(cxx_pipe_conf) CXX_GENERATE_TEST(cxx_pipe) CXX_GENERATE_TEST(cxx_z00_dyn_cmd) -CXX_GENERATE_TEST(cxx_old_poll) \ No newline at end of file +CXX_GENERATE_TEST(cxx_old_poll) +CXX_GENERATE_TEST(cxx_test_reconnection) + + +#utilities +configure_file(bin/start_server.sh.cmake bin/start_server.sh @ONLY) +configure_file(bin/kill_server.sh.cmake bin/kill_server.sh @ONLY) + +configure_file(include/config.h.cmake include/config.h @ONLY) diff --git a/test/cpp_test_suite/cxxtest/bin/kill_server.sh.cmake b/test/cpp_test_suite/cxxtest/bin/kill_server.sh.cmake new file mode 100644 index 000000000..84ab8a367 --- /dev/null +++ b/test/cpp_test_suite/cxxtest/bin/kill_server.sh.cmake @@ -0,0 +1,15 @@ +#!/bin/bash + +kill_servers(){ + PIDS=`ps -e | grep DevTest | grep -v grep | awk '{print $1}'` + echo "PIDS = $PIDS" + for pid in $PIDS + do + echo "Killing process with PID $pid" + kill $pid + done + + sleep 2 +} + +kill_servers \ No newline at end of file diff --git a/test/cpp_test_suite/cxxtest/bin/start_server.sh.cmake b/test/cpp_test_suite/cxxtest/bin/start_server.sh.cmake new file mode 100644 index 000000000..f081583f6 --- /dev/null +++ b/test/cpp_test_suite/cxxtest/bin/start_server.sh.cmake @@ -0,0 +1,10 @@ +#!/bin/bash + +start_server(){ + echo "Starting DevTest $1" + @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest $1 -v5 1>@PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.out 2>&1 & + echo $! > @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.pid + echo "Done. PID="`cat @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.pid` +} + +start_server $1 \ No newline at end of file diff --git a/test/cpp_test_suite/cxxtest/include/config.h.cmake b/test/cpp_test_suite/cxxtest/include/config.h.cmake new file mode 100644 index 000000000..e01262334 --- /dev/null +++ b/test/cpp_test_suite/cxxtest/include/config.h.cmake @@ -0,0 +1,12 @@ +#ifndef Config_h +#define Config_h + +#include + +namespace Tango { + const std::string kProjectBinaryDir{"@PROJECT_BINARY_DIR@"}; + const std::string kStartServerCmd{"@CMAKE_CURRENT_BINARY_DIR@/bin/start_server.sh "}; + const std::string kKillServerCmd{"@CMAKE_CURRENT_BINARY_DIR@/bin/kill_server.sh"}; +} + +#endif \ No newline at end of file diff --git a/test/cpp_test_suite/new_tests/cxx_test_reconnection.cpp b/test/cpp_test_suite/new_tests/cxx_test_reconnection.cpp new file mode 100644 index 000000000..a617f9a27 --- /dev/null +++ b/test/cpp_test_suite/new_tests/cxx_test_reconnection.cpp @@ -0,0 +1,126 @@ +// +// Created by ingvord on 12/13/16. +// +#ifndef ReconnectionTestSuite_h +#define ReconnectionTestSuite_h + +#include +#include +#include +#include +#include +#include + +using namespace Tango; +using namespace std; + +void start_server(const char* instance); +void kill_server(); + + +#define cout cout << "\t" + +#undef SUITE_NAME +#define SUITE_NAME ReconnectionTestSuite + +class ReconnectionTestSuite: public CxxTest::TestSuite +{ +protected: + DeviceProxy *device1, *device2; + string device1_name, device2_name, dev1_instance_name, dev2_instance_name; + +public: + SUITE_NAME(): + dev1_instance_name("test"),//TODO pass via cli + dev2_instance_name("test2") + { + +// +// Arguments check ------------------------------------------------- +// + + device1_name = CxxTest::TangoPrinter::get_param("device1"); + device2_name = CxxTest::TangoPrinter::get_param("device2"); + + CxxTest::TangoPrinter::validate_args(); + + +// +// Initialization -------------------------------------------------- +// + + try + { + device1 = new DeviceProxy(device1_name); + device2 = new DeviceProxy(device2_name); + } + catch (CORBA::Exception &e) + { + Except::print_exception(e); + exit(-1); + } + + } + + virtual ~SUITE_NAME() + { + if (CxxTest::TangoPrinter::is_restore_set(dev2_instance_name + " started.")) + kill_server(); + + delete device1; + delete device2; + } + + static SUITE_NAME *createSuite() + { + return new SUITE_NAME(); + } + + static void destroySuite(SUITE_NAME *suite) + { + delete suite; + } + +// +// Tests ------------------------------------------------------- +// + + void test_server_event(void) + { + //TODO start server 2 and set fallback point + start_server(dev2_instance_name.c_str()); + CxxTest::TangoPrinter::restore_set(dev2_instance_name + " started."); + //TODO + + kill_server(); + CxxTest::TangoPrinter::restore_unset(dev2_instance_name + " started."); + } + + void test_event_reconnection(void) + { + //TODO + } + + void test_stateless_event_connection(void) + { + //TODO + } + +}; + +void start_server(const char* instance){ + string command=kStartServerCmd; + command += instance; + system(command.c_str()); + + cout << std::ifstream(kProjectBinaryDir + "/DevTest_" + instance + ".out").rdbuf(); +} + +void kill_server(){ + system(kKillServerCmd.c_str()); +} + +#undef cout +#endif // ReconnectionTestSuite_h + + From 1ec65be2a014487c319895c3c191f0e2622971a8 Mon Sep 17 00:00:00 2001 From: ingvord Date: Wed, 14 Dec 2016 13:19:38 +0100 Subject: [PATCH 2/6] Progress: --- test/cpp_test_suite/cxxtest/CMakeLists.txt | 3 +- .../cxxtest/bin/start_server.sh.cmake | 2 + .../cxxtest/include/cxxtest/TangoPrinter.h | 14 +- .../new_tests/cxx_server_event.cpp | 145 ++++++++++++++++++ .../new_tests/cxx_test_reconnection.cpp | 126 --------------- 5 files changed, 162 insertions(+), 128 deletions(-) create mode 100644 test/cpp_test_suite/new_tests/cxx_server_event.cpp delete mode 100644 test/cpp_test_suite/new_tests/cxx_test_reconnection.cpp diff --git a/test/cpp_test_suite/cxxtest/CMakeLists.txt b/test/cpp_test_suite/cxxtest/CMakeLists.txt index c4275ff1b..2ebbbb875 100644 --- a/test/cpp_test_suite/cxxtest/CMakeLists.txt +++ b/test/cpp_test_suite/cxxtest/CMakeLists.txt @@ -19,6 +19,7 @@ macro(CXX_GENERATE_TEST name) --device1=${DEV1} --device2=${DEV2} --device3=${DEV3} + --device20=${DEV20} --fwd_device=${FWD_DEV} --loop=1 --fulldsname=${SERV_NAME}/${INST_NAME} @@ -72,7 +73,7 @@ CXX_GENERATE_TEST(cxx_pipe_conf) CXX_GENERATE_TEST(cxx_pipe) CXX_GENERATE_TEST(cxx_z00_dyn_cmd) CXX_GENERATE_TEST(cxx_old_poll) -CXX_GENERATE_TEST(cxx_test_reconnection) +CXX_GENERATE_TEST(cxx_server_event) #utilities diff --git a/test/cpp_test_suite/cxxtest/bin/start_server.sh.cmake b/test/cpp_test_suite/cxxtest/bin/start_server.sh.cmake index f081583f6..da026e55b 100644 --- a/test/cpp_test_suite/cxxtest/bin/start_server.sh.cmake +++ b/test/cpp_test_suite/cxxtest/bin/start_server.sh.cmake @@ -4,6 +4,8 @@ start_server(){ echo "Starting DevTest $1" @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest $1 -v5 1>@PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.out 2>&1 & echo $! > @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.pid + + sleep 7 echo "Done. PID="`cat @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.pid` } diff --git a/test/cpp_test_suite/cxxtest/include/cxxtest/TangoPrinter.h b/test/cpp_test_suite/cxxtest/include/cxxtest/TangoPrinter.h index 7fc7645cd..9f650fcdf 100644 --- a/test/cpp_test_suite/cxxtest/include/cxxtest/TangoPrinter.h +++ b/test/cpp_test_suite/cxxtest/include/cxxtest/TangoPrinter.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include // Tango exceptions handling //#undef _TS_CATCH_ABORT @@ -130,7 +132,6 @@ namespace CxxTest * in case a test case fails before restoring these settings by itself */ static set restore_points; - public: TangoPrinter( CXXTEST_STD(ostream) &o = CXXTEST_STD(cout), const char *preLine = ":", const char *postLine = "" ) : ErrorFormatter( new Adapter(o), preLine, postLine ) {} @@ -748,6 +749,7 @@ namespace CxxTest params_tmp["device1"] = param_desc("--device1=", "device1 name, e.g. test/device/1"); params_tmp["device2"] = param_desc("--device2=", "device2 name, e.g. test/device/2"); params_tmp["device3"] = param_desc("--device3=", "device3 name, e.g. test/device/3"); + params_tmp["device20"] = param_desc("--device20=", "device20 name, e.g. test2/debian8/20"); params_tmp["fulldsname"] = param_desc("--fulldsname=", "full device server name, e.g. devTest/myserver"); params_tmp["clienthost"] = param_desc("--clienthost=", "client host's fully qualified domain name, e.g. mypc.myinstitute.com (small caps)"); params_tmp["serverhost"] = param_desc("--serverhost=", "fully qualified domain name of the host on which the server is running, e.g. myserver.myinstitute.com (small caps)"); @@ -764,6 +766,16 @@ namespace CxxTest return params_tmp; } + static void start_server(const std::string& instance){ + std::string command = Tango::kStartServerCmd; + command += instance; + system(command.c_str()); + } + + static void kill_server() { + system(Tango::kKillServerCmd.c_str()); + } + private: class Adapter : public OutputStream { diff --git a/test/cpp_test_suite/new_tests/cxx_server_event.cpp b/test/cpp_test_suite/new_tests/cxx_server_event.cpp new file mode 100644 index 000000000..ef1e9d8b3 --- /dev/null +++ b/test/cpp_test_suite/new_tests/cxx_server_event.cpp @@ -0,0 +1,145 @@ +// +// Created by ingvord on 12/14/16. +// +#ifndef ServerEventTestSuite_h +#define ServerEventTestSuite_h + + +#include +#include +#include +#include + +using namespace Tango; +using namespace std; + +#define cout cout << "\t" +#define coutv if (verbose == true) cout + +#undef SUITE_NAME +#define SUITE_NAME ServerEventTestSuite + +class ServerEventTestSuite : public CxxTest::TestSuite { +protected: + DeviceProxy *device1, *device2; + string device1_name, device2_name; + bool verbose; + DevLong eve_id; + +public: + SUITE_NAME() { + +// +// Arguments check ------------------------------------------------- +// + + device1_name = CxxTest::TangoPrinter::get_param("device1"); + device2_name = CxxTest::TangoPrinter::get_param("device20"); + + verbose = CxxTest::TangoPrinter::is_param_defined("verbose"); + + CxxTest::TangoPrinter::validate_args(); + + +// +// Initialization -------------------------------------------------- +// + + try { + device1 = new DeviceProxy(device1_name); + device2 = new DeviceProxy(device2_name); + + //TODO start server 2 and set fallback point + CxxTest::TangoPrinter::start_server("test2"); + CxxTest::TangoPrinter::restore_set("test2/debian8/20 started."); + } + catch (CORBA::Exception &e) { + Except::print_exception(e); + exit(-1); + } + + } + + virtual ~SUITE_NAME() { + if (CxxTest::TangoPrinter::is_restore_set("test2/debian8/20 started.")) + CxxTest::TangoPrinter::kill_server(); + + delete device1; + delete device2; + } + + static SUITE_NAME *createSuite() { + return new SUITE_NAME(); + } + + static void destroySuite(SUITE_NAME *suite) { + delete suite; + } + +// +// Tests ------------------------------------------------------- +// + +// +// Ask the device server to subscribe to an event +// + void test_device_server_subscribe_to_event(void) { + coutv << endl << "new DeviceProxy(" << device1->name() << ") returned" << endl << endl; + + + vector vs{device2_name, "Short_attr", "periodic"}; + + DeviceData dd_in, dd_out; + dd_in << vs; + TS_ASSERT_THROWS_NOTHING(dd_out = device1->command_inout("IOSubscribeEvent", dd_in)); + dd_out >> eve_id; + } + + + +// +// Wait for event to be executed +// + + void test_wait_event(void) { + Tango_sleep(3); + + DeviceData da; + TS_ASSERT_THROWS_NOTHING(da = device1->command_inout("IOGetCbExecuted")); + Tango::DevLong cb; + da >> cb; + + coutv << "cb executed = " << cb << endl; + TS_ASSERT_LESS_THAN_EQUALS(2, cb); + TS_ASSERT_LESS_THAN_EQUALS(cb, 4); + } + +// +// Ask server to unsubsribe from event +// + void test_server_unsubscribes_from_event(void) { + DeviceData dd_un; + dd_un << eve_id; + + DeviceData da; + TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOUnSubscribeEvent", dd_un)); + TS_ASSERT_THROWS_NOTHING(da = device1->command_inout("IOGetCbExecuted")); + + Tango::DevLong cb; + da >> cb; + + Tango_sleep(2); + TS_ASSERT_THROWS_NOTHING(da = device1->command_inout("IOGetCbExecuted")); + Tango::DevLong cb2; + da >> cb2; + + TS_ASSERT_EQUALS(cb2, cb); + } +}; + +#undef cout +#endif // ServerEventTestSuite_h + + + + diff --git a/test/cpp_test_suite/new_tests/cxx_test_reconnection.cpp b/test/cpp_test_suite/new_tests/cxx_test_reconnection.cpp deleted file mode 100644 index a617f9a27..000000000 --- a/test/cpp_test_suite/new_tests/cxx_test_reconnection.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// -// Created by ingvord on 12/13/16. -// -#ifndef ReconnectionTestSuite_h -#define ReconnectionTestSuite_h - -#include -#include -#include -#include -#include -#include - -using namespace Tango; -using namespace std; - -void start_server(const char* instance); -void kill_server(); - - -#define cout cout << "\t" - -#undef SUITE_NAME -#define SUITE_NAME ReconnectionTestSuite - -class ReconnectionTestSuite: public CxxTest::TestSuite -{ -protected: - DeviceProxy *device1, *device2; - string device1_name, device2_name, dev1_instance_name, dev2_instance_name; - -public: - SUITE_NAME(): - dev1_instance_name("test"),//TODO pass via cli - dev2_instance_name("test2") - { - -// -// Arguments check ------------------------------------------------- -// - - device1_name = CxxTest::TangoPrinter::get_param("device1"); - device2_name = CxxTest::TangoPrinter::get_param("device2"); - - CxxTest::TangoPrinter::validate_args(); - - -// -// Initialization -------------------------------------------------- -// - - try - { - device1 = new DeviceProxy(device1_name); - device2 = new DeviceProxy(device2_name); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(-1); - } - - } - - virtual ~SUITE_NAME() - { - if (CxxTest::TangoPrinter::is_restore_set(dev2_instance_name + " started.")) - kill_server(); - - delete device1; - delete device2; - } - - static SUITE_NAME *createSuite() - { - return new SUITE_NAME(); - } - - static void destroySuite(SUITE_NAME *suite) - { - delete suite; - } - -// -// Tests ------------------------------------------------------- -// - - void test_server_event(void) - { - //TODO start server 2 and set fallback point - start_server(dev2_instance_name.c_str()); - CxxTest::TangoPrinter::restore_set(dev2_instance_name + " started."); - //TODO - - kill_server(); - CxxTest::TangoPrinter::restore_unset(dev2_instance_name + " started."); - } - - void test_event_reconnection(void) - { - //TODO - } - - void test_stateless_event_connection(void) - { - //TODO - } - -}; - -void start_server(const char* instance){ - string command=kStartServerCmd; - command += instance; - system(command.c_str()); - - cout << std::ifstream(kProjectBinaryDir + "/DevTest_" + instance + ".out").rdbuf(); -} - -void kill_server(){ - system(kKillServerCmd.c_str()); -} - -#undef cout -#endif // ReconnectionTestSuite_h - - From 7b19d0159d3c6be1969e0d62fb3381ddcfad24d1 Mon Sep 17 00:00:00 2001 From: ingvord Date: Wed, 14 Dec 2016 16:32:31 +0100 Subject: [PATCH 3/6] Progress: --- test/cpp_test_suite/cxxtest/CMakeLists.txt | 5 +- .../new_tests/cxx_reconnection_zmq.cpp | 234 ++++++++++++++++++ .../new_tests/cxx_server_event.cpp | 11 +- 3 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 test/cpp_test_suite/new_tests/cxx_reconnection_zmq.cpp diff --git a/test/cpp_test_suite/cxxtest/CMakeLists.txt b/test/cpp_test_suite/cxxtest/CMakeLists.txt index 2ebbbb875..3c924c0b0 100644 --- a/test/cpp_test_suite/cxxtest/CMakeLists.txt +++ b/test/cpp_test_suite/cxxtest/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package (Threads REQUIRED) + macro(CXX_GENERATE_TEST name) message("Generate ${name}.cpp") execute_process(COMMAND python cxxtestgen.py --template=${CMAKE_CURRENT_SOURCE_DIR}/template/tango_template.tpl @@ -12,7 +14,7 @@ macro(CXX_GENERATE_TEST name) add_executable(${name} $ ${name}.cpp) target_include_directories(${name} PRIVATE include ${CMAKE_CURRENT_BINARY_DIR}/include) - target_link_libraries(${name} PRIVATE tango) + target_link_libraries(${name} PRIVATE tango ${CMAKE_THREAD_LIBS_INIT}) target_compile_definitions(${name} PRIVATE "-DVALGRIND -D_PTHREADS -D_REENTRANT") add_test(NAME "CXX::${name}" COMMAND $ @@ -74,6 +76,7 @@ CXX_GENERATE_TEST(cxx_pipe) CXX_GENERATE_TEST(cxx_z00_dyn_cmd) CXX_GENERATE_TEST(cxx_old_poll) CXX_GENERATE_TEST(cxx_server_event) +CXX_GENERATE_TEST(cxx_reconnection_zmq) #utilities diff --git a/test/cpp_test_suite/new_tests/cxx_reconnection_zmq.cpp b/test/cpp_test_suite/new_tests/cxx_reconnection_zmq.cpp new file mode 100644 index 000000000..b218da793 --- /dev/null +++ b/test/cpp_test_suite/new_tests/cxx_reconnection_zmq.cpp @@ -0,0 +1,234 @@ +// +// Created by ingvord on 12/14/16. +// +#ifndef RecoZmqTestSuite_h +#define RecoZmqTestSuite_h + + +#include +#include +#include +#include +#include + +using namespace Tango; +using namespace std; + +#define cout cout << "\t" +#define coutv if (verbose == true) cout + +#undef SUITE_NAME +#define SUITE_NAME RecoZmqTestSuite + +class EventCallback : public Tango::CallBack +{ +public: + EventCallback() { }; + ~EventCallback() { }; + void push_event( Tango::EventData *ed ){ + cout << "In callback with error flag = " << std::boolalpha << ed->err << endl; + if(ed->err) { + cb_err++; + cout << "Error: " << ed->errors[0].reason << endl; + } else { + cb_executed++; + } + } + + + int cb_executed; + int cb_err; +}; + +class RecoZmqTestSuite : public CxxTest::TestSuite { +protected: + DeviceProxy *device1, *device2; + string device1_name, device2_name, device1_instance_name, device2_instance_name; + bool verbose; + EventCallback eventCallback; + +public: + SUITE_NAME() : + device1_instance_name{"test"},//TODO pass via cl + device2_instance_name{"test2"}, + eventCallback{} + { + +// +// Arguments check ------------------------------------------------- +// + + device1_name = CxxTest::TangoPrinter::get_param("device1"); + device2_name = CxxTest::TangoPrinter::get_param("device20"); + + verbose = CxxTest::TangoPrinter::is_param_defined("verbose"); + + CxxTest::TangoPrinter::validate_args(); + + +// +// Initialization -------------------------------------------------- +// + + try { + device1 = new DeviceProxy(device1_name); + device2 = new DeviceProxy(device2_name); + + //TODO start server 2 and set fallback point + CxxTest::TangoPrinter::start_server(device2_instance_name); + CxxTest::TangoPrinter::restore_set("test2/debian8/20 started."); + + //sleep 18 && start_server "@INST_NAME@" & + thread([this]() { + Tango_sleep(18); + CxxTest::TangoPrinter::start_server(device1_instance_name); + }).detach(); + + //sleep 62 && start_server "@INST_NAME@" & + thread([this]() { + Tango_sleep(62); + CxxTest::TangoPrinter::start_server(device1_instance_name); + }).detach(); + } + catch (CORBA::Exception &e) { + Except::print_exception(e); + exit(-1); + } + + } + + virtual ~SUITE_NAME() { + if (CxxTest::TangoPrinter::is_restore_set("test2/debian8/20 started.")) + CxxTest::TangoPrinter::kill_server(); + + CxxTest::TangoPrinter::start_server(device1_instance_name); + + delete device1; + delete device2; + } + + static SUITE_NAME *createSuite() { + return new SUITE_NAME(); + } + + static void destroySuite(SUITE_NAME *suite) { + delete suite; + } + +// +// Tests ------------------------------------------------------- +// + +// +// Subscribe to a user event +// + void test_subscribe_to_user_event(void) { + string att_name("event_change_tst"); + + const vector filters; + eventCallback.cb_executed = 0; + eventCallback.cb_err = 0; + + TS_ASSERT_THROWS_NOTHING(device1->subscribe_event(att_name, Tango::USER_EVENT, &eventCallback, filters)); + +// +// Fire one event +// + + TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOPushEvent")); + TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOPushEvent")); + + Tango_sleep(1); + + coutv << "Callback execution before re-connection = " << eventCallback.cb_executed << endl; + coutv << "Callback error before re-connection = " << eventCallback.cb_err << endl; + + TS_ASSERT_EQUALS (eventCallback.cb_executed, 3); + TS_ASSERT_EQUALS (eventCallback.cb_err, 0); + +// +// Kill device server (using its admin device) +// + + string adm_name = device1->adm_name(); + DeviceProxy admin_dev(adm_name); + TS_ASSERT_THROWS_NOTHING(admin_dev.command_inout("kill")); + +// +// Wait for some error and re-connection +// + + Tango_sleep(40); + +// +// Check error and re-connection +// + + coutv << "Callback execution after re-connection = " << eventCallback.cb_executed << endl; + coutv << "Callback error after re-connection = " << eventCallback.cb_err << endl; + + TS_ASSERT_LESS_THAN_EQUALS (1, eventCallback.cb_err); + TS_ASSERT_EQUALS (eventCallback.cb_executed, 4); + +// +// Fire another event +// + + TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOPushEvent")); + TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOPushEvent")); + + Tango_sleep(1); + + coutv << "Callback execution after re-connection and event = " << eventCallback.cb_executed << endl; + coutv << "Callback error after re-connection and event = " << eventCallback.cb_err << endl; + + TS_ASSERT_EQUALS (eventCallback.cb_executed, 6); + TS_ASSERT_LESS_THAN_EQUALS (1, eventCallback.cb_err); + } + +// +// Clear call back counters and kill device server once more +// + void test_clear_cb_kill_ds(void) { + eventCallback.cb_executed = 0; + eventCallback.cb_err = 0; + + string adm_name = device1->adm_name(); + DeviceProxy admin_dev(adm_name); + TS_ASSERT_THROWS_NOTHING(admin_dev.command_inout("kill")); + +// +// Wait for some error and re-connection +// + + Tango_sleep(40); + +// +// Check error and re-connection +// + + coutv << "Callback execution after second re-connection = " << eventCallback.cb_executed << endl; + coutv << "Callback error after second re-connection = " << eventCallback.cb_err << endl; + + TS_ASSERT_LESS_THAN_EQUALS (1, eventCallback.cb_err); + TS_ASSERT_EQUALS (eventCallback.cb_executed, 1); + +// +// Fire yet another event +// + + TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOPushEvent")); + + Tango_sleep(2); + + coutv << "Callback execution after second re-connection and event = " << eventCallback.cb_executed << endl; + coutv << "Callback error after second re-connection and event = " << eventCallback.cb_err << endl; + + TS_ASSERT_EQUALS (eventCallback.cb_executed, 2); + TS_ASSERT_LESS_THAN_EQUALS (1, eventCallback.cb_err); + } +}; + +#undef cout +#endif // RecoZmqTestSuite_h + diff --git a/test/cpp_test_suite/new_tests/cxx_server_event.cpp b/test/cpp_test_suite/new_tests/cxx_server_event.cpp index ef1e9d8b3..8b3fd29f3 100644 --- a/test/cpp_test_suite/new_tests/cxx_server_event.cpp +++ b/test/cpp_test_suite/new_tests/cxx_server_event.cpp @@ -22,12 +22,15 @@ using namespace std; class ServerEventTestSuite : public CxxTest::TestSuite { protected: DeviceProxy *device1, *device2; - string device1_name, device2_name; + string device1_name, device2_name, device1_instance_name, device2_instance_name; bool verbose; DevLong eve_id; public: - SUITE_NAME() { + SUITE_NAME(): + device1_instance_name{"test"},//TODO pass via cl + device2_instance_name{"test2"} + { // // Arguments check ------------------------------------------------- @@ -50,7 +53,7 @@ class ServerEventTestSuite : public CxxTest::TestSuite { device2 = new DeviceProxy(device2_name); //TODO start server 2 and set fallback point - CxxTest::TangoPrinter::start_server("test2"); + CxxTest::TangoPrinter::start_server(device2_instance_name); CxxTest::TangoPrinter::restore_set("test2/debian8/20 started."); } catch (CORBA::Exception &e) { @@ -64,6 +67,8 @@ class ServerEventTestSuite : public CxxTest::TestSuite { if (CxxTest::TangoPrinter::is_restore_set("test2/debian8/20 started.")) CxxTest::TangoPrinter::kill_server(); + CxxTest::TangoPrinter::start_server(device1_instance_name); + delete device1; delete device2; } From 9436e721e35297968343b9a584e5076a202e7581 Mon Sep 17 00:00:00 2001 From: ingvord Date: Wed, 14 Dec 2016 17:03:12 +0100 Subject: [PATCH 4/6] Progress: --- test/cpp_test_suite/cxxtest/CMakeLists.txt | 1 + test/cpp_test_suite/event/CMakeLists.txt | 15 +- .../new_tests/cxx_stateless_subscription.cpp | 157 ++++++++++++++++++ 3 files changed, 160 insertions(+), 13 deletions(-) create mode 100644 test/cpp_test_suite/new_tests/cxx_stateless_subscription.cpp diff --git a/test/cpp_test_suite/cxxtest/CMakeLists.txt b/test/cpp_test_suite/cxxtest/CMakeLists.txt index 3c924c0b0..aa6c4a64d 100644 --- a/test/cpp_test_suite/cxxtest/CMakeLists.txt +++ b/test/cpp_test_suite/cxxtest/CMakeLists.txt @@ -77,6 +77,7 @@ CXX_GENERATE_TEST(cxx_z00_dyn_cmd) CXX_GENERATE_TEST(cxx_old_poll) CXX_GENERATE_TEST(cxx_server_event) CXX_GENERATE_TEST(cxx_reconnection_zmq) +CXX_GENERATE_TEST(cxx_stateless_subscription) #utilities diff --git a/test/cpp_test_suite/event/CMakeLists.txt b/test/cpp_test_suite/event/CMakeLists.txt index fbb1a34ec..073556010 100644 --- a/test/cpp_test_suite/event/CMakeLists.txt +++ b/test/cpp_test_suite/event/CMakeLists.txt @@ -18,11 +18,7 @@ set(TESTS archive_event data_ready_event_buffer dev_intr_event multi_dev_event - per_event -# reco_event - reco_zmq - server_event - stateless_sub) + per_event) foreach(TEST ${TESTS}) TEST_SUITE_ADD_TEST(${TEST}) @@ -44,11 +40,4 @@ add_test(NAME "event::data_ready_event_buffer" COMMAND $ ${DEV1} ${DEV2} ${DEV3}) add_test(NAME "event::dev_intr_event" COMMAND $ ${DEV1}) add_test(NAME "event::pipe_event" COMMAND $ ${DEV1}) -add_test(NAME "event::event_lock" COMMAND $ ${DEV1}) - - -#the following test performs several kill/start sequences, but must keep DEV1 alive in the end -configure_file(test_reconnection.sh.cmake test_reconnection.sh @ONLY) -execute_process(COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/test_reconnection.sh) -add_test(NAME "event::reconnect" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_reconnection.sh - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) \ No newline at end of file +add_test(NAME "event::event_lock" COMMAND $ ${DEV1}) \ No newline at end of file diff --git a/test/cpp_test_suite/new_tests/cxx_stateless_subscription.cpp b/test/cpp_test_suite/new_tests/cxx_stateless_subscription.cpp new file mode 100644 index 000000000..e2eaef62d --- /dev/null +++ b/test/cpp_test_suite/new_tests/cxx_stateless_subscription.cpp @@ -0,0 +1,157 @@ +// +// Created by ingvord on 12/14/16. +// +#ifndef StatelessSubTestSuite_h +#define StatelessSubTestSuite_h + + +#include +#include +#include +#include +#include + +using namespace Tango; +using namespace std; + +#define cout cout << "\t" +#define coutv if (verbose == true) cout + +#undef SUITE_NAME +#define SUITE_NAME StatelessSubTestSuite + +class EventCallback : public Tango::CallBack { +public: + EventCallback() {}; + + ~EventCallback() {}; + + void push_event(Tango::EventData *ed) { + cout << "In callback with error flag = " << std::boolalpha << ed->err << endl; + if (ed->err) { + cb_err++; + cout << "Error: " << ed->errors[0].reason << endl; + } else { + cb_executed++; + } + } + + + int cb_executed; + int cb_err; +}; + +class StatelessSubTestSuite : public CxxTest::TestSuite { +protected: + DeviceProxy *device2; + string device2_name, device1_instance_name, device2_instance_name; + bool verbose; + EventCallback eventCallback; + +public: + SUITE_NAME() : + device2_instance_name{"test2"}, + eventCallback{} { + +// +// Arguments check ------------------------------------------------- +// + + device2_name = CxxTest::TangoPrinter::get_param("device20"); + + verbose = CxxTest::TangoPrinter::is_param_defined("verbose"); + + CxxTest::TangoPrinter::validate_args(); + + +// +// Initialization -------------------------------------------------- +// + + try { + device2 = new DeviceProxy(device2_name); + + //sleep 24 && start_server "@INST_NAME@2" & + thread([this]() { + Tango_sleep(24); + CxxTest::TangoPrinter::start_server(device2_instance_name); + CxxTest::TangoPrinter::restore_set("test2/debian8/20 started."); + }).detach(); + } + catch (CORBA::Exception &e) { + Except::print_exception(e); + exit(-1); + } + + } + + virtual ~SUITE_NAME() { + if (CxxTest::TangoPrinter::is_restore_set("test2/debian8/20 started.")) + CxxTest::TangoPrinter::kill_server(); + + CxxTest::TangoPrinter::start_server("test"); + + delete device2; + } + + static SUITE_NAME *createSuite() { + return new SUITE_NAME(); + } + + static void destroySuite(SUITE_NAME *suite) { + delete suite; + } + +// +// Tests ------------------------------------------------------- +// + +// +// Subscribe to event with stateless flag set +// + void test_unsubscribe_from_stateless_event(void) { + string att_name("event_change_tst"); + + int eventID = 0; + const vector filters; + eventCallback.cb_executed = 0; + eventCallback.cb_err = 0; + + TS_ASSERT_THROWS_NOTHING( + eventID = device2->subscribe_event(att_name, Tango::CHANGE_EVENT, &eventCallback, filters, true)); + + Tango_sleep(6); + + TS_ASSERT_THROWS_NOTHING(device2->unsubscribe_event(eventID)); + } + +// +// Re-subscribe +// + void test_re_subscribe_and_check(void) { + string att_name("event_change_tst"); + int eventID; + TS_ASSERT_THROWS_NOTHING(eventID = device2->subscribe_event(att_name, Tango::CHANGE_EVENT, &eventCallback, true)); + +// +// Wait for connection and event +// + + Tango_sleep(40); + +// +// Check error and connection +// + + coutv << "cb err = " << eventCallback.cb_err << endl; + coutv << "cb executed = " << eventCallback.cb_executed << endl; + + TS_ASSERT_LESS_THAN_EQUALS (1, eventCallback.cb_err); + TS_ASSERT_LESS_THAN_EQUALS (1, eventCallback.cb_executed); + } +}; + +#undef cout +#endif // StatelessSubTestSuite_h + + From 32ec1d1fdd53e8089e3fbf02915de20e8da81f65 Mon Sep 17 00:00:00 2001 From: ingvord Date: Wed, 14 Dec 2016 21:10:13 +0300 Subject: [PATCH 5/6] Progress: --- test/cpp_test_suite/cxxtest/CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/cpp_test_suite/cxxtest/CMakeLists.txt b/test/cpp_test_suite/cxxtest/CMakeLists.txt index aa6c4a64d..aaf4d9c2e 100644 --- a/test/cpp_test_suite/cxxtest/CMakeLists.txt +++ b/test/cpp_test_suite/cxxtest/CMakeLists.txt @@ -81,7 +81,17 @@ CXX_GENERATE_TEST(cxx_stateless_subscription) #utilities -configure_file(bin/start_server.sh.cmake bin/start_server.sh @ONLY) -configure_file(bin/kill_server.sh.cmake bin/kill_server.sh @ONLY) +configure_file(bin/start_server.sh.cmake ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/start_server.sh @ONLY) +configure_file(bin/kill_server.sh.cmake ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/kill_server.sh @ONLY) + +# now copy the temporary into the final destination, setting the permissions +file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/start_server.sh + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ + GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) +file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/kill_server.sh + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ + GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) configure_file(include/config.h.cmake include/config.h @ONLY) From 5d433ac11ae205871ec5fcc527bc145e0439d941 Mon Sep 17 00:00:00 2001 From: ingvord Date: Wed, 14 Dec 2016 22:04:57 +0300 Subject: [PATCH 6/6] Progress: cleanup --- test/cpp_test_suite/event/reco_event.cpp | 388 --------------- test/cpp_test_suite/event/reco_svc.cpp | 446 ------------------ test/cpp_test_suite/event/reco_zmq.cpp | 190 -------- test/cpp_test_suite/event/server_event.cpp | 118 ----- test/cpp_test_suite/event/stateless_sub.cpp | 124 ----- .../event/test_reconnection.sh.cmake | 81 ---- 6 files changed, 1347 deletions(-) delete mode 100644 test/cpp_test_suite/event/reco_event.cpp delete mode 100644 test/cpp_test_suite/event/reco_svc.cpp delete mode 100644 test/cpp_test_suite/event/reco_zmq.cpp delete mode 100644 test/cpp_test_suite/event/server_event.cpp delete mode 100644 test/cpp_test_suite/event/stateless_sub.cpp delete mode 100644 test/cpp_test_suite/event/test_reconnection.sh.cmake diff --git a/test/cpp_test_suite/event/reco_event.cpp b/test/cpp_test_suite/event/reco_event.cpp deleted file mode 100644 index 297c7f5d5..000000000 --- a/test/cpp_test_suite/event/reco_event.cpp +++ /dev/null @@ -1,388 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#ifdef WIN32 -#include -#include -#else -#include -#include -#endif - -#define coutv if (verbose == true) cout - -using namespace Tango; - -void wait_and_dot(int); - -bool verbose = false; - -class EventCallBack : public Tango::CallBack -{ - void push_event(Tango::EventData*); - -public: - int cb_executed; - int cb_no_err; - int cb_err; - int old_sec,old_usec; - int delta_msec; -}; - -void EventCallBack::push_event(Tango::EventData* event_data) -{ - struct timeval now_timeval; -#ifdef WIN32 - struct _timeb before_win; - _ftime(&before_win); - now_timeval.tv_sec = (unsigned long)before_win.time; - now_timeval.tv_usec = (long)before_win.millitm * 1000; -#else - gettimeofday(&now_timeval,NULL); -#endif - - coutv << "date : tv_sec = " << now_timeval.tv_sec; - coutv << ", tv_usec = " << now_timeval.tv_usec << endl; - - int delta_s = now_timeval.tv_sec - old_sec; - if (delta_s == 0) - delta_msec = (now_timeval.tv_usec - old_usec) / 1000; - else - { - delta_msec = (now_timeval.tv_usec + (1000000 - old_usec)) / 1000; - if (delta_s > 1) - delta_msec = delta_msec + ((delta_s - 1)* 1000); - } - old_sec = now_timeval.tv_sec; - old_usec = now_timeval.tv_usec; - - coutv << "delta_msec = " << delta_msec << endl; - - cb_executed++; - try - { - coutv << "StateEventCallBack::push_event(): called attribute " << event_data->attr_name << " event " << event_data->event << "\n"; - if (!event_data->err) - { - - coutv << "CallBack without error " << endl; - cb_no_err++; - } - else - { - coutv << "Error send to callback" << endl; - cb_err++; - } - } - catch (...) - { - coutv << "EventCallBack::push_event(): could not extract data !\n"; - } - -} - -int main(int argc, char **argv) -{ - DeviceProxy *device; - - if (argc == 1) - { - cout << "usage: %s device [-v]" << endl; - exit(-1); - } - - string device_name = argv[1]; - - if (argc == 3) - { - if (strcmp(argv[2],"-v") == 0) - verbose = true; - } - - try - { - device = new DeviceProxy(device_name); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(1); - } - - coutv << endl << "new DeviceProxy(" << device->name() << ") returned" << endl << endl; - - - - - try - { - - string att_name("short_attr"); - string att_name_change("event_change_tst"); - -// -// Test set up (stop polling and clear event_period attribute property but -// restart device to take this into account) -// - - if (device->is_attribute_polled(att_name)) - device->stop_poll_attribute(att_name); - if (device->is_attribute_polled(att_name_change)) - device->stop_poll_attribute(att_name_change); - - DbAttribute dba(att_name,device_name); - DbData dbd; - DbDatum a(att_name); - a << (short)1; - dbd.push_back(a); - dbd.push_back(DbDatum("event_period")); - dba.delete_property(dbd); - - DeviceProxy adm_dev(device->adm_name().c_str()); - DeviceData di; - di << device_name; - adm_dev.command_inout("DevRestart",di); - - delete device; - device = new DeviceProxy(device_name); - Tango_sleep(1); - -// -// subscribe to a periodic event and a change event -// - - int eve_id,eve_id_change; - vector filters; - - EventCallBack cb; - cb.cb_executed = 0; - cb.cb_err = 0; - cb.cb_no_err = 0; - cb.old_sec = cb.old_usec = 0; - - EventCallBack cb_change; - cb_change.cb_executed = 0; - cb_change.cb_err = 0; - cb_change.cb_no_err = 0; - cb_change.old_sec = cb.old_usec = 0; - - // start the polling first! - device->poll_attribute(att_name,1000); - device->poll_attribute(att_name_change,1000); - - eve_id = device->subscribe_event(att_name,Tango::PERIODIC_EVENT,&cb,filters); - eve_id_change = device->subscribe_event(att_name_change,Tango::CHANGE_EVENT,&cb_change,filters); - - cout << " subscribe_event --> OK" << endl; - -// -// Check that callback was called -// - -// A trick for gdb. The thread created by omniORB for the callback execution -// is just started during the sleep. Gdb has a breakpoint reached at each thread -// creation to display message on the console. This breakpoint is a software -// signal which interrupts the sleep..... -// - -#ifndef WIN32 - int rest = sleep(3); - if (rest != 0) - sleep(3); -#else - Sleep(3000); -#endif - - coutv << "cb excuted = " << cb.cb_executed << endl; - assert (cb.cb_executed >= 2); - assert (cb.cb_executed < 5); - assert (cb.delta_msec > 950); - assert (cb.delta_msec < 1050); - - cout << " CallBack executed every 1000 mS for periodic event--> OK" << endl; - - assert (cb_change.cb_executed != 0); - cout << " CallBack executed once for change event--> OK" << endl; - -// -// Now, kill the notifd -// - - string key; - cout << "Kill notifd process and hit \"return\" key when done" << endl; - cout << "Process will wait for callback with error during 30 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - wait_and_dot(30); - - assert (cb.cb_err != 0); - assert (cb_change.cb_err != 0); - - cout << "\n CallBacks executed with error --> OK" << endl; - -// -// Now, kill device server -// - - cout << "Kill device server process and hit \"return\" key when done" << endl; - cout << "Process will wait for callback with error during 25 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - int old_cb_err = cb.cb_err; - int old_cb_err_ch = cb_change.cb_err; - - wait_and_dot(25); - - int new_cb_err = cb.cb_err; - int new_cb_err_ch = cb_change.cb_err; - - assert ((new_cb_err - old_cb_err) >= 2); - assert ((new_cb_err_ch - old_cb_err_ch) >= 2); - - cout << "\n CallBacks executed with error --> OK" << endl; - -// -// Now, Restart notifd -// - -#ifdef WIN32 - cout << "Restart notifd (notifd -n -DFactoryIORFileName=C:\\Temp\\evfact.ior)" << endl; - cout << "and hit \"return\" key when done" << endl; -#else - cout << "Restart notifd (notifd -n) and hit \"return\" key when done" << endl; -#endif - cout << "Process will wait for callback with error during 25 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - old_cb_err = cb.cb_err; - old_cb_err_ch = cb_change.cb_err; - - wait_and_dot(25); - - new_cb_err = cb.cb_err; - new_cb_err_ch = cb_change.cb_err; - - assert ((new_cb_err - old_cb_err) >= 2); - assert ((new_cb_err_ch - old_cb_err_ch) >= 2); - - cout << "\n CallBacks executed with error --> OK" << endl; - -// -// Now, export notifd to db -// - -#ifdef WIN32 - cout << "Export notifd to db (notifd2db C:\\Temp\\evfact.ior) and hit \"return\" key when done" << endl; -#else - cout << "Export notifd to db (notifd2db) and hit \"return\" key when done" << endl; -#endif - cout << "Process will wait for callback with error during 25 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - old_cb_err = cb.cb_err; - old_cb_err_ch = cb_change.cb_err; - - wait_and_dot(25); - - new_cb_err = cb.cb_err; - new_cb_err_ch = cb_change.cb_err; - - assert ((new_cb_err - old_cb_err) >= 2); - assert ((new_cb_err_ch - old_cb_err_ch) >= 2); - - cout << "\n CallBacks executed with error --> OK" << endl; - -// -// Now, restart device server -// - - int old_cb_no_err = cb_change.cb_no_err; - cout << "Restart device server and hit \"return\" key when done" << endl; - cout << "Process will wait for callback during 25 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - old_cb_err = cb.cb_executed; - old_cb_err_ch = cb_change.cb_executed; - - wait_and_dot(25); - - new_cb_err = cb.cb_executed; - new_cb_err_ch = cb_change.cb_executed; - int new_cb_no_err = cb_change.cb_no_err; - - assert ((new_cb_err - old_cb_err) > 4); - assert ((new_cb_no_err - old_cb_no_err) >= 1); - - cout << "\n CallBacks executed after reconnection to notifd --> OK" << endl; - -// -// unsubscribe to the event -// - - device->unsubscribe_event(eve_id); - device->unsubscribe_event(eve_id_change); - - cout << " unsubscribe_event --> OK" << endl; -// -// Stop polling -// - device->stop_poll_attribute(att_name); - device->stop_poll_attribute(att_name_change); - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - exit(-1); - } - catch (CORBA::Exception &ex) - { - Except::print_exception(ex); - exit(-1); - } - - delete device; - - return 0; -} - - -void wait_and_dot(int max) -{ - int loop = 0; - for (loop = 0;loop < max;loop++) - { -#ifndef WIN32 - int rest = sleep(1); - if (rest != 0) - sleep(1); -#else - Sleep(1000); -#endif - cout << "."; - cout.flush(); - } -} diff --git a/test/cpp_test_suite/event/reco_svc.cpp b/test/cpp_test_suite/event/reco_svc.cpp deleted file mode 100644 index cc7188cc6..000000000 --- a/test/cpp_test_suite/event/reco_svc.cpp +++ /dev/null @@ -1,446 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#ifdef WIN32 -#include -#include -#else -#include -#include -#endif - -#define coutv if (verbose == true) cout - -using namespace Tango; - -void wait_and_dot(int); - -bool verbose = false; - -class EventCallBack : public Tango::CallBack -{ - void push_event(Tango::EventData*); - -public: - int cb_executed; - int cb_err; - int cb_no_err; - int old_sec,old_usec; - int delta_msec; -}; - -void EventCallBack::push_event(Tango::EventData* event_data) -{ - struct timeval now_timeval; -#ifdef WIN32 - struct _timeb before_win; - _ftime(&before_win); - now_timeval.tv_sec = (unsigned long)before_win.time; - now_timeval.tv_usec = (long)before_win.millitm * 1000; -#else - gettimeofday(&now_timeval,NULL); -#endif - - coutv << "date : tv_sec = " << now_timeval.tv_sec; - coutv << ", tv_usec = " << now_timeval.tv_usec << endl; - - int delta_s = now_timeval.tv_sec - old_sec; - if (delta_s == 0) - delta_msec = (now_timeval.tv_usec - old_usec) / 1000; - else - { - delta_msec = (now_timeval.tv_usec + (1000000 - old_usec)) / 1000; - if (delta_s > 1) - delta_msec = delta_msec + ((delta_s - 1)* 1000); - } - old_sec = now_timeval.tv_sec; - old_usec = now_timeval.tv_usec; - - coutv << "delta_msec = " << delta_msec << endl; - - cb_executed++; - try - { - coutv << "StateEventCallBack::push_event(): called attribute " << event_data->attr_name << " event " << event_data->event << "\n"; - if (!event_data->err) - { - coutv << "CallBack without error " << endl; - cb_no_err++; - } - else - { - coutv << "Error send to callback" << endl; - cb_err++; - } - } - catch (...) - { - coutv << "EventCallBack::push_event(): could not extract data !\n"; - } - -} - -int main(int argc, char **argv) -{ - DeviceProxy *device; - - if (argc == 1) - { - cout << "usage: %s device [-v]" << endl; - exit(-1); - } - - string device_name = argv[1]; - - if (argc == 3) - { - if (strcmp(argv[2],"-v") == 0) - verbose = true; - } - - try - { - device = new DeviceProxy(device_name); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(1); - } - - coutv << endl << "new DeviceProxy(" << device->name() << ") returned" << endl << endl; - - try - { - - string att_name("short_attr"); - string att_name_change("event_change_tst"); - -// -// Test set up (stop polling and clear event_period attribute property but -// restart device to take this into account) -// - - if (device->is_attribute_polled(att_name)) - device->stop_poll_attribute(att_name); - if (device->is_attribute_polled(att_name_change)) - device->stop_poll_attribute(att_name_change); - - DbAttribute dba(att_name,device_name); - DbData dbd; - DbDatum a(att_name); - a << (short)1; - dbd.push_back(a); - dbd.push_back(DbDatum("event_period")); - dba.delete_property(dbd); - - DeviceProxy adm_dev(device->adm_name().c_str()); - DeviceData di; - di << device_name; - adm_dev.command_inout("DevRestart",di); - - delete device; - device = new DeviceProxy(device_name); - Tango_sleep(1); - -// -// subscribe to a periodic and to a change event -// - - int eve_id1,eve_id2; - int eve_id_change1,eve_id_change2; - vector filters; - - EventCallBack cb1; - cb1.cb_executed = 0; - cb1.cb_err = 0; - cb1.cb_no_err = 0; - cb1.old_sec = cb1.old_usec = 0; - - EventCallBack cb2; - cb2.cb_executed = 0; - cb2.cb_err = 0; - cb2.cb_no_err = 0; - cb2.old_sec = cb2.old_usec = 0; - - EventCallBack cb_change1; - cb_change1.cb_executed = 0; - cb_change1.cb_err = 0; - cb_change1.cb_no_err = 0; - cb_change1.old_sec = cb_change1.old_usec = 0; - - EventCallBack cb_change2; - cb_change2.cb_executed = 0; - cb_change2.cb_err = 0; - cb_change2.cb_no_err = 0; - cb_change2.old_sec = cb_change2.old_usec = 0; - - // start the polling first! - device->poll_attribute(att_name,1000); - device->poll_attribute(att_name_change,1000); - - eve_id1 = device->subscribe_event(att_name,Tango::PERIODIC_EVENT,&cb1,filters); - eve_id2 = device->subscribe_event(att_name,Tango::PERIODIC_EVENT,&cb2,filters); - eve_id_change1 = device->subscribe_event(att_name_change,Tango::CHANGE_EVENT,&cb_change1,filters); - eve_id_change2 = device->subscribe_event(att_name_change,Tango::CHANGE_EVENT,&cb_change2,filters); - - cout << " subscribe_event --> OK" << endl; - -// -// Check that callback was called -// - -// A trick for gdb. The thread created by omniORB for the callback execution -// is just started during the sleep. Gdb has a breakpoint reached at each thread -// creation to display message on the console. This breakpoint is a software -// signal which interrupts the sleep..... -// - -#ifndef WIN32 - int rest = sleep(3); - if (rest != 0) - sleep(3); -#else - Sleep(3000); -#endif - - coutv << "cb excuted = " << cb1.cb_executed << endl; - assert (cb1.cb_executed >= 2); - assert (cb1.cb_executed < 5); - assert (cb1.delta_msec > 950); - assert (cb1.delta_msec < 1050); - - assert (cb2.cb_executed >= 2); - assert (cb2.cb_executed < 5); - assert (cb2.delta_msec > 950); - assert (cb2.delta_msec < 1050); - - cout << " CallBack executed every 1000 mS for periodic event--> OK" << endl; - - assert (cb_change1.cb_executed != 0); - assert (cb_change2.cb_executed != 0); - -cout << " CallBack executed once for change event--> OK" << endl; - -// -// Now, kill the server -// - - string key; - cout << "Kill device server and hit \"return\" key when done" << endl; - cout << "Process will wait for callback with error during 25 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - wait_and_dot(25); - - assert (cb1.cb_err != 0); - assert (cb_change1.cb_err != 0); - - assert (cb2.cb_err != 0); - assert (cb_change2.cb_err != 0); - - cout << "\n CallBacks executed with error --> OK" << endl; - -// -// Now, Restart DS -// - - int old_cb_no_err1,old_cb_no_err2; - int new_cb_no_err1,new_cb_no_err2; - - old_cb_no_err1 = cb_change1.cb_no_err; - old_cb_no_err2 = cb_change2.cb_no_err; - cout << "Restart DS and hit \"return\" key when done" << endl; - cout << "Process will wait for callback without error during 25 sec"; - getline(cin,key); - - int old_cb_err1,old_cb_err_ch1; - int new_cb_err1,new_cb_err_ch1; - int old_cb_err2,old_cb_err_ch2; - int new_cb_err2,new_cb_err_ch2; - - old_cb_err1 = cb1.cb_executed; - old_cb_err_ch1 = cb_change1.cb_executed; - - old_cb_err2 = cb2.cb_executed; - old_cb_err_ch2 = cb_change2.cb_executed; - - wait_and_dot(25); - - new_cb_err1 = cb1.cb_executed; - new_cb_err_ch1 = cb_change1.cb_executed; - new_cb_no_err1 = cb_change1.cb_no_err; - - new_cb_err2 = cb2.cb_executed; - new_cb_err_ch2 = cb_change2.cb_executed; - new_cb_no_err2 = cb_change2.cb_no_err; - - assert ((new_cb_err1 - old_cb_err1) > 4); - assert ((new_cb_no_err1 - old_cb_no_err1) >= 1); - - assert ((new_cb_err2 - old_cb_err2) > 4); - assert ((new_cb_no_err2 - old_cb_no_err2) >= 1); - - cout << "\n CallBacks executed after reconnection to notifd --> OK" << endl; - -// -// Now, kill the notifd -// - - cout << "Kill notifd process and hit \"return\" key when done" << endl; - cout << "Process will wait for callback with error during 30 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - wait_and_dot(30); - - assert (cb1.cb_err != 0); - assert (cb_change1.cb_err != 0); - - assert (cb2.cb_err != 0); - assert (cb_change2.cb_err != 0); - - cout << "\n CallBacks executed with error --> OK" << endl; - -// -// Now, Restart notifd -// - -#ifdef WIN32 - cout << "Restart notifd (notifd -n -DFactoryIORFileName=C:\\Temp\\evfact.ior)" << endl; - cout << "and hit \"return\" key when done" << endl; -#else - cout << "Restart notifd (notifd -n) and hit \"return\" key when done" << endl; -#endif - cout << "Process will wait for callback with error during 25 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - old_cb_err1 = cb1.cb_err; - old_cb_err_ch1 = cb_change1.cb_err; - - old_cb_err2 = cb2.cb_err; - old_cb_err_ch2 = cb_change2.cb_err; - - wait_and_dot(25); - - new_cb_err1 = cb1.cb_err; - new_cb_err_ch1 = cb_change1.cb_err; - - new_cb_err2 = cb2.cb_err; - new_cb_err_ch2 = cb_change2.cb_err; - - assert ((new_cb_err1 - old_cb_err1) >= 2); - assert ((new_cb_err_ch1 - old_cb_err_ch1) >= 2); - - assert ((new_cb_err2 - old_cb_err2) >= 2); - assert ((new_cb_err_ch2 - old_cb_err_ch2) >= 2); - - cout << "\n CallBacks executed with error --> OK" << endl; - -// -// Now, export notifd to db -// - - old_cb_no_err1 = cb_change1.cb_no_err; - old_cb_no_err2 = cb_change2.cb_no_err; -#ifdef WIN32 - cout << "Export notifd to db (notifd2db C:\\Temp\\evfact.ior) and hit \"return\" key when done" << endl; -#else - cout << "Export notifd to db (notifd2db) and hit \"return\" key when done" << endl; -#endif - cout << "Process will wait for callback during 20 sec"; - getline(cin,key); - -// -// Checking for error in callback -// - - old_cb_err1 = cb1.cb_executed; - old_cb_err_ch1 = cb_change1.cb_executed; - - old_cb_err2 = cb2.cb_executed; - old_cb_err_ch2 = cb_change2.cb_executed; - - wait_and_dot(20); - - new_cb_err1 = cb1.cb_executed; - new_cb_err_ch1 = cb_change1.cb_executed; - new_cb_no_err1 = cb_change1.cb_no_err; - - new_cb_err2 = cb2.cb_executed; - new_cb_err_ch2 = cb_change2.cb_executed; - new_cb_no_err2 = cb_change2.cb_no_err; - - assert ((new_cb_err1 - old_cb_err1) > 4); - assert ((new_cb_no_err1 - old_cb_no_err1) >= 1); - - assert ((new_cb_err2 - old_cb_err2) > 4); - assert ((new_cb_no_err2 - old_cb_no_err2) >= 1); - - cout << "\n CallBacks executed after reconnection to notifd --> OK" << endl; - -// -// unsubscribe to the event -// - - device->unsubscribe_event(eve_id1); - device->unsubscribe_event(eve_id2); - device->unsubscribe_event(eve_id_change1); - device->unsubscribe_event(eve_id_change2); - - cout << " unsubscribe_event --> OK" << endl; -// -// Stop polling -// - device->stop_poll_attribute(att_name); - device->stop_poll_attribute(att_name_change); - - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - exit(-1); - } - catch (CORBA::Exception &ex) - { - Except::print_exception(ex); - exit(-1); - } - - delete device; - - return 0; -} - - -void wait_and_dot(int max) -{ - int loop = 0; - for (loop = 0;loop < max;loop++) - { -#ifndef WIN32 - int rest = sleep(1); - if (rest != 0) - sleep(1); -#else - Sleep(1000); -#endif - cout << "."; - cout.flush(); - } -} diff --git a/test/cpp_test_suite/event/reco_zmq.cpp b/test/cpp_test_suite/event/reco_zmq.cpp deleted file mode 100644 index c3c039cf9..000000000 --- a/test/cpp_test_suite/event/reco_zmq.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#ifndef WIN32 -#include -#endif - -#define coutv if (verbose == true) cout - -using namespace Tango; - -bool verbose = false; - -class EventCallback : public Tango::CallBack -{ -public: - EventCallback() { }; - ~EventCallback() { }; - void push_event( Tango::EventData *ed ); - - int cb_executed; - int cb_err; -}; - -void EventCallback::push_event( Tango::EventData *ed ) -{ - coutv << "In callback with error flag = " << std::boolalpha << ed->err << endl; - //TODO is it thread safe? - if(ed->err == false) - cb_executed++; - else { - cb_err++; - coutv << "Error: " << ed->errors[0].reason << endl; - } -} - -int main(int argc, char **argv) -{ - DeviceProxy *device; - - if (argc == 1) - { - cout << "usage: %s device [-v]" << endl; - exit(-1); - } - - string device_name = argv[1]; - - if (argc == 3) - { - if (strcmp(argv[2],"-v") == 0) - verbose = true; - } - - try - { - device = new DeviceProxy(device_name); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(1); - } - - string att_name ("event_change_tst"); - - try - { - -// -// Subscribe to a user event -// - - const vector filters; - EventCallback *eventCallback = new EventCallback(); - eventCallback->cb_executed = 0; - eventCallback->cb_err = 0; - - device->subscribe_event(att_name,Tango::USER_EVENT,eventCallback,filters); - -// -// Fire one event -// - - device->command_inout("IOPushEvent"); - device->command_inout("IOPushEvent"); - - Tango_sleep(1); - - coutv << "Callback execution before re-connection = " << eventCallback->cb_executed << endl; - coutv << "Callback error before re-connection = " << eventCallback->cb_err << endl; - - assert (eventCallback->cb_executed == 3); - assert (eventCallback->cb_err == 0); - -// -// Kill device server (using its admin device) -// - - string adm_name = device->adm_name(); - DeviceProxy admin_dev(adm_name); - admin_dev.command_inout("kill"); - -// -// Wait for some error and re-connection -// - - Tango_sleep(40); - -// -// Check error and re-connection -// - - coutv << "Callback execution after re-connection = " << eventCallback->cb_executed << endl; - coutv << "Callback error after re-connection = " << eventCallback->cb_err << endl; - - assert (eventCallback->cb_err >= 1); - assert (eventCallback->cb_executed == 4); - -// -// Fire another event -// - - device->command_inout("IOPushEvent"); - device->command_inout("IOPushEvent"); - - Tango_sleep(1); - - coutv << "Callback execution after re-connection and event = " << eventCallback->cb_executed << endl; - coutv << "Callback error after re-connection and event = " << eventCallback->cb_err << endl; - - assert (eventCallback->cb_executed == 6); - assert (eventCallback->cb_err >= 1); - - cout << " Event re-connection (differents ports) --> OK" << endl; - -// -// Clear call back counters and kill device server once more -// - - eventCallback->cb_executed = 0; - eventCallback->cb_err = 0; - - admin_dev.command_inout("kill"); - -// -// Wait for some error and re-connection -// - - Tango_sleep(40); - -// -// Check error and re-connection -// - - coutv << "Callback execution after second re-connection = " << eventCallback->cb_executed << endl; - coutv << "Callback error after second re-connection = " << eventCallback->cb_err << endl; - - assert (eventCallback->cb_err >= 1); - assert (eventCallback->cb_executed == 1); - -// -// Fire yet another event -// - - device->command_inout("IOPushEvent"); - - Tango_sleep(2); - - coutv << "Callback execution after second re-connection and event = " << eventCallback->cb_executed << endl; - coutv << "Callback error after second re-connection and event = " << eventCallback->cb_err << endl; - - assert (eventCallback->cb_executed == 2); - assert (eventCallback->cb_err >= 1); - - cout << " Event re-connection (same ports) --> OK" << endl; - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - exit(-1); - } - delete device; - - return 0; -} diff --git a/test/cpp_test_suite/event/server_event.cpp b/test/cpp_test_suite/event/server_event.cpp deleted file mode 100644 index 4b4ae8944..000000000 --- a/test/cpp_test_suite/event/server_event.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#ifndef WIN32 -#include -#endif - -#define coutv if (verbose == true) cout - -using namespace Tango; - -bool verbose = false; - -int main(int argc, char **argv) -{ - DeviceProxy *device; - - if (argc < 3 || argc > 4) - { - cout << "usage: %s local_device remote_device [-v]" << endl; - exit(-1); - } - - string device_name = argv[1]; - - if (argc == 4) - { - if (strcmp(argv[3],"-v") == 0) - verbose = true; - } - - try - { - device = new DeviceProxy(device_name); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(1); - } - - coutv << endl << "new DeviceProxy(" << device->name() << ") returned" << endl << endl; - - try - { - -// -// Ask the device server to subscribe to an event -// - - vector vs; - vs.push_back(argv[2]); - vs.push_back("Short_attr"); - vs.push_back("periodic"); - - DeviceData dd_in,dd_out; - dd_in << vs; - dd_out = device->command_inout("IOSubscribeEvent",dd_in); - DevLong eve_id; - dd_out >> eve_id; - - cout << " Server subscribe to event --> OK" << endl; - -// -// Wait for event to be executed -// - - Tango_sleep(3); - - DeviceData da; - da = device->command_inout("IOGetCbExecuted"); - Tango::DevLong cb; - da >> cb; - - coutv << "cb executed = " << cb << endl; - assert (cb >= 2); - assert (cb <= 4); - - cout << " Callback executed --> OK" << endl; - -// -// Ask server to unsubsribe from event -// - - DeviceData dd_un; - dd_un << eve_id; - - device->command_inout("IOUnSubscribeEvent",dd_un); - da = device->command_inout("IOGetCbExecuted"); - da >> cb; - - Tango_sleep(2); - da = device->command_inout("IOGetCbExecuted"); - Tango::DevLong cb2; - da >> cb2; - - assert (cb2 == cb); - cout << " Server unsubscribe to event --> OK" << endl; - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - exit(-1); - } - catch (CORBA::Exception &ex) - { - Except::print_exception(ex); - exit(-1); - } - - delete device; - - return 0; -} diff --git a/test/cpp_test_suite/event/stateless_sub.cpp b/test/cpp_test_suite/event/stateless_sub.cpp deleted file mode 100644 index 044fcbc5c..000000000 --- a/test/cpp_test_suite/event/stateless_sub.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#ifndef WIN32 -#include -#endif - -#define coutv if (verbose == true) cout - -using namespace Tango; - -bool verbose = false; - -class EventCallback : public Tango::CallBack -{ -public: - EventCallback() { }; - ~EventCallback() { }; - void push_event( Tango::EventData *ed ); - - int cb_executed; - int cb_err; -}; - -void EventCallback::push_event( Tango::EventData *ed ) -{ - coutv << "In callback with error flag = " << std::boolalpha << ed->err << endl; - //TODO is it thread safe? - if(ed->err == false) - cb_executed++; - else { - cb_err++; - coutv << "Error: " << ed->errors[0].reason << endl; - } -} - -int main(int argc, char **argv) -{ - DeviceProxy *device; - - if (argc == 1) - { - cout << "usage: %s device [-v]" << endl; - exit(-1); - } - - string device_name = argv[1]; - - if (argc == 3) - { - if (strcmp(argv[2],"-v") == 0) - verbose = true; - } - - try - { - device = new DeviceProxy(device_name); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(1); - } - - string att_name ("event_change_tst"); - - try - { - -// -// Subscribe to event with stateless flag set -// - - int eventID = 0; - const vector< string > filters; - EventCallback *eventCallback = new EventCallback(); - eventCallback->cb_executed = 0; - eventCallback->cb_err = 0; - - eventID = device->subscribe_event(att_name,Tango::CHANGE_EVENT,eventCallback,filters,true); - - Tango_sleep(6); - - device->unsubscribe_event(eventID); - - cout << " Unsubscription while event still not connected --> OK" << endl; - -// -// Re-subscribe -// - - eventID = device->subscribe_event(att_name,Tango::CHANGE_EVENT,eventCallback,true); - -// -// Wait for connection and event -// - - Tango_sleep(40); - -// -// Check error and connection -// - - coutv << "cb err = " << eventCallback->cb_err << endl; - coutv << "cb executed = " << eventCallback->cb_executed << endl; - - assert (eventCallback->cb_err >= 1); - assert (eventCallback->cb_executed >= 1); - - cout << " Stateless connection to event --> OK" << endl; - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - exit(-1); - } - delete device; - - return 0; -} diff --git a/test/cpp_test_suite/event/test_reconnection.sh.cmake b/test/cpp_test_suite/event/test_reconnection.sh.cmake deleted file mode 100644 index a5147e278..000000000 --- a/test/cpp_test_suite/event/test_reconnection.sh.cmake +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env bash -check_return_value () { - if [ $1 != "0" ] - then - echo "Event Test Suite has FAILED !!!!!!!!!!!!!!!!!!" - echo "Leaving test suite, try to fix it" - date - exit -1 - fi -} - -start_server(){ - echo "Starting DevTest $1" - @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest $1 -v5 1>@PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.out 2>&1 & - echo $! > @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.pid - echo "Done. PID="`cat @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_$1.pid` -} - -kill_servers(){ - PIDS=`ps -e | grep DevTest | grep -v grep | awk '{print $1}'` - echo "PIDS = $PIDS" - for pid in $PIDS - do - echo "Killing process with PID $pid" - kill $pid - done - - sleep 2 -} - - -start_server "@INST_NAME@2" -sleep 20 - -echo "Testing server_event" -./server_event @DEV1@ @DEV20@ -ret=$? -check_return_value $ret - -# -# kill DevTest servers (/10 and /20) -# -kill_servers - -# -# Start DevTest server -# - -start_server "@INST_NAME@" -sleep 20 -# -# Next test will restart server -# - -echo "Testing event re-connection (takes time...)" -sleep 18 && start_server "@INST_NAME@" & -sleep 62 && start_server "@INST_NAME@" & -./reco_zmq @DEV1@ -v -ret=$? -check_return_value $ret - -# -# kill servers -# -kill_servers - -echo "Testing stateless event connection (takes time...)" -sleep 24 && start_server "@INST_NAME@2" & -./stateless_sub @DEV20@ -v -ret=$? -check_return_value $ret - -#kill extra server -kill_servers - -#restart DEV1 -start_server "@INST_NAME@" - -sleep 20 - -echo "PID=$(<@PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_@INST_NAME@.pid)" \ No newline at end of file