]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
check the output of the check_validity.py script
authormbs <martin.bernhard@opencascade.com>
Mon, 15 Jan 2024 08:56:44 +0000 (08:56 +0000)
committermbs <martin.bernhard@opencascade.com>
Fri, 19 Jan 2024 23:11:08 +0000 (23:11 +0000)
check_validity.py
src/SHAPERGUI/SHAPERGUI_CheckBackup.cpp
test_backup.py

index f51d08f41ba6b53db423f74dc3106ef0165c0744..90ddf6b15b582f8a997e61f6b545bbeb3808ca9d 100755 (executable)
@@ -6,61 +6,62 @@ import ModelAPI
 #import PartSetAPI
 #from salome.shaper import model
 
-
-if len(sys.argv) < 2:
-  raise Exception("no study given to validate")
+errCode = 0
 
 outFolder,filename = os.path.split(sys.argv[1])
 base = os.path.splitext(filename)[0]
 
 with open(os.path.join(outFolder, base+"_valid.log"), "w") as f:
-  f.write("#args = {}\n".format(len(sys.argv)))
-  lastIdx = len(sys.argv)-1
-  f.write("#arg[{}] = {}\n".format(lastIdx, sys.argv[lastIdx]))
+  try:
+    f.write("#args = {}\n".format(len(sys.argv)))
+    lastIdx = len(sys.argv)-1
+    f.write("#arg[{}] = {}\n".format(lastIdx, sys.argv[lastIdx]))
 
-  salome.standalone()
-  f.write("initializing SALOME\n")
-  salome.salome_init(sys.argv[1], embedded=True, forced=True)
-  f.write("StudyName = {}\n".format(salome.myStudyName))
-  f.write("Study = {}\n".format(salome.myStudy))
+    salome.standalone()
+    f.write("initializing SALOME\n")
+    salome.salome_init(sys.argv[1], embedded=True, forced=True)
+    f.write("StudyName = {}\n".format(salome.myStudyName))
+    f.write("Study = {}\n".format(salome.myStudy))
 
-  session = salome.naming_service.Resolve('/Kernel/Session')
-  f.write("session = {}\n".format(session))
-  session.emitMessage("connect_to_study")
-  f.write("session = {}\n".format(session))
+    session = salome.naming_service.Resolve('/Kernel/Session')
+    f.write("session = {}\n".format(session))
+    session.emitMessage("connect_to_study")
+    f.write("session = {}\n".format(session))
 
-  sg = SalomePyQt.SalomePyQt()
-  sg.activateModule("Shaper")
-  session = ModelAPI.ModelAPI_Session.get()
-  aFactory = session.validators()
-  aPartSet = session.moduleDocument()
-  numParts = aPartSet.size("Parts")
-  # f.write("NumParts = {}\n".format(numParts))
-  # numFeats = aPartSet.size("Features")
-  # f.write("NumFeats = {}\n".format(numFeats))
-  # numBodies = aPartSet.size("Bodies")
-  # f.write("NumBodies = {}\n".format(numBodies))
-  # numGroups = aPartSet.size("Groups")
-  # f.write("NumGroups = {}\n".format(numGroups))
-  # numConsts = aPartSet.size("Construction")
-  # f.write("NumConstr = {}\n".format(numConsts))
-  # numFolders = aPartSet.size("Folders")
-  # f.write("NumFolder = {}\n".format(numFolders))
-  for partIdx in range(numParts+1):
-    aPart = session.document(partIdx)
-    if aPart is None:
-      continue
-    aPart.setActive(True)
-    if partIdx == 0:
-      f.write("---PartSet:------------------\n")
-    else:
-      f.write(f"---Part_{partIdx}:------------------\n")
-    for aFeat in aPart.allFeatures():
-      if aFeat.isInHistory():
-        f.write("  * {} --> [{}]\n".format(aFeat.getKind(), aFeat.data().name()))
+    sg = SalomePyQt.SalomePyQt()
+    sg.activateModule("Shaper")
+    session = ModelAPI.ModelAPI_Session.get()
+    aFactory = session.validators()
+    aPartSet = session.moduleDocument()
+    numParts = aPartSet.size("Parts")
+    for partIdx in range(numParts+1):
+      aPart = session.document(partIdx)
+      if aPart is None:
+        continue
+      aPart.setActive(True)
+      if partIdx == 0:
+        f.write("---PartSet:------------------\n")
       else:
