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