Salome HOME
Merge master branch into V9_dev
[modules/kernel.git] / bin / appliskel / salome_tester / salome_test_driver.py
index ee468557b3643d9167c4e2ddf273841c7248a087..62dcc5fe2c6f933aae92ca7ceb4d497c51c93d47 100644 (file)
@@ -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 <timeout_delay> <test_file.py> [test file arguments]
+Usage: salome_test_driver.py <timeout_delay> <test command> [test command arguments]
 """
 
 import sys
@@ -28,7 +28,7 @@ import signal
 
 # Run test
 def runTest(command):
-  print "Running:", " ".join(command)
+  print("Running:", " ".join(command))
   p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
   out, err = p.communicate()
   res = p.returncode
@@ -38,49 +38,23 @@ def runTest(command):
   return res, out, err
 #
 
-def processResultSpecialParavis(res, out, err):
-  # :TRICKY: Special case of returncode=127
-  # When using paraview in SALOME environment, the following error
-  # systematically appears when exiting paraview (it's also true when using
-  # PARAVIS and exiting SALOME):
-  # Inconsistency detected by ld.so: dl-close.c: 738: _dl_close: Assertion `map->l_init_called' failed!
-  # For PARAVIS tests purpose, paraview functionalities are accessed in each
-  # test; these tests are run in the above subprocess call.
-  # The assertion error implies a subprocess return code of 127, and the test
-  # status is considered as "failed".
-  # The tricky part here is to discard such return codes, waiting for a fix
-  # maybe in paraview...
-  if res == 127 and err.startswith("Inconsistency detected by ld.so: dl-close.c"):
-      print "    ** THE FOLLOWING MESSAGE IS DISCARDED WHEN ANALYZING TEST SUCCESSFULNESS **"
-      print err,
-      print "    ** end of message **"
-      res = 0
-  elif err:
-      print "    ** Detected error **"
-      print "Error code: ", res
-      print err,
-      print "    ** end of message **"
-      pass
-
-  if out:
-      print out
-  return res
-#
-
 # Display output and errors
 def processResult(res, out, err):
   if out:
-    print out
+    print(out)
     pass
   if err:
-    print err
-  print "Status code: ", res
+    print("    ** Detected error **")
+    print("Error code: ", res)
+    print(err, end=' ')
+    print("    ** end of message **")
+    pass
   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()
@@ -93,8 +67,8 @@ if __name__ == "__main__":
   # Add explicit call to python executable if a Python script is passed as
   # first argument
   if not args:
-    print "Invalid arguments for salome_test_helper.py. No command defined."
-    exit(1)
+    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
@@ -106,26 +80,37 @@ if __name__ == "__main__":
   setOmniOrbUserPath()
 
   # 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)
+  print("Test timeout explicitely set to: %s seconds"%timeout_delay)
+  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()
+    salome_instance = SalomeInstance.start(shutdown_servers=True)
+    port = salome_instance.get_port()
     res, out, err = runTest(test_and_args)
-    #res = processResult(res, out, err)
-    res = processResultSpecialParavis(res, out, err)
+    res = processResult(res, out, err)
   except TimeoutException:
-    print "FAILED : timeout(%s) is reached"%timeout_delay
+    print("FAILED : timeout(%s) is reached"%timeout_delay)
   except:
     import traceback
     traceback.print_exc()
     pass
-
-  terminateSession(port)
-  print "Exit test with status code:", res
-  exit(res)
+  try:
+    salome_instance.stop()
+    os.kill(pid, signal.SIGTERM)
+  except:
+    pass
+  if sys.platform == 'win32':
+    timer.cancel()
+  print("Exit test with status code:", res)
+  sys.exit(res)
 #