2 # Copyright (C) 2015-2019 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 Usage: salome_test_driver.py <timeout_delay> <test command> [test command arguments]
32 print("Running:", " ".join(command))
33 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
34 out, err = p.communicate()
37 # A negative value -N indicates that the child was terminated by signal N (Unix only).
38 # On Unix, the value 11 generally corresponds to a segmentation fault.
42 # Display output and errors
43 def processResult(res, out, err):
45 print(out.decode('utf_8'))
48 print(" ** Detected error **")
49 print("Error code: ", res)
50 print(err.decode('utf_8'), end=' \n')
51 print(" ** end of message **")
57 class TimeoutException(Exception):
58 """Exception raised when test timeout is reached."""
60 def timeoutHandler(signum, frame):
61 raise TimeoutException()
64 if __name__ == "__main__":
65 timeout_delay = sys.argv[1]
68 # Add explicit call to python executable if a Python script is passed as
71 print("Invalid arguments for salome_test_driver.py. No command defined.")
73 _, ext = os.path.splitext(args[0])
75 test_and_args = [sys.executable] + args
79 # Ensure OMNIORB_USER_PATH is set
80 from salomeContextUtils import setOmniOrbUserPath
84 print("Test timeout explicitly set to: %s seconds"%timeout_delay)
85 timeout_sec = abs(int(timeout_delay)-10)
86 if sys.platform == 'win32':
87 from threading import Timer
88 timer = Timer(timeout_sec, timeoutHandler)
91 signal.alarm(timeout_sec)
92 signal.signal(signal.SIGALRM, timeoutHandler)
94 # Run test in a new SALOME instance
95 from salome_instance import SalomeInstance
98 salome_instance = SalomeInstance.start(shutdown_servers=True)
99 port = salome_instance.get_port()
100 res, out, err = runTest(test_and_args)
101 res = processResult(res, out, err)
102 except TimeoutException:
103 print("FAILED : timeout(%s) is reached"%timeout_delay)
106 traceback.print_exc()
109 salome_instance.stop()
110 os.kill(pid, signal.SIGTERM)
113 if sys.platform == 'win32':
115 print("Exit test with status code:", res)