diff --git a/test.py b/test.py index b7753c7..e0f2753 100755 --- a/test.py +++ b/test.py @@ -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=
CommitDateAuthorSummary
%%h%%ai%%an%%s
' % (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=
CommitDateAuthorSummary
%%h%%ai%%an%%s
' % (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 = "" diff --git a/testmodel.py b/testmodel.py index a1c9705..c0718bf 100755 --- a/testmodel.py +++ b/testmodel.py @@ -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) @@ -73,6 +79,8 @@ 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(): @@ -80,6 +88,8 @@ def target(res): 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") @@ -117,6 +127,8 @@ 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(): @@ -124,6 +136,8 @@ def target(res): 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: @@ -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: