Salome HOME
Merge branch 'omu/launcher_evol'
[modules/kernel.git] / bin / appliskel / salome_tester / salome_test_driver.py
index 60b8fd9a20d347d99529d7db00bd946d4c80adb2..c167e97f6452f586f721ae2f6258e6bc425e018a 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2016  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
@@ -26,18 +26,6 @@ import os
 import subprocess
 import signal
 
-# Run test
-def runTest(command):
-  print "Running:", " ".join(command)
-  p = subprocess.Popen(command)
-  p.communicate()
-  res = p.returncode
-  # 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):
   """Exception raised when test timeout is reached."""
@@ -54,7 +42,7 @@ if __name__ == "__main__":
   # first argument
   if not args:
     print "Invalid arguments for salome_test_driver.py. No command defined."
-    exit(1)
+    sys.exit(1)
   _, ext = os.path.splitext(args[0])
   if ext == ".py":
     test_and_args = [sys.executable] + args
@@ -66,7 +54,7 @@ if __name__ == "__main__":
   setOmniOrbUserPath()
 
   # Set timeout handler
-  print "Test timeout explicitely set to: %s seconds"%timeout_delay
+  print "Test timeout explicitly set to: %s seconds"%timeout_delay
   timeout_sec = abs(int(timeout_delay)-10)
   if sys.platform == 'win32':
     from threading import Timer
@@ -82,17 +70,28 @@ if __name__ == "__main__":
   try:
     salome_instance = SalomeInstance.start(shutdown_servers=True)
     port = salome_instance.get_port()
-    res = runTest(test_and_args)
+    # Run the test
+    print "Running:", " ".join(test_and_args)
+    p = subprocess.Popen(test_and_args)
+    pid = p.pid
+    p.communicate()
+    res = p.returncode
+    # 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.
   except TimeoutException:
     print "FAILED : timeout(%s) is reached"%timeout_delay
   except:
     import traceback
     traceback.print_exc()
     pass
-
-  salome_instance.stop()
+  try:
+    salome_instance.stop()
+    os.kill(pid, signal.SIGTERM)
+  except:
+    pass
   if sys.platform == 'win32':
     timer.cancel()
   print "Exit test with status code:", res
-  exit(res)
+  sys.exit(res)
 #