From fef0ebcc88b49a08e9ff27d134048a821e536636 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Wed, 27 May 2015 11:22:10 +0200 Subject: [PATCH] add tests --- CMakeLists.txt | 72 ++++++----- ....cmake.in => CTestTestfileInstall.cmake.in | 1 + .../salome_tester/salome_instance.py | 10 +- bin/appliskel/tests/CMakeLists.txt | 1 + bin/appliskel/tests/connect/CMakeLists.txt | 30 +++++ .../tests/connect/CTestTestfileInstall.cmake | 26 ++++ bin/appliskel/tests/connect/instances.py | 112 ++++++++++++++++++ bin/runConsole.py | 4 +- src/CMakeLists.txt | 8 -- 9 files changed, 219 insertions(+), 45 deletions(-) rename src/CTestTestfileInstall.cmake.in => CTestTestfileInstall.cmake.in (98%) create mode 100644 bin/appliskel/tests/connect/CMakeLists.txt create mode 100644 bin/appliskel/tests/connect/CTestTestfileInstall.cmake create mode 100644 bin/appliskel/tests/connect/instances.py diff --git a/CMakeLists.txt b/CMakeLists.txt index ab2e7838e..7b85d3c25 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,7 @@ ENDIF() IF(NOT SALOME_LIGHT_ONLY) FIND_PACKAGE(SalomeOmniORB REQUIRED) FIND_PACKAGE(SalomeOmniORBPy REQUIRED) -ENDIF() +ENDIF() IF(SALOME_USE_MPI) FIND_PACKAGE(SalomeMPI REQUIRED) IF(HDF5_IS_PARALLEL) @@ -114,7 +114,7 @@ ENDIF() IF(SALOME_BUILD_TESTS) ENABLE_TESTING() FIND_PACKAGE(SalomeCppUnit) - SALOME_LOG_OPTIONAL_PACKAGE(CppUnit SALOME_BUILD_TESTS) + SALOME_LOG_OPTIONAL_PACKAGE(CppUnit SALOME_BUILD_TESTS) ENDIF() IF(SALOME_BUILD_DOC) FIND_PACKAGE(SalomeDoxygen) @@ -137,27 +137,27 @@ SET(SALOME_INSTALL_BINS bin/salome CACHE PATH "Install path: SALOME binaries") SET(SALOME_INSTALL_LIBS lib/salome CACHE PATH "Install path: SALOME libs") SET(SALOME_INSTALL_IDLS idl/salome CACHE PATH "Install path: SALOME IDL files") SET(SALOME_INSTALL_HEADERS include/salome CACHE PATH "Install path: SALOME headers") -SET(SALOME_INSTALL_SCRIPT_SCRIPTS ${SALOME_INSTALL_BINS} CACHE PATH +SET(SALOME_INSTALL_SCRIPT_SCRIPTS ${SALOME_INSTALL_BINS} CACHE PATH "Install path: SALOME scripts") -SET(SALOME_INSTALL_SCRIPT_DATA ${SALOME_INSTALL_BINS} CACHE PATH +SET(SALOME_INSTALL_SCRIPT_DATA ${SALOME_INSTALL_BINS} CACHE PATH "Install path: SALOME script data") -SET(SALOME_INSTALL_SCRIPT_PYTHON ${SALOME_INSTALL_BINS} CACHE PATH +SET(SALOME_INSTALL_SCRIPT_PYTHON ${SALOME_INSTALL_BINS} CACHE PATH "Install path: SALOME Python scripts") -SET(SALOME_INSTALL_APPLISKEL_SCRIPTS ${SALOME_INSTALL_BINS}/appliskel CACHE PATH +SET(SALOME_INSTALL_APPLISKEL_SCRIPTS ${SALOME_INSTALL_BINS}/appliskel CACHE PATH "Install path: SALOME application skeleton - scripts") -SET(SALOME_INSTALL_APPLISKEL_PYTHON ${SALOME_INSTALL_BINS}/appliskel CACHE PATH +SET(SALOME_INSTALL_APPLISKEL_PYTHON ${SALOME_INSTALL_BINS}/appliskel CACHE PATH "Install path: SALOME application skeleton - Python") SET(SALOME_INSTALL_CMAKE salome_adm/cmake_files CACHE PATH "Install path: SALOME CMake files") -SET(SALOME_INSTALL_CMAKE_LOCAL adm_local/cmake_files CACHE PATH +SET(SALOME_INSTALL_CMAKE_LOCAL adm_local/cmake_files CACHE PATH "Install path: local SALOME CMake files") -SET(SALOME_INSTALL_AMCONFIG salome_adm/unix CACHE PATH +SET(SALOME_INSTALL_AMCONFIG salome_adm/unix CACHE PATH "Install path: SALOME config files (obsolete, to be removed)") -SET(SALOME_INSTALL_AMCONFIG_LOCAL adm_local/unix CACHE PATH +SET(SALOME_INSTALL_AMCONFIG_LOCAL adm_local/unix CACHE PATH "Install path: local SALOME config files (obsolete, to be removed)") SET(_pydir lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages) SET(SALOME_INSTALL_PYTHON ${_pydir}/salome CACHE PATH "Install path: SALOME Python stuff") -SET(SALOME_INSTALL_PYTHON_SHARED ${SALOME_INSTALL_PYTHON}/shared_modules CACHE PATH +SET(SALOME_INSTALL_PYTHON_SHARED ${SALOME_INSTALL_PYTHON}/shared_modules CACHE PATH "Install path: SALOME Python shared modules") SET(SALOME_INSTALL_RES share/salome/resources CACHE PATH "Install path: SALOME resources") @@ -180,7 +180,15 @@ SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${SALOM ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_PYTHON_SHARED}) SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_LIBS}) -# Sources +# For salome test +SET(KERNEL_TEST_DIR ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test) +SET(KERNEL_TEST_LIB ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test/lib) +CONFIGURE_FILE(CTestTestfileInstall.cmake.in CTestTestfileInstall.cmake @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/CTestTestfileInstall.cmake + DESTINATION ${KERNEL_TEST_DIR} + RENAME CTestTestfile.cmake) + +# Sources # ======== IF(NOT SALOME_LIGHT_ONLY) ADD_SUBDIRECTORY(idl) @@ -205,40 +213,40 @@ INCLUDE(CMakePackageConfigHelpers) # List of targets in this project we want to make visible to the rest of the world. # They all have to be INSTALL'd with the option "EXPORT ${PROJECT_NAME}TargetGroup" -SET(_${PROJECT_NAME}_exposed_targets +SET(_${PROJECT_NAME}_exposed_targets SALOMEBasics SALOMELocalTrace SalomeHDFPersist OpUtil) - + # CORBA specific targets: IF(NOT SALOME_LIGHT_ONLY) - LIST(APPEND _${PROJECT_NAME}_exposed_targets - DF SalomeLoggerServer with_loggerTraceCollector SalomeNS SalomeGenericObj + LIST(APPEND _${PROJECT_NAME}_exposed_targets + DF SalomeLoggerServer with_loggerTraceCollector SalomeNS SalomeGenericObj Registry SalomeCatalog ResourcesManager SalomeResourcesManager SalomeNotification SalomeContainer SalomeSDS Launcher SalomeLauncher SalomeLifeCycleCORBA SalomeDSClient TOOLSDS SalomeKernelHelpers SalomeDSImpl SalomeDS SalomeCommunication SalomeDSCContainer) # Temporary solution for package src\DSC on windows IF(NOT WIN32) - LIST(APPEND _${PROJECT_NAME}_exposed_targets - CalciumC SalomeCalcium SalomeDatastream SalomePalm SalomeDSCSupervBasic + LIST(APPEND _${PROJECT_NAME}_exposed_targets + CalciumC SalomeCalcium SalomeDatastream SalomePalm SalomeDSCSupervBasic SalomeDSCSuperv) IF(SALOME_PACO_PARALLEL) LIST(APPEND _${PROJECT_NAME}_exposed_targets SalomeParallelDSCContainer) ENDIF() ENDIF() ENDIF() - + # MPI specific targets: IF(SALOME_USE_MPI) - LIST(APPEND _${PROJECT_NAME}_exposed_targets + LIST(APPEND _${PROJECT_NAME}_exposed_targets SalomeMPIContainer SalomeTestMPIComponentEngine) ENDIF() - + # Test targets: IF(SALOME_BUILD_TESTS) LIST(APPEND _${PROJECT_NAME}_exposed_targets SALOMELocalTraceTest UnitTests) IF(NOT SALOME_LIGHT_ONLY) - LIST(APPEND _${PROJECT_NAME}_exposed_targets - SALOMETraceCollectorTest UtilsTest NamingServiceTest SalomeTestComponentEngine + LIST(APPEND _${PROJECT_NAME}_exposed_targets + SALOMETraceCollectorTest UtilsTest NamingServiceTest SalomeTestComponentEngine LifeCycleCORBATest SalomeKernelHelpersTest SALOMEDSImplTest SALOMEDSTest) ENDIF() ENDIF() @@ -247,14 +255,14 @@ ENDIF() IF(SALOME_PACO_PARALLEL) LIST(APPEND _${PROJECT_NAME}_exposed_targets SalomeParallelContainer) ENDIF() - + IF(NOT SALOME_LIGHT_ONLY) LIST(APPEND _${PROJECT_NAME}_exposed_targets SalomeIDLKernel) IF(SALOME_PACO_PARALLEL) LIST(APPEND _${PROJECT_NAME}_exposed_targets SalomeParallelIDLKernel) ENDIF() ENDIF() - + # Add all targets to the build-tree export set EXPORT(TARGETS ${_${PROJECT_NAME}_exposed_targets} FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake) @@ -276,10 +284,10 @@ SET(SIMANIO_ROOT_DIR "${SIMANIO_ROOT_DIR}") SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") # Build variables that will be expanded when configuring SalomeConfig.cmake: -SALOME_CONFIGURE_PREPARE(CppUnit Graphviz Doxygen Sphinx MPI omniORB LibBatch +SALOME_CONFIGURE_PREPARE(CppUnit Graphviz Doxygen Sphinx MPI omniORB LibBatch PThread Boost HDF5 libXml2 Python SimanIO) -CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in +CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE}" PATH_VARS CONF_INCLUDE_DIRS SALOME_INSTALL_CMAKE CMAKE_INSTALL_PREFIX @@ -289,13 +297,13 @@ CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in PYTHON_ROOT_DIR SWIG_ROOT_DIR) # - in the install tree (VSR 16/08/2013: TEMPORARILY COMMENT THIS - TO REMOVE?): -# Get the relative path of the include directory so +# Get the relative path of the include directory so # we can register it in the generated configuration files: #SET(CONF_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/${INSTALL_INCLUDE_DIR}") -#CONFIGURE_PACKAGE_CONFIG_FILE(salome_adm/cmake_files/${PROJECT_NAME}Config.cmake.in +#CONFIGURE_PACKAGE_CONFIG_FILE(salome_adm/cmake_files/${PROJECT_NAME}Config.cmake.in # ${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake # INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE}" -# PATH_VARS CONF_INCLUDE_DIRS SALOME_INSTALL_CMAKE CMAKE_INSTALL_PREFIX +# PATH_VARS CONF_INCLUDE_DIRS SALOME_INSTALL_CMAKE CMAKE_INSTALL_PREFIX # CPPUNIT_ROOT_DIR GRAPHVIZ_ROOT_DIR DOXYGEN_ROOT_DIR # SPHINX_ROOT_DIR MPI_ROOT_DIR OMNIORB_ROOT_DIR OMNIORBPY_ROOT_DIR LIBBATCH_ROOT_DIR # SIMANIO_ROOT_DIR PTHREAD_ROOT_DIR BOOST_ROOT_DIR HDF5_ROOT_DIR LIBXML2_ROOT_DIR @@ -304,7 +312,7 @@ CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in WRITE_BASIC_PACKAGE_VERSION_FILE(${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${${PROJECT_NAME_UC}_VERSION} COMPATIBILITY AnyNewerVersion) - + # Install the CMake configuration files: INSTALL(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @@ -312,5 +320,5 @@ INSTALL(FILES DESTINATION "${SALOME_INSTALL_CMAKE}") # Install the export set for use with the install-tree -INSTALL(EXPORT ${PROJECT_NAME}TargetGroup DESTINATION "${SALOME_INSTALL_CMAKE}" +INSTALL(EXPORT ${PROJECT_NAME}TargetGroup DESTINATION "${SALOME_INSTALL_CMAKE}" FILE ${PROJECT_NAME}Targets.cmake) diff --git a/src/CTestTestfileInstall.cmake.in b/CTestTestfileInstall.cmake.in similarity index 98% rename from src/CTestTestfileInstall.cmake.in rename to CTestTestfileInstall.cmake.in index 97f990c0d..b739c2e22 100644 --- a/src/CTestTestfileInstall.cmake.in +++ b/CTestTestfileInstall.cmake.in @@ -38,4 +38,5 @@ SUBDIRS( Launcher SALOMEDSImpl Utils UnitTests + connect ) diff --git a/bin/appliskel/salome_tester/salome_instance.py b/bin/appliskel/salome_tester/salome_instance.py index e6d88d27a..53dd31779 100644 --- a/bin/appliskel/salome_tester/salome_instance.py +++ b/bin/appliskel/salome_tester/salome_instance.py @@ -86,8 +86,14 @@ class SalomeInstance(object): # def stop(self): - import killSalomeWithPort - killSalomeWithPort.killMyPort(self.port) + from multiprocessing import Process + from killSalomeWithPort import killMyPort + import tempfile + with tempfile.NamedTemporaryFile(): + p = Process(target = killMyPort, args=(self.port,)) + p.start() + p.join() + pass # # diff --git a/bin/appliskel/tests/CMakeLists.txt b/bin/appliskel/tests/CMakeLists.txt index fab581f2a..539148322 100644 --- a/bin/appliskel/tests/CMakeLists.txt +++ b/bin/appliskel/tests/CMakeLists.txt @@ -18,4 +18,5 @@ # ADD_SUBDIRECTORY(concurrentSession) +ADD_SUBDIRECTORY(connect) ADD_SUBDIRECTORY(launcher) diff --git a/bin/appliskel/tests/connect/CMakeLists.txt b/bin/appliskel/tests/connect/CMakeLists.txt new file mode 100644 index 000000000..7370292d0 --- /dev/null +++ b/bin/appliskel/tests/connect/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (C) 2013-2015 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +FILE(GLOB py_scripts "${CMAKE_CURRENT_SOURCE_DIR}/*.py") + +LIST(APPEND scripts ${py_scripts}) + +# Application tests +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${KERNEL_TEST_DIR}/connect + RENAME CTestTestfile.cmake) + +INSTALL(FILES ${scripts} + DESTINATION ${KERNEL_TEST_DIR}/connect) diff --git a/bin/appliskel/tests/connect/CTestTestfileInstall.cmake b/bin/appliskel/tests/connect/CTestTestfileInstall.cmake new file mode 100644 index 000000000..964be5ba2 --- /dev/null +++ b/bin/appliskel/tests/connect/CTestTestfileInstall.cmake @@ -0,0 +1,26 @@ +# Copyright (C) 2015 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(TEST_NAMES instances) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME CONNECT_${tfile}) + ADD_TEST(${TEST_NAME} python ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() diff --git a/bin/appliskel/tests/connect/instances.py b/bin/appliskel/tests/connect/instances.py new file mode 100644 index 000000000..00c1e6510 --- /dev/null +++ b/bin/appliskel/tests/connect/instances.py @@ -0,0 +1,112 @@ +# Copyright (C) 2015 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import unittest +import multiprocessing + +def new_instance(running_instances): + from salome_instance import SalomeInstance + instance = SalomeInstance.start() + print "Instance created and now running on port", instance.get_port() + running_instances.put(instance) +# + +class TestLauncher(unittest.TestCase): + + def __createInstances(self, nb): + running_instances = multiprocessing.Queue() + processes = [ + multiprocessing.Process(target=new_instance, args=(running_instances,)) + for i in range(nb) + ] + return running_instances, processes + # + + def __terminateInstances(self, running_instances): + while not running_instances.empty(): + instance = running_instances.get() + print "Terminate instance running on port", instance.get_port() + instance.stop() + # + + def __connectToInstance(self, port): + import setenv + setenv.main(True) + import runConsole + return runConsole.connect(["-p", port, "-c", "exit()"]) # auto-logout + # + + def testSequential(self): + running_instances, processes = self.__createInstances(3) + for p in processes: + p.start() + p.join() + pass + + self.__terminateInstances(running_instances) + # + + def testConcurrent(self): + running_instances, processes = self.__createInstances(5) + for p in processes: + p.start() + pass + for p in processes: + p.join() + pass + + self.__terminateInstances(running_instances) + # + + def testConnectInstance(self): + # Create some instances + running_instances, processes = self.__createInstances(5) + for p in processes: + p.start() + pass + for p in processes: + p.join() + pass + + # move queued instances to a list + all_instances = [] + while not running_instances.empty(): + all_instances.append(running_instances.get()) + + # Connect to one instance + import runConsole + port = all_instances[len(all_instances)/2].get_port() + print "Connect to instance running on port", port + self.__connectToInstance(port) + + # Connect to another instance + import runConsole + port = all_instances[len(all_instances)/4].get_port() + print "Connect to instance running on port", port + self.__connectToInstance(port) + + # Terminate instances + for instance in all_instances: + print "Terminate instance running on port", instance.get_port() + instance.stop() + # + +if __name__ == "__main__": + unittest.main() +# diff --git a/bin/runConsole.py b/bin/runConsole.py index 337b1eb94..30f4c2ee6 100644 --- a/bin/runConsole.py +++ b/bin/runConsole.py @@ -103,7 +103,7 @@ def __get_running_session(requested_port=None, lastInstanceByDefault=False): host, port, filename = None, None, None if requested_port: print "Search for running instance on port %s..."%requested_port - found = [(h,p,f) for h,p,f in available_connexions if p == requested_port] + found = [(h,p,f) for h,p,f in available_connexions if int(p) == int(requested_port)] if not found: print " ...no running instance found" elif len(found) == 1: @@ -150,8 +150,6 @@ class client(orbmodule.client): # def start_client(): - print os.getenv("OMNIORB_CONFIG") - try: clt = client() except Exception: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a028e422..11dadcbf1 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,14 +95,6 @@ IF(SALOME_PACO_PARALLEL) LIST(APPEND SUBDIRS ${SUBDIR_PARALLEL}) ENDIF() -# For salome test -SET(KERNEL_TEST_DIR ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test) -SET(KERNEL_TEST_LIB ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test/lib) -CONFIGURE_FILE(CTestTestfileInstall.cmake.in CTestTestfileInstall.cmake @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/CTestTestfileInstall.cmake - DESTINATION ${KERNEL_TEST_DIR} - RENAME CTestTestfile.cmake) - FOREACH(_dir ${SUBDIRS}) ADD_SUBDIRECTORY(${_dir}) ENDFOREACH() -- 2.39.2