]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Added salome_test_driver_gui.py to run application tests with GUI.
authorabn <adrien.bruneton@cea.fr>
Mon, 18 Apr 2016 12:33:52 +0000 (14:33 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 2 May 2016 08:46:03 +0000 (10:46 +0200)
bin/appliskel/salome_tester/CMakeLists.txt
bin/appliskel/salome_tester/salome_instance.py
bin/appliskel/salome_tester/salome_test_driver.py
bin/appliskel/salome_tester/salome_test_driver_gui.py [new file with mode: 0644]

index 50477ec3cc066bc8c8d9231a1ddea4e69ea19931..921785edbf435bcf25629816161bf7049388af53 100644 (file)
@@ -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)
index 76bd6666276f4eaa40ca035b036e6d34d44713f6..950ea281c3f4ca46e17e149c33cff41ae36c615e 100644 (file)
@@ -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):
index 46ca9853068afba7659fcc4f58e77e176d60405a..f2a1fc5509f1ff3a65b02b769a98a61b8dc2a60c 100644 (file)
@@ -18,7 +18,7 @@
 #
 
 """
-Usage: salome_test_helper.py <timeout_delay> <test command> [test command arguments]
+Usage: salome_test_driver.py <timeout_delay> <test command> [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 (file)
index 0000000..de4fbc5
--- /dev/null
@@ -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 <timeout_delay> <test command> [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)
+#