KernelHelpers
SALOMEDS
SALOMEDSImpl
- SALOMESDS
+ SALOMESDS
Utils
UnitTests
- connect
+ salomeInstance
+ salomeCommand
+ concurrentSession
)
#
ADD_SUBDIRECTORY(concurrentSession)
-ADD_SUBDIRECTORY(connect)
-ADD_SUBDIRECTORY(launcher)
+ADD_SUBDIRECTORY(salomeInstance)
+ADD_SUBDIRECTORY(salomeCommand)
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)
--- /dev/null
+# 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()
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)
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)
#
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!'")
+++ /dev/null
-# 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)
+++ /dev/null
-# 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()
+++ /dev/null
-# 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()
-#
+++ /dev/null
-# 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)
+++ /dev/null
-# 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()
-#
+++ /dev/null
-# 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()
-#
+++ /dev/null
-#! /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))
-#
+++ /dev/null
-# 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
-#
+++ /dev/null
-#! /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)))
-#
+++ /dev/null
-#! /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))
-#
--- /dev/null
+# 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)
--- /dev/null
+# 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()
--- /dev/null
+# 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()
+#
--- /dev/null
+# 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()
+#
--- /dev/null
+#! /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))
+#
--- /dev/null
+# 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
+#
--- /dev/null
+#! /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)))
+#
--- /dev/null
+#! /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))
+#
--- /dev/null
+# 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)
--- /dev/null
+# 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()
--- /dev/null
+# 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()
+#