Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions conversionscript.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from OMPython import OMCSessionZMQ
import pyparsing
from OMPython import OMCSessionZMQ, pyparsing
import argparse
import glob
import json
Expand All @@ -13,6 +12,7 @@
from multiprocessing import Pool
import time


parser = argparse.ArgumentParser(description='OpenModelica library testing tool')
parser.add_argument('libdir', nargs=1)
parser.add_argument('--diff', action="store_true")
Expand All @@ -32,6 +32,17 @@
os.mkdir("converted-libraries/.openmodelica")
os.mkdir("converted-libraries/.openmodelica/libraries")

def omcAssert(omc, cmd, extra=""):
res = omc.sendExpression(cmd)
if not res:
raise Exception(cmd + "\n" + extra + "\n" + (omc.sendExpression("getErrorString()") or ""))

def omcSendExpression(omc, cmd, extra=""):
try:
return omc.sendExpression(cmd)
except pyparsing.ParseException as e:
raise Exception(str(e) + "\n" + cmd + "\n" + extra + "\n" + (omc.sendExpression("getErrorString()") or ""))

mslPath = "%s/Modelica 4.0.0+maint.om/" % libdir
with open("%s/openmodelica.metadata.json" % mslPath) as f:
mslData = json.load(f)
Expand Down Expand Up @@ -72,7 +83,7 @@ def convertPackage(p):
print("Start working on %s" % libnameOnFile)
omc = OMCSessionZMQ()
libnameOnFileFullPath = "converted-libraries/.openmodelica/libraries/%s/package.mo" % libnameOnFile
omc.sendExpression('loadFile("%s", uses=false)' % libnameOnFileFullPath)
omcAssert(omc, 'loadFile("%s", uses=false)' % libnameOnFileFullPath)
errString = omc.sendExpression("getErrorString()")
if errString:
print(errString)
Expand All @@ -81,12 +92,12 @@ def convertPackage(p):
raise Exception("Expected to have loaded %s but got %s" % (libnameOnFileFullPath, loadedFilePath))
gcProfStatsBeforeConversion = omc.sendExpression("GC_get_prof_stats()")
timeBeforeConvert = time.time()
omc.sendExpression('runConversionScript(%s, "%s")' % (libname, conversionScript))
omcAssert(omc, 'runConversionScript(%s, "%s")' % (libname, conversionScript))
print("runConversionScript(%s, %s) OK" % (libnameOnFile, conversionScript))
uses = data["uses"]
for (n,v) in data["uses"].items():
if n in ["Modelica", "ModelicaServices", "Complex"]:
omc.sendExpression('addClassAnnotation(%s, annotate=$annotation(uses(%s(version="4.0.0"))))' % (libname, n))
omcAssert(omc, 'addClassAnnotation(%s, annotate=$annotation(uses(%s(version="4.0.0"))))' % (libname, n))
data["uses"][n] = "4.0.0"
names = omc.sendExpression('getClassNames(%s, sort=true, recursive=true)' % libname)
names = list(names)
Expand Down Expand Up @@ -138,7 +149,7 @@ def convertPackage(p):
print(errStr)
raise Exception('--allowErrorsInDiff is not active:\necho(false);before:=readFile("%s");\nafter:=readFile("%s");echo(true);\ndiffModelicaFileListings(before, after, OpenModelica.Scripting.DiffFormat.plain, failOnSemanticsChange=true);\ngetErrorString();' % (oldFile, newFile))
else:
omc.sendExpression('writeFile("%s", res)' % (newFile))
omcAssert(omc, 'writeFile("%s", res)' % (newFile))
isDiff = before != res
if before != res:
nDiff += 1
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ juliacall
matplotlib
monotonic
natsort
OMPython==4.0
ompython==3.6
psutil
simplejson
5 changes: 2 additions & 3 deletions shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ def getReferenceFileName(conf):
else:
modelName += "."+conf["referenceFileNameExtraName"]
referenceFile = conf["referenceFiles"]+"/"+modelName.replace(".",conf["referenceFileNameDelimiter"])+(conf.get("referenceFinalDot") or ".")+conf["referenceFileExtension"]
if os.path.exists(referenceFile):
referenceFile = os.path.abspath(referenceFile)