-        f.write("    - {}\n".format(aFeat.data().name()))
+        f.write(f"---Part_{partIdx}:------------------\n")
+
+      ## Simulate an exception during execution:
+      ##raise Exception("study failed to validate")
+      ## Cause an exception
+      #x = 1/0
+
+      for aFeat in aPart.allFeatures():
+        if aFeat.isInHistory():
+          f.write("  * {} --> [{}]\n".format(aFeat.getKind(), aFeat.data().name()))
+        else:
+          f.write("    - {}\n".format(aFeat.data().name()))
+  except Exception as ex:
+    f.write("Exception caught: {}\n".format(ex))
+    errCode = 88
 
-  f.write("done!\n")
+  f.write("errCode = {}\n".format(errCode))
+  if errCode == 0:
+    f.write("HDF Test - PASSED\n")
+  else:
+    f.write("HDF Test - FAILED\n")
 
-exit()
+exit(errCode)
index 6af1d0a5ae5c090a5ffb4f598b5e84f30715a685..728adab996e87472265e95c32d20e2d474f3ed5b 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "SHAPERGUI_CheckBackup.h"
+#include <fstream>
 #include <QDir>
 #include <QFileInfo>
 #include <QStringList>
@@ -85,7 +86,7 @@ int SHAPERGUI_CheckBackup::run(const QString &theTestScript)
   //   * opens the previously backed up HDF study
   SHOW(aProgName);
   SHOW(args);
-  myProcess->setStandardOutputFile((QStringList() << myFolder << myBaseName+".log").join(aSep));
+  //myProcess->setStandardOutputFile((QStringList() << myFolder << myBaseName+".log").join(aSep));
   myProcess->start(aProgName, args);
   myProcess->waitForFinished(300000);
   int exitStat = myProcess->exitStatus();
@@ -98,7 +99,41 @@ int SHAPERGUI_CheckBackup::run(const QString &theTestScript)
     aResult = 99;
   myProcess->deleteLater();
 
-  return 0;
+  // Check the output of the log file
+  if (exitStat == 0 && exitCode == 0)
+  {
+    std::ifstream log((QStringList() << myFolder << myBaseName+"_valid.log").join(aSep).toStdString().c_str());
+    if (log)
+    {
+      aResult = 76;
+      std::string line;
+      while (std::getline(log, line))
+      {
+        if (line.find("HDF Test - ") == 0)
+        {
+          std::string strResult = line.substr(11);
+          if (strResult.find("PASSED") == 0)
+          {
+            MSGEL("HDF Test --> PASSED");
+            aResult = 0;
+          }
+          else if (strResult.find("FAILED") == 0)
+          {
+            MSGEL("HDF Test --> FAILED");
+            aResult = 75;
+          }
+          break;
+        }
+      }
+    }
+    else
+    {
+      std::cout << "WARNING: cannot open log file from check_validity.py script" << std::endl;
+      aResult = 77; // log file not found
+    }
+  }
+
+  return aResult;
 }
 
 
index 792390150e4a9ce688197da1d7eeffefb9f60f0b..d671432f0067ff41ac7de4d7b1f4e55a505b931b 100755 (executable)
@@ -48,10 +48,19 @@ with open(os.path.join(backupFolder, baseName+"_test.log"), "w") as f:
     f.write("start communication with SALOME\n")
     proc.communicate(timeout = testTimeout)
     f.write("SALOME terminated\n")
+    errCode = proc.returncode
+    f.write("SALOME returned: {}\n".format(errCode))
   except subprocess.TimeoutExpired:
     errCode = 99
     f.write("SALOME timed out\n")
+  except Exception as ex:
+    errCode = 33
+    f.write("Exception caught: {}\n".format(ex))
 
-  f.write("\ndone.\n")
+  f.write("errCode = {}\n".format(errCode))
+  if errCode == 0:
+    f.write("Backup Test - PASSED\n")
+  else:
+    f.write("Backup Test - FAILED\n")
 
 exit(errCode)
\ No newline at end of file