diff --git a/cpp_test_suite/cxxtest/CMakeLists.txt b/cpp_test_suite/cxxtest/CMakeLists.txt index 76bf52f49..64dc27358 100644 --- a/cpp_test_suite/cxxtest/CMakeLists.txt +++ b/cpp_test_suite/cxxtest/CMakeLists.txt @@ -1,67 +1,97 @@ -message("Generate runner.cpp") +find_package (Threads REQUIRED) -execute_process(COMMAND python cxxtestgen.py --template=${CMAKE_CURRENT_SOURCE_DIR}/template/tango_template.tpl - -o ${CMAKE_CURRENT_SOURCE_DIR}/runner.cpp - ../../new_tests/cxx_syntax.cpp - ../../new_tests/cxx_poll.cpp - ../../new_tests/cxx_poll_admin.cpp - ../../new_tests/cxx_dserver_cmd.cpp - ../../new_tests/cxx_dserver_misc.cpp - ../../new_tests/cxx_always_hook.cpp - ../../new_tests/cxx_blackbox.cpp - ../../new_tests/cxx_class_dev_signal.cpp - ../../new_tests/cxx_class_signal.cpp - ../../new_tests/cxx_attr_misc.cpp - ../../new_tests/cxx_attrprop.cpp - ../../new_tests/cxx_attr_write.cpp - ../../new_tests/cxx_attr_conf.cpp - ../../new_tests/cxx_attr.cpp - ../../new_tests/cxx_misc_util.cpp - ../../new_tests/cxx_templ_cmd.cpp - ../../new_tests/cxx_exception.cpp - ../../new_tests/cxx_cmd_query.cpp - ../../new_tests/cxx_seq_vec.cpp - ../../new_tests/cxx_signal.cpp - ../../new_tests/cxx_test_state_on.cpp - ../../new_tests/cxx_misc.cpp - ../../new_tests/cxx_cmd_types.cpp - ../../new_tests/cxx_group.cpp - ../../new_tests/cxx_encoded.cpp - ../../new_tests/cxx_database.cpp - ../../new_tests/cxx_mem_attr.cpp - ../../new_tests/cxx_enum_att.cpp - ../../new_tests/cxx_write_attr_hard.cpp - ../../new_tests/cxx_fwd_att.cpp - ../../new_tests/cxx_pipe_conf.cpp - ../../new_tests/cxx_pipe.cpp - ../../new_tests/cxx_z00_dyn_cmd.cpp - ../../new_tests/cxx_nan_inf_in_prop.cpp +macro(CXX_GENERATE_TEST name) + message("Generate ${name}.cpp") + execute_process(COMMAND python cxxtestgen.py --template=${CMAKE_CURRENT_SOURCE_DIR}/template/tango_template.tpl + -o ${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp + ../../new_tests/${name}.cpp + ../../new_tests/cxx_nan_inf_in_prop.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) -add_executable(runner $ ${CMAKE_CURRENT_SOURCE_DIR}/runner.cpp) -target_include_directories(runner PUBLIC include) -target_link_libraries(runner PUBLIC tango ${CMAKE_DL_LIBS}) -target_compile_definitions(runner PUBLIC "-DVALGRIND -D_PTHREADS -D_REENTRANT") + if(${FAILED}) + message(SEND_ERROR " Failed to generate ${name}.cpp. rv=${FAILED}") + endif() -add_test("CXX::runner" runner - --device1=${DEV1} - --device2=${DEV2} - --device3=${DEV3} - --fwd_device=${FWD_DEV} - --loop=1 - --fulldsname=${SERV_NAME}/${INST_NAME} - --serverhost=${HOST_NAME} - --clienthost=${HOST_NAME} - --serverversion=5 - --docurl=http://www.tango-controls.org - --devtype=TestDevice - --dbserver=sys/database/2 - --outpath=/tmp/ - --refpath=${CMAKE_CURRENT_SOURCE_DIR}/../new_tests/out/ - --loglevel=0 - --dsloglevel=5 - --suiteloop=1 - --devicealias=${DEV1_ALIAS} - --attributealias=${ATTR_ALIAS} - --verbose=true -) + add_executable(${name} $ ${name}.cpp) + target_include_directories(${name} PRIVATE include ${CMAKE_CURRENT_BINARY_DIR}/include) + 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 $ + --device1=${DEV1} + --device2=${DEV2} + --device3=${DEV3} + --device20=${DEV20} + --fwd_device=${FWD_DEV} + --loop=1 + --fulldsname=${SERV_NAME}/${INST_NAME} + --serverhost=${HOST_NAME} + --clienthost=${HOST_NAME} + --serverversion=5 + --docurl=http://www.tango-controls.org + --devtype=TestDevice + --dbserver=sys/database/2 + --outpath=/tmp/ + --refpath=${CMAKE_CURRENT_SOURCE_DIR}/../new_tests/out/ + --loglevel=0 + --dsloglevel=5 + --suiteloop=1 + --devicealias=${DEV1_ALIAS} + --attributealias=${ATTR_ALIAS} + --verbose=true) +endmacro() + +CXX_GENERATE_TEST(cxx_syntax) +CXX_GENERATE_TEST(cxx_poll) +CXX_GENERATE_TEST(cxx_poll_admin) +CXX_GENERATE_TEST(cxx_dserver_cmd) +CXX_GENERATE_TEST(cxx_dserver_misc) +CXX_GENERATE_TEST(cxx_always_hook) +CXX_GENERATE_TEST(cxx_blackbox) +CXX_GENERATE_TEST(cxx_class_dev_signal) +CXX_GENERATE_TEST(cxx_class_signal) +CXX_GENERATE_TEST(cxx_attr_misc) +CXX_GENERATE_TEST(cxx_attrprop) +CXX_GENERATE_TEST(cxx_attr_write) +CXX_GENERATE_TEST(cxx_attr_conf) +CXX_GENERATE_TEST(cxx_attr) +CXX_GENERATE_TEST(cxx_misc_util) +CXX_GENERATE_TEST(cxx_templ_cmd) +CXX_GENERATE_TEST(cxx_exception) +CXX_GENERATE_TEST(cxx_cmd_query) +CXX_GENERATE_TEST(cxx_seq_vec) +CXX_GENERATE_TEST(cxx_signal)#TODO Windows +CXX_GENERATE_TEST(cxx_test_state_on) +CXX_GENERATE_TEST(cxx_misc) +CXX_GENERATE_TEST(cxx_cmd_types) +CXX_GENERATE_TEST(cxx_group) +CXX_GENERATE_TEST(cxx_encoded) +CXX_GENERATE_TEST(cxx_database) +CXX_GENERATE_TEST(cxx_mem_attr) +CXX_GENERATE_TEST(cxx_enum_att) +CXX_GENERATE_TEST(cxx_write_attr_hard) +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) +CXX_GENERATE_TEST(cxx_server_event) +CXX_GENERATE_TEST(cxx_reconnection_zmq) +CXX_GENERATE_TEST(cxx_stateless_subscription) + + +#utilities +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) diff --git a/cpp_test_suite/cxxtest/bin/kill_server.sh.cmake b/cpp_test_suite/cxxtest/bin/kill_server.sh.cmake new file mode 100644 index 000000000..84ab8a367 --- /dev/null +++ b/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/cpp_test_suite/cxxtest/bin/start_server.sh.cmake b/cpp_test_suite/cxxtest/bin/start_server.sh.cmake new file mode 100644 index 000000000..da026e55b --- /dev/null +++ b/cpp_test_suite/cxxtest/bin/start_server.sh.cmake @@ -0,0 +1,12 @@ +#!/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 + + sleep 7 + 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/cpp_test_suite/cxxtest/include/config.h.cmake b/cpp_test_suite/cxxtest/include/config.h.cmake new file mode 100644 index 000000000..e01262334 --- /dev/null +++ b/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/cpp_test_suite/cxxtest/include/cxxtest/TangoPrinter.h b/cpp_test_suite/cxxtest/include/cxxtest/TangoPrinter.h index 7e35f2455..f4f5c9531 100644 --- a/cpp_test_suite/cxxtest/include/cxxtest/TangoPrinter.h +++ b/cpp_test_suite/cxxtest/include/cxxtest/TangoPrinter.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include // Tango exceptions handling //#undef _TS_CATCH_ABORT @@ -761,6 +763,7 @@ class TangoPrinter: public ErrorFormatter 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)"); @@ -783,6 +786,16 @@ class TangoPrinter: public ErrorFormatter 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/cpp_test_suite/event/CMakeLists.txt b/cpp_test_suite/event/CMakeLists.txt index fbb1a34ec..073556010 100644 --- a/cpp_test_suite/event/CMakeLists.txt +++ b/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/cpp_test_suite/event/reco_event.cpp b/cpp_test_suite/event/reco_event.cpp deleted file mode 100644 index 297c7f5d5..000000000 --- a/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/cpp_test_suite/event/reco_svc.cpp b/cpp_test_suite/event/reco_svc.cpp deleted file mode 100644 index cc7188cc6..000000000 --- a/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/cpp_test_suite/event/reco_zmq.cpp b/cpp_test_suite/event/reco_zmq.cpp deleted file mode 100644 index c3c039cf9..000000000 --- a/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/cpp_test_suite/event/server_event.cpp b/cpp_test_suite/event/server_event.cpp deleted file mode 100644 index 4b4ae8944..000000000 --- a/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/cpp_test_suite/event/stateless_sub.cpp b/cpp_test_suite/event/stateless_sub.cpp deleted file mode 100644 index 044fcbc5c..000000000 --- a/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/cpp_test_suite/event/test_reconnection.sh.cmake b/cpp_test_suite/event/test_reconnection.sh.cmake deleted file mode 100644 index a5147e278..000000000 --- a/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 diff --git a/cpp_test_suite/new_tests/cxx_old_poll.cpp b/cpp_test_suite/new_tests/cxx_old_poll.cpp new file mode 100644 index 000000000..c8961b181 --- /dev/null +++ b/cpp_test_suite/new_tests/cxx_old_poll.cpp @@ -0,0 +1,1346 @@ +#ifndef PollTestSuite_h +#define PollTestSuite_h + +#include +#include +#include +#include +#include +#include + +using namespace Tango; +using namespace std; + +#define cout cout << "\t" +#define BASIC_NB_POLL 16 +#define TEST_CLASS "devTest" + +#undef SUITE_NAME +#define SUITE_NAME OldPollTestSuite__loop + +typedef enum { + FIRST_EXCEPT = 0, + SECOND_EXCEPT, + FIRST_DATA, + SECOND_DATA +} AttrResult; + +typedef enum { + EXCEPT = 0, + FIRST_STR, + SECOND_STR +} CmdResult; + +void split_string(string &, char, vector &); + +void stop_poll_att_no_except(DeviceProxy *, const char *); + +void stop_poll_cmd_no_except(DeviceProxy *, const char *); + +void del_device_no_error(Database &, string&); + +class OldPollTestSuite__loop : public CxxTest::TestSuite { +protected: + DeviceProxy *device; + string device_name, device2_name, alias_name, serv_name, admin_dev_name, inst_name; + string new_dev, new_dev1_th2, new_dev2_th2, new_dev1_th3; + vector ref_polling_pool_conf; + + bool verbose; + int hist_depth; + +public: + SUITE_NAME() : hist_depth{10}, admin_dev_name{"dserver/"}, + inst_name{"debian8"},//TODO pass from cmd + new_dev{"test/debian8/77"}, + new_dev1_th2{"test/debian8/800"}, + new_dev2_th2{"test/debian8/801"}, + new_dev1_th3{"test/debian8/9000"}, + ref_polling_pool_conf{1, "test/debian8/10,test/debian8/11"} { + +// +// Arguments check ------------------------------------------------- +// + + device_name = CxxTest::TangoPrinter::get_param("device1"); + device2_name = CxxTest::TangoPrinter::get_param("device2"); + alias_name = CxxTest::TangoPrinter::get_param("devicealias"); + serv_name = CxxTest::TangoPrinter::get_param("fulldsname"); + + admin_dev_name += serv_name; + + verbose = CxxTest::TangoPrinter::is_param_set("verbose"); + + CxxTest::TangoPrinter::validate_args(); + + +// +// Initialization -------------------------------------------------- +// + + try { + device = new DeviceProxy(device_name); + device->ping(); + } + catch (const CORBA::Exception &e) { + Except::print_exception(e); + exit(-1); + } + + try { + device->poll_command("IOPollStr1", 500); + device->poll_command("IOPollArray2", 500); + device->poll_command("IOExcept", 2000); + device->poll_command("OEncoded", 500); + device->poll_command("State", 2000); + device->poll_command("Status", 2000); + + device->poll_attribute("PollLong_attr", 1000); + device->poll_attribute("PollString_spec_attr", 500); + device->poll_attribute("attr_wrong_type", 500); + + device->poll_attribute("Long64_attr_rw", 500); + device->poll_attribute("ULong_spec_attr_rw", 500); + device->poll_attribute("ULong64_attr_rw", 500); + device->poll_attribute("State_spec_attr_rw", 500); + device->poll_attribute("Encoded_attr", 500); + } + catch (const CORBA::Exception &e) { + Except::print_exception(e); + exit(-1); + } + + cout << "Wait for 7 seconds to fill in polling buffer..." << endl; + this_thread::sleep_for(chrono::seconds{7}); + cout << "Done." << endl; + } + + virtual ~SUITE_NAME() { + +// +// Clean up -------------------------------------------------------- +// +// cout << "Device name = " << device_name << endl; +// cout << "Kill device name = " << kill_device_name << endl; + + + if (CxxTest::TangoPrinter::is_restore_set("dev1_source_cache")) + device->set_source(Tango::CACHE_DEV); + + if (CxxTest::TangoPrinter::is_restore_set("dev2_poll_PollLong_attr_1000")) + stop_poll_att_no_except(new DeviceProxy(device2_name), "PollLong_attr"); + +// cout << endl << "new DeviceProxy(" << device->name() << ") returned" << endl << endl; + stop_poll_cmd_no_except(device, "IOPollStr1"); + stop_poll_cmd_no_except(device, "IOArray1"); + stop_poll_cmd_no_except(device, "IOPollArray2"); + stop_poll_cmd_no_except(device, "IOExcept"); + stop_poll_cmd_no_except(device, "OEncoded"); + stop_poll_cmd_no_except(device, "State"); + stop_poll_cmd_no_except(device, "Status"); + + stop_poll_att_no_except(device, "PollLong_attr"); + stop_poll_att_no_except(device, "PollString_spec_attr"); + stop_poll_att_no_except(device, "attr_wrong_type"); + + stop_poll_att_no_except(device, "Long64_attr_rw"); + stop_poll_att_no_except(device, "ULong_spec_attr_rw"); + stop_poll_att_no_except(device, "ULong64_attr_rw"); + stop_poll_att_no_except(device, "State_spec_attr_rw"); + stop_poll_att_no_except(device, "Encoded_attr"); + + stop_poll_att_no_except(device, "event_change_tst"); + stop_poll_att_no_except(device, "event64_change_tst"); + stop_poll_att_no_except(device, "short_attr"); + stop_poll_att_no_except(device, "slow_actuator"); + stop_poll_att_no_except(device, "fast_actuator"); + + if (CxxTest::TangoPrinter::is_restore_set("reset_device_server")) + reset_device_server(); + + delete device; + } + + static SUITE_NAME *createSuite() { + return new SUITE_NAME(); + } + + static void destroySuite(SUITE_NAME *suite) { + delete suite; + } + +// +// Tests ------------------------------------------------------- +// + + void test_read_command_history_string(void) { + auto d_hist = device->command_history("IOPollStr1", hist_depth); + + TSM_ASSERT_LESS_THAN("Not enough data in the polling buffer, restart later", 4, d_hist->size()); + + CmdResult cr; + + if ((*d_hist)[0].has_failed() == true) { + cr = EXCEPT; + } else { + string str; + (*d_hist)[0] >> str; + if (str[0] == 'E') + cr = FIRST_STR; + else + cr = SECOND_STR; + } + + for (size_t i = 0; i < d_hist->size(); i++) { + string str; + if ((*d_hist)[i].has_failed() == false) + (*d_hist)[i] >> str; + + if (verbose) { + cout << "Command failed = " << (*d_hist)[i].has_failed() << endl; + if ((*d_hist)[i].has_failed() == false) { + (*d_hist)[i] >> str; + cout << "Value = " << str << endl; + } + TimeVal &t = (*d_hist)[i].get_date(); + cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; + cout << "Error stack depth = " << (*d_hist)[i].get_err_stack().length() << endl; + cout << endl; + } + } + + DevErrorList del; + string simple_str; + + switch (cr) { + case EXCEPT: + TS_ASSERT((*d_hist)[0].has_failed() == true); + TS_ASSERT((*d_hist)[0].get_err_stack().length() == 1); + del = (*d_hist)[0].get_err_stack(); + TS_ASSERT(::strcmp(del[0].desc.in(), "www") == 0); + + (*d_hist)[1] >> simple_str; + TS_ASSERT((*d_hist)[1].has_failed() == false); + TS_ASSERT((*d_hist)[1].get_err_stack().length() == 0); + TS_ASSERT(simple_str == "Even value from IOPollStr1"); + + (*d_hist)[2] >> simple_str; + TS_ASSERT((*d_hist)[2].has_failed() == false); + TS_ASSERT((*d_hist)[2].get_err_stack().length() == 0); + TS_ASSERT(simple_str == "Odd value from IOPollStr1"); + break; + + case FIRST_STR: + (*d_hist)[0] >> simple_str; + TS_ASSERT((*d_hist)[0].has_failed() == false); + TS_ASSERT((*d_hist)[0].get_err_stack().length() == 0); + TS_ASSERT(simple_str == "Even value from IOPollStr1"); + + (*d_hist)[1] >> simple_str; + TS_ASSERT((*d_hist)[1].has_failed() == false); + TS_ASSERT((*d_hist)[1].get_err_stack().length() == 0); + TS_ASSERT(simple_str == "Odd value from IOPollStr1"); + + TS_ASSERT((*d_hist)[2].has_failed() == true); + TS_ASSERT((*d_hist)[2].get_err_stack().length() == 1); + del = (*d_hist)[2].get_err_stack(); + TS_ASSERT(::strcmp(del[0].desc.in(), "www") == 0); + break; + + case SECOND_STR: + (*d_hist)[0] >> simple_str; + TS_ASSERT((*d_hist)[0].has_failed() == false); + TS_ASSERT((*d_hist)[0].get_err_stack().length() == 0); + TS_ASSERT(simple_str == "Odd value from IOPollStr1"); + + TS_ASSERT((*d_hist)[1].has_failed() == true); + TS_ASSERT((*d_hist)[1].get_err_stack().length() == 1); + del = (*d_hist)[1].get_err_stack(); + TS_ASSERT(::strcmp(del[0].desc.in(), "www") == 0); + + (*d_hist)[2] >> simple_str; + TS_ASSERT((*d_hist)[2].has_failed() == false); + TS_ASSERT((*d_hist)[2].get_err_stack().length() == 0); + TS_ASSERT(simple_str == "Even value from IOPollStr1"); + break; + } + + delete d_hist; + } + + void test_command_history_array(void) { + auto d_hist = device->command_history("IOPollArray2", hist_depth); + + TSM_ASSERT_LESS_THAN("Not enough data in the polling buffer, restart later", 4, d_hist->size()); + + short first_val_first_rec; + for (size_t i = 0; i < d_hist->size(); i++) { + vector vect; + (*d_hist)[i] >> vect; + + if (verbose) { + cout << "Command failed = " << (*d_hist)[i].has_failed() << endl; + cout << "Value 0 = " << vect[0] << ", Value 1 = " << vect[1] << endl; + TimeVal &t = (*d_hist)[i].get_date(); + cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; + cout << "Error stack depth = " << (*d_hist)[i].get_err_stack().length() << endl; + cout << endl; + } + + if (i == 0) + first_val_first_rec = vect[0]; + + TS_ASSERT((*d_hist)[i].has_failed() == false); + TS_ASSERT((*d_hist)[i].get_err_stack().length() == 0); + if (i != 0) { + if (first_val_first_rec == 100) { + if ((i % 2) == 0) { + TS_ASSERT(vect[0] == 100); + TS_ASSERT(vect[1] == 200); + } else { + TS_ASSERT(vect[0] == 300); + TS_ASSERT(vect[1] == 400); + } + } else { + if ((i % 2) == 0) { + TS_ASSERT(vect[0] == 300); + TS_ASSERT(vect[1] == 400); + } else { + TS_ASSERT(vect[0] == 100); + TS_ASSERT(vect[1] == 200); + } + } + } + } + delete d_hist; + } + + void test_command_history_with_exception(void) { + auto d_hist = device->command_history("IOExcept", hist_depth); + + for (size_t i = 0; i < d_hist->size(); i++) { + if (verbose) { + cout << "Command failed = " << (*d_hist)[i].has_failed() << endl; + TimeVal &t = (*d_hist)[i].get_date(); + cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; + cout << "Error stack depth = " << (*d_hist)[i].get_err_stack().length() << endl; + cout << endl; + } + + TS_ASSERT((*d_hist)[i].has_failed() == true); + TS_ASSERT((*d_hist)[i].get_err_stack().length() == 1); + TS_ASSERT(!strcmp((*d_hist)[i].get_err_stack()[0].reason, "API_ThrowException")); + } + delete d_hist; + } + + + void test_command_history_for_state(void) { + auto d_hist = device->command_history("State", hist_depth); + + for (size_t i = 0; i < d_hist->size(); i++) { + if (verbose) { + cout << (*d_hist)[i] << endl; + } + + TS_ASSERT((*d_hist)[i].has_failed() == false); + TS_ASSERT((*d_hist)[i].get_err_stack().length() == 0); + Tango::DevState ds; + (*d_hist)[i] >> ds; + TS_ASSERT(ds == Tango::ON); + } + delete d_hist; + } + + void test_command_history_for_status(void) { + auto d_hist = device->command_history("Status", hist_depth); + + for (size_t i = 0; i < d_hist->size(); i++) { + if (verbose) { + cout << (*d_hist)[i] << endl; + } + + TS_ASSERT((*d_hist)[i].has_failed() == false); + TS_ASSERT((*d_hist)[i].get_err_stack().length() == 0); + string str; + (*d_hist)[i] >> str; + TS_ASSERT(::strcmp(str.c_str(), "The device is in ON state.") == 0); + } + delete d_hist; + } + + void test_command_history_DevEncoded(void) { + auto d_hist = device->command_history("OEncoded", hist_depth); + + TSM_ASSERT_LESS_THAN("Not enough data in the polling buffer, restart later", 4, d_hist->size()); + + unsigned char first_val_enc; + for (size_t i = 0; i < d_hist->size(); i++) { + DevEncoded the_enc; + (*d_hist)[i] >> the_enc; + + if (verbose) { + cout << "Command failed = " << (*d_hist)[i].has_failed() << endl; + cout << "Encoded_format = " << the_enc.encoded_format << endl; + for (unsigned int ii = 0; ii < the_enc.encoded_data.length(); ++ii) + cout << "Encoded_data = " << (int) the_enc.encoded_data[ii] << endl; + TimeVal &t = (*d_hist)[i].get_date(); + cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; + cout << "Error stack depth = " << (*d_hist)[i].get_err_stack().length() << endl; + cout << endl; + } + + TS_ASSERT((*d_hist)[i].has_failed() == false); + TS_ASSERT((*d_hist)[i].get_err_stack().length() == 0); + + if (i == 0) + first_val_enc = the_enc.encoded_data[0]; + + if ((i % 2) == 0) { + if (first_val_enc == 11) { + TS_ASSERT(!strcmp(the_enc.encoded_format, "Odd - OEncoded format")); + TS_ASSERT(the_enc.encoded_data.length() == 2); + TS_ASSERT(the_enc.encoded_data[0] == 11); + TS_ASSERT(the_enc.encoded_data[1] == 21); + } else { + TS_ASSERT(!strcmp(the_enc.encoded_format, "Even - OEncoded format")); + TS_ASSERT(the_enc.encoded_data[0] == 10); + TS_ASSERT(the_enc.encoded_data[1] == 20); + TS_ASSERT(the_enc.encoded_data[2] == 30); + TS_ASSERT(the_enc.encoded_data[3] == 40); + } + } else { + if (first_val_enc == 11) { + TS_ASSERT(!strcmp(the_enc.encoded_format, "Even - OEncoded format")); + TS_ASSERT(the_enc.encoded_data[0] == 10); + TS_ASSERT(the_enc.encoded_data[1] == 20); + TS_ASSERT(the_enc.encoded_data[2] == 30); + TS_ASSERT(the_enc.encoded_data[3] == 40); + } else { + TS_ASSERT(!strcmp(the_enc.encoded_format, "Odd - OEncoded format")); + TS_ASSERT(the_enc.encoded_data.length() == 2); + TS_ASSERT(the_enc.encoded_data[0] == 11); + TS_ASSERT(the_enc.encoded_data[1] == 21); + } + } + } + delete d_hist; + } + + void test_attribute_history_for_long(void) { + auto a_hist = device->attribute_history("PollLong_attr", hist_depth); + + DevLong first_val; + for (size_t i = 0; i < a_hist->size(); i++) { + DevLong lo; + (*a_hist)[i] >> lo; + + if (i == 0) + first_val = lo; + + if (verbose) { + cout << "Attribute failed = " << (*a_hist)[i].has_failed() << endl; + cout << "Value = " << lo << endl; + TimeVal &t = (*a_hist)[i].get_date(); + cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; + cout << "Error stack depth = " << (*a_hist)[i].get_err_stack().length() << endl; + cout << endl; + } + + TS_ASSERT((*a_hist)[i].has_failed() == false); + TS_ASSERT((*a_hist)[i].get_err_stack().length() == 0); + + TS_ASSERT((*a_hist)[i].get_dim_x() == 1); + TS_ASSERT((*a_hist)[i].get_dim_y() == 0); + + if (first_val == 5555) { + if ((i % 2) == 0) { + TS_ASSERT(lo == 5555); + } else { + TS_ASSERT(lo == 6666); + } + } else { + if ((i % 2) == 0) { + TS_ASSERT(lo == 6666); + } else { + TS_ASSERT(lo == 5555); + } + } + } + delete a_hist; + } + + void test_attribute_history_for_strings_spectrum(void) { + auto a_hist = device->attribute_history("PollString_spec_attr", hist_depth); + + string first_string; + AttrResult ar; + + vector str; + + if ((*a_hist)[0].has_failed() == true) { + if (::strcmp(((*a_hist)[0].get_err_stack())[0].reason.in(), "aaaa") == 0) + ar = FIRST_EXCEPT; + else + ar = SECOND_EXCEPT; + } else { + (*a_hist)[0] >> str; + if (str.size() == 2) + ar = FIRST_DATA; + else + ar = SECOND_DATA; + } + + for (size_t i = 0; i < a_hist->size(); i++) { + if (verbose) { + cout << "Attribute failed = " << (*a_hist)[i].has_failed() << endl; + TimeVal &t = (*a_hist)[i].get_date(); + cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; + if ((*a_hist)[i].has_failed() == false) { + (*a_hist)[i] >> str; + cout << "Value = " << str[0]; + if (str.size() == 2) + cout << ", Value = " << str[1]; + cout << endl; + } else { + cout << "Error stack depth = " << (*a_hist)[i].get_err_stack().length() << endl; + cout << "Error level 0 reason = " << ((*a_hist)[i].get_err_stack())[0].reason << endl; + cout << "Error level 0 desc = " << ((*a_hist)[i].get_err_stack())[0].desc << endl; + } + cout << endl; + } + } + + switch (ar) { + case FIRST_EXCEPT: + TS_ASSERT((*a_hist)[0].has_failed() == true); + TS_ASSERT((*a_hist)[0].get_err_stack().length() == 1); + TS_ASSERT(::strcmp(((*a_hist)[0].get_err_stack())[0].desc.in(), "bbb") == 0); + TS_ASSERT(::strcmp(((*a_hist)[0].get_err_stack())[0].reason.in(), "aaaa") == 0); + + TS_ASSERT((*a_hist)[1].has_failed() == true); + TS_ASSERT((*a_hist)[1].get_err_stack().length() == 1); + TS_ASSERT(::strcmp(((*a_hist)[1].get_err_stack())[0].desc.in(), "yyy") == 0); + TS_ASSERT(::strcmp(((*a_hist)[1].get_err_stack())[0].reason.in(), "xxx") == 0); + + (*a_hist)[2] >> str; + TS_ASSERT(str.size() == 2); + TS_ASSERT(str[0] == "Hello world"); + TS_ASSERT(str[1] == "Hello universe"); + + (*a_hist)[3] >> str; + TS_ASSERT(str.size() == 1); + TS_ASSERT(str[0] == "Hello Grenoble"); + break; + + case SECOND_EXCEPT: + TS_ASSERT((*a_hist)[0].has_failed() == true); + TS_ASSERT((*a_hist)[0].get_err_stack().length() == 1); + TS_ASSERT(::strcmp(((*a_hist)[0].get_err_stack())[0].desc.in(), "yyy") == 0); + TS_ASSERT(::strcmp(((*a_hist)[0].get_err_stack())[0].reason.in(), "xxx") == 0); + + (*a_hist)[1] >> str; + TS_ASSERT(str.size() == 2); + TS_ASSERT(str[0] == "Hello world"); + TS_ASSERT(str[1] == "Hello universe"); + + (*a_hist)[2] >> str; + TS_ASSERT(str.size() == 1); + TS_ASSERT(str[0] == "Hello Grenoble"); + + TS_ASSERT((*a_hist)[3].has_failed() == true); + TS_ASSERT((*a_hist)[3].get_err_stack().length() == 1); + TS_ASSERT(::strcmp(((*a_hist)[3].get_err_stack())[0].desc.in(), "bbb") == 0); + TS_ASSERT(::strcmp(((*a_hist)[3].get_err_stack())[0].reason.in(), "aaaa") == 0); + break; + + case FIRST_DATA: + (*a_hist)[0] >> str; + TS_ASSERT(str.size() == 2); + TS_ASSERT(str[0] == "Hello world"); + TS_ASSERT(str[1] == "Hello universe"); + + (*a_hist)[1] >> str; + TS_ASSERT(str.size() == 1); + TS_ASSERT(str[0] == "Hello Grenoble"); + + TS_ASSERT((*a_hist)[2].has_failed() == true); + TS_ASSERT((*a_hist)[2].get_err_stack().length() == 1); + TS_ASSERT(::strcmp(((*a_hist)[2].get_err_stack())[0].desc.in(), "bbb") == 0); + TS_ASSERT(::strcmp(((*a_hist)[2].get_err_stack())[0].reason.in(), "aaaa") == 0); + + TS_ASSERT((*a_hist)[3].has_failed() == true); + TS_ASSERT((*a_hist)[3].get_err_stack().length() == 1); + TS_ASSERT(::strcmp(((*a_hist)[3].get_err_stack())[0].desc.in(), "yyy") == 0); + TS_ASSERT(::strcmp(((*a_hist)[3].get_err_stack())[0].reason.in(), "xxx") == 0); + break; + + case SECOND_DATA: + (*a_hist)[0] >> str; + TS_ASSERT(str.size() == 1); + TS_ASSERT(str[0] == "Hello Grenoble"); + + TS_ASSERT((*a_hist)[1].has_failed() == true); + TS_ASSERT((*a_hist)[1].get_err_stack().length() == 1); + TS_ASSERT(::strcmp(((*a_hist)[1].get_err_stack())[0].desc.in(), "bbb") == 0); + TS_ASSERT(::strcmp(((*a_hist)[1].get_err_stack())[0].reason.in(), "aaaa") == 0); + + TS_ASSERT((*a_hist)[2].has_failed() == true); + TS_ASSERT((*a_hist)[2].get_err_stack().length() == 1); + TS_ASSERT(::strcmp(((*a_hist)[2].get_err_stack())[0].desc.in(), "yyy") == 0); + TS_ASSERT(::strcmp(((*a_hist)[2].get_err_stack())[0].reason.in(), "xxx") == 0); + + (*a_hist)[3] >> str; + TS_ASSERT(str.size() == 2); + TS_ASSERT(str[0] == "Hello world"); + TS_ASSERT(str[1] == "Hello universe"); + break; + } + delete a_hist; + } + + void test_attribute_history_for_dev_encoded(void) { + auto enc_hist = device->attribute_history("Encoded_attr", hist_depth); + + for (size_t i = 0; i < enc_hist->size(); i++) { + + if (verbose) { + cout << "Value = " << (*enc_hist)[i] << endl; + cout << endl; + } + + TS_ASSERT((*enc_hist)[i].has_failed() == false); + TS_ASSERT((*enc_hist)[i].get_err_stack().length() == 0); + + TS_ASSERT((*enc_hist)[i].get_dim_x() == 1); + TS_ASSERT((*enc_hist)[i].get_dim_y() == 0); + + DevEncoded enc; + (*enc_hist)[i] >> enc; + + TS_ASSERT(::strcmp(enc.encoded_format, "Which format?") == 0); + TS_ASSERT(enc.encoded_data[0] == 97); + TS_ASSERT(enc.encoded_data[1] == 98); + TS_ASSERT(enc.encoded_data[2] == 99); + TS_ASSERT(enc.encoded_data[3] == 100); + } + delete enc_hist; + } + + void test_attribute_history_with_exception(void) { + auto a_hist = device->attribute_history("attr_wrong_type", hist_depth); + + for (size_t i = 0; i < a_hist->size(); i++) { + if (verbose) { + cout << "Command failed = " << (*a_hist)[i].has_failed() << endl; + TimeVal &t = (*a_hist)[i].get_date(); + cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; + cout << "Error stack depth = " << (*a_hist)[i].get_err_stack().length() << endl; + cout << "Error level 0 reason = " << ((*a_hist)[i].get_err_stack())[0].reason << endl; + cout << "Error level 0 desc = " << ((*a_hist)[i].get_err_stack())[0].desc << endl; + cout << endl; + } + + TS_ASSERT((*a_hist)[i].has_failed() == true); + TS_ASSERT((*a_hist)[i].get_err_stack().length() == 1); + TS_ASSERT(!strcmp((*a_hist)[i].get_err_stack()[0].reason, "API_AttrOptProp")); +// AttributeDimension dim; +// dim = (*a_hist)[i].get_r_dimension(); + + TS_ASSERT((*a_hist)[i].get_dim_x() == 0); + TS_ASSERT((*a_hist)[i].get_dim_y() == 0); + +// dim = (*a_hist)[i].get_w_dimension(); + +// TS_ASSERT ( dim.dim_x == 0); +// TS_ASSERT ( dim.dim_y == 0); + + } + delete a_hist; + } + + void test_getting_a_long_64_attribute_from_polling_buffer(void) { + TS_ASSERT_THROWS_NOTHING(device->set_source(Tango::CACHE)); + CxxTest::TangoPrinter::restore_set("dev1_source_cache"); + + DeviceAttribute da; + int data_type; + + TS_ASSERT_THROWS_NOTHING(da = device->read_attribute("Long64_attr_rw")); + DevLong64 lo; + da >> lo; + data_type = da.get_type(); + if (verbose) + cout << "64 bits attribute data = " << hex << lo << dec << endl; + TS_ASSERT(lo == 0x800000000LL); + TS_ASSERT(data_type == Tango::DEV_LONG64); + } + + void test_getting_an_unsigned_long_64_bits_attribute_from_polling_buffer(void) { + TS_ASSERT_THROWS_NOTHING(device->set_source(Tango::CACHE)); + CxxTest::TangoPrinter::restore_set("dev1_source_cache"); + + DeviceAttribute da_ulo; + TS_ASSERT_THROWS_NOTHING(da_ulo = device->read_attribute("ULong64_attr_rw")); + DevULong64 ulo; + da_ulo >> ulo; + int data_type_ulo = da_ulo.get_type(); + if (verbose) + cout << "unsigned 64 bits attribute data = " << hex << ulo << dec << endl; + TS_ASSERT(ulo == 0xC000000000000000LL); + TS_ASSERT(data_type_ulo == Tango::DEV_ULONG64); + } + + void test_getting_a_unsigned_long_spectrum_attribute_from_polling_buffer(void) { + TS_ASSERT_THROWS_NOTHING(device->set_source(Tango::CACHE)); + CxxTest::TangoPrinter::restore_set("dev1_source_cache"); + + DeviceAttribute da; + TS_ASSERT_THROWS_NOTHING(da = device->read_attribute("ULong_spec_attr_rw")); + vector v_lo; + auto ret = (da >> v_lo); + + TS_ASSERT(ret == true); + TS_ASSERT(v_lo[0] == 2222); + TS_ASSERT(v_lo[1] == 22222); + TS_ASSERT(v_lo[2] == 222222); + } + + void test_getting_a_state_spectrum_attribute_from_polling_buffer(void) { + TS_ASSERT_THROWS_NOTHING(device->set_source(Tango::CACHE)); + CxxTest::TangoPrinter::restore_set("dev1_source_cache"); + + DeviceAttribute da; + TS_ASSERT_THROWS_NOTHING(da = device->read_attribute("State_spec_attr_rw")); + vector v_sta; + auto ret = (da >> v_sta); + + TS_ASSERT(ret == true); + TS_ASSERT(v_sta[0] == Tango::ON); + TS_ASSERT(v_sta[1] == Tango::OFF); + } + + void test_getting_a_dev_encoded_attribute_from_polling_buffer(void) { + TS_ASSERT_THROWS_NOTHING(device->set_source(Tango::CACHE)); + CxxTest::TangoPrinter::restore_set("dev1_source_cache"); + + DeviceAttribute da; + TS_ASSERT_THROWS_NOTHING(da = device->read_attribute("Encoded_attr")); + DevEncoded enc_lo; + da >> enc_lo; + auto data_type = da.get_type(); + TS_ASSERT(::strcmp(enc_lo.encoded_format.in(), "Which format?") == 0); + TS_ASSERT(data_type == Tango::DEV_ENCODED); + TS_ASSERT(enc_lo.encoded_data.length() == 4); + TS_ASSERT(enc_lo.encoded_data[0] == 97); + TS_ASSERT(enc_lo.encoded_data[1] == 98); + TS_ASSERT(enc_lo.encoded_data[2] == 99); + TS_ASSERT(enc_lo.encoded_data[3] == 100); + } + + void test_polling_status_from_device_name(void) { + if (CxxTest::TangoPrinter::is_restore_set("dev1_source_cache")) + TS_ASSERT_THROWS_NOTHING(device->set_source(Tango::CACHE_DEV)); + + vector *poll_str; + TS_ASSERT_THROWS_NOTHING(poll_str = device->polling_status()); + + unsigned long nb_polled = BASIC_NB_POLL; + for (unsigned int i = 0; i < poll_str->size(); i++) { + if ((*poll_str)[i].find("String_attr") != string::npos) { + nb_polled++; + } + if ((*poll_str)[i].find("IOStartPoll") != string::npos) { + nb_polled++; + } + } + + if (verbose) { + cout << poll_str->size() << " object(s) polled for device" << endl; + cout << endl; + for (unsigned int i = 0; i < poll_str->size(); i++) + cout << "Polling status = " << (*poll_str)[i] << endl; + cout << endl; + } + + TS_ASSERT(poll_str->size() == nb_polled); + + delete poll_str; + } + + void test_polling_status_from_device_name_2(void) { + auto device2 = new DeviceProxy(device2_name); + vector *poll_str; + TS_ASSERT_THROWS_NOTHING(poll_str = device2->polling_status()); + + if (verbose) { + cout << poll_str->size() << " object(s) polled for device" << endl; + cout << endl; + for (unsigned int i = 0; i < poll_str->size(); i++) + cout << "Polling status = " << (*poll_str)[i] << endl; + cout << endl; + } + + TS_ASSERT(poll_str->size() == 0); + delete poll_str; + delete device2; + } + + void test_polling_status_from_alias_name(void) { + + string adm_name = device->adm_name(); + DeviceProxy *admin_dev = new DeviceProxy(adm_name); + + + DeviceData d_send, d_received; + d_send << alias_name; + TS_ASSERT_THROWS_NOTHING(d_received = admin_dev->command_inout("DevPollStatus", d_send)); + vector v_str; + d_received >> v_str; + + auto nb_polled = BASIC_NB_POLL; + for (unsigned int i = 0; i < v_str.size(); i++) { + if (v_str[i].find("String_attr") != string::npos) { + nb_polled++; + continue; + } + if (v_str[i].find("IOStartPoll") != string::npos) { + nb_polled++; + } + } + + if (verbose) { + cout << v_str.size() << " object(s) polled for device" << endl; + cout << endl; + for (unsigned int i = 0; i < v_str.size(); i++) + cout << "Polling status = " << v_str[i] << endl; + cout << endl; + } + + TS_ASSERT(v_str.size() == nb_polled); + } + + void test_get_command_poll_period(void) { + + string cmd("IOExcept"); + int per; + TS_ASSERT_THROWS_NOTHING(per = device->get_command_poll_period(cmd)); + + if (verbose) { + cout << "Cmd " << cmd << " polling period = " << per << endl; + } + + TS_ASSERT(per == 2000); + + string attr("PollLong_attr"); + TS_ASSERT_THROWS_NOTHING(per = device->get_attribute_poll_period(attr)); + + if (verbose) + cout << "Attr " << attr << " polling period = " << per << endl; + + TS_ASSERT(per == 1000); + } + + void test_poll_command(void) { + + string cmd{"IOArray1"}; + bool poll; + TS_ASSERT_THROWS_NOTHING(poll = device->is_command_polled(cmd)); + + TS_ASSERT(poll == false); + + TS_ASSERT_THROWS_NOTHING(device->poll_command(cmd, 3000)); + TS_ASSERT_THROWS_NOTHING(poll = device->is_command_polled(cmd)); + + TS_ASSERT(poll == true); + + int per; + TS_ASSERT_THROWS_NOTHING(per = device->get_command_poll_period(cmd)); + + TS_ASSERT(per == 3000); + +#ifdef WIN32 + Sleep(3000); +#else + this_thread::sleep_for(chrono::seconds{3}); +#endif + + TS_ASSERT_THROWS_NOTHING(device->poll_command(cmd, 5000)); + TS_ASSERT_THROWS_NOTHING(per = device->get_command_poll_period(cmd)); + + TS_ASSERT(per == 5000); + +#ifdef WIN32 + Sleep(3000); +#else + this_thread::sleep_for(chrono::seconds{3}); +#endif + vector *poll_str; + TS_ASSERT_THROWS_NOTHING(poll_str = device->polling_status()); + + if (verbose) { + cout << poll_str->size() << " object(s) polled for device" << endl; + cout << endl; + for (unsigned int i = 0; i < poll_str->size(); i++) + cout << "Polling status = " << (*poll_str)[i] << endl; + cout << endl; + } + + auto nb_polled = BASIC_NB_POLL + 1; + for (unsigned int i = 0; i < poll_str->size(); i++) { + if ((*poll_str)[i].find("String_attr") != string::npos) { + nb_polled++; + } + if ((*poll_str)[i].find("IOStartPoll") != string::npos) { + nb_polled++; + } + } + + TS_ASSERT(poll_str->size() == nb_polled); + + delete poll_str; + } + + void test_min_polling_period(void) { +// +// WARNING, this test works only if device property min_poll_period set to 200 +// and cmd_min_poll_period set to IOExcept,500 +// + + TS_ASSERT_THROWS(device->poll_command("IOExcept", 300), Tango::DevFailed); + + TS_ASSERT_THROWS(device->poll_command("IOExcept", 100), Tango::DevFailed); + + TS_ASSERT_THROWS_NOTHING(device->poll_command("IOExcept", 500)); + +#ifdef WIN32 + Sleep(3000); +#else + this_thread::sleep_for(chrono::seconds{3}); +#endif + + TS_ASSERT_THROWS_NOTHING(device->poll_command("IOExcept", 2000)); + + DbData db; + vector prop_vs; + prop_vs.push_back("IOExcept"); + prop_vs.push_back("500"); + db.push_back(DbDatum("cmd_min_poll_period")); + db[0] << prop_vs; + TS_ASSERT_THROWS_NOTHING(device->put_property(db)); + } + + void test_stop_poll_command(void) { + string cmd{"IOArray1"}; + TS_ASSERT_THROWS_NOTHING(device->stop_poll_command(cmd)); + + bool poll; + TS_ASSERT_THROWS_NOTHING(poll = device->is_command_polled(cmd)); + + TS_ASSERT(poll == false); + + vector *poll_str; + TS_ASSERT_THROWS_NOTHING(poll_str = device->polling_status()); + + if (verbose) { + cout << poll_str->size() << " object(s) polled for device" << endl; + cout << endl; + for (unsigned int i = 0; i < poll_str->size(); i++) + cout << "Polling status = " << (*poll_str)[i] << endl; + cout << endl; + } + + auto nb_polled = BASIC_NB_POLL; + for (unsigned int i = 0; i < poll_str->size(); i++) { + if ((*poll_str)[i].find("String_attr") != string::npos) { + nb_polled++; + } + if ((*poll_str)[i].find("IOStartPoll") != string::npos) { + nb_polled++; + } + } + + TS_ASSERT(poll_str->size() == nb_polled); + + delete poll_str; + } + + void test_poll_attribute(void) { + + string attr{"Double_attr"}; + bool poll; + TS_ASSERT_THROWS_NOTHING(poll = device->is_attribute_polled(attr)); + + TS_ASSERT(poll == false); + + TS_ASSERT_THROWS_NOTHING(device->poll_attribute(attr, 3000)); + TS_ASSERT_THROWS_NOTHING(poll = device->is_attribute_polled(attr)); + + TS_ASSERT(poll == true); + + int per; + TS_ASSERT_THROWS_NOTHING(per = device->get_attribute_poll_period(attr)); + + TS_ASSERT(per == 3000); + +#ifdef WIN32 + Sleep(3000); +#else + this_thread::sleep_for(chrono::seconds{3}); +#endif + + TS_ASSERT_THROWS_NOTHING(device->poll_attribute(attr, 5000)); + TS_ASSERT_THROWS_NOTHING(per = device->get_attribute_poll_period(attr)); + + TS_ASSERT(per == 5000); + +#ifdef WIN32 + Sleep(3000); +#else + this_thread::sleep_for(chrono::seconds{3}); +#endif + + vector *poll_str; + TS_ASSERT_THROWS_NOTHING(poll_str = device->polling_status()); + + if (verbose) { + cout << poll_str->size() << " object(s) polled for device" << endl; + cout << endl; + for (unsigned int i = 0; i < poll_str->size(); i++) + cout << "Polling status = " << (*poll_str)[i] << endl; + cout << endl; + } + + auto nb_polled = BASIC_NB_POLL + 1; + for (unsigned int i = 0; i < poll_str->size(); i++) { + if ((*poll_str)[i].find("String_attr") != string::npos) { + nb_polled++; + } + if ((*poll_str)[i].find("IOStartPoll") != string::npos) { + nb_polled++; + } + } + + TS_ASSERT(poll_str->size() == nb_polled); + + delete poll_str; + } + + void test_stop_poll_attribute(void) { + string attr{"Double_attr"}; + TS_ASSERT_THROWS_NOTHING(device->stop_poll_attribute(attr)); + + bool poll; + TS_ASSERT_THROWS_NOTHING(poll = device->is_attribute_polled(attr)); + + TS_ASSERT(poll == false); + + vector *poll_str; + TS_ASSERT_THROWS_NOTHING(poll_str = device->polling_status()); + + if (verbose) { + cout << poll_str->size() << " object(s) polled for device" << endl; + cout << endl; + for (unsigned int i = 0; i < poll_str->size(); i++) + cout << "Polling status = " << (*poll_str)[i] << endl; + cout << endl; + } + + auto nb_polled = BASIC_NB_POLL; + for (unsigned int i = 0; i < poll_str->size(); i++) { + if ((*poll_str)[i].find("String_attr") != string::npos) { + nb_polled++; + } + if ((*poll_str)[i].find("IOStartPoll") != string::npos) { + nb_polled++; + } + } + + TS_ASSERT(poll_str->size() == nb_polled); + + delete poll_str; + } + + void test_poll_device_2(void) { + auto dev2 = new DeviceProxy(device2_name); + TS_ASSERT_THROWS_NOTHING(dev2->poll_attribute("PollLong_attr", 1000)); + CxxTest::TangoPrinter::restore_set("dev2_poll_PollLong_attr_1000"); + + this_thread::sleep_for(chrono::seconds{2}); + + vector polled_devs; + split_string(ref_polling_pool_conf[0], ',', polled_devs); + int nb_polled_devs = polled_devs.size(); + +// Add a device into device server and restart it +// Also add property to poll one of the device attribute + + + DbDevInfo my_device_info{ + new_dev.c_str(), + TEST_CLASS, + serv_name.c_str() + }; + + Database db{}; + TS_ASSERT_THROWS_NOTHING(db.add_device(my_device_info)); + + DbDatum poll_prop("polled_attr"); + vector poll_param; + poll_param.push_back("PollLong_attr"); + poll_param.push_back("1000"); + poll_prop << poll_param; + DbData db_poll; + db_poll.push_back(poll_prop); + TS_ASSERT_THROWS_NOTHING(db.put_device_property(new_dev.c_str(), db_poll)); + CxxTest::TangoPrinter::restore_set("reset_device_server"); + + auto admin_dev = new DeviceProxy(admin_dev_name); + TS_ASSERT_THROWS_NOTHING(admin_dev->command_inout("RestartServer")); + + this_thread::sleep_for(chrono::seconds{5}); + +// Read polling threads pool conf once more + + DeviceData da; + + DeviceProxy dev{device_name}; + TS_ASSERT_THROWS_NOTHING(da = dev.command_inout("PollingPoolTst")); + vector new_polling_pool_conf; + da >> new_polling_pool_conf; + + TS_ASSERT(ref_polling_pool_conf.size() == new_polling_pool_conf.size()); + split_string(new_polling_pool_conf[0], ',', polled_devs); + int new_nb_polled_devs = polled_devs.size(); + + TS_ASSERT(new_nb_polled_devs == nb_polled_devs + 1); + + auto iter = find(polled_devs.begin(), polled_devs.end(), new_dev); + TS_ASSERT(iter != polled_devs.end()); + } + + void test_change_polling_thread_number_and_add_2_more_devices(void) { + DbDevInfo my_device_info{ + new_dev1_th2.c_str(), + TEST_CLASS, + serv_name.c_str() + }; + + Database db{}; + TS_ASSERT_THROWS_NOTHING(db.add_device(my_device_info)); + + my_device_info.name = new_dev2_th2.c_str(); + TS_ASSERT_THROWS_NOTHING(db.add_device(my_device_info)); + + DbDatum pool_size("polling_threads_pool_size"); + DbData db_data; + + pool_size << 2L; + db_data.push_back(pool_size); + TS_ASSERT_THROWS_NOTHING(db.put_device_property(admin_dev_name.c_str(), db_data)); + + + DbDatum poll_prop("polled_attr"); + vector poll_param; + poll_param.push_back("PollLong_attr"); + poll_param.push_back("1000"); + poll_prop << poll_param; + DbData db_poll; + db_poll.push_back(poll_prop); + + TS_ASSERT_THROWS_NOTHING(db.put_device_property(new_dev1_th2.c_str(), db_poll)); + TS_ASSERT_THROWS_NOTHING(db.put_device_property(new_dev2_th2.c_str(), db_poll)); + CxxTest::TangoPrinter::restore_set("reset_device_server"); + + auto admin_dev = new DeviceProxy(admin_dev_name); + TS_ASSERT_THROWS_NOTHING(admin_dev->command_inout("RestartServer")); + + this_thread::sleep_for(chrono::seconds{5}); + +// Check new pool conf + + DeviceData dz; + + DeviceProxy dev(device_name); + TS_ASSERT_THROWS_NOTHING(dz = dev.command_inout("PollingPoolTst")); + + vector new_polling_pool_conf{}; + dz >> new_polling_pool_conf; + + TS_ASSERT(new_polling_pool_conf.size() == ref_polling_pool_conf.size() + 1); + + vector polled_devs{}; + split_string(new_polling_pool_conf[1], ',', polled_devs); + auto new_nb_polled_devs = polled_devs.size(); + + TS_ASSERT(new_nb_polled_devs == 2); + + auto iter = find(polled_devs.begin(), polled_devs.end(), new_dev1_th2); + TS_ASSERT(iter != polled_devs.end()); + + iter = find(polled_devs.begin(), polled_devs.end(), new_dev2_th2); + TS_ASSERT(iter != polled_devs.end()); + } + + void test_change_polling_thread_number_to_3_and_add_1_more_device(void) { + DbDevInfo my_device_info{ + new_dev1_th3.c_str(), + TEST_CLASS, + serv_name.c_str() + }; + + Database db{}; + TS_ASSERT_THROWS_NOTHING(db.add_device(my_device_info)); + + DbDatum pool_size3("polling_threads_pool_size"); + DbData db_data3; + + pool_size3 << 3L; + db_data3.push_back(pool_size3); + TS_ASSERT_THROWS_NOTHING(db.put_device_property(admin_dev_name.c_str(), db_data3)); + + DbDatum poll_prop("polled_attr"); + vector poll_param; + poll_param.push_back("PollLong_attr"); + poll_param.push_back("1000"); + poll_prop << poll_param; + DbData db_poll; + db_poll.push_back(poll_prop); + + TS_ASSERT_THROWS_NOTHING(db.put_device_property(new_dev1_th3.c_str(), db_poll)); + CxxTest::TangoPrinter::restore_set("reset_device_server"); + + auto admin_dev = new DeviceProxy(admin_dev_name); + TS_ASSERT_THROWS_NOTHING(admin_dev->command_inout("RestartServer")); + + this_thread::sleep_for(chrono::seconds{5}); + +// Check new pool conf + + DeviceData dx; + + DeviceProxy dev{device_name}; + TS_ASSERT_THROWS_NOTHING(dx = dev.command_inout("PollingPoolTst")); + + vector new_polling_pool_conf{}; + dx >> new_polling_pool_conf; + + TS_ASSERT(new_polling_pool_conf.size() == ref_polling_pool_conf.size() + 2); + + vector polled_devs; + split_string(new_polling_pool_conf[2], ',', polled_devs); + + auto new_nb_polled_devs = polled_devs.size(); + TS_ASSERT(new_nb_polled_devs == 1); + + auto iter = find(polled_devs.begin(), polled_devs.end(), new_dev1_th3); + TS_ASSERT(iter != polled_devs.end()); + } + + void test_delete_1_device_to_check_automatic_polling_pool_reconfiguration(void) { + Database db{}; + TS_ASSERT_THROWS_NOTHING(db.delete_device(new_dev1_th3)); + + auto admin_dev = new DeviceProxy(admin_dev_name); + TS_ASSERT_THROWS_NOTHING(admin_dev->command_inout("RestartServer")); + + this_thread::sleep_for(chrono::seconds{5}); + +// Check pool conf + + DeviceData dv; + + DeviceProxy dev{device_name}; + TS_ASSERT_THROWS_NOTHING(dv = dev.command_inout("PollingPoolTst")); + + vector new_polling_pool_conf; + dv >> new_polling_pool_conf; + + TS_ASSERT(new_polling_pool_conf.size() == ref_polling_pool_conf.size() + 1); + + vector polled_devs; + split_string(new_polling_pool_conf[1], ',', polled_devs); + auto new_nb_polled_devs = polled_devs.size(); + + TS_ASSERT(new_nb_polled_devs == 2); + + auto iter = find(polled_devs.begin(), polled_devs.end(), new_dev1_th2); + TS_ASSERT(iter != polled_devs.end()); + + iter = find(polled_devs.begin(), polled_devs.end(), new_dev2_th2); + TS_ASSERT(iter != polled_devs.end()); + } + + void reset_device_server() { + Database db{}; + + del_device_no_error(db, new_dev); + del_device_no_error(db, new_dev1_th2); + del_device_no_error(db, new_dev1_th3); + del_device_no_error(db, new_dev2_th2); + + DbDatum pool_conf("polling_threads_pool_conf"); + DbData db_data; + + pool_conf << ref_polling_pool_conf; + db_data.push_back(pool_conf); + db.put_device_property(admin_dev_name.c_str(), db_data); + + DbDatum del_prop("polling_threads_pool_size"); + db_data.clear(); + db_data.push_back(del_prop); + db.delete_device_property(admin_dev_name.c_str(), db_data); + + auto admin_dev = new DeviceProxy(admin_dev_name); + admin_dev->command_inout("RestartServer"); + + this_thread::sleep_for(chrono::seconds{5}); + } +}; + +void split_string(string &the_str, char delim, vector &splitted_str) { + string::size_type pos, start; + splitted_str.clear(); + + start = 0; + while ((pos = the_str.find(delim, start)) != string::npos) { + splitted_str.push_back(the_str.substr(start, pos - start)); + start = pos + 1; + } + + splitted_str.push_back(the_str.substr(start)); +} + + +void stop_poll_att_no_except(DeviceProxy *dev, const char *att_name) { + try { + dev->stop_poll_attribute(att_name); + } + catch (Tango::DevFailed &) {} + catch (CORBA::Exception &e) { + Except::print_exception(e); + exit(-1); + } +} + +void stop_poll_cmd_no_except(DeviceProxy *dev, const char *cmd_name) { + try { + dev->stop_poll_command(cmd_name); + } + catch (Tango::DevFailed &) {} + catch (CORBA::Exception &e) { + Except::print_exception(e); + exit(-1); + } +} + +void del_device_no_error(Database &db, string& d_name) { + try { + db.delete_device(d_name.c_str()); + } + catch (DevFailed &) {} +} + + +#undef cout +#endif // PollTestSuite_h diff --git a/cpp_test_suite/new_tests/cxx_reconnection_zmq.cpp b/cpp_test_suite/new_tests/cxx_reconnection_zmq.cpp new file mode 100644 index 000000000..b218da793 --- /dev/null +++ b/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/cpp_test_suite/new_tests/cxx_server_event.cpp b/cpp_test_suite/new_tests/cxx_server_event.cpp new file mode 100644 index 000000000..8b3fd29f3 --- /dev/null +++ b/cpp_test_suite/new_tests/cxx_server_event.cpp @@ -0,0 +1,150 @@ +// +// 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, device1_instance_name, device2_instance_name; + bool verbose; + DevLong eve_id; + +public: + SUITE_NAME(): + device1_instance_name{"test"},//TODO pass via cl + device2_instance_name{"test2"} + { + +// +// 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."); + } + 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 ------------------------------------------------------- +// + +// +// 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/cpp_test_suite/new_tests/cxx_stateless_subscription.cpp b/cpp_test_suite/new_tests/cxx_stateless_subscription.cpp new file mode 100644 index 000000000..e2eaef62d --- /dev/null +++ b/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 + + diff --git a/cpp_test_suite/old_tests/CMakeLists.txt b/cpp_test_suite/old_tests/CMakeLists.txt index 21e1fa37f..668a8a6b8 100644 --- a/cpp_test_suite/old_tests/CMakeLists.txt +++ b/cpp_test_suite/old_tests/CMakeLists.txt @@ -23,17 +23,12 @@ set(TESTS acc_right multiple_new new_devproxy obj_prop - poll_attr - Poll poll_except - poll_met - poll_pool print_data print_data_hist prop_list rds read_attr - read_hist read_hist_ext reconnect_attr reconnect @@ -41,7 +36,6 @@ set(TESTS acc_right ring_depth size state_attr - StopPoll sub_dev unlock wait_mcast_dev @@ -69,12 +63,6 @@ add_test(NAME "old_tests::write_attr" COMMAND $ ${DEV1} add_test(NAME "old_tests::copy_devproxy" COMMAND $ ${DEV1} ${DEV2} ${DEV3}) add_test(NAME "old_tests::attr_misc" COMMAND $ ${DEV1}) add_test(NAME "old_tests::obj_prop" COMMAND $) - -configure_file(test_polling.sh.cmake test_polling.sh @ONLY) -execute_process(COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/test_polling.sh) -add_test(NAME "old_tests::polling" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_polling.sh - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - add_test(NAME "old_tests::attr_proxy" COMMAND $ ${DEV1}/Short_attr_rw) add_test(NAME "old_tests::write_attr_3" COMMAND $ ${DEV1} 10) add_test(NAME "old_tests::read_hist_ext" COMMAND $ ${DEV1}) diff --git a/cpp_test_suite/old_tests/poll_attr.cpp b/cpp_test_suite/old_tests/poll_attr.cpp deleted file mode 100644 index 3733913ee..000000000 --- a/cpp_test_suite/old_tests/poll_attr.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#define coutv if (verbose == true) cout - -using namespace Tango; -using namespace std; - -bool verbose = false; - -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 - { - - device->set_source(Tango::CACHE); - -// Test getting a long 64 attribute from polling buffer - - DeviceAttribute da; - int data_type; - - try - { - da = device->read_attribute("Long64_attr_rw"); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(-1); - } - DevLong64 lo; - da >> lo; - data_type = da.get_type(); - coutv << "64 bits attribute data = " << hex << lo << dec << endl; - assert ( lo == 0x800000000LL ); - assert ( data_type == Tango::DEV_LONG64 ); - - cout << " Scalar long 64 bits from CACHE buffer --> OK" << endl; - -// Test getting a unsigned long 64 bits attribute from polling buffer - - DeviceAttribute da_ulo; - try - { - da_ulo = device->read_attribute("ULong64_attr_rw"); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(-1); - } - DevULong64 ulo; - da_ulo >> ulo; - int data_type_ulo = da_ulo.get_type(); - coutv << "unsigned 64 bits attribute data = " << hex << ulo << dec << endl; - assert ( ulo == 0xC000000000000000LL ); - assert ( data_type_ulo == Tango::DEV_ULONG64 ); - - cout << " Scalar unsigned long 64 bits from CACHE buffer --> OK" << endl; - -// Test getting a unsigned long spectrum attribute from polling buffer - - bool ret; - try - { - da = device->read_attribute("ULong_spec_attr_rw"); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(-1); - } - vector v_lo; - ret = (da >> v_lo); - - assert (ret == true); - assert ( v_lo[0] == 2222 ); - assert ( v_lo[1] == 22222 ); - assert ( v_lo[2] == 222222 ); - - cout << " Spectrum unsigned long from CACHE buffer --> OK" << endl; - -// Test getting a state spectrum attribute from polling buffer - - try - { - da = device->read_attribute("State_spec_attr_rw"); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(-1); - } - vector v_sta; - ret = (da >> v_sta); - - assert (ret == true); - assert ( v_sta[0] == Tango::ON ); - assert ( v_sta[1] == Tango::OFF ); - - cout << " Spectrum state from CACHE buffer --> OK" << endl; - -// Test getting a DevEncoded attribute from polling buffer - -#ifndef COMPAT - try - { - da = device->read_attribute("Encoded_attr"); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(-1); - } - - DevEncoded enc_lo; - da >> enc_lo; - data_type = da.get_type(); - assert ( ::strcmp(enc_lo.encoded_format.in(),"Which format?") == 0 ); - assert ( data_type == Tango::DEV_ENCODED ); - assert ( enc_lo.encoded_data.length() == 4 ); - assert ( enc_lo.encoded_data[0] == 97 ); - assert ( enc_lo.encoded_data[1] == 98 ); - assert ( enc_lo.encoded_data[2] == 99 ); - assert ( enc_lo.encoded_data[3] == 100 ); - - cout << " DevEncoded attribute from CACHE buffer --> OK" << endl; -#endif - - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - exit(-1); - } - - delete device; - return 0; -} diff --git a/cpp_test_suite/old_tests/poll_met.cpp b/cpp_test_suite/old_tests/poll_met.cpp deleted file mode 100644 index 87f2bff3b..000000000 --- a/cpp_test_suite/old_tests/poll_met.cpp +++ /dev/null @@ -1,450 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#ifndef COMPAT -#define BASIC_NB_POLL 16 -#else -#define BASIC_NB_POLL 14 -#endif - -using namespace Tango; -using namespace std; - -int main(int argc, char **argv) -{ - DeviceProxy *device,*device1; - - if (argc != 4) - { - cout << "usage: poll_met " << endl; - exit(-1); - } - - string device_name = argv[1]; - string device2_name = argv[2]; - string alias_name = argv[3]; - bool print = false; - - if (argc == 2) - { - string verb = argv[1]; - if (verb != "-v") - { - cout << "Usage: %s [-v]" << endl; - exit(-1); - } - else - print = true; - } - - try - { - device = new DeviceProxy(device_name); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(1); - } - - cout << endl << "new DeviceProxy(" << device->name() << ") returned" << endl << endl; - - try - { - -// Test polling_status from device name - - vector *poll_str; - poll_str = device->polling_status(); - - unsigned long nb_polled = BASIC_NB_POLL; - for (unsigned int i = 0;i < poll_str->size();i++) - { - if ((*poll_str)[i].find("String_attr") != string::npos) - { - nb_polled++; - } - if ((*poll_str)[i].find("IOStartPoll") != string::npos) - { - nb_polled++; - } - } - - if (print == true) - { - cout << poll_str->size() << " object(s) polled for device" << endl; - cout << endl; - for (unsigned int i = 0;i < poll_str->size();i++) - cout << "Polling status = " << (*poll_str)[i] << endl; - cout << endl; - } - - assert (poll_str->size() == nb_polled ); - - delete poll_str; - - device1 = new DeviceProxy(device2_name); - poll_str = device1->polling_status(); - - if (print == true) - { - cout << poll_str->size() << " object(s) polled for device" << endl; - cout << endl; - for (unsigned int i = 0;i < poll_str->size();i++) - cout << "Polling status = " << (*poll_str)[i] << endl; - cout << endl; - } - - assert (poll_str->size() == 0); - delete poll_str; - - delete device1; - -// Test polling status from alias name - - string adm_name = device->adm_name(); - DeviceProxy *admin_dev = new DeviceProxy(adm_name); - - DeviceData d_send,d_received; - d_send << alias_name; - d_received = admin_dev->command_inout("DevPollStatus",d_send); - vector v_str; - d_received >> v_str; - - nb_polled = BASIC_NB_POLL; - for (unsigned int i = 0;i < v_str.size();i++) - { - if (v_str[i].find("String_attr") != string::npos) - { - nb_polled++; - continue; - } - if (v_str[i].find("IOStartPoll") != string::npos) - { - nb_polled++; - } - } - - if (print == true) - { - cout << v_str.size() << " object(s) polled for device" << endl; - cout << endl; - for (unsigned int i = 0;i < v_str.size();i++) - cout << "Polling status = " << v_str[i] << endl; - cout << endl; - } - - assert ( v_str.size() == nb_polled); - - cout << " Polling_status (from device name and alias) --> OK" << endl; - -// Test get_command_poll_period - - string cmd("IOExcept"); - int per = device->get_command_poll_period(cmd); - - if (print == true) - { - cout << "Cmd " << cmd << " polling period = " << per << endl; - } - - assert( per == 2000 ); - - string attr("PollLong_attr"); - per = device->get_attribute_poll_period(attr); - - if (print == true) - cout << "Attr " << attr << " polling period = " << per << endl; - - assert ( per == 1000 ); - - cout << " Get polling period (cmd and attr) --> OK" << endl; - -// Test poll_command - - cmd = ("IOArray1"); - bool poll = device->is_command_polled(cmd); - - assert( poll == false ); - - device->poll_command(cmd,3000); - poll = device->is_command_polled(cmd); - - assert ( poll == true ); - - per = device->get_command_poll_period(cmd); - - assert (per == 3000 ); - -#ifdef WIN32 - Sleep(3000); -#else - sleep(3); -#endif - - device->poll_command(cmd,5000); - per = device->get_command_poll_period(cmd); - - assert ( per == 5000 ); - -#ifdef WIN32 - Sleep(3000); -#else - sleep(3); -#endif - poll_str = device->polling_status(); - - if (print == true) - { - cout << poll_str->size() << " object(s) polled for device" << endl; - cout << endl; - for (unsigned int i = 0;i < poll_str->size();i++) - cout << "Polling status = " << (*poll_str)[i] << endl; - cout << endl; - } - - nb_polled = BASIC_NB_POLL + 1; - for (unsigned int i = 0;i < poll_str->size();i++) - { - if ((*poll_str)[i].find("String_attr") != string::npos) - { - nb_polled++; - } - if ((*poll_str)[i].find("IOStartPoll") != string::npos) - { - nb_polled++; - } - } - - assert ( poll_str->size() == nb_polled); - - delete poll_str; - - cout << " Poll command method --> OK" << endl; - -// Test min polling period -// -// WARNING, this test works only if device property min_poll_period set to 200 -// and cmd_min_poll_period set to IOExcept,500 -// - - bool except = false; - try - { - device->poll_command("IOExcept",300); - } - catch (Tango::DevFailed &) - { - except = true; - } - - assert (except == true); - except = false; - - string prop_name("cmd_min_poll_period"); - device->delete_property(prop_name); - - try - { - device->poll_command("IOExcept",100); - } - catch (Tango::DevFailed &) - { - except = true; - } - - assert (except == true); - except = false; - - try - { - device->poll_command("IOExcept",500); - } - catch (Tango::DevFailed e) - { - except = true; - } - - assert (except = true); - except = false; - -#ifdef WIN32 - Sleep(3000); -#else - sleep(3); -#endif - - try - { - device->poll_command("IOExcept",2000); - } - catch (Tango::DevFailed &) - { - except = true; - } - - assert (except == false); - - DbData db; - vector prop_vs; - prop_vs.push_back("IOExcept"); - prop_vs.push_back("500"); - db.push_back(DbDatum("cmd_min_poll_period")); - db[0] << prop_vs; - device->put_property(db); - - cout << " min polling period management --> OK" << endl; - -// Test stop_poll_command - - device->stop_poll_command(cmd); - - poll = device->is_command_polled(cmd); - - assert ( poll == false ); - - poll_str = device->polling_status(); - - if (print == true) - { - cout << poll_str->size() << " object(s) polled for device" << endl; - cout << endl; - for (unsigned int i = 0;i < poll_str->size();i++) - cout << "Polling status = " << (*poll_str)[i] << endl; - cout << endl; - } - - nb_polled = BASIC_NB_POLL; - for (unsigned int i = 0;i < poll_str->size();i++) - { - if ((*poll_str)[i].find("String_attr") != string::npos) - { - nb_polled++; - } - if ((*poll_str)[i].find("IOStartPoll") != string::npos) - { - nb_polled++; - } - } - - assert ( poll_str->size() == nb_polled); - - delete poll_str; - - cout << " Stop poll command method --> OK" << endl; - -// Test poll_attribute - - attr = ("Double_attr"); - poll = device->is_attribute_polled(attr); - - assert( poll == false ); - - device->poll_attribute(attr,3000); - poll = device->is_attribute_polled(attr); - - assert ( poll == true ); - - per = device->get_attribute_poll_period(attr); - - assert (per == 3000 ); - -#ifdef WIN32 - Sleep(3000); -#else - sleep(3); -#endif - - device->poll_attribute(attr,5000); - per = device->get_attribute_poll_period(attr); - - assert ( per == 5000 ); - -#ifdef WIN32 - Sleep(3000); -#else - sleep(3); -#endif - - poll_str = device->polling_status(); - - if (print == true) - { - cout << poll_str->size() << " object(s) polled for device" << endl; - cout << endl; - for (unsigned int i = 0;i < poll_str->size();i++) - cout << "Polling status = " << (*poll_str)[i] << endl; - cout << endl; - } - - nb_polled = BASIC_NB_POLL + 1; - for (unsigned int i = 0;i < poll_str->size();i++) - { - if ((*poll_str)[i].find("String_attr") != string::npos) - { - nb_polled++; - } - if ((*poll_str)[i].find("IOStartPoll") != string::npos) - { - nb_polled++; - } - } - - assert ( poll_str->size() == nb_polled); - - delete poll_str; - - cout << " Poll attribute method --> OK" << endl; - -// Test stop_poll_command - - device->stop_poll_attribute(attr); - - poll = device->is_attribute_polled(attr); - - assert ( poll == false ); - - poll_str = device->polling_status(); - - if (print == true) - { - cout << poll_str->size() << " object(s) polled for device" << endl; - cout << endl; - for (unsigned int i = 0;i < poll_str->size();i++) - cout << "Polling status = " << (*poll_str)[i] << endl; - cout << endl; - } - - nb_polled = BASIC_NB_POLL; - for (unsigned int i = 0;i < poll_str->size();i++) - { - if ((*poll_str)[i].find("String_attr") != string::npos) - { - nb_polled++; - } - if ((*poll_str)[i].find("IOStartPoll") != string::npos) - { - nb_polled++; - } - } - - assert ( poll_str->size() == nb_polled); - - delete poll_str; - - cout << " Stop poll attribute method --> OK" << endl; - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - exit(-1); - } - - - delete device; - return 0; -} diff --git a/cpp_test_suite/old_tests/poll_pool.cpp b/cpp_test_suite/old_tests/poll_pool.cpp deleted file mode 100644 index 1e63d08bf..000000000 --- a/cpp_test_suite/old_tests/poll_pool.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#define coutv if (verbose == true) cout - -using namespace Tango; -using namespace std; - -bool verbose = false; - -#define TEST_CLASS "devTest" - -void split_string(string &,char,vector &); -void reset_device_server(Database *,vector &,string &,DeviceProxy *,string &,DeviceProxy *); -void del_device_no_error(Database *,const char *); - -int main(int argc, char **argv) -{ - if (argc != 4) - { - cout << "usage: %s device1 device2 inst_name [-v]" << endl; - exit(-1); - } - - string device_name1 = argv[1]; - string device_name2 = argv[2]; - string inst_name = argv[3]; - - vector ref_polling_pool_conf; - string admin_dev_name("dserver/"); - Database *db = new Database(); - DeviceProxy *admin_dev = NULL; - DeviceProxy *dev2 = NULL; - - try - { - -// First poll device 2 - - dev2 = new DeviceProxy(device_name2); - dev2->poll_attribute("PollLong_attr",1000); - - Tango_sleep(2); - -// Get a reference polling thread pool - - DeviceProxy dev(device_name1); - DeviceData dd; - - dd = dev.command_inout("PollingPoolTst"); - vector polled_devs; - - dd >> ref_polling_pool_conf; - split_string(ref_polling_pool_conf[0],',',polled_devs); - int nb_polled_devs = polled_devs.size(); - -// Add a device into device server and restart it -// Also add property to poll one of the device attribute - - DbDevInfo my_device_info; - string new_dev("test/"); - new_dev = new_dev + inst_name + "/77"; - - my_device_info.name = new_dev.c_str(); - my_device_info._class = TEST_CLASS; - string serv_name(TEST_CLASS); - serv_name = serv_name + '/' + inst_name; - my_device_info.server = serv_name.c_str(); - - db->add_device(my_device_info); - - DbDatum poll_prop("polled_attr"); - vector poll_param; - poll_param.push_back("PollLong_attr"); - poll_param.push_back("1000"); - poll_prop << poll_param; - DbData db_poll; - db_poll.push_back(poll_prop); - db->put_device_property(new_dev.c_str(),db_poll); - - admin_dev_name = admin_dev_name + serv_name; - - admin_dev = new DeviceProxy(admin_dev_name); - admin_dev->command_inout("RestartServer"); - - Tango_sleep(5); - -// Read polling threads pool conf once more - - DeviceData da; - - da = dev.command_inout("PollingPoolTst"); - vector new_polling_pool_conf; - da >> new_polling_pool_conf; - - assert (ref_polling_pool_conf.size() == new_polling_pool_conf.size()); - split_string(new_polling_pool_conf[0],',',polled_devs); - int new_nb_polled_devs = polled_devs.size(); - - assert (new_nb_polled_devs == nb_polled_devs + 1); - vector::iterator iter; - iter = find(polled_devs.begin(),polled_devs.end(),new_dev); - - assert (iter != polled_devs.end()); - - cout << " Add one device to a polling thread pool with 1 thread --> OK" << endl; - -// Change polling thread number and add 2 more devices - - string new_dev1_th2 = "test/"; - new_dev1_th2 = new_dev1_th2 + inst_name + "/800"; - - my_device_info.name = new_dev1_th2.c_str(); - db->add_device(my_device_info); - - string new_dev2_th2 = "test/"; - new_dev2_th2 = new_dev2_th2 + inst_name + "/801"; - - my_device_info.name = new_dev2_th2.c_str(); - db->add_device(my_device_info); - - DbDatum pool_size("polling_threads_pool_size"); - DbData db_data; - - pool_size << 2L; - db_data.push_back(pool_size); - db->put_device_property(admin_dev_name.c_str(),db_data); - - db->put_device_property(new_dev1_th2.c_str(),db_poll); - db->put_device_property(new_dev2_th2.c_str(),db_poll); - - admin_dev->command_inout("RestartServer"); - - Tango_sleep(5); - -// Check new pool conf - - DeviceData dz; - - dz = dev.command_inout("PollingPoolTst"); - dz >> new_polling_pool_conf; - - assert (new_polling_pool_conf.size() == ref_polling_pool_conf.size() + 1); - split_string(new_polling_pool_conf[1],',',polled_devs); - new_nb_polled_devs = polled_devs.size(); - - assert (new_nb_polled_devs == 2); - - iter = find(polled_devs.begin(),polled_devs.end(),new_dev1_th2); - assert (iter != polled_devs.end()); - - iter = find(polled_devs.begin(),polled_devs.end(),new_dev2_th2); - assert (iter != polled_devs.end()); - - cout << " Add two other devices to the polling threads pool with now 2 threads --> OK" << endl; - -// Change polling thread number to 3 and add 1 more device - - string new_dev1_th3 = "test/"; - new_dev1_th3 = new_dev1_th3 + inst_name + "/9000"; - - my_device_info.name = new_dev1_th3.c_str(); - db->add_device(my_device_info); - - DbDatum pool_size3("polling_threads_pool_size"); - DbData db_data3; - - pool_size3 << 3L; - db_data3.push_back(pool_size3); - db->put_device_property(admin_dev_name.c_str(),db_data3); - - db->put_device_property(new_dev1_th3.c_str(),db_poll); - - admin_dev->command_inout("RestartServer"); - - Tango_sleep(5); - -// Check new pool conf - - DeviceData dx; - - dx = dev.command_inout("PollingPoolTst"); - dx >> new_polling_pool_conf; - - assert (new_polling_pool_conf.size() == ref_polling_pool_conf.size() + 2); - split_string(new_polling_pool_conf[2],',',polled_devs); - new_nb_polled_devs = polled_devs.size(); - - assert (new_nb_polled_devs == 1); - - iter = find(polled_devs.begin(),polled_devs.end(),new_dev1_th3); - assert (iter != polled_devs.end()); - - cout << " Add one device to the polling threads pool with now 3 threads --> OK" << endl; - -// Delete one device to check automatic polling pool re-configuration - - db->delete_device(new_dev1_th3); - - admin_dev->command_inout("RestartServer"); - - Tango_sleep(5); - -// Check pool conf - - DeviceData dv; - - dv = dev.command_inout("PollingPoolTst"); - dv >> new_polling_pool_conf; - - assert (new_polling_pool_conf.size() == ref_polling_pool_conf.size() + 1); - split_string(new_polling_pool_conf[1],',',polled_devs); - new_nb_polled_devs = polled_devs.size(); - - assert (new_nb_polled_devs == 2); - - iter = find(polled_devs.begin(),polled_devs.end(),new_dev1_th2); - assert (iter != polled_devs.end()); - - iter = find(polled_devs.begin(),polled_devs.end(),new_dev2_th2); - assert (iter != polled_devs.end()); - - cout << " Automatic polling threads pool reconfig after device removal --> OK" << endl; - - reset_device_server(db,ref_polling_pool_conf,admin_dev_name,admin_dev,inst_name,dev2); - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - reset_device_server(db,ref_polling_pool_conf,admin_dev_name,admin_dev,inst_name,dev2); - exit(-1); - } - - delete db; - delete admin_dev; - delete dev2; - return 0; -} - -// -// Split a string according to a delimiter character -// - -void split_string(string &the_str,char delim,vector &splitted_str) -{ - string::size_type pos,start; - splitted_str.clear(); - - start = 0; - while ((pos = the_str.find(delim,start)) != string::npos) - { - splitted_str.push_back(the_str.substr(start,pos - start)); - start = pos + 1; - } - - splitted_str.push_back(the_str.substr(start)); -} - - -void del_device_no_error(Database *db,const char *d_name) -{ - try - { - db->delete_device(d_name); - } - catch (DevFailed &) {} -} - -// -// Reset device server to default conf -// - -void reset_device_server(Database *db,vector &polling_pool_conf,string &admin_dev_name,DeviceProxy *adm_dev,string &inst_name,DeviceProxy *dev2) -{ - string base_name("test/"); - base_name = base_name + inst_name; - - string dev_name = base_name + "/77"; - del_device_no_error(db,dev_name.c_str()); - - dev_name = base_name + "/800"; - del_device_no_error(db,dev_name.c_str()); - - dev_name = base_name + "/801"; - del_device_no_error(db,dev_name.c_str()); - - dev_name = base_name + "/9000"; - del_device_no_error(db,dev_name.c_str()); - - DbDatum pool_conf("polling_threads_pool_conf"); - DbData db_data; - - pool_conf << polling_pool_conf; - db_data.push_back(pool_conf); - db->put_device_property(admin_dev_name.c_str(),db_data); - - DbDatum del_prop("polling_threads_pool_size"); - db_data.clear(); - db_data.push_back(del_prop); - db->delete_device_property(admin_dev_name.c_str(),db_data); - - try - { - dev2->stop_poll_attribute("PollLong_attr"); - } - catch(DevFailed &) {} - - adm_dev->command_inout("RestartServer"); - - Tango_sleep(3); -} diff --git a/cpp_test_suite/old_tests/read_hist.cpp b/cpp_test_suite/old_tests/read_hist.cpp deleted file mode 100644 index 7faa4c94b..000000000 --- a/cpp_test_suite/old_tests/read_hist.cpp +++ /dev/null @@ -1,657 +0,0 @@ -/* - * example of a client using the TANGO device api. - */ - -#include -#include - -#include - -typedef enum -{ - FIRST_EXCEPT = 0, - SECOND_EXCEPT, - FIRST_DATA, - SECOND_DATA -}AttrResult; - -typedef enum -{ - EXCEPT = 0, - FIRST_STR, - SECOND_STR -}CmdResult; - -using namespace Tango; -using namespace std; - -int main(int argc, char **argv) -{ - DeviceProxy *device; - - if (argc < 2) - { - cout << "usage: %s device [-v]" << endl; - exit(-1); - } - - string device_name = argv[1]; - bool print = false; - - if (argc == 3) - { - string verb = argv[2]; - if (verb != "-v") - { - cout << "Usage: %s device [-v]" << endl; - exit(-1); - } - else - print = true; - } - - try - { - device = new DeviceProxy(device_name); - } - catch (CORBA::Exception &e) - { - Except::print_exception(e); - exit(1); - } - - cout << endl << "new DeviceProxy(" << device->name() << ") returned" << endl << endl; - - unsigned int i; - vector *d_hist; - - try - { - -// Test command_history (for strings) - - int hist_depth = 10; - d_hist = device->command_history("IOPollStr1",hist_depth); - - if (d_hist->size() < 4) - { - cout << "Not enought data in polling buffer, restart later" << endl; - exit(-1); - } - - CmdResult cr; - - if ((*d_hist)[0].has_failed() == true) - { - cr = EXCEPT; - } - else - { - string str; - (*d_hist)[0] >> str; - if (str[0] == 'E') - cr = FIRST_STR; - else - cr = SECOND_STR; - } - - for (i = 0;i < d_hist->size();i++) - { - string str; - if ((*d_hist)[i].has_failed() == false) - (*d_hist)[i] >> str; - - if (print == true) - { - cout << "Command failed = " << (*d_hist)[i].has_failed() << endl; - if ((*d_hist)[i].has_failed() == false) - { - (*d_hist)[i] >> str; - cout << "Value = " << str << endl; - } - TimeVal &t = (*d_hist)[i].get_date(); - cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; - cout << "Error stack depth = " << (*d_hist)[i].get_err_stack().length() << endl; - cout << endl; - } - } - - DevErrorList del; - string simple_str; - - switch(cr) - { - case EXCEPT: - assert( (*d_hist)[0].has_failed() == true); - assert( (*d_hist)[0].get_err_stack().length() == 1); - del = (*d_hist)[0].get_err_stack(); - assert( ::strcmp(del[0].desc.in(),"www") == 0); - - (*d_hist)[1] >> simple_str; - assert( (*d_hist)[1].has_failed() == false); - assert( (*d_hist)[1].get_err_stack().length() == 0); - assert( simple_str == "Even value from IOPollStr1"); - - (*d_hist)[2] >> simple_str; - assert( (*d_hist)[2].has_failed() == false); - assert( (*d_hist)[2].get_err_stack().length() == 0); - assert( simple_str == "Odd value from IOPollStr1"); - break; - - case FIRST_STR: - (*d_hist)[0] >> simple_str; - assert( (*d_hist)[0].has_failed() == false); - assert( (*d_hist)[0].get_err_stack().length() == 0); - assert( simple_str == "Even value from IOPollStr1"); - - (*d_hist)[1] >> simple_str; - assert( (*d_hist)[1].has_failed() == false); - assert( (*d_hist)[1].get_err_stack().length() == 0); - assert( simple_str == "Odd value from IOPollStr1"); - - assert( (*d_hist)[2].has_failed() == true); - assert( (*d_hist)[2].get_err_stack().length() == 1); - del = (*d_hist)[2].get_err_stack(); - assert( ::strcmp(del[0].desc.in(),"www") == 0); - break; - - case SECOND_STR: - (*d_hist)[0] >> simple_str; - assert( (*d_hist)[0].has_failed() == false); - assert( (*d_hist)[0].get_err_stack().length() == 0); - assert( simple_str == "Odd value from IOPollStr1"); - - assert( (*d_hist)[1].has_failed() == true); - assert( (*d_hist)[1].get_err_stack().length() == 1); - del = (*d_hist)[1].get_err_stack(); - assert( ::strcmp(del[0].desc.in(),"www") == 0); - - (*d_hist)[2] >> simple_str; - assert( (*d_hist)[2].has_failed() == false); - assert( (*d_hist)[2].get_err_stack().length() == 0); - assert( simple_str == "Even value from IOPollStr1"); - break; - } - - delete d_hist; - - cout << " Read command history (string) --> OK" << endl; - -// Test command_history (array) - - d_hist = device->command_history("IOPollArray2",hist_depth); - - if (d_hist->size() < 4) - { - cout << "Not enought data in polling buffer, retry later" << endl; - exit(-1); - } - - short first_val_first_rec; - for (i = 0;i < d_hist->size();i++) - { - vector vect; - (*d_hist)[i] >> vect; - - if (print == true) - { - cout << "Command failed = " << (*d_hist)[i].has_failed() << endl; - cout << "Value 0 = " << vect[0] << ", Value 1 = " << vect[1] << endl; - TimeVal &t = (*d_hist)[i].get_date(); - cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; - cout << "Error stack depth = " << (*d_hist)[i].get_err_stack().length() << endl; - cout << endl; - } - - if (i == 0) - first_val_first_rec = vect[0]; - - assert( (*d_hist)[i].has_failed() == false); - assert( (*d_hist)[i].get_err_stack().length() == 0); - if (i != 0) - { - if (first_val_first_rec == 100) - { - if ((i % 2) == 0) - { - assert( vect[0] == 100 ); - assert( vect[1] == 200 ); - } - else - { - assert( vect[0] == 300 ); - assert( vect[1] == 400 ); - } - } - else - { - if ((i % 2) == 0) - { - assert( vect[0] == 300); - assert( vect[1] == 400); - } - else - { - assert( vect[0] == 100 ); - assert( vect[1] == 200 ); - } - } - } - } - delete d_hist; - - cout << " Read command history (array) --> OK" << endl; - -// Test command_history with exception - - d_hist = device->command_history("IOExcept",hist_depth); - - for (i = 0;i < d_hist->size();i++) - { - if (print == true) - { - cout << "Command failed = " << (*d_hist)[i].has_failed() << endl; - TimeVal &t = (*d_hist)[i].get_date(); - cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; - cout << "Error stack depth = " << (*d_hist)[i].get_err_stack().length() << endl; - cout << endl; - } - - assert( (*d_hist)[i].has_failed() == true); - assert( (*d_hist)[i].get_err_stack().length() == 1); - assert( !strcmp((*d_hist)[i].get_err_stack()[0].reason ,"API_ThrowException") ); - } - delete d_hist; - - cout << " Read command history with exception --> OK" << endl; - -// Test command_history for State - - d_hist = device->command_history("State",hist_depth); - - for (i = 0;i < d_hist->size();i++) - { - if (print == true) - { - cout << (*d_hist)[i] << endl; - } - - assert( (*d_hist)[i].has_failed() == false); - assert( (*d_hist)[i].get_err_stack().length() == 0); - Tango::DevState ds; - (*d_hist)[i] >> ds; - assert( ds == Tango::ON ); - } - delete d_hist; - - cout << " Read command history (State) --> OK" << endl; - -// Test command_history for Status - - d_hist = device->command_history("Status",hist_depth); - - for (i = 0;i < d_hist->size();i++) - { - if (print == true) - { - cout << (*d_hist)[i] << endl; - } - - assert( (*d_hist)[i].has_failed() == false); - assert( (*d_hist)[i].get_err_stack().length() == 0); - string str; - (*d_hist)[i] >> str; - assert( ::strcmp(str.c_str(),"The device is in ON state.") == 0 ); - } - delete d_hist; - - cout << " Read command history (Status) --> OK" << endl; - -// Test command_history (DevEncoded) - - d_hist = device->command_history("OEncoded",hist_depth); - - if (d_hist->size() < 4) - { - cout << "Not enought data in polling buffer, retry later" << endl; - exit(-1); - } - - unsigned char first_val_enc; - for (i = 0;i < d_hist->size();i++) - { - DevEncoded the_enc; - (*d_hist)[i] >> the_enc; - - if (print == true) - { - cout << "Command failed = " << (*d_hist)[i].has_failed() << endl; - cout << "Encoded_format = " << the_enc.encoded_format << endl; - for (unsigned int ii = 0;ii < the_enc.encoded_data.length();++ii) - cout << "Encoded_data = " << (int)the_enc.encoded_data[ii] << endl; - TimeVal &t = (*d_hist)[i].get_date(); - cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; - cout << "Error stack depth = " << (*d_hist)[i].get_err_stack().length() << endl; - cout << endl; - } - - assert( (*d_hist)[i].has_failed() == false); - assert( (*d_hist)[i].get_err_stack().length() == 0); - - if (i == 0) - first_val_enc = the_enc.encoded_data[0]; - - if ((i % 2) == 0) - { - if (first_val_enc == 11) - { - assert (!strcmp(the_enc.encoded_format,"Odd - OEncoded format")); - assert (the_enc.encoded_data.length() == 2); - assert (the_enc.encoded_data[0] == 11); - assert (the_enc.encoded_data[1] == 21); - } - else - { - assert (!strcmp(the_enc.encoded_format,"Even - OEncoded format")); - assert (the_enc.encoded_data[0] == 10); - assert (the_enc.encoded_data[1] == 20); - assert (the_enc.encoded_data[2] == 30); - assert (the_enc.encoded_data[3] == 40); - } - } - else - { - if (first_val_enc == 11) - { - assert (!strcmp(the_enc.encoded_format,"Even - OEncoded format")); - assert (the_enc.encoded_data[0] == 10); - assert (the_enc.encoded_data[1] == 20); - assert (the_enc.encoded_data[2] == 30); - assert (the_enc.encoded_data[3] == 40); - } - else - { - assert (!strcmp(the_enc.encoded_format,"Odd - OEncoded format")); - assert (the_enc.encoded_data.length() == 2); - assert (the_enc.encoded_data[0] == 11); - assert (the_enc.encoded_data[1] == 21); - } - } - } - delete d_hist; - - cout << " Read command history (DevEncoded) --> OK" << endl; - -// Test attribute_history (for long) - - vector *a_hist; - hist_depth = 10; - a_hist = device->attribute_history("PollLong_attr",hist_depth); - - DevLong first_val; - for (i = 0;i < a_hist->size();i++) - { - DevLong lo; - (*a_hist)[i] >> lo; - - if (i == 0) - first_val = lo; - - if (print == true) - { - cout << "Attribute failed = " << (*a_hist)[i].has_failed() << endl; - cout << "Value = " << lo << endl; - TimeVal &t = (*a_hist)[i].get_date(); - cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; - cout << "Error stack depth = " << (*a_hist)[i].get_err_stack().length() << endl; - cout << endl; - } - - assert( (*a_hist)[i].has_failed() == false); - assert( (*a_hist)[i].get_err_stack().length() == 0); - - assert ( (*a_hist)[i].get_dim_x() == 1); - assert ( (*a_hist)[i].get_dim_y() == 0); - - if (first_val == 5555) - { - if ((i % 2) == 0) - assert( lo == 5555 ); - else - assert( lo == 6666 ); - } - else - { - if ((i % 2) == 0) - assert( lo == 6666 ); - else - assert( lo == 5555 ); - } - } - delete a_hist; - - cout << " Read attribute history (long) --> OK" << endl; - -// Test attribute_history (for strings spectrum) - - a_hist = device->attribute_history("PollString_spec_attr",hist_depth); - - string first_string; - AttrResult ar; - - vector str; - - if ((*a_hist)[0].has_failed() == true) - { - if (::strcmp(((*a_hist)[0].get_err_stack())[0].reason.in(),"aaaa") == 0) - ar = FIRST_EXCEPT; - else - ar = SECOND_EXCEPT; - } - else - { - (*a_hist)[0] >> str; - if (str.size() == 2) - ar = FIRST_DATA; - else - ar = SECOND_DATA; - } - - for (i = 0;i < a_hist->size();i++) - { - if (print == true) - { - cout << "Attribute failed = " << (*a_hist)[i].has_failed() << endl; - TimeVal &t = (*a_hist)[i].get_date(); - cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; - if ((*a_hist)[i].has_failed() == false) - { - (*a_hist)[i] >> str; - cout << "Value = " << str[0]; - if (str.size() == 2) - cout << ", Value = " << str[1]; - cout << endl; - } - else - { - cout << "Error stack depth = " << (*a_hist)[i].get_err_stack().length() << endl; - cout << "Error level 0 reason = " << ((*a_hist)[i].get_err_stack())[0].reason << endl; - cout << "Error level 0 desc = " << ((*a_hist)[i].get_err_stack())[0].desc << endl; - } - cout << endl; - } - } - - switch(ar) - { - case FIRST_EXCEPT: - assert( (*a_hist)[0].has_failed() == true ); - assert( (*a_hist)[0].get_err_stack().length() == 1); - assert( ::strcmp(((*a_hist)[0].get_err_stack())[0].desc.in(),"bbb") == 0 ); - assert( ::strcmp(((*a_hist)[0].get_err_stack())[0].reason.in(),"aaaa") == 0 ); - - assert( (*a_hist)[1].has_failed() == true ); - assert( (*a_hist)[1].get_err_stack().length() == 1); - assert( ::strcmp(((*a_hist)[1].get_err_stack())[0].desc.in(),"yyy") == 0 ); - assert( ::strcmp(((*a_hist)[1].get_err_stack())[0].reason.in(),"xxx") == 0 ); - - (*a_hist)[2] >> str; - assert( str.size() == 2 ); - assert( str[0] == "Hello world" ); - assert( str[1] == "Hello universe"); - - (*a_hist)[3] >> str; - assert( str.size() == 1 ); - assert( str[0] == "Hello Grenoble" ); - break; - - case SECOND_EXCEPT: - assert( (*a_hist)[0].has_failed() == true ); - assert( (*a_hist)[0].get_err_stack().length() == 1); - assert( ::strcmp(((*a_hist)[0].get_err_stack())[0].desc.in(),"yyy") == 0 ); - assert( ::strcmp(((*a_hist)[0].get_err_stack())[0].reason.in(),"xxx") == 0 ); - - (*a_hist)[1] >> str; - assert( str.size() == 2 ); - assert( str[0] == "Hello world" ); - assert( str[1] == "Hello universe"); - - (*a_hist)[2] >> str; - assert( str.size() == 1 ); - assert( str[0] == "Hello Grenoble" ); - - assert( (*a_hist)[3].has_failed() == true ); - assert( (*a_hist)[3].get_err_stack().length() == 1); - assert( ::strcmp(((*a_hist)[3].get_err_stack())[0].desc.in(),"bbb") == 0 ); - assert( ::strcmp(((*a_hist)[3].get_err_stack())[0].reason.in(),"aaaa") == 0 ); - break; - - case FIRST_DATA: - (*a_hist)[0] >> str; - assert( str.size() == 2 ); - assert( str[0] == "Hello world" ); - assert( str[1] == "Hello universe"); - - (*a_hist)[1] >> str; - assert( str.size() == 1 ); - assert( str[0] == "Hello Grenoble" ); - - assert( (*a_hist)[2].has_failed() == true ); - assert( (*a_hist)[2].get_err_stack().length() == 1); - assert( ::strcmp(((*a_hist)[2].get_err_stack())[0].desc.in(),"bbb") == 0 ); - assert( ::strcmp(((*a_hist)[2].get_err_stack())[0].reason.in(),"aaaa") == 0 ); - - assert( (*a_hist)[3].has_failed() == true ); - assert( (*a_hist)[3].get_err_stack().length() == 1); - assert( ::strcmp(((*a_hist)[3].get_err_stack())[0].desc.in(),"yyy") == 0 ); - assert( ::strcmp(((*a_hist)[3].get_err_stack())[0].reason.in(),"xxx") == 0 ); - break; - - case SECOND_DATA: - (*a_hist)[0] >> str; - assert( str.size() == 1 ); - assert( str[0] == "Hello Grenoble" ); - - assert( (*a_hist)[1].has_failed() == true ); - assert( (*a_hist)[1].get_err_stack().length() == 1); - assert( ::strcmp(((*a_hist)[1].get_err_stack())[0].desc.in(),"bbb") == 0 ); - assert( ::strcmp(((*a_hist)[1].get_err_stack())[0].reason.in(),"aaaa") == 0 ); - - assert( (*a_hist)[2].has_failed() == true ); - assert( (*a_hist)[2].get_err_stack().length() == 1); - assert( ::strcmp(((*a_hist)[2].get_err_stack())[0].desc.in(),"yyy") == 0 ); - assert( ::strcmp(((*a_hist)[2].get_err_stack())[0].reason.in(),"xxx") == 0 ); - - (*a_hist)[3] >> str; - assert( str.size() == 2 ); - assert( str[0] == "Hello world" ); - assert( str[1] == "Hello universe"); - break; - } - delete a_hist; - - cout << " Read attribute history (string spectrum) --> OK" << endl; - -// Test attribute_history (for DevEncoded) - -#ifndef COMPAT - vector *enc_hist; - hist_depth = 10; - enc_hist = device->attribute_history("Encoded_attr",hist_depth); - - for (i = 0;i < enc_hist->size();i++) - { - - if (print == true) - { - cout << "Value = " << (*enc_hist)[i] << endl; - cout << endl; - } - - assert( (*enc_hist)[i].has_failed() == false); - assert( (*enc_hist)[i].get_err_stack().length() == 0); - - assert ( (*enc_hist)[i].get_dim_x() == 1); - assert ( (*enc_hist)[i].get_dim_y() == 0); - - DevEncoded enc; - (*enc_hist)[i] >> enc; - - assert (::strcmp(enc.encoded_format,"Which format?") == 0); - assert (enc.encoded_data[0] == 97); - assert (enc.encoded_data[1] == 98); - assert (enc.encoded_data[2] == 99); - assert (enc.encoded_data[3] == 100); - } - delete enc_hist; - - cout << " Read attribute history (DevEncoded) --> OK" << endl; -#endif - -// Test attribute_history with exception - - a_hist = device->attribute_history("attr_wrong_type",hist_depth); - - for (i = 0;i < a_hist->size();i++) - { - if (print == true) - { - cout << "Command failed = " << (*a_hist)[i].has_failed() << endl; - TimeVal &t = (*a_hist)[i].get_date(); - cout << "Date : " << t.tv_sec << " sec, " << t.tv_usec << " usec" << endl; - cout << "Error stack depth = " << (*a_hist)[i].get_err_stack().length() << endl; - cout << "Error level 0 reason = " << ((*a_hist)[i].get_err_stack())[0].reason << endl; - cout << "Error level 0 desc = " << ((*a_hist)[i].get_err_stack())[0].desc << endl; - cout << endl; - } - - assert( (*a_hist)[i].has_failed() == true); - assert( (*a_hist)[i].get_err_stack().length() == 1); - assert( !strcmp((*a_hist)[i].get_err_stack()[0].reason ,"API_AttrOptProp") ); -// AttributeDimension dim; -// dim = (*a_hist)[i].get_r_dimension(); - - assert ( (*a_hist)[i].get_dim_x() == 0); - assert ( (*a_hist)[i].get_dim_y() == 0); - -// dim = (*a_hist)[i].get_w_dimension(); - -// assert ( dim.dim_x == 0); -// assert ( dim.dim_y == 0); - - } - delete a_hist; - - cout << " Read attribute history with exception --> OK" << endl; - - } - catch (Tango::DevFailed &e) - { - Except::print_exception(e); - exit(-1); - } - - - delete device; - return 0; -} diff --git a/cpp_test_suite/old_tests/test_polling.sh.cmake b/cpp_test_suite/old_tests/test_polling.sh.cmake deleted file mode 100644 index dd27bc181..000000000 --- a/cpp_test_suite/old_tests/test_polling.sh.cmake +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -check_return_value () { -if [ $1 != "0" ] -then - echo "Polling Test Suite has FAILED !!!!!!!!!!!!!!!!!!" - echo "Leaving test suite, try to fix it" - date - sleep 120 - date - ./StopPoll @DEV1@ - exit -1 -fi -} - -./Poll @DEV1@ -ret=$? -check_return_value $ret - -sleep 7 - -echo "Testing command_history and attribute_history DeviceProxy methods" -./read_hist @DEV1@ -ret=$? -check_return_value $ret - -echo "Testing polling of new attribute data types" -./poll_attr @DEV1@ -ret=$? -check_return_value $ret - -echo "Testing all DeviceProxy polling methods" -./poll_met @DEV1@ @DEV2@ @DEV1_ALIAS@ -ret=$? -check_return_value $ret - -echo "Testing polling threads pool" -./poll_pool @DEV1@ @DEV2@ @INST_NAME@ -ret=$? -check_return_value $ret - -./StopPoll @DEV1@ \ No newline at end of file