Salome HOME
fixed bos#38593 - middle point was incorrectly loaded
[modules/shaper.git] / test.hdfs / testme.py
index 395c6c0629e9f95251af4103a17005cdcfe16fcd..3a89659438163b92c3d8f2a95a5b0ef19d1691a5 100644 (file)
@@ -1,4 +1,6 @@
-# Copyright (C) 2020  CEA/DEN, EDF R&D
+#!/usr/bin/env python3
+
+# Copyright (C) 2020-2023  CEA, EDF
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-#!/usr/bin/env python
-
 if __name__ == '__main__':
 
   import subprocess
   from time import sleep
   import sys, os
+  import tempfile
 
-  salomeKernelDir = sys.argv[1]
-  sourceDir = sys.argv[2]
-  testfile = sys.argv[3]
+  testTimeout = 600
+  if len(sys.argv) > 3:
+    testTimeout = int(sys.argv[1])
+    hdffile = sys.argv[2]
+    testdatafile = sys.argv[3]
+  else:
+    hdffile = sys.argv[1]
+    testdatafile = sys.argv[2]
 
-  portlogfile = os.getcwd() + "/.salome_port"
-  testlogfile = os.getcwd() + "/test.log"
-  # remove port file if any
-  try:
-    os.remove(portlogfile)
-  except:
-    pass
+  tempfile = tempfile.NamedTemporaryFile()
+  hdffile_basename = os.path.basename(hdffile)
+  test_hdfpy = "test_hdf.py"
+  if not os.path.exists(test_hdfpy):
+    # add absolute path in SHAPER install directory
+    test_hdfpy = os.path.join(os.getenv("SHAPER_ROOT_DIR"), "bin", "salome", "test", "HDFs", test_hdfpy)
+    if not os.path.exists(test_hdfpy):
+      raise Exception("test_hdf.py could not be found. Check your environment.")
+  testlogfile = tempfile.name + "_" + hdffile_basename.replace(".", "_")
+  tempfile.close()
 
   isOk = True
   error = ""
 
-  proc = subprocess.Popen([salomeKernelDir + "/bin/salome/runSalome.py", "--modules", "SHAPER,GEOM", "--gui", "--splash", "0", "--ns-port-log=" + portlogfile, sourceDir + "/test_hdf.py", "args:" + testfile + "," + portlogfile + "," + testlogfile + "," + salomeKernelDir + "," + sourceDir], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+  proc = subprocess.Popen(["runSalome.py", "--modules", "SHAPER,GEOM,SHAPERSTUDY", "--gui", "--splash", "0", test_hdfpy, "args:" + hdffile + "," + testdatafile + "," + testlogfile])
   try:
-    proc.communicate(timeout = 600)
-  except TimeoutExpired:
+    proc.communicate(timeout = testTimeout)
+  except subprocess.TimeoutExpired:
     isOk = False
-    proc.kill()
-    out, err = proc.communicate()
+    import salome_utils
+    port = salome_utils.getPortNumber()
+    import killSalomeWithPort
+    killSalomeWithPort.killMyPort(port)
     error = "Killed by CPU limit."
-    print(err)
+
+  assert isOk, "Test failed. {}".format(error)
 
   with open(testlogfile, 'r') as inputFile:
     s = inputFile.read()
-    print(s)
-    isOk = isOk and s.find("FAIL") < 0
+    #print("logfile: ", s)
+    if s.find("FAIL") > 0:
+      isOk = False
+      error = s
+    elif s.find("OK") < 0:
+      isOk = False
+      error = "Test not ended until OK. Maybe a SIGSEGV."
+
   try:
     os.remove(testlogfile)
   except: