X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2Fappliskel%2Fsalome_tester%2Fsalome_test_driver.py;h=7b119d1765804d61475874548adc55737d26d484;hb=08ede0f3e66fb972c8f3373e204c47ac21f84e56;hp=b7367366367105a6a3781de56591faf8c119018f;hpb=7b8afe9697cd7ae55ec6c3ea9cbf1e26ca83dfd1;p=modules%2Fkernel.git diff --git a/bin/appliskel/salome_tester/salome_test_driver.py b/bin/appliskel/salome_tester/salome_test_driver.py index b73673663..7b119d176 100644 --- a/bin/appliskel/salome_tester/salome_test_driver.py +++ b/bin/appliskel/salome_tester/salome_test_driver.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2015-2017 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 @@ -18,7 +18,7 @@ # """ -Usage: salome_test_helper.py [test file arguments] +Usage: salome_test_driver.py [test command arguments] """ import sys @@ -29,26 +29,18 @@ import signal # Run test def runTest(command): print "Running:", " ".join(command) - p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() + p = subprocess.Popen(command) + p.communicate() res = p.returncode - - return res, out, err -# - -# Display output and errors -def processResult(res, out, err): - if out: - print out - pass - if err: - print err - print "Status code: ", res + # About res value: + # A negative value -N indicates that the child was terminated by signal N (Unix only). + # On Unix, the value 11 generally corresponds to a segmentation fault. + return res # # Timeout management class TimeoutException(Exception): - """Execption raised when test timeout is reached.""" + """Exception raised when test timeout is reached.""" # def timeoutHandler(signum, frame): raise TimeoutException() @@ -61,7 +53,8 @@ if __name__ == "__main__": # Add explicit call to python executable if a Python script is passed as # first argument if not args: - exit(0) + print "Invalid arguments for salome_test_driver.py. No command defined." + sys.exit(1) _, ext = os.path.splitext(args[0]) if ext == ".py": test_and_args = [sys.executable] + args @@ -74,23 +67,34 @@ if __name__ == "__main__": # Set timeout handler print "Test timeout explicitely set to: %s seconds"%timeout_delay - signal.alarm(abs(int(timeout_delay)-10)) - signal.signal(signal.SIGALRM, timeoutHandler) + 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 session - from salome_test_session import startSession, terminateSession + # Run test in a new SALOME instance + from salome_instance import SalomeInstance res = 1 try: - port = startSession() - res, out, err = runTest(test_and_args) - processResult(res, out, err) + salome_instance = SalomeInstance.start(shutdown_servers=True) + port = salome_instance.get_port() + res = runTest(test_and_args) except TimeoutException: print "FAILED : timeout(%s) is reached"%timeout_delay except: import traceback traceback.print_exc() pass - - terminateSession(port) - exit(res) + try: + salome_instance.stop() + except: + pass + if sys.platform == 'win32': + timer.cancel() + print "Exit test with status code:", res + sys.exit(res) #