if not os.path.exists(referenceFile) and not os.path.isdir(referenceFile):
if conf.get("allReferenceFilesExist"):
raise Exception("Missing reference file %s for config %s" % (referenceFile,conf))
Expand Down Expand Up @@ -108,3 +105,5 @@ def isFMPy(fmisimulator):
return 'fmpy' in fmisimulator
else:
return False


6 changes: 4 additions & 2 deletions single-model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import argparse
import sys, argparse
import simplejson as json
import shared

parser = argparse.ArgumentParser(description='OpenModelica model testing report generation tool')
Expand All @@ -20,7 +21,8 @@

libs = {}

import sqlite3, datetime
import cgi, sqlite3, time, datetime
from omcommon import friendlyStr, multiple_replace

conn = sqlite3.connect('sqlite3.db')
cursor = conn.cursor()
Expand Down
34 changes: 11 additions & 23 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
if (sys.version_info < (3, 0)):
raise Exception("Python2 is no longer supported")

import html, shutil, os, re, glob, time, argparse, sqlite3, datetime, math
import html, shutil, os, re, glob, time, argparse, sqlite3, datetime, math, platform
from joblib import Parallel, delayed
import simplejson as json
import psutil, subprocess, threading, hashlib
from subprocess import call
from monotonic import monotonic
from omcommon import friendlyStr, multiple_replace
from natsort import natsorted
Expand Down Expand Up @@ -259,19 +260,14 @@ def target():
print("Error: Expected at least one configuration file to start the library test")
sys.exit(1)

from OMPython import OMCSessionZMQ, OMCProcessDocker, OMCSessionException
from OMPython import OMCSession, OMCSessionZMQ

# Try to make the processes a bit nicer...
os.environ["GC_MARKERS"]="1"

print("Start OMC version")

if docker:
omc = OMCProcessDocker(docker=docker, dockerExtraArgs=dockerExtraArgs)
omhome=omc.sendExpression('getInstallationDirectoryPath()')
omc_version=omc.sendExpression('getVersion()')
ompython_omc_version=omc_version
elif ompython_omhome != "":
if ompython_omhome != "":
# Use a different OMC for running OMPython than for running the tests
omhome = os.environ["OPENMODELICAHOME"]
omc_version = check_output_log(omc_cmd + ["--version"], stderr=subprocess.STDOUT).decode("ascii").strip()
Expand All @@ -280,11 +276,10 @@ def target():
ompython_omc_version=omc.sendExpression('getVersion()')
os.environ["OPENMODELICAHOME"] = omhome
else:
omc = OMCSessionZMQ()
omc = OMCSessionZMQ(docker=docker, dockerExtraArgs=dockerExtraArgs)
omhome=omc.sendExpression('getInstallationDirectoryPath()')
omc_version=omc.sendExpression('getVersion()')
ompython_omc_version=omc_version

ompython_omc_version=ompython_omc_version.replace("OMCompiler","").strip()

def timeSeconds(f):
Expand Down Expand Up @@ -663,12 +658,11 @@ def hashReferenceFiles(s):
raise Exception("Library %s has both libraryVersionLatestInPackageManager:true and libraryVersionExactMatch:true! Make up your mind." % libName)
exactMatch=', requireExactVersion=true'

try:
omc.sendExpression('loadModel(%s,%s%s)' % (lib,versions,exactMatch))
except OMCSessionException as e:
print("Failed to load library %s %s" % (library,versions))
print(e)

