From: Cédric Aguerre Date: Wed, 9 Sep 2015 14:54:16 +0000 (+0200) Subject: tests for salome command X-Git-Tag: V7_7_0b1^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aa4f5b39af91369de09bcc615fc1c87e066b22bd;p=modules%2Fkernel.git tests for salome command --- 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/connect/CMakeLists.txt b/bin/appliskel/tests/connect/CMakeLists.txt deleted file mode 100644 index 7370292d0..000000000 --- a/bin/appliskel/tests/connect/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# 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 deleted file mode 100644 index 964be5ba2..000000000 --- a/bin/appliskel/tests/connect/CTestTestfileInstall.cmake +++ /dev/null @@ -1,26 +0,0 @@ -# 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 deleted file mode 100644 index 00c1e6510..000000000 --- a/bin/appliskel/tests/connect/instances.py +++ /dev/null @@ -1,112 +0,0 @@ -# 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/appliskel/tests/launcher/CMakeLists.txt b/bin/appliskel/tests/launcher/CMakeLists.txt deleted file mode 100644 index 89fea58a6..000000000 --- a/bin/appliskel/tests/launcher/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# 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 scripts "${CMAKE_CURRENT_SOURCE_DIR}/*.py") -SALOME_INSTALL_SCRIPTS("${scripts}" ${SALOME_INSTALL_SCRIPT_SCRIPTS}/appliskel/tests/launcher) diff --git a/bin/appliskel/tests/launcher/TestLauncherSessionArgs.py b/bin/appliskel/tests/launcher/TestLauncherSessionArgs.py deleted file mode 100644 index de5066d88..000000000 --- a/bin/appliskel/tests/launcher/TestLauncherSessionArgs.py +++ /dev/null @@ -1,158 +0,0 @@ -# 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 -# - -import unittest - -import os -import sys -import imp -from cStringIO import StringIO -import logging - -logger = logging.getLogger("TestLauncherLogger") -logger.level = logging.DEBUG -logger.addHandler(logging.StreamHandler()) - -class TestSessionArgs(unittest.TestCase): - # - logFile = "log.txt" - # Set some predefined command args and corresponding output messages - hello0 = ["hello.py", "args:outfile="+logFile] - hello0Msg = "Hello!" - hello1 = ["hello.py", "args:you,outfile="+logFile] - hello1Msg = "Hello to: you" - helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile="+logFile] - helloToAddMsg = "Hello to: add.py, 1, 2, 3" - add0 = ["add.py", "args:outfile="+logFile] - add0Msg = "No args!" - add3 = ["add.py", "args:1,2,3,outfile="+logFile] - add3Msg = "1+2+3 = 6" - lines0 = ["lines.py", "args:outfile="+logFile] - lines0Msg = "No files given" - lines2 = ["lines.py", "args:hello.py,add.py,outfile="+logFile] - lines2Msg = "hello.py is 35 lines longadd.py is 37 lines long" - linesUnreadable = ["lines.py", "args:hello.py,add.py,1,2,outfile="+logFile] - 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] - - sys.stdout = StringIO() - self.removeLogFile() - # - def tearDown(self): - self.removeLogFile() - # - def session(self, args=None): - if args is None: - args = [] - try: - self.SALOME.main(self.SALOME_args + args) - except SystemExit, e: - if str(e) != '0': - logger.error(e) - pass - # - def removeLogFile(self): - try: - os.remove(self.logFile) - except OSError: - pass - # - def assertLogFileContentsEqual(self, message): - with open(self.logFile, "r") as f: - contents = f.read().replace('\n', '') - - self.assertTrue(contents==message, "Contents differ!\n\tGenerated contents: %s\n\tExpected contents: %s"%(contents, message)) - # - def testHello0(self): - self.session(self.hello0) - self.assertLogFileContentsEqual(self.hello0Msg) - # - def testPythonHello0(self): - self.session(["python"]+self.hello0) - self.assertLogFileContentsEqual(self.hello0Msg) - # - def testHello1(self): - self.session(self.hello1) - self.assertLogFileContentsEqual(self.hello1Msg) - # - def testAdd0(self): - self.session(self.add0) - self.assertLogFileContentsEqual(self.add0Msg) - # - def testAdd3(self): - self.session(self.add3) - self.assertLogFileContentsEqual(self.add3Msg) - # - def testHello0Add3(self): - self.session(self.hello0+self.add3) - self.assertLogFileContentsEqual(self.hello0Msg+self.add3Msg) - # - def testHello1Add3(self): - self.session(self.hello1+self.add3) - self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg) - # - def testHelloToAdd(self): - self.session(self.helloToAdd) - self.assertLogFileContentsEqual(self.helloToAddMsg) - # - def testLines0(self): - self.session(self.lines0) - self.assertLogFileContentsEqual(self.lines0Msg) - # - def testLines2(self): - self.session(self.lines2) - self.assertLogFileContentsEqual(self.lines2Msg) - # - def testLines2Add3(self): - self.session(self.lines2+self.add3) - self.assertLogFileContentsEqual(self.lines2Msg+self.add3Msg) - # - def testLinesUnreadable(self): - self.session(self.linesUnreadable) - self.assertLogFileContentsEqual(self.linesUnreadableMsg) - # - def testAddAddHello(self): - self.session(self.add3+self.add3+self.hello1) - self.assertLogFileContentsEqual(self.add3Msg+self.add3Msg+self.hello1Msg) - # - def testHello0Add3Hello0Add3Hello0(self): - self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0) - self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg) - # -# - - -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/launcher/TestLauncherSimple.py deleted file mode 100644 index fb35b12e2..000000000 --- a/bin/appliskel/tests/launcher/TestLauncherSimple.py +++ /dev/null @@ -1,53 +0,0 @@ -# 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 -# - -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")) - # - - def testHello(self): - try: - self.SALOME.main(["shell", "hello.py"]) - except SystemExit, e: - if str(e) != '0': - logging.error(e) - # -# - -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/launcher/add.py deleted file mode 100755 index 637354e93..000000000 --- a/bin/appliskel/tests/launcher/add.py +++ /dev/null @@ -1,37 +0,0 @@ -#! /usr/bin/env python - -# 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 -# - -import sys -import logging - -from getLogger import getLogger - -if __name__ == "__main__": - args = sys.argv[1:] - logger, args = getLogger(args) - - if len(args)==0: - logger.info("No args!") - else: - msg = "+".join(args) - res = sum(map(int, args)) - logger.info("%s = %s"%(msg, res)) -# diff --git a/bin/appliskel/tests/launcher/getLogger.py b/bin/appliskel/tests/launcher/getLogger.py deleted file mode 100644 index 0eb870de1..000000000 --- a/bin/appliskel/tests/launcher/getLogger.py +++ /dev/null @@ -1,45 +0,0 @@ -# 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 -# - -import os -import sys -import logging - -def getLogger(args=None): - if args is None: - args = [] - outfileOptionPrefix = "outfile=" - outfileArgs = [ str(x) for x in args if str(x).startswith(outfileOptionPrefix) ] - allFiles = [ x.replace(outfileOptionPrefix, '') for x in outfileArgs ] - args = [ x for x in args if not str(x).startswith(outfileOptionPrefix) ] - - logger = logging.getLogger(__name__) - if len(allFiles) == 0: - logger.addHandler(logging.StreamHandler()) - else: - for currentFile in allFiles: - elements = currentFile.split(',') - for elt in elements: - elt = os.path.realpath(os.path.expanduser(elt)) - hdlr = logging.FileHandler(elt) - logger.addHandler(hdlr) - # - logger.level = logging.DEBUG - return logger, args -# diff --git a/bin/appliskel/tests/launcher/hello.py b/bin/appliskel/tests/launcher/hello.py deleted file mode 100755 index 01ba0a0e8..000000000 --- a/bin/appliskel/tests/launcher/hello.py +++ /dev/null @@ -1,35 +0,0 @@ -#! /usr/bin/env python - -# 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 -# - -import sys -import logging - -from getLogger import getLogger - -if __name__ == "__main__": - args = sys.argv[1:] - logger, args = getLogger(args) - - if len(args)==0: - logger.info("Hello!") - else: - logger.info("Hello to: %s"%(", ".join(args))) -# diff --git a/bin/appliskel/tests/launcher/lines.py b/bin/appliskel/tests/launcher/lines.py deleted file mode 100755 index 8c557a07e..000000000 --- a/bin/appliskel/tests/launcher/lines.py +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/env python - -# 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 -# - -import sys -import logging - -from getLogger import getLogger - - -def file_len(fname): - with open(fname) as f: - for i, l in enumerate(f): - pass - return i + 1 -# - -if __name__ == "__main__": - args = sys.argv[1:] - logger, args = getLogger(args) - - if len(args)==0: - logger.info("No files given") - else: - for filename in args: - try: - nb = file_len(filename) - logger.info("%s is %s lines long"%(filename, nb)) - except IOError: - logger.info("File '%s' cannot be read"%(filename)) -# diff --git a/bin/appliskel/tests/salomeCommand/CMakeLists.txt b/bin/appliskel/tests/salomeCommand/CMakeLists.txt new file mode 100644 index 000000000..509bbd1fb --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/CMakeLists.txt @@ -0,0 +1,28 @@ +# 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 scripts "${CMAKE_CURRENT_SOURCE_DIR}/*.py") + +# 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/salomeCommand/TestLauncherSessionArgs.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py new file mode 100644 index 000000000..75441f8b3 --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py @@ -0,0 +1,152 @@ +# 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 +# + +import unittest + +import os +import sys +import imp +from cStringIO import StringIO +import logging + +logger = logging.getLogger("TestLauncherLogger") +logger.level = logging.DEBUG +logger.addHandler(logging.StreamHandler()) + +class TestSessionArgs(unittest.TestCase): + # + logFile = "log.txt" + # Set some predefined command args and corresponding output messages + hello0 = ["hello.py", "args:outfile="+logFile] + hello0Msg = "Hello!" + hello1 = ["hello.py", "args:you,outfile="+logFile] + hello1Msg = "Hello to: you" + helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile="+logFile] + helloToAddMsg = "Hello to: add.py, 1, 2, 3" + add0 = ["add.py", "args:outfile="+logFile] + add0Msg = "No args!" + add3 = ["add.py", "args:1,2,3,outfile="+logFile] + add3Msg = "1+2+3 = 6" + lines0 = ["lines.py", "args:outfile="+logFile] + lines0Msg = "No files given" + lines2 = ["lines.py", "args:hello.py,add.py,outfile="+logFile] + lines2Msg = "hello.py is 35 lines longadd.py is 37 lines long" + linesUnreadable = ["lines.py", "args:hello.py,add.py,1,2,outfile="+logFile] + linesUnreadableMsg = "hello.py is 35 lines longadd.py is 37 lines longFile '1' cannot be readFile '2' cannot be read" + # + def setUp(self): + 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: + 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) + pass + # + def removeLogFile(self): + try: + os.remove(self.logFile) + except OSError: + pass + # + def assertLogFileContentsEqual(self, message): + with open(self.logFile, "r") as f: + contents = f.read().replace('\n', '') + + self.assertTrue(contents==message, "Contents differ!\n\tGenerated contents: %s\n\tExpected contents: %s"%(contents, message)) + # + def testHello0(self): + self.session(self.hello0) + self.assertLogFileContentsEqual(self.hello0Msg) + # + def testPythonHello0(self): + self.session(["python"]+self.hello0) + self.assertLogFileContentsEqual(self.hello0Msg) + # + def testHello1(self): + self.session(self.hello1) + self.assertLogFileContentsEqual(self.hello1Msg) + # + def testAdd0(self): + self.session(self.add0) + self.assertLogFileContentsEqual(self.add0Msg) + # + def testAdd3(self): + self.session(self.add3) + self.assertLogFileContentsEqual(self.add3Msg) + # + def testHello0Add3(self): + self.session(self.hello0+self.add3) + self.assertLogFileContentsEqual(self.hello0Msg+self.add3Msg) + # + def testHello1Add3(self): + self.session(self.hello1+self.add3) + self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg) + # + def testHelloToAdd(self): + self.session(self.helloToAdd) + self.assertLogFileContentsEqual(self.helloToAddMsg) + # + def testLines0(self): + self.session(self.lines0) + self.assertLogFileContentsEqual(self.lines0Msg) + # + def testLines2(self): + self.session(self.lines2) + self.assertLogFileContentsEqual(self.lines2Msg) + # + def testLines2Add3(self): + self.session(self.lines2+self.add3) + self.assertLogFileContentsEqual(self.lines2Msg+self.add3Msg) + # + def testLinesUnreadable(self): + self.session(self.linesUnreadable) + self.assertLogFileContentsEqual(self.linesUnreadableMsg) + # + def testAddAddHello(self): + self.session(self.add3+self.add3+self.hello1) + self.assertLogFileContentsEqual(self.add3Msg+self.add3Msg+self.hello1Msg) + # + def testHello0Add3Hello0Add3Hello0(self): + self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0) + self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg) + # +# + +if __name__ == "__main__": + unittest.main() +# diff --git a/bin/appliskel/tests/salomeCommand/TestLauncherSimple.py b/bin/appliskel/tests/salomeCommand/TestLauncherSimple.py new file mode 100644 index 000000000..5f17f3d9d --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSimple.py @@ -0,0 +1,52 @@ +# 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 +# + +import unittest +import logging + +class TestLauncher(unittest.TestCase): + + def setUp(self): + 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: + 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) + # +# + +if __name__ == "__main__": + unittest.main() +# diff --git a/bin/appliskel/tests/salomeCommand/add.py b/bin/appliskel/tests/salomeCommand/add.py new file mode 100755 index 000000000..637354e93 --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/add.py @@ -0,0 +1,37 @@ +#! /usr/bin/env python + +# 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 +# + +import sys +import logging + +from getLogger import getLogger + +if __name__ == "__main__": + args = sys.argv[1:] + logger, args = getLogger(args) + + if len(args)==0: + logger.info("No args!") + else: + msg = "+".join(args) + res = sum(map(int, args)) + logger.info("%s = %s"%(msg, res)) +# diff --git a/bin/appliskel/tests/salomeCommand/getLogger.py b/bin/appliskel/tests/salomeCommand/getLogger.py new file mode 100644 index 000000000..0eb870de1 --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/getLogger.py @@ -0,0 +1,45 @@ +# 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 +# + +import os +import sys +import logging + +def getLogger(args=None): + if args is None: + args = [] + outfileOptionPrefix = "outfile=" + outfileArgs = [ str(x) for x in args if str(x).startswith(outfileOptionPrefix) ] + allFiles = [ x.replace(outfileOptionPrefix, '') for x in outfileArgs ] + args = [ x for x in args if not str(x).startswith(outfileOptionPrefix) ] + + logger = logging.getLogger(__name__) + if len(allFiles) == 0: + logger.addHandler(logging.StreamHandler()) + else: + for currentFile in allFiles: + elements = currentFile.split(',') + for elt in elements: + elt = os.path.realpath(os.path.expanduser(elt)) + hdlr = logging.FileHandler(elt) + logger.addHandler(hdlr) + # + logger.level = logging.DEBUG + return logger, args +# diff --git a/bin/appliskel/tests/salomeCommand/hello.py b/bin/appliskel/tests/salomeCommand/hello.py new file mode 100755 index 000000000..01ba0a0e8 --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/hello.py @@ -0,0 +1,35 @@ +#! /usr/bin/env python + +# 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 +# + +import sys +import logging + +from getLogger import getLogger + +if __name__ == "__main__": + args = sys.argv[1:] + logger, args = getLogger(args) + + if len(args)==0: + logger.info("Hello!") + else: + logger.info("Hello to: %s"%(", ".join(args))) +# diff --git a/bin/appliskel/tests/salomeCommand/lines.py b/bin/appliskel/tests/salomeCommand/lines.py new file mode 100755 index 000000000..8c557a07e --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/lines.py @@ -0,0 +1,48 @@ +#! /usr/bin/env python + +# 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 +# + +import sys +import logging + +from getLogger import getLogger + + +def file_len(fname): + with open(fname) as f: + for i, l in enumerate(f): + pass + return i + 1 +# + +if __name__ == "__main__": + args = sys.argv[1:] + logger, args = getLogger(args) + + if len(args)==0: + logger.info("No files given") + else: + for filename in args: + try: + nb = file_len(filename) + logger.info("%s is %s lines long"%(filename, nb)) + except IOError: + logger.info("File '%s' cannot be read"%(filename)) +# diff --git a/bin/appliskel/tests/salomeInstance/CMakeLists.txt b/bin/appliskel/tests/salomeInstance/CMakeLists.txt new file mode 100644 index 000000000..1406f926e --- /dev/null +++ b/bin/appliskel/tests/salomeInstance/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}/salomeInstance + RENAME CTestTestfile.cmake) + +INSTALL(FILES ${scripts} + DESTINATION ${KERNEL_TEST_DIR}/salomeInstance) diff --git a/bin/appliskel/tests/salomeInstance/CTestTestfileInstall.cmake b/bin/appliskel/tests/salomeInstance/CTestTestfileInstall.cmake new file mode 100644 index 000000000..67db531b3 --- /dev/null +++ b/bin/appliskel/tests/salomeInstance/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 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/salomeInstance/instances.py b/bin/appliskel/tests/salomeInstance/instances.py new file mode 100644 index 000000000..00c1e6510 --- /dev/null +++ b/bin/appliskel/tests/salomeInstance/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() +#