Salome HOME
Merge branch 'gdd_env_modules_in_config_appli' into gdd/merge_gdd_env_modules_in_conf...
[modules/kernel.git] / bin / appliskel / salome_tester / salome_test_driver_gui.py
1 # Copyright (C) 2015-2017  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 """
21 Usage: salome_test_driver_gui.py <timeout_delay> <test command> [test command arguments]
22 """
23
24 import sys
25 import os
26 import subprocess
27 import signal
28
29 # Timeout management
30 class TimeoutException(Exception):
31   """Exception raised when test timeout is reached."""
32 #
33 def timeoutHandler(signum, frame):
34   raise TimeoutException()
35 #
36
37 if __name__ == "__main__":
38   timeout_delay = sys.argv[1]
39   args = sys.argv[2:]
40
41   # Add explicit call to python executable if a Python script is passed as
42   # first argument
43   if not args:
44     print "Invalid arguments for salome_test_driver_gui.py. No command defined."
45     sys.exit(1)
46   _, ext = os.path.splitext(args[0])
47   test_and_args = args
48
49   # Ensure OMNIORB_USER_PATH is set
50   from salomeContextUtils import setOmniOrbUserPath
51   setOmniOrbUserPath()
52
53   # Set timeout handler
54   print "Test timeout explicitely set to: %s seconds"%timeout_delay
55   timeout_sec = abs(int(timeout_delay)-10)
56   if sys.platform == 'win32':
57     from threading import Timer
58     timer = Timer(timeout_sec, timeoutHandler)
59     timer.start()
60   else:
61     signal.alarm(timeout_sec)
62     signal.signal(signal.SIGALRM, timeoutHandler)
63
64   # Run test in a new SALOME instance
65   from salome_instance import SalomeInstance
66   try:
67     salome_instance = SalomeInstance.start(with_gui=True, args=test_and_args)
68   except TimeoutException:
69     print "FAILED : timeout(%s) is reached"%timeout_delay
70   except:
71     import traceback
72     traceback.print_exc()
73     pass
74   try:
75     salome_instance.stop()
76   except:
77     pass
78   if sys.platform == 'win32':
79     timer.cancel()
80 #  print "Exit test with status code:", res
81 #  sys.exit(res)
82 #