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
62 changes: 37 additions & 25 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,37 +1015,49 @@ def cpu_name():
# adrpo: attempt to get the revision of the reference files if possible
if conf.get("referenceFiles"):
c = conf.get("referenceFiles")
print("referenceFiles git ... attempting to retrieve info from directory: %s" % c)
sys.stdout.flush()
try:
gitReferenceFiles = c
if isinstance(c, (str, bytes)):
print("referenceFiles git ... see if directory has an evironment variable")
if DEBUG:
print("referenceFiles git ... attempting to retrieve info from directory: %s" % c)
sys.stdout.flush()
gitReferenceFiles = c
# see if we have a commit file
f = os.path.join(c, "commit")
if os.path.exists(f):
with open(f) as fin:
gitReferenceFilesVersion = fin.read()
print("referenceFiles git ... read from file %s" % f)
sys.stdout.flush()
m = re.search("^[$][A-Z_]+", c)
if m:
k = m.group(0)[1:]
if k not in os.environ:
print("referenceFiles git ... environment variable used in the directory cannot be found in the environment: %s" % k)
else:
try:
if isinstance(c, (str, bytes)):
if DEBUG:
print("referenceFiles git ... see if directory has an evironment variable")
sys.stdout.flush()
raise Exception("Environment variable %s not defined, but used in JSON config for reference files" % k)
gitReferenceFiles = c.replace(m.group(0), os.environ[k])
print("referenceFiles git ... directory after replacing the environment variable: %s" % gitReferenceFiles)
m = re.search("^[$][A-Z_]+", c)
if m:
k = m.group(0)[1:]
if k not in os.environ:
if DEBUG:
print("referenceFiles git ... environment variable used in the directory cannot be found in the environment: %s" % k)
sys.stdout.flush()
raise Exception("Environment variable %s not defined, but used in JSON config for reference files" % k)
gitReferenceFiles = c.replace(m.group(0), os.environ[k])
if DEBUG:
print("referenceFiles git ... directory after replacing the environment variable: %s" % gitReferenceFiles)
sys.stdout.flush()
sys.stdout.flush()
try:
gitReferenceFilesURL = check_output_log(["git", "config", "get", "remote.origin.url"], cwd=gitReferenceFiles).decode("utf-8")
except subprocess.CalledProcessError as e:
print(str(e))
gitReferenceFilesURL = gitReferenceFiles
gitReferenceFilesVersion = check_output_log(["git", "log", '--pretty=<table><tr><th>Commit</th><th>Date</th><th>Author</th><th>Summary</th></tr><tr><td><a href="%s/%%h">%%h</a></td><td>%%ai</td><td>%%an</td><td>%%s</td></tr></table>' % (gitReferenceFilesURL), "-1"], cwd=gitReferenceFiles).decode("utf-8")
print("referenceFiles git ... got version information: %s" % gitReferenceFilesVersion)
sys.stdout.flush()
try:
gitReferenceFilesURL = check_output_log(["git", "config", "get", "remote.origin.url"], cwd=gitReferenceFiles).decode("utf-8")
except subprocess.CalledProcessError as e:
print("referenceFiles git ... something went wrong with getting the git info for directory: %s" % c)
print(str(e))
gitReferenceFilesURL = gitReferenceFiles
gitReferenceFilesVersion = check_output_log(["git", "log", '--pretty=<table><tr><th>Commit</th><th>Date</th><th>Author</th><th>Summary</th></tr><tr><td><a href="%s/%%h">%%h</a></td><td>%%ai</td><td>%%an</td><td>%%s</td></tr></table>' % (gitReferenceFilesURL), "-1"], cwd=gitReferenceFiles).decode("utf-8")
print("referenceFiles git ... got version information: %s" % gitReferenceFilesVersion)
sys.stdout.flush()
except subprocess.CalledProcessError as e:
print("referenceFiles git ... something went wrong with getting the git info for directory: %s" % c)
print(str(e))
sys.stdout.flush()
gitReferenceFilesVersion = ""
sys.stdout.flush()
gitReferenceFilesVersion = ""
else:
gitReferenceFilesVersion = ""

Expand Down
16 changes: 14 additions & 2 deletions testmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ def sendExpressionTimeout(omc, cmd, timeout):
fp.write("%s [Timeout %s]\n" % (cmd, timeout))
def target(res):
try:
ignore = omc.sendExpression("alarm(%s)" % timeout)
res[0] = omc.sendExpression(cmd)
with open(errFile, 'a+') as fp:
fp.write(omc.sendExpression('OpenModelica.Scripting.getErrorString()'))
elapsed = omc.sendExpression("alarm(0)")
with open(errFile, 'a+') as fp:
fp.write("[Timeout remaining time %s]\n" % elapsed)
except Exception as e:
res[1] = cmd + " " + str(e)

Expand All @@ -73,13 +79,17 @@ def target(res):
try:
os.kill(process.pid, signal.SIGINT)
except OSError:
with open(errFile, 'a+') as fp:
fp.write("Could not SIGINT process: %s.\n" % process.pid)
pass
thread.join(2)
if thread.is_alive():
for process in psutil.Process().children(recursive=True):
try:
os.kill(process.pid, signal.SIGKILL)
except OSError:
with open(errFile, 'a+') as fp:
fp.write("Could not SIGKILL process: %s.\n" % process.pid)
pass
with open(errFile, 'a+') as fp:
fp.write("Aborted the command.\n")
Expand Down Expand Up @@ -117,13 +127,17 @@ def target(res):
try:
os.killpg(process.pid, signal.SIGINT)
except OSError:
with open(errFile, 'a+') as fp:
fp.write("Could not SIGINT process: %s.\n" % process.pid)
pass
thread.join(2)
if thread.is_alive():
for process in psutil.Process().children(recursive=True):
try:
os.kill(process.pid, signal.SIGKILL)
except OSError:
with open(errFile, 'a+') as fp:
fp.write("Could not SIGKILL process: %s.\n" % process.pid)
pass
thread.join()
if res[1] is None:
Expand Down Expand Up @@ -270,8 +284,6 @@ def createOmcSessionNew():
def loadModels(omc, conf):
for f in conf["loadFiles"]:
if not sendExpressionTimeout(omc, 'loadFile("%s", uses=false)' % f, conf["ulimitLoadModel"]):
with open(errFile, 'a+') as fp:
fp.write(omc.sendExpression('OpenModelica.Scripting.getErrorString()'))
writeResultAndExit(0)
loadedFiles = sorted(omc.sendExpression("{getSourceFile(cl) for cl in getClassNames()}"))
if sorted(conf["loadFiles"]) != loadedFiles:
Expand Down