if not omc.sendExpression('loadModel(%s,%s%s)' % (lib,versions,exactMatch)):
try:
print("Failed to load library %s %s: %s" % (library,versions,omc.sendExpression('OpenModelica.Scripting.getErrorString()')))
except:
print("Failed to load library %s %s. OpenModelica.Scripting.getErrorString() failed..." % (library,conf["libraryVersion"]))
# adrpo: do not sort the top level names as sometimes that loads a bad MSL version
# conf["loadFiles"] = sorted(omc.sendExpression("{getSourceFile(cl) for cl in getClassNames()}"))
conf["loadFiles"] = omc.sendExpression("{getSourceFile(cl) for cl in getClassNames()}")
Expand Down Expand Up @@ -727,13 +721,7 @@ def hashReferenceFiles(s):
if conf.get("fmi") and fmisimulatorversion:
conf["libraryVersionRevision"] = conf["libraryVersionRevision"] + " " + fmisimulatorversion.decode("ascii")
conf["libraryLastChange"] = conf["libraryLastChange"] + " " + fmisimulatorversion.decode("ascii")
res = []
try:
res = omc.sendExpression('{c for c guard isExperiment(c) and not regexBool(typeNameString(x), "^Modelica_Synchronous\\\\.WorkInProgress") in getClassNames(%s, recursive=true)}' % library)
except OMCSessionException as e:
print("Failed to get class names of library %s", library)
print(e)

res=omc.sendExpression('{c for c guard isExperiment(c) and not regexBool(typeNameString(x), "^Modelica_Synchronous\\.WorkInProgress") in getClassNames(%s, recursive=true)}' % library)
if conf.get("ignoreModelPrefix"):
if isinstance(conf["ignoreModelPrefix"], list):
prefixes = conf["ignoreModelPrefix"]
Expand Down
15 changes: 6 additions & 9 deletions testmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# -*- coding: utf-8 -*-

import argparse, os, sys, signal, threading, psutil, subprocess, shutil
from asyncio.subprocess import STDOUT
import simplejson as json
from monotonic import monotonic
from OMPython import OMCSessionZMQ, OMCProcessDocker
from OMPython import FindBestOMCSession, OMCSession, OMCSessionZMQ
import shared, glob

parser = argparse.ArgumentParser(description='OpenModelica library testing tool helper (single model)')
Expand Down Expand Up @@ -57,7 +58,7 @@ def writeResult():

startJob=monotonic()

def quit_omc(omc: OMCSessionZMQ | None):
def quit_omc(omc):
if omc is None:
return omc
try:
Expand All @@ -71,7 +72,7 @@ def quit_omc(omc: OMCSessionZMQ | None):
omc = None
return omc

def writeResultAndExit(exitStatus: int, useOsExit: bool = False, omc: OMCSessionZMQ | None = None, omc_new: OMCSessionZMQ | None = None):
def writeResultAndExit(exitStatus, useOsExit=False, omc=None, omc_new=None):
writeResult()
print("Calling exit ...")
with open(errFile, 'a+') as fp:
Expand All @@ -89,7 +90,7 @@ def writeResultAndExit(exitStatus: int, useOsExit: bool = False, omc: OMCSession
else:
sys.exit(exitStatus)

def sendExpressionTimeout(omc: OMCSessionZMQ, cmd: str, timeout: int):
def sendExpressionTimeout(omc, cmd, timeout):
with open(errFile, 'a+') as fp:
fp.write("%s [Timeout %s]\n" % (cmd, timeout))
def target(res):
Expand Down Expand Up @@ -250,11 +251,7 @@ def target(res):
os.environ["OPENMODELICAHOME"] = omhome

def createOmcSession():
if docker:
return OMCProcessDocker(docker=docker, dockerExtraArgs=dockerExtraArgs, timeout=5)
else:
return OMCSessionZMQ(timeout=5)

return OMCSession(docker=docker, dockerExtraArgs=dockerExtraArgs, timeout=5) if corbaStyle else OMCSessionZMQ(docker=docker, dockerExtraArgs=dockerExtraArgs, timeout=5)
def createOmcSessionNew():
if ompython_omhome != "":
os.environ["OPENMODELICAHOME"] = ompython_omhome
Expand Down
Loading