Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions CTestCustom.cmake
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[DRAFT]

# Prerequisites

* tango-idl
* docker (for tests)

# How to install

- clone
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<desired installation path>] [-DOMNI_BASE=<omniORB4 home folder>] [-DZMQ_BASE=<zmq home folder>] [-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)
6 changes: 3 additions & 3 deletions cpp_test_ds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
5 changes: 3 additions & 2 deletions cpp_test_suite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -16,11 +16,12 @@ 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 $<TARGET_FILE:${test}> ${DEV1})
add_test(NAME "CPP::${test}" COMMAND $<TARGET_FILE:${test}> ${DEV1} ${DEV2} ${DEV3} ${DEV1_ALIAS})
endmacro()

add_subdirectory(asyn)
add_subdirectory(event)
add_subdirectory(old_tests)
add_subdirectory(new_tests)
add_subdirectory(cxxtest)
add_subdirectory(environment)
6 changes: 3 additions & 3 deletions cpp_test_suite/asyn/asyn_faf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 11 additions & 11 deletions cpp_test_suite/asyn/asyn_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
20 changes: 20 additions & 0 deletions cpp_test_suite/environment/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions cpp_test_suite/environment/post_test.sh.cmake
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions cpp_test_suite/environment/pre_test.sh.cmake
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions cpp_test_suite/environment/run.sh.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
source tango_host
echo "TANGO_HOST=$TANGO_HOST"
@CMAKE_CTEST_COMMAND@ -V
36 changes: 36 additions & 0 deletions cpp_test_suite/environment/setup.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions cpp_test_suite/environment/shutdown.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions cpp_test_suite/environment/tango_host.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
export TANGO_HOST=@TANGO_HOST@
4 changes: 2 additions & 2 deletions cpp_test_suite/event/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(TESTS archive_event
event_lock
multi_event
pipe_event
reco_svc
# reco_svc
scan
state_event
user_event
Expand All @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions cpp_test_suite/new_tests/conf_devtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
//
Expand Down