From 05280dbb454ff0b940e55659293e33e0dcfe8703 Mon Sep 17 00:00:00 2001 From: abn Date: Mon, 18 Apr 2016 14:33:52 +0200 Subject: [PATCH] Added salome_test_driver_gui.py to run application tests with GUI. --- bin/appliskel/salome_tester/CMakeLists.txt | 1 + .../salome_tester/salome_instance.py | 29 ++++--- .../salome_tester/salome_test_driver.py | 4 +- .../salome_tester/salome_test_driver_gui.py | 80 +++++++++++++++++++ 4 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 bin/appliskel/salome_tester/salome_test_driver_gui.py diff --git a/bin/appliskel/salome_tester/CMakeLists.txt b/bin/appliskel/salome_tester/CMakeLists.txt index 50477ec3c..921785edb 100644 --- a/bin/appliskel/salome_tester/CMakeLists.txt +++ b/bin/appliskel/salome_tester/CMakeLists.txt @@ -20,3 +20,4 @@ SALOME_INSTALL_SCRIPTS(salome_instance.py ${SALOME_INSTALL_SCRIPT_SCRIPTS}) SALOME_INSTALL_SCRIPTS(salome_test_driver.py ${SALOME_INSTALL_SCRIPT_SCRIPTS}/appliskel) +SALOME_INSTALL_SCRIPTS(salome_test_driver_gui.py ${SALOME_INSTALL_SCRIPT_SCRIPTS}/appliskel) diff --git a/bin/appliskel/salome_tester/salome_instance.py b/bin/appliskel/salome_tester/salome_instance.py index 76bd66662..950ea281c 100644 --- a/bin/appliskel/salome_tester/salome_instance.py +++ b/bin/appliskel/salome_tester/salome_instance.py @@ -34,7 +34,7 @@ class SalomeInstance(object): # @staticmethod - def start(shutdown_servers=False): + def start(shutdown_servers=False, with_gui=False, args=[]): import tempfile log = tempfile.NamedTemporaryFile(suffix='_nsport.log', delete=False) log.close() @@ -42,9 +42,10 @@ class SalomeInstance(object): instance_args = [ "--ns-port-log=%s"%log.name, "--shutdown-servers=%d"%shutdown_servers - ] + ] + args + salome_instance = SalomeInstance() - salome_instance.__run(args=instance_args) + salome_instance.__run(args=instance_args, with_gui=with_gui) with open(log.name) as f: salome_instance.port = int(f.readline()) @@ -53,12 +54,13 @@ class SalomeInstance(object): return salome_instance # - def __run(self, args=None): + def __run(self, args=None, with_gui=False): if args is None: args = [] + sys.argv = ['runSalome'] + args - if "INGUI" in args: + if with_gui: # :WARNING: NOT TESTED YET sys.argv += ["--gui"] sys.argv += ["--show-desktop=1"] @@ -75,14 +77,15 @@ class SalomeInstance(object): setenv.main(True) import runSalome runSalome.runSalome() - - import salome - salome.salome_init() - session_server = salome.naming_service.Resolve('/Kernel/Session') - if session_server: - session_server.emitMessage("connect_to_study") - session_server.emitMessage("activate_viewer/ParaView") - pass + + if not with_gui: + import salome + salome.salome_init() + session_server = salome.naming_service.Resolve('/Kernel/Session') + if session_server: + session_server.emitMessage("connect_to_study") + session_server.emitMessage("activate_viewer/ParaView") + pass # def stop(self): diff --git a/bin/appliskel/salome_tester/salome_test_driver.py b/bin/appliskel/salome_tester/salome_test_driver.py index 46ca98530..f2a1fc550 100644 --- a/bin/appliskel/salome_tester/salome_test_driver.py +++ b/bin/appliskel/salome_tester/salome_test_driver.py @@ -18,7 +18,7 @@ # """ -Usage: salome_test_helper.py [test command arguments] +Usage: salome_test_driver.py [test command arguments] """ import sys @@ -93,7 +93,7 @@ if __name__ == "__main__": # Add explicit call to python executable if a Python script is passed as # first argument if not args: - print "Invalid arguments for salome_test_helper.py. No command defined." + print "Invalid arguments for salome_test_driver.py. No command defined." exit(1) _, ext = os.path.splitext(args[0]) if ext == ".py": diff --git a/bin/appliskel/salome_tester/salome_test_driver_gui.py b/bin/appliskel/salome_tester/salome_test_driver_gui.py new file mode 100644 index 000000000..de4fbc5f4 --- /dev/null +++ b/bin/appliskel/salome_tester/salome_test_driver_gui.py @@ -0,0 +1,80 @@ +# Copyright (C) 2015-2016 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 +# + +""" +Usage: salome_test_driver_gui.py [test command arguments] +""" + +import sys +import os +import subprocess +import signal + +# Timeout management +class TimeoutException(Exception): + """Exception raised when test timeout is reached.""" +# +def timeoutHandler(signum, frame): + raise TimeoutException() +# + +if __name__ == "__main__": + timeout_delay = sys.argv[1] + args = sys.argv[2:] + + # Add explicit call to python executable if a Python script is passed as + # first argument + if not args: + print "Invalid arguments for salome_test_driver_gui.py. No command defined." + exit(1) + _, ext = os.path.splitext(args[0]) + test_and_args = args + + # Ensure OMNIORB_USER_PATH is set + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() + + # Set timeout handler + print "Test timeout explicitely set to: %s seconds"%timeout_delay + timeout_sec = abs(int(timeout_delay)-10) + if sys.platform == 'win32': + from threading import Timer + timer = Timer(timeout_sec, timeoutHandler) + timer.start() + else: + signal.alarm(timeout_sec) + signal.signal(signal.SIGALRM, timeoutHandler) + + # Run test in a new SALOME instance + from salome_instance import SalomeInstance + try: + salome_instance = SalomeInstance.start(with_gui=True, args=test_and_args) + except TimeoutException: + print "FAILED : timeout(%s) is reached"%timeout_delay + except: + import traceback + traceback.print_exc() + pass + + salome_instance.stop() + if sys.platform == 'win32': + timer.cancel() +# print "Exit test with status code:", res +# exit(res) +# -- 2.39.2