diff --git a/diff.html.tpl b/diff.html.tpl new file mode 100644 index 0000000..a768bea --- /dev/null +++ b/diff.html.tpl @@ -0,0 +1,214 @@ + + + + + +#title# + + + +
+

#title#

+ + +
+
+ +
+
▬ reference▬ result
+ +Drag to zoom the time axis, double-click to reset. +
+
+ + + diff --git a/library.html.tpl b/library.html.tpl index 9813ba9..6d17218 100644 --- a/library.html.tpl +++ b/library.html.tpl @@ -55,15 +55,5 @@ Config:
#config#
ModelVerifiedSimulateTotal buildModelParsingFrontendBackendSimCodeTemplatesCompileTotal Execution #testsHTML# - diff --git a/shared.py b/shared.py index 69234eb..e627214 100644 --- a/shared.py +++ b/shared.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import collections, re, os, signal, string, subprocess, threading, traceback +import base64, collections, gzip, html, re, os, signal, string, subprocess, threading, traceback import simplejson as json # Windows has no SIGKILL, and no process group to signal instead; os.kill there @@ -448,3 +448,20 @@ def branchForSimulator(branch, name): together or on their own. """ return branch + fmiSimulator(name).get("branchSuffix", "-%s" % name) + +def writeDiffPage(prefix, title): + """Write prefix.html from prefix.mat and prefix.ref.mat, the differing + variables of a failed verification. The page holds both files, so that it + also works from a local disk and on servers that need a login. + """ + files = {"result": prefix + ".mat", "reference": prefix + ".ref.mat"} + if not all(os.path.exists(f) for f in files.values()): + return + with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "diff.html.tpl")) as fin: + page = fin.read() + for key, f in files.items(): + with open(f, "rb") as fin: + page = page.replace('"#%s#"' % key, '"%s"' % base64.b64encode(gzip.compress(fin.read())).decode()) + page = page.replace("#title#", html.escape(title)).replace("#basename#", os.path.basename(prefix)) + with open(prefix + ".html", "w") as fout: + fout.write(page) diff --git a/test.py b/test.py index 6ef2300..d3e0bce 100755 --- a/test.py +++ b/test.py @@ -1536,6 +1536,7 @@ def publishLibrary(libname): if (s[3].get("diff") or {}).get("vars"): filesList.write("/%s.diff.mat\n" % filename_prefix) filesList.write("/%s.diff.ref.mat\n" % filename_prefix) + filesList.write("/%s.diff.html\n" % filename_prefix) filesList.close() testsHTML = "\n".join(['%s%s%s%s%s%s%s%s%s%s%s%s\n' % (lambda filename_prefix, errPrefix, diff: @@ -1546,7 +1547,7 @@ def publishLibrary(libname): # Nothing was compared, whatever phase the model reports. " " if diff is None else (("%s (%d verified)" % (timeSeconds(diff.get("time")), diff.get("numCompared"))) if s[3]["phase"]>=7 else - ('%s (%d/%d failed)' % (timeSeconds(diff.get("time")), filename_prefix, filename_prefix, len(diff.get("vars")), diff.get("numCompared")))), + ('%s (%d/%d failed)' % (timeSeconds(diff.get("time")), filename_prefix, len(diff.get("vars")), diff.get("numCompared")))), checkPhase(s[3]["phase"], 6), timeSeconds(s[3].get("sim") or 0), checkPhase(s[3]["phase"], 5), diff --git a/testmodel.py b/testmodel.py index 6f7843b..997c786 100755 --- a/testmodel.py +++ b/testmodel.py @@ -1175,10 +1175,11 @@ def verifyAgainstReference(resFile, prefix, stat): fp.write("\nVariables in the result:" ) fp.write(",".join(resVars)+"\n") stat["diff"]["vars"]=diffVars - # Both files reduced to the differing variables: what the report's OMPlot - # link compares, instead of a CSV and an HTML page per variable. + # Both files reduced to the differing variables: what the page linked from + # the report plots, instead of a CSV and an HTML page per variable. filterDiffVars(resFile, prefix + ".mat", diffVars) filterDiffVars(referenceFile, prefix + ".ref.mat", diffVars) + shared.writeDiffPage(prefix, conf["modelName"]) def filterDiffVars(inFile, outFile, diffVars): vars = ", ".join('"%s"' % v.replace('\\', '\\\\').replace('"', '\\"') for v in diffVars)