Skip to content

Commit

Permalink
exit the interactive OMPython session (#178)
Browse files Browse the repository at this point in the history
* exit the interactive OMPython sessions

* use all cores as we should have got rid of zombies

* define OMPython sessions as None earlier
  • Loading branch information
adrpo authored Nov 21, 2024
1 parent 6e42432 commit 0bb942c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
20 changes: 10 additions & 10 deletions .CI/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pipeline {
expression { params.fmi_v1_23 }
}
steps {
runRegressiontest('maintenance/v1.23', 'v1.23-fmi', '', omsimulatorHash(), 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('maintenance/v1.23', 'v1.23-fmi', '', omsimulatorHash(), 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}
stage('v1.24 FMI with OMSimulator') {
Expand All @@ -151,7 +151,7 @@ pipeline {
expression { params.fmi_v1_24 }
}
steps {
runRegressiontest('maintenance/v1.24', 'v1.24-fmi', '', omsimulatorHash(), 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('maintenance/v1.24', 'v1.24-fmi', '', omsimulatorHash(), 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}
stage('master FMI with OMSimulator') {
Expand All @@ -167,7 +167,7 @@ pipeline {
expression { params.fmi_master }
}
steps {
runRegressiontest('master', 'master-fmi', '', 'origin/master', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('master', 'master-fmi', '', 'origin/master', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}

Expand All @@ -185,7 +185,7 @@ pipeline {
expression { params.fmpy_fmi_v1_23 }
}
steps {
runRegressiontest('maintenance/v1.23', 'v1.23-fmi-fmpy', '', omsimulatorHash(), 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('maintenance/v1.23', 'v1.23-fmi-fmpy', '', omsimulatorHash(), 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}
stage('v1.24 FMI with FMPy') {
Expand All @@ -201,7 +201,7 @@ pipeline {
expression { params.fmpy_fmi_v1_24 }
}
steps {
runRegressiontest('maintenance/v1.24', 'v1.24-fmi-fmpy', '', omsimulatorHash(), 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('maintenance/v1.24', 'v1.24-fmi-fmpy', '', omsimulatorHash(), 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}
stage('master FMI with FMPy') {
Expand All @@ -217,7 +217,7 @@ pipeline {
expression { params.fmpy_fmi_master }
}
steps {
runRegressiontest('master', 'master-fmi-fmpy', '', 'origin/master', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('master', 'master-fmi-fmpy', '', 'origin/master', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}
stage('newInst-daeMode') {
Expand Down Expand Up @@ -330,7 +330,7 @@ pipeline {
expression { params.cpp_v1_23 }
}
steps {
runRegressiontest('maintenance/v1.23', 'v1.23-cpp', 'setCommandLineOptions("--simCodeTarget=Cpp")', '', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('maintenance/v1.23', 'v1.23-cpp', 'setCommandLineOptions("--simCodeTarget=Cpp")', '', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}
stage('C++ v1.24') {
Expand All @@ -346,7 +346,7 @@ pipeline {
expression { params.cpp_v1_23 }
}
steps {
runRegressiontest('maintenance/v1.24', 'v1.24-cpp', 'setCommandLineOptions("--simCodeTarget=Cpp")', '', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('maintenance/v1.24', 'v1.24-cpp', 'setCommandLineOptions("--simCodeTarget=Cpp")', '', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}
stage('C++') {
Expand All @@ -362,7 +362,7 @@ pipeline {
expression { params.cpp }
}
steps {
runRegressiontest('master', 'cpp', 'setCommandLineOptions("--simCodeTarget=Cpp")', '', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false, 8)
runRegressiontest('master', 'cpp', 'setCommandLineOptions("--simCodeTarget=Cpp")', '', 'ripper2', 'LibraryTestingRipper2DB', false, '', false, false)
}
}
} }
Expand Down Expand Up @@ -551,7 +551,7 @@ pipeline {
}
}
def omsimulatorHash() {
return '634b0193a3eb14e75622a8e720bf0fb6dab77487'
return 'master'
}
def installLibraries(boolean removePackageOrder, boolean conversionScript, name, String omhomeTestedOMC) {
sh "rm -rf '${env.HOME}/saved_omc/libraries/.openmodelica/libraries'"
Expand Down
61 changes: 38 additions & 23 deletions testmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
msysEnvironment = args.msysEnvironment
addmsl = args.addmsl

# our OMPython sessions
omc = None
omc_new = None

# add openmodelica libraries path if the Modelica libraries are not found in the libraries path
MSLpath = ''
if addmsl and len(glob.glob('Modelica *', root_dir=libraries)) == 0:
Expand All @@ -54,7 +58,21 @@ def writeResult():

startJob=monotonic()

def writeResultAndExit(exitStatus, useOsExit=False):
def quit_omc(omc):
if omc is None:
return omc
try:
omc.sendExpression("quit()")
except:
pass
try:
del omc
except:
pass
omc = None
return omc

def writeResultAndExit(exitStatus, useOsExit=False, omc=None, omc_new=None):
writeResult()
print("Calling exit ...")
with open(errFile, 'a+') as fp:
Expand All @@ -65,6 +83,8 @@ def writeResultAndExit(exitStatus, useOsExit=False):
fp.write(msg % (exitStatus, monotonic()-startJob))
fp.flush()
sys.stdout.flush()
omc = quit_omc(omc)
omc_new = quit(omc_new)
if useOsExit:
os._exit(exitStatus)
else:
Expand Down Expand Up @@ -117,7 +137,7 @@ def target(res):
pass
with open(errFile, 'a+') as fp:
fp.write("Aborted the command.\n")
writeResultAndExit(0, True)
writeResultAndExit(0, True, omc, omc_new)
if res[1] is None:
res[1] = ""
if res[1] is not None:
Expand Down Expand Up @@ -311,7 +331,7 @@ def createOmcSessionNew():
def loadModels(omc, conf):
for f in conf["loadFiles"]:
if not sendExpressionTimeout(omc, 'loadFile("%s", uses=false)' % f, conf["ulimitLoadModel"]):
writeResultAndExit(0)
writeResultAndExit(0, False, omc, omc_new)
loadedFiles = sorted(omc.sendExpression("{getSourceFile(cl) for cl in getClassNames()}"))
if sorted(conf["loadFiles"]) != loadedFiles:
print("Loaded the wrong files. Expected:\n%s\nActual:\n%s" % ("\n".join(sorted(conf["loadFiles"])), "\n".join(loadedFiles)))
Expand All @@ -333,7 +353,7 @@ def loadLibraryInNewOM():
execstat["parsing"]=monotonic()-start
with open(errFile, 'a+') as fp:
fp.write("Timeout error for cmd: %s\n%s"%(cmd,str(e)))
writeResultAndExit(0, True)
writeResultAndExit(0, True, omc, omc_new)
execstat["parsing"]=monotonic()-start

try:
Expand Down Expand Up @@ -399,7 +419,7 @@ def sendExpressionOldOrNew(cmd):
except:
pass

writeResultAndExit(0)
writeResultAndExit(0, omc, omc_new)

# See which translateModel phases completed

Expand All @@ -413,14 +433,7 @@ def sendExpressionOldOrNew(cmd):
frontend = omc.sendExpression("OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_FRONTEND)")

writeResult()
try:
omc.sendExpression("quit()")
except:
pass
try:
del omc
except:
pass
omc = quit_omc(omc)

print(execTimeTranslateModel,frontend,backend)
if backend != -1:
Expand Down Expand Up @@ -452,7 +465,7 @@ def sendExpressionOldOrNew(cmd):
fp.write(err)

if execstat["phase"] < 4:
writeResultAndExit(0)
writeResultAndExit(0, False, omc, omc_new)

start=monotonic()
try:
Expand All @@ -463,7 +476,7 @@ def sendExpressionOldOrNew(cmd):
if not os.path.exists(os.path.normpath(fmuExpectedLocation)):
err += "\nFMU was not generated in the expected location: %s" % fmuExpectedLocation
execstat["phase"]=4
writeResultAndExit(0)
writeResultAndExit(0, False, omc, omc_new)
execstat["phase"] = 5
else:
if isWin:
Expand All @@ -477,7 +490,7 @@ def sendExpressionOldOrNew(cmd):
execstat["build"] = monotonic()-start
with open(errFile, 'a+') as fp:
fp.write(str(e))
writeResultAndExit(0, True)
writeResultAndExit(0, True, omc, omc_new)

writeResult()
# Do the simulation
Expand All @@ -493,7 +506,7 @@ def sendExpressionOldOrNew(cmd):
if not conf.get("fmisimulator"):
with open(simFile,"w") as fp:
fp.write("OMSimulator not available\n")
writeResultAndExit(0)
writeResultAndExit(0, False, omc, omc_new)
fmitmpdir = "temp_%s_fmu" % conf["fileName"].replace(".","_")
with open("%s.tmpfiles" % conf["fileName"], "a+") as fp:
fp.write("%s\n" % fmitmpdir)
Expand Down Expand Up @@ -527,20 +540,19 @@ def sendExpressionOldOrNew(cmd):
execstat["phase"] = 6
except TimeoutError as e:
execstat["sim"] = monotonic()-start
writeResultAndExit(0, True)
writeResultAndExit(0, True, omc, omc_new)

if referenceFile=="":
writeResultAndExit(0)
writeResultAndExit(0, False, omc, omc_new)
if len(referenceVars)==0:
execstat["diff"] = {"time":0.0, "vars":[], "numCompared":0}
execstat["phase"]=7
writeResultAndExit(0)
writeResultAndExit(0, False, omc, omc_new)

# Check the reference file...

prefix = os.path.abspath("../files/%s.diff" % conf["fileName"]).replace('\\','/')


if not os.path.exists(os.path.normpath(resFile)):
with open(errFile, 'a+') as fp:
fp.write("TODO: How the !@#!# did the simulation report success but simulation result %s does not exist to compare? outputFormat=%s" % (resFile,outputFormat))
Expand All @@ -551,7 +563,7 @@ def sendExpressionOldOrNew(cmd):
if not sendExpressionTimeout(omc_new, 'filterSimulationResults("%s", "updated%s", vars={%s}, removeDescription=false, hintReadAllVars=false)' % (resFile, resFile, ", ".join(['"%s"' % s for s in referenceVars])), conf["ulimitOmc"]):
with open(errFile, 'a+') as fp:
fp.write("Failed to filter simulation results. Took time: %.2f\n" % (monotonic()-start))
writeResultAndExit(0)
writeResultAndExit(0, False, omc, omc_new)
os.remove(resFile)
os.rename("updated" + resFile, resFile)
with open(errFile, 'a+') as fp:
Expand All @@ -563,7 +575,7 @@ def sendExpressionOldOrNew(cmd):
except TimeoutError as e:
with open(errFile, 'a+') as fp:
fp.write("Timeout error for diffSimulationResults")
writeResultAndExit(0)
writeResultAndExit(0, False, omc, omc_new)

execstat["diff"] = {"time":monotonic()-start, "vars":[], "numCompared":len(referenceVars)}
if len(diffVars)==0 and referenceOK:
Expand Down Expand Up @@ -635,4 +647,7 @@ def sendExpressionOldOrNew(cmd):
</body>
</html>""" % (tolerance, conf["reference_reltolDiffMinMax"], conf["reference_rangeDelta"], os.path.basename(prefix + "." + var + ".csv"), var))

# quit omc_new
omc_new = quit_omc(omc_new)

writeResultAndExit(0)

0 comments on commit 0bb942c

Please sign in to comment.