diff --git a/CMakeLists.txt b/CMakeLists.txt index e8259e842..ab244cf54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8) project(libtango) include(CTest) +configure_file(CTestCustom.cmake CTestCustom.cmake) enable_testing() #need to define the version of the library set(MAJOR_VERSION "9") diff --git a/CTestCustom.cmake b/CTestCustom.cmake new file mode 100644 index 000000000..3dcfb9b33 --- /dev/null +++ b/CTestCustom.cmake @@ -0,0 +1,2 @@ +set(CTEST_CUSTOM_PRE_TEST ${PROJECT_BINARY_DIR}/cpp_test_suite/environment/pre_test.sh) +set(CTEST_CUSTOM_POST_TEST ${PROJECT_BINARY_DIR}/cpp_test_suite/environment/post_test.sh) \ No newline at end of file diff --git a/INSTALL.md b/INSTALL.md index 41943e7e0..b7584b497 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,5 +1,10 @@ [DRAFT] +# Prerequisites + +* tango-idl +* docker (for tests) + # How to install - clone diff --git a/README.md b/README.md index 0e9b5f043..d376c273c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,45 @@ This repository is the result of svn2git migration of tango source code. It is c `mkdir build; cd build; cmake .. [-DCMAKE_INSTALL_PREFIX=] [-DOMNI_BASE=] [-DZMQ_BASE=] [-DCMAKE_BUILD_TYPE=RELEASE|DEBUG] [-DCMAKE_VERBOSE_MAKEFILE=true]; make; make install` +# How to test + +## With docker provided TANGO environment + +### 1. First build everything + + `mkdir build; cd build; cmake ..; make` + +### 2. Start TANGO environment + + `make start-tango` + + Typical output: +Note env.TANGO_HOST value: this is normal TANGO_HOST that can be used, for instance, in Jive + +``` +Setup test environment + 174fda8cad89ac457a6129c599368d2842547575eac05f1d9b4ad60966cf0018 + CONTAINER=6130013cf55d420552df9dddd488b7564d58f49d10831d4880774443faf1a22b + TANGO_HOST=172.17.0.3:10000 + Create tango_host file + Wait till tango-cs is online +``` + +### 3. Run tests + `make run-tests` + + Before running tests CTest runs conf_devtest (located in cpp_test_suite/new_tests) and starts DevTest and FwdTest device servers (located in cpp_test_ds) + +### 4. Shutdown TANGO environment + `make stop-tango` + +## Without docker provided TANGO environment +One can setup TANGO environment on the local machine manually. In this case CTest can be used directly: + +`ctest -V` + +See [CTest guide](https://cmake.org/Wiki/CMake/Testing_With_CTest) + # Links [Tango Controls web page](http://tango-controls.org) \ No newline at end of file diff --git a/cpp_test_ds/CMakeLists.txt b/cpp_test_ds/CMakeLists.txt index f13723ebc..f2066e622 100644 --- a/cpp_test_ds/CMakeLists.txt +++ b/cpp_test_ds/CMakeLists.txt @@ -18,6 +18,6 @@ set(SOURCES main.cpp add_subdirectory(fwd_ds) -add_executable(devTest ${SOURCES}) -target_include_directories(devTest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(devTest PUBLIC tango ${CMAKE_DL_LIBS}) +add_executable(DevTest ${SOURCES}) +target_include_directories(DevTest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(DevTest PUBLIC tango ${CMAKE_DL_LIBS}) diff --git a/cpp_test_suite/CMakeLists.txt b/cpp_test_suite/CMakeLists.txt index 3a3964f1e..fb4bc165f 100644 --- a/cpp_test_suite/CMakeLists.txt +++ b/cpp_test_suite/CMakeLists.txt @@ -3,7 +3,7 @@ set(DEV1 "test/debian8/10") set(DEV2 "test/debian8/11") set(DEV3 "test/debian8/12") set(FWD_DEV "test/fwd_debian8/10") -set(SERV_NAME "devTest") +set(SERV_NAME "DevTest") set(INST_NAME "debian8") set(DEV1_ALIAS "debian8_alias") set(ATTR_ALIAS "debian8_attr_alias") @@ -16,7 +16,7 @@ macro(TEST_SUITE_ADD_TEST test) target_compile_definitions(${test} PUBLIC "-DVALGRIND -D_PTHREADS -D_REENTRANT") # target_include_directories(${test} PUBLIC ../cxxtest/include) target_link_libraries(${test} tango ${CMAKE_DL_LIBS}) - add_test(NAME "CPP::${test}" COMMAND $ ${DEV1}) + add_test(NAME "CPP::${test}" COMMAND $ ${DEV1} ${DEV2} ${DEV3} ${DEV1_ALIAS}) endmacro() add_subdirectory(asyn) @@ -24,3 +24,4 @@ add_subdirectory(event) add_subdirectory(old_tests) add_subdirectory(new_tests) add_subdirectory(cxxtest) +add_subdirectory(environment) \ No newline at end of file diff --git a/cpp_test_suite/asyn/asyn_faf.cpp b/cpp_test_suite/asyn/asyn_faf.cpp index fa0472c71..1a971a13c 100644 --- a/cpp_test_suite/asyn/asyn_faf.cpp +++ b/cpp_test_suite/asyn/asyn_faf.cpp @@ -39,9 +39,9 @@ int main(int argc, char **argv) long id; - char key; - cout << "Hit any key : "; - cin >> key; +// char key; +// cout << "Hit any key : "; +// cin >> key; id = device->command_inout_asynch("State",true); diff --git a/cpp_test_suite/asyn/asyn_thread.cpp b/cpp_test_suite/asyn/asyn_thread.cpp index 511348781..83de10544 100644 --- a/cpp_test_suite/asyn/asyn_thread.cpp +++ b/cpp_test_suite/asyn/asyn_thread.cpp @@ -43,29 +43,29 @@ int main(int argc, char **argv) // Start callback thread // - char key; - cout << "Hit any key "; - cin >> key; +// char key; +// cout << "Hit any key "; +// cin >> key; au->set_asynch_cb_sub_model(PUSH_CALLBACK); - cout << "Hit any key "; - cin >> key; +// cout << "Hit any key "; +// cin >> key; au->set_asynch_cb_sub_model(PULL_CALLBACK); - cout << "Hit any key "; - cin >> key; +// cout << "Hit any key "; +// cin >> key; au->set_asynch_cb_sub_model(PUSH_CALLBACK); - cout << "Hit any key "; - cin >> key; +// cout << "Hit any key "; +// cin >> key; au->set_asynch_cb_sub_model(PULL_CALLBACK); - cout << "Hit any key "; - cin >> key; +// cout << "Hit any key "; +// cin >> key; } catch (Tango::DevFailed &e) { diff --git a/cpp_test_suite/environment/CMakeLists.txt b/cpp_test_suite/environment/CMakeLists.txt new file mode 100644 index 000000000..40eeeb7c3 --- /dev/null +++ b/cpp_test_suite/environment/CMakeLists.txt @@ -0,0 +1,20 @@ +#TODO windows +message("System TANGO_HOST=$ENV{TANGO_HOST}") +set(TANGO_HOST $ENV{TANGO_HOST}) +configure_file(tango_host.cmake ${PROJECT_BINARY_DIR}/tango_host @ONLY) + +configure_file(pre_test.sh.cmake pre_test.sh @ONLY) +configure_file(post_test.sh.cmake post_test.sh @ONLY) + +add_custom_target(start-tango ${CMAKE_CURRENT_SOURCE_DIR}/setup.sh + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + SOURCES setup.sh) + +configure_file(run.sh.cmake run.sh @ONLY) +add_custom_target(run-tests ${CMAKE_CURRENT_BINARY_DIR}/run.sh + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + SOURCES run.sh.cmake) + +add_custom_target(stop-tango ${CMAKE_CURRENT_SOURCE_DIR}/shutdown.sh + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + SOURCES shutdown.sh) \ No newline at end of file diff --git a/cpp_test_suite/environment/post_test.sh.cmake b/cpp_test_suite/environment/post_test.sh.cmake new file mode 100644 index 000000000..16f419921 --- /dev/null +++ b/cpp_test_suite/environment/post_test.sh.cmake @@ -0,0 +1,9 @@ +#!/bin/bash + +#TODO Starter? + +PID=$(<@PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_@INST_NAME@.pid) +kill $PID + +PID=$(<@PROJECT_BINARY_DIR@/cpp_test_ds/fwd_ds/FwdTest_@INST_NAME@.pid) +kill $PID \ No newline at end of file diff --git a/cpp_test_suite/environment/pre_test.sh.cmake b/cpp_test_suite/environment/pre_test.sh.cmake new file mode 100644 index 000000000..4c6538e2c --- /dev/null +++ b/cpp_test_suite/environment/pre_test.sh.cmake @@ -0,0 +1,24 @@ +#!/bin/bash +source tango_host + +echo "TANGO_HOST=$TANGO_HOST" + +echo "Run conf_devtest" +@PROJECT_BINARY_DIR@/cpp_test_suite/new_tests/conf_devtest @SERV_NAME@/@INST_NAME@ @DEV1@ @DEV2@ @DEV3@ @DEV1_ALIAS@ @ATTR_ALIAS@ + +echo "Start DevTest" +echo "DevTest libraries:" +echo "`ldd @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest`" +#TODO Starter? +@PROJECT_BINARY_DIR@/cpp_test_ds/DevTest @INST_NAME@ -v6 1>@PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_@INST_NAME@.out 2>&1 & +echo $! > @PROJECT_BINARY_DIR@/cpp_test_ds/DevTest_@INST_NAME@.pid + +sleep 3 + +echo "Start FwdTest" +echo "FwdTest libraries:" +echo "`ldd @PROJECT_BINARY_DIR@/cpp_test_ds/fwd_ds/FwdTest`" +@PROJECT_BINARY_DIR@/cpp_test_ds/fwd_ds/FwdTest @INST_NAME@ -v6 1>@PROJECT_BINARY_DIR@/cpp_test_ds/fwd_ds/FwdTest_@INST_NAME@.out 2>&1 & +echo $! > @PROJECT_BINARY_DIR@/cpp_test_ds/fwd_ds/FwdTest_@INST_NAME@.pid + +sleep 3 \ No newline at end of file diff --git a/cpp_test_suite/environment/run.sh.cmake b/cpp_test_suite/environment/run.sh.cmake new file mode 100644 index 000000000..3aaeabb43 --- /dev/null +++ b/cpp_test_suite/environment/run.sh.cmake @@ -0,0 +1,4 @@ +#!/bin/bash +source tango_host +echo "TANGO_HOST=$TANGO_HOST" +@CMAKE_CTEST_COMMAND@ -V \ No newline at end of file diff --git a/cpp_test_suite/environment/setup.sh b/cpp_test_suite/environment/setup.sh new file mode 100644 index 000000000..3d7e6779d --- /dev/null +++ b/cpp_test_suite/environment/setup.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +echo "Setup test environment" + +#run mysql-tango docker +docker run --name mysql_db \ + -e MYSQL_ROOT_PASSWORD=root \ + -d tangocs/mysql:9.2.2 --sql-mode="" + +#run tango-cs docker +CONTAINER=$(docker run --name tango_cs \ + -e TANGO_HOST=127.0.0.1:10000 \ + -e MYSQL_HOST=mysql_db:3306 \ + -e MYSQL_USER=tango \ + -e MYSQL_PASSWORD=tango \ + -e MYSQL_DATABASE=tango \ + --link mysql_db:mysql_db \ + -d mliszcz/tango-cs:latest) + +echo "CONTAINER=$CONTAINER" + +IPADDR=$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' $CONTAINER) +#export TANGO_HOST +TANGO_HOST=$IPADDR:10000 +echo "TANGO_HOST=$TANGO_HOST" +export TANGO_HOST + +echo "Create tango_host file" +echo "#!/bin/bash" > tango_host +echo "export TANGO_HOST=$TANGO_HOST" >> tango_host + +echo "Wait till tango-cs is online" +#TODO notification? +sleep 30 + +#ctest \ No newline at end of file diff --git a/cpp_test_suite/environment/shutdown.sh b/cpp_test_suite/environment/shutdown.sh new file mode 100644 index 000000000..771151e52 --- /dev/null +++ b/cpp_test_suite/environment/shutdown.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +echo "Shutdown test environment" + +#kill tango-cs docker +docker stop tango_cs +docker rm tango_cs + +#kill mysql-tango docker +docker stop mysql_db +docker rm mysql_db + +echo "Revert tango_host file" +echo "TANGO_HOST=$TANGO_HOST" +echo "#!/bin/bash" > tango_host +echo "export TANGO_HOST=$TANGO_HOST" >> tango_host \ No newline at end of file diff --git a/cpp_test_suite/environment/tango_host.cmake b/cpp_test_suite/environment/tango_host.cmake new file mode 100644 index 000000000..3a38ccf06 --- /dev/null +++ b/cpp_test_suite/environment/tango_host.cmake @@ -0,0 +1,2 @@ +#!/bin/bash +export TANGO_HOST=@TANGO_HOST@ \ No newline at end of file diff --git a/cpp_test_suite/event/CMakeLists.txt b/cpp_test_suite/event/CMakeLists.txt index 8e778954d..854700fdd 100644 --- a/cpp_test_suite/event/CMakeLists.txt +++ b/cpp_test_suite/event/CMakeLists.txt @@ -7,7 +7,7 @@ set(TESTS archive_event event_lock multi_event pipe_event - reco_svc +# reco_svc scan state_event user_event @@ -19,7 +19,7 @@ set(TESTS archive_event dev_intr_event multi_dev_event per_event - reco_event +# reco_event reco_zmq server_event stateless_sub) diff --git a/cpp_test_suite/new_tests/conf_devtest.cpp b/cpp_test_suite/new_tests/conf_devtest.cpp index 52dbfb047..26445c8df 100644 --- a/cpp_test_suite/new_tests/conf_devtest.cpp +++ b/cpp_test_suite/new_tests/conf_devtest.cpp @@ -53,6 +53,33 @@ int main(int argc, char **argv) DbDevInfos db_dev_infos; DbDevInfo db_dev_info_1, db_dev_info_2, db_dev_info_3; + //Define device server + str = dserver_name; + db_dev_info_1.name = device1_name; + db_dev_info_1._class = CLASS_NAME; + db_dev_info_2.name = device2_name; + db_dev_info_2._class = CLASS_NAME; + db_dev_info_3.name = device3_name; + db_dev_info_3._class = CLASS_NAME; + db_dev_infos.push_back(db_dev_info_1); + db_dev_infos.push_back(db_dev_info_2); + db_dev_infos.push_back(db_dev_info_3); + + try + { + db->add_server(str, db_dev_infos); + for(size_t i = 0; i < db_dev_infos.size(); i++) + cout << "Added test server : " << str << " -> " << db_dev_infos[i].name << ", class : " << db_dev_infos[i]._class << endl; + cout << endl; + } + catch(...) + { + cout << "Exception: cannot create test server" << endl; + } + + + db_dev_infos.clear(); + // // DsCache/test pseudo server (creation & properties) //