From: mbs Date: Mon, 15 Jan 2024 08:56:44 +0000 (+0000) Subject: check the output of the check_validity.py script X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17a541128dd569732104efd1cfeeee28700d49fa;p=modules%2Fshaper.git check the output of the check_validity.py script --- diff --git a/check_validity.py b/check_validity.py index f51d08f41..90ddf6b15 100755 --- a/check_validity.py +++ b/check_validity.py @@ -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) diff --git a/src/SHAPERGUI/SHAPERGUI_CheckBackup.cpp b/src/SHAPERGUI/SHAPERGUI_CheckBackup.cpp index 6af1d0a5a..728adab99 100644 --- a/src/SHAPERGUI/SHAPERGUI_CheckBackup.cpp +++ b/src/SHAPERGUI/SHAPERGUI_CheckBackup.cpp @@ -18,6 +18,7 @@ // #include "SHAPERGUI_CheckBackup.h" +#include #include #include #include @@ -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; } diff --git a/test_backup.py b/test_backup.py index 792390150..d671432f0 100755 --- a/test_backup.py +++ b/test_backup.py @@ -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