From aa4f5b39af91369de09bcc615fc1c87e066b22bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Wed, 9 Sep 2015 16:54:16 +0200 Subject: [PATCH] tests for salome command --- CTestTestfileInstall.cmake.in | 6 +- bin/appliskel/tests/CMakeLists.txt | 4 +- .../tests/concurrentSession/CMakeLists.txt | 8 +- .../CTestTestfileInstall.cmake | 29 +++++++ .../TestConcurrentSession.py | 82 +++++++++++-------- .../CMakeLists.txt | 9 +- .../salomeCommand/CTestTestfileInstall.cmake | 29 +++++++ .../TestLauncherSessionArgs.py | 26 +++--- .../TestLauncherSimple.py | 29 ++++--- .../tests/{launcher => salomeCommand}/add.py | 0 .../{launcher => salomeCommand}/getLogger.py | 0 .../{launcher => salomeCommand}/hello.py | 0 .../{launcher => salomeCommand}/lines.py | 0 .../CMakeLists.txt | 4 +- .../CTestTestfileInstall.cmake | 2 +- .../{connect => salomeInstance}/instances.py | 0 16 files changed, 153 insertions(+), 75 deletions(-) create mode 100644 bin/appliskel/tests/concurrentSession/CTestTestfileInstall.cmake rename bin/appliskel/tests/{launcher => salomeCommand}/CMakeLists.txt (79%) create mode 100644 bin/appliskel/tests/salomeCommand/CTestTestfileInstall.cmake rename bin/appliskel/tests/{launcher => salomeCommand}/TestLauncherSessionArgs.py (86%) rename bin/appliskel/tests/{launcher => salomeCommand}/TestLauncherSimple.py (67%) rename bin/appliskel/tests/{launcher => salomeCommand}/add.py (100%) rename bin/appliskel/tests/{launcher => salomeCommand}/getLogger.py (100%) rename bin/appliskel/tests/{launcher => salomeCommand}/hello.py (100%) rename bin/appliskel/tests/{launcher => salomeCommand}/lines.py (100%) rename bin/appliskel/tests/{connect => salomeInstance}/CMakeLists.txt (90%) rename bin/appliskel/tests/{connect => salomeInstance}/CTestTestfileInstall.cmake (96%) rename bin/appliskel/tests/{connect => salomeInstance}/instances.py (100%) diff --git a/CTestTestfileInstall.cmake.in b/CTestTestfileInstall.cmake.in index 05f1720ca..817d1ff9d 100644 --- a/CTestTestfileInstall.cmake.in +++ b/CTestTestfileInstall.cmake.in @@ -36,8 +36,10 @@ SUBDIRS( Launcher KernelHelpers SALOMEDS SALOMEDSImpl - SALOMESDS + SALOMESDS Utils UnitTests - connect + salomeInstance + salomeCommand + concurrentSession ) diff --git a/bin/appliskel/tests/CMakeLists.txt b/bin/appliskel/tests/CMakeLists.txt index 539148322..7a21edf0e 100644 --- a/bin/appliskel/tests/CMakeLists.txt +++ b/bin/appliskel/tests/CMakeLists.txt @@ -18,5 +18,5 @@ # ADD_SUBDIRECTORY(concurrentSession) -ADD_SUBDIRECTORY(connect) -ADD_SUBDIRECTORY(launcher) +ADD_SUBDIRECTORY(salomeInstance) +ADD_SUBDIRECTORY(salomeCommand) diff --git a/bin/appliskel/tests/concurrentSession/CMakeLists.txt b/bin/appliskel/tests/concurrentSession/CMakeLists.txt index 1502d2fc0..7481d0be2 100644 --- a/bin/appliskel/tests/concurrentSession/CMakeLists.txt +++ b/bin/appliskel/tests/concurrentSession/CMakeLists.txt @@ -22,4 +22,10 @@ FILE(GLOB sh_scripts "${CMAKE_CURRENT_SOURCE_DIR}/*.sh") LIST(APPEND scripts ${py_scripts} ${sh_scripts}) -SALOME_INSTALL_SCRIPTS("${scripts}" ${SALOME_INSTALL_SCRIPT_SCRIPTS}/appliskel/tests/concurrentSession) +# Application tests +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${KERNEL_TEST_DIR}/concurrentSession + RENAME CTestTestfile.cmake) + +INSTALL(FILES ${scripts} + DESTINATION ${KERNEL_TEST_DIR}/concurrentSession) diff --git a/bin/appliskel/tests/concurrentSession/CTestTestfileInstall.cmake b/bin/appliskel/tests/concurrentSession/CTestTestfileInstall.cmake new file mode 100644 index 000000000..1e43e8a45 --- /dev/null +++ b/bin/appliskel/tests/concurrentSession/CTestTestfileInstall.cmake @@ -0,0 +1,29 @@ +# 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 + TestMinimalExample + TestConcurrentSession + ) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME SALOME_CONCURRENT_${tfile}) + ADD_TEST(${TEST_NAME} python ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() diff --git a/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py b/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py index 18d24d2fc..99e4f419d 100644 --- a/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py +++ b/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py @@ -27,26 +27,38 @@ from cStringIO import StringIO import multiprocessing import logging -class TestConcurrentLaunch(unittest.TestCase): - def setUp(self): - # Initialize path to SALOME application - path_to_launcher = os.getenv("SALOME_LAUNCHER") - appli_dir = os.path.dirname(path_to_launcher) - sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")] +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) +# - # Configure session startup - self.SALOME = imp.load_source("SALOME", os.path.join(appli_dir,"salome")) - self.SALOME_appli_args = ["start", "-t"] - self.SALOME_shell_args = ["shell"] +class TestConcurrentLaunch(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 tearDown(self): - pass + 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 appli(self, args=None): if args is None: args = [] try: - self.SALOME.main(self.SALOME_appli_args + args) + sys.argv = ['runSalome', '-t'] + import setenv + setenv.main(True, exeName="salome start") + import runSalome + runSalome.runSalome() except SystemExit, e: if str(e) != '0': logging.error(e) @@ -56,7 +68,11 @@ class TestConcurrentLaunch(unittest.TestCase): if args is None: args = [] try: - self.SALOME.main(self.SALOME_shell_args + args) + import setenv + setenv.main(True) + import runSession + params, args = runSession.configureSession(args, exe="salome shell") + return runSession.runSession(params, args) except SystemExit, e: if str(e) != '0': logging.error(e) @@ -79,37 +95,33 @@ class TestConcurrentLaunch(unittest.TestCase): # def test03_SingleAppli(self): print "** Testing single appli **" - current_directory = os.path.dirname(os.path.abspath(__file__)) - session_log = tempfile.NamedTemporaryFile(prefix='session_', suffix='.log') - self.appli(["--ns-port-log=%s"%session_log.name]) - port_number = None - with open(session_log.name, "r") as f: - port_number = f.readline() + running_instances, processes = self.__createInstances(1) + for p in processes: + p.start() + pass + for p in processes: + p.join() + pass + self.session(["hello.py"]) - self.session(["-p", port_number, "killSalomeWithPort.py", "args:%s"%port_number]) - session_log.close() + self.__terminateInstances(running_instances) # def test04_MultiAppli(self): print "** Testing multi appli **" - jobs = [] - for i in range(9): - p = multiprocessing.Process(target=self.test03_SingleAppli) - jobs.append(p) + running_instances, processes = self.__createInstances(9) + for p in processes: p.start() + pass + for p in processes: + p.join() + pass - for j in jobs: - j.join() + self.session(["hello.py"]) + self.__terminateInstances(running_instances) # # if __name__ == "__main__": - path_to_launcher = os.getenv("SALOME_LAUNCHER") - if not path_to_launcher: - msg = "\n" - msg += "Error: please set SALOME_LAUNCHER variable to the salome command in your application folder.\n" - logging.error(msg) - sys.exit(1) - if not os.path.isfile("hello.py"): with open("hello.py", "w") as f: f.write("print 'Hello!'") diff --git a/bin/appliskel/tests/launcher/CMakeLists.txt b/bin/appliskel/tests/salomeCommand/CMakeLists.txt similarity index 79% rename from bin/appliskel/tests/launcher/CMakeLists.txt rename to bin/appliskel/tests/salomeCommand/CMakeLists.txt index 89fea58a6..509bbd1fb 100644 --- a/bin/appliskel/tests/launcher/CMakeLists.txt +++ b/bin/appliskel/tests/salomeCommand/CMakeLists.txt @@ -18,4 +18,11 @@ # FILE(GLOB scripts "${CMAKE_CURRENT_SOURCE_DIR}/*.py") -SALOME_INSTALL_SCRIPTS("${scripts}" ${SALOME_INSTALL_SCRIPT_SCRIPTS}/appliskel/tests/launcher) + +# Application tests +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${KERNEL_TEST_DIR}/salomeCommand + RENAME CTestTestfile.cmake) + +INSTALL(FILES ${scripts} + DESTINATION ${KERNEL_TEST_DIR}/salomeCommand) diff --git a/bin/appliskel/tests/salomeCommand/CTestTestfileInstall.cmake b/bin/appliskel/tests/salomeCommand/CTestTestfileInstall.cmake new file mode 100644 index 000000000..205f3cf41 --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/CTestTestfileInstall.cmake @@ -0,0 +1,29 @@ +# 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 + TestLauncherSimple + TestLauncherSessionArgs + ) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME SALOME_COMMAND_${tfile}) + ADD_TEST(${TEST_NAME} python ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() diff --git a/bin/appliskel/tests/launcher/TestLauncherSessionArgs.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py similarity index 86% rename from bin/appliskel/tests/launcher/TestLauncherSessionArgs.py rename to bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py index de5066d88..75441f8b3 100644 --- a/bin/appliskel/tests/launcher/TestLauncherSessionArgs.py +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py @@ -51,27 +51,27 @@ class TestSessionArgs(unittest.TestCase): linesUnreadableMsg = "hello.py is 35 lines longadd.py is 37 lines longFile '1' cannot be readFile '2' cannot be read" # def setUp(self): - # Initialize path to SALOME application - path_to_launcher = os.getenv("SALOME_LAUNCHER") - appli_dir = os.path.dirname(path_to_launcher) - envd_dir = os.path.join(appli_dir, "env.d") - sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")] - - # Configure session startup - self.SALOME = imp.load_source("SALOME", os.path.join(appli_dir,"salome")) - self.SALOME_args = ["shell", "--config="+envd_dir] + from salome_instance import SalomeInstance + self.instance = SalomeInstance.start() + print "Instance created and now running on port", self.instance.get_port() sys.stdout = StringIO() self.removeLogFile() # def tearDown(self): self.removeLogFile() + print "Terminate instance running on port", self.instance.get_port() + self.instance.stop() # def session(self, args=None): if args is None: args = [] try: - self.SALOME.main(self.SALOME_args + args) + import setenv + setenv.main(True) + import runSession + params, args = runSession.configureSession(args, exe="salome shell") + return runSession.runSession(params, args) except SystemExit, e: if str(e) != '0': logger.error(e) @@ -147,12 +147,6 @@ class TestSessionArgs(unittest.TestCase): # # - if __name__ == "__main__": - path_to_launcher = os.getenv("SALOME_LAUNCHER") - if not path_to_launcher: - msg = "Error: please set SALOME_LAUNCHER variable to the salome command of your application folder." - raise Exception(msg) - unittest.main() # diff --git a/bin/appliskel/tests/launcher/TestLauncherSimple.py b/bin/appliskel/tests/salomeCommand/TestLauncherSimple.py similarity index 67% rename from bin/appliskel/tests/launcher/TestLauncherSimple.py rename to bin/appliskel/tests/salomeCommand/TestLauncherSimple.py index fb35b12e2..5f17f3d9d 100644 --- a/bin/appliskel/tests/launcher/TestLauncherSimple.py +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSimple.py @@ -18,25 +18,29 @@ # import unittest - -import os -import sys -import imp import logging class TestLauncher(unittest.TestCase): def setUp(self): - path_to_launcher = os.getenv("SALOME_LAUNCHER") - appli_dir = os.path.dirname(path_to_launcher) - sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")] - - self.SALOME = imp.load_source("SALOME", os.path.join(appli_dir,"salome")) + from salome_instance import SalomeInstance + self.instance = SalomeInstance.start() + print "Instance created and now running on port", self.instance.get_port() # + def tearDown(self): + print "Terminate instance running on port", self.instance.get_port() + self.instance.stop() + # + def testHello(self): try: - self.SALOME.main(["shell", "hello.py"]) + import setenv + setenv.main(True) + import runSession + args = ["hello.py"] + params, args = runSession.configureSession(args, exe="salome shell") + return runSession.runSession(params, args) except SystemExit, e: if str(e) != '0': logging.error(e) @@ -44,10 +48,5 @@ class TestLauncher(unittest.TestCase): # if __name__ == "__main__": - path_to_launcher = os.getenv("SALOME_LAUNCHER") - if not path_to_launcher: - msg = "Error: please set SALOME_LAUNCHER variable to the salome command of your application folder." - raise Exception(msg) - unittest.main() # diff --git a/bin/appliskel/tests/launcher/add.py b/bin/appliskel/tests/salomeCommand/add.py similarity index 100% rename from bin/appliskel/tests/launcher/add.py rename to bin/appliskel/tests/salomeCommand/add.py diff --git a/bin/appliskel/tests/launcher/getLogger.py b/bin/appliskel/tests/salomeCommand/getLogger.py similarity index 100% rename from bin/appliskel/tests/launcher/getLogger.py rename to bin/appliskel/tests/salomeCommand/getLogger.py diff --git a/bin/appliskel/tests/launcher/hello.py b/bin/appliskel/tests/salomeCommand/hello.py similarity index 100% rename from bin/appliskel/tests/launcher/hello.py rename to bin/appliskel/tests/salomeCommand/hello.py diff --git a/bin/appliskel/tests/launcher/lines.py b/bin/appliskel/tests/salomeCommand/lines.py similarity index 100% rename from bin/appliskel/tests/launcher/lines.py rename to bin/appliskel/tests/salomeCommand/lines.py diff --git a/bin/appliskel/tests/connect/CMakeLists.txt b/bin/appliskel/tests/salomeInstance/CMakeLists.txt similarity index 90% rename from bin/appliskel/tests/connect/CMakeLists.txt rename to bin/appliskel/tests/salomeInstance/CMakeLists.txt index 7370292d0..1406f926e 100644 --- a/bin/appliskel/tests/connect/CMakeLists.txt +++ b/bin/appliskel/tests/salomeInstance/CMakeLists.txt @@ -23,8 +23,8 @@ LIST(APPEND scripts ${py_scripts}) # Application tests INSTALL(FILES CTestTestfileInstall.cmake - DESTINATION ${KERNEL_TEST_DIR}/connect + DESTINATION ${KERNEL_TEST_DIR}/salomeInstance RENAME CTestTestfile.cmake) INSTALL(FILES ${scripts} - DESTINATION ${KERNEL_TEST_DIR}/connect) + DESTINATION ${KERNEL_TEST_DIR}/salomeInstance) diff --git a/bin/appliskel/tests/connect/CTestTestfileInstall.cmake b/bin/appliskel/tests/salomeInstance/CTestTestfileInstall.cmake similarity index 96% rename from bin/appliskel/tests/connect/CTestTestfileInstall.cmake rename to bin/appliskel/tests/salomeInstance/CTestTestfileInstall.cmake index 964be5ba2..67db531b3 100644 --- a/bin/appliskel/tests/connect/CTestTestfileInstall.cmake +++ b/bin/appliskel/tests/salomeInstance/CTestTestfileInstall.cmake @@ -20,7 +20,7 @@ SET(TEST_NAMES instances) FOREACH(tfile ${TEST_NAMES}) - SET(TEST_NAME CONNECT_${tfile}) + SET(TEST_NAME SALOME_INSTANCE_${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/salomeInstance/instances.py similarity index 100% rename from bin/appliskel/tests/connect/instances.py rename to bin/appliskel/tests/salomeInstance/instances.py -- 2.39.2