Salome HOME
Adding test for bos #41748 [CEA] Issue in interpolation edition
[modules/shaper.git] / test.hdfs / testme.py
index cd56bcd3a4e9ce1ed5349c5a8406668813a01406..187afebb46c19e04d66f85f981880739da479a93 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# Copyright (C) 2020-2021  CEA/DEN, EDF R&D
+# Copyright (C) 2020-2024  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
 #
-
 if __name__ == '__main__':
 
   import subprocess
   from time import sleep
   import sys, os
   import tempfile
+  import platform
 
   testTimeout = 600
   if len(sys.argv) > 3:
@@ -35,32 +35,46 @@ if __name__ == '__main__':
     hdffile = sys.argv[1]
     testdatafile = sys.argv[2]
 
-  tempdir = tempfile.gettempdir()
-  portlogfile = tempdir + "/.salome_port"
-  testlogfile = tempdir + "/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(["runSalome.py", "--modules", "SHAPER,GEOM,SHAPERSTUDY", "--gui", "--splash", "0", "--ns-port-log=" + portlogfile, "test_hdf.py", "args:" + hdffile + "," + testdatafile + "," + portlogfile + "," + testlogfile], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+  runSalome = os.path.join(os.getenv("KERNEL_ROOT_DIR"), "bin", "salome", "runSalome.py")
+  cmd= [runSalome , "--modules", "SHAPER,GEOM,SHAPERSTUDY", "--gui", "--splash", "0", test_hdfpy, "args:" + hdffile + "," + testdatafile + "," + testlogfile]
+  if platform.system() == "Windows" :
+    cmd = ["python3", *cmd]
+  proc = subprocess.Popen(cmd)
   try:
     proc.communicate(timeout = testTimeout)
-  except TimeoutExpired:
+  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: