Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 66b19e0

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
More options for ModelicaCompliance testing
- Added the ability to add custom flags (to test newInst) - Optionally add a list of tests expected to fail (for Jenkins) Belonging to [master]: - #2571
1 parent c44a538 commit 66b19e0

File tree

2 files changed

+85
-22
lines changed

2 files changed

+85
-22
lines changed

Examples/ComplianceSuite.mos

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
// Runs the ModelicaCompliance suite
2-
// Output is the files "openmodelica.xml" and "openmodelica.html", which is a valid jUnit testcase and possible to generate html reports from (the generated file is one example, using the default xsl)
2+
// Default output is the files "openmodelica.xml" and "openmodelica.html", which is a valid jUnit testcase and possible to generate html reports from (the generated file is one example, using the default xsl)
3+
// A file called "openmodelica.ignore.xml" is also generated, which can be used together with a file to mark skipped tests (they still run to see if the results have improved)
4+
// COMPLIANCEEXTRAOMFLAGS=-d=newInst COMPLIANCEEXTRAREPORTFLAGS=--prefix=openmodelica-newinst can be used as well
35

46
setCommandLineOptions("-g=Modelica");
57
loadModel(ModelicaCompliance);getErrorString();
68
setCommandLineOptions("-g=MetaModelica");
79
writeFile("version","omc "+getVersion()+" compliance suite "+getVersion(ModelicaCompliance));getErrorString();
810

11+
COMPLIANCEEXTRAOMFLAGS := getEnvironmentVar("COMPLIANCEEXTRAFLAGS");
12+
COMPLIANCEEXTRAREPORTFLAGS := getEnvironmentVar("COMPLIANCEEXTRAREPORTFLAGS");
13+
914
loadString("
1015
function last
1116
input String str[:];
12-
output String ostr := str[end];
17+
output String ostr = str[end];
1318
end last;
1419
function fixName
1520
input String str;
@@ -23,12 +28,12 @@ system("rm -f ModelicaCompliance.*.res");getErrorString();
2328

2429
echo(false);
2530
allClasses:={cl for cl guard classAnnotationExists(cl,__ModelicaAssociation.TestCase.shouldPass) in getClassNames(recursive=true)};getErrorString();
26-
commands:={"ulimit -t 120 && ("+getInstallationDirectoryPath()+"/bin/omc -d=nogen \"" + fixName(OpenModelica.Scripting.typeNameString(cl)) + ".mos\" > /dev/null 2>&1)" for cl in allClasses};
31+
commands:={"ulimit -t 120 && ("+getInstallationDirectoryPath()+"/bin/omc -d=nogen "+COMPLIANCEEXTRAOMFLAGS+" \"" + fixName(OpenModelica.Scripting.typeNameString(cl)) + ".mos\" > /dev/null 2>&1)" for cl in allClasses};
2732
echo(true);
2833
String(size(allClasses,1)) + " number of classes";
2934

3035
min(OpenModelica.Scripting.writeFile(fixName(typeNameString(cl))+".mos","
31-
OpenModelica.Scripting.writeFile(\""+fixName(typeNameString(cl))+".res\",\"<testcase name=\\\""+fixName(last(OpenModelica.Scripting.typeNameStrings(cl)))+"\\\"><error type=\\\"killed\\\" message=\\\"killed or crashed\\\"/></testcase>\");
36+
OpenModelica.Scripting.writeFile(\""+fixName(typeNameString(cl))+".res\",\"{\\\"killed\\\":true}\");
3237

3338
loadModel(ModelicaCompliance);getErrorString();
3439
// delete classes that generate errors all the time
@@ -59,27 +64,14 @@ success := if shouldPass then resultFile<>\"\" else resultFile==\"\";
5964
messages := rec.messages;
6065
messages := messages + err;
6166
messages := messages + (if not success and not shouldPass /* This is correct; try to figure out why (hint: success is a poor name) */ then \"\nSucceeded, but expected failure\" else \"\");
62-
messages := OpenModelica.Scripting.escapeXML(firstPart(messages));
67+
messages := stringReplace(stringReplace(firstPart(messages),\"\\\"\",\"\\\\\\\"\"),\"\n\",\"\\\\n\");
6368
errorType := if shouldPass then \"failed\" else \"expected failure\";
64-
writeFile(\""+fixName(typeNameString(cl))+".res\",\"<testcase name=\\\""+fixName(last(OpenModelica.Scripting.typeNameStrings(cl)))+"\\\">\"+(if not success then \"<error type=\\\"\"+errorType+\"\\\" message=\\\"\"+messages+\"\\\"/>\" else \"\")+\"</testcase>\n\");
69+
time := rec.timeTotal;
70+
writeFile(\""+fixName(typeNameString(cl))+".res\",\"{\\\"time\\\":\"+String(time)+\", \\\"success\\\":\"+String(success)+\", \\\"messages\\\":\\\"\"+messages+\"\\\", \\\"shouldPass\\\":\"+String(shouldPass)+\"}\n\");
6571
") for cl in allClasses);
6672
getErrorString();
67-
system_parallel(commands);getErrorString();
6873

69-
writeFile("ComplianceSuite.sh","#!/bin/bash
70-
OMCRESULT=openmodelica.xml
71-
echo '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' > \"$OMCRESULT\"
72-
echo '<testsuites name=\"'`cat version`'\">' >> \"$OMCRESULT\"
73-
for f in `ls ModelicaCompliance.*.res | sed 's/[.][^.]*[.]res$//' | sort -u`; do
74-
echo \"<testsuite name=\\\"$f\\\">\" >> \"$OMCRESULT\"
75-
for t in `ls \"$f\".*.res | grep \"$f[.][^.]*[.]res\"`; do
76-
iconv -f utf8 -t utf8 -c \"$t\" >> \"$OMCRESULT\"
77-
done
78-
echo \"</testsuite>\" >> \"$OMCRESULT\"
79-
done
80-
echo '</testsuites>' >> \"$OMCRESULT\"
81-
echo \"$OMCRESULT\"
82-
");getErrorString();
83-
system("bash ComplianceSuite.sh");
8474
filename := OpenModelica.Scripting.uriToFilename("modelica://ModelicaCompliance/Resources/tools/xml-report/report.xsl");getErrorString();
75+
system_parallel(commands);getErrorString();
76+
system("python3 "+getInstallationDirectoryPath()+"/share/doc/omc/testmodels/ComplianceSuite.py --version=\"`cat version`\"" + COMPLIANCEEXTRAREPORTFLAGS);getErrorString();
8577
system("xsltproc -o openmodelica.html '" + filename + "' openmodelica.xml");getErrorString();

Examples/ComplianceSuite.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
from junit_xml import TestSuite, TestCase
5+
import glob
6+
import simplejson
7+
import subprocess
8+
import time
9+
10+
def readTest(f, expectedFailures):
11+
cl = ".".join(f.split(".")[:-1])
12+
name = f.split(".")[-2]
13+
with open(f) as fin:
14+
res = simplejson.load(fin)
15+
if "killed" in res:
16+
tc = TestCase(name, cl, 0, '', '')
17+
tc.add_error_info('Killed or crashed')
18+
return (tc, tc, cl)
19+
20+
tc1 = TestCase(name, cl, res["time"], res["messages"], '')
21+
tc2 = TestCase(name, cl, res["time"], res["messages"], '')
22+
success = res["success"]
23+
shouldPass = res["shouldPass"]
24+
expectFail = cl in expectedFailures
25+
if expectFail:
26+
if success:
27+
tc1.add_error_info('This testcase started working (failure was expected)')
28+
else:
29+
tc1.add_skipped_info('This testcase still fails (as expected)')
30+
elif not success:
31+
if shouldPass:
32+
tc1.add_error_info('failed')
33+
else:
34+
tc1.add_error_info('expected failure, but passed')
35+
if not success:
36+
if shouldPass:
37+
tc2.add_error_info('failed')
38+
else:
39+
tc2.add_error_info('expected failure, but passed')
40+
return (tc1, tc2, None if success else cl)
41+
42+
if __name__ == '__main__':
43+
parser = argparse.ArgumentParser(description='OpenModelica ModelicaCompliance testing tool')
44+
parser.add_argument('--expectedFailures', default=None)
45+
parser.add_argument('--outPrefix', default="openmodelica")
46+
parser.add_argument('--version', default="OpenModelica ???")
47+
args = parser.parse_args()
48+
expectedFailuresFile = args.expectedFailures
49+
outPrefix = args.outPrefix
50+
version = args.version
51+
52+
expectedFailures = set()
53+
if expectedFailuresFile:
54+
with open(expectedFailuresFile) as fin:
55+
expectedFailures = set(l.strip() for l in fin.readlines())
56+
print(expectedFailures)
57+
58+
res = [readTest(f, expectedFailures) for f in glob.glob("*.res")]
59+
60+
(tcs1,tcs2,failures) = zip(*res)
61+
ts1 = TestSuite(version, tcs1)
62+
ts2 = TestSuite(version, tcs2)
63+
if outPrefix:
64+
with open("%s.ignore.xml" % outPrefix, "w") as fout:
65+
TestSuite.to_file(fout, [ts1], prettyprint=False)
66+
with open("%s.xml" % outPrefix, "w") as fout:
67+
TestSuite.to_file(fout, [ts2], prettyprint=False)
68+
with open("%s.failures" % outPrefix, "w") as fout:
69+
for fail in failures:
70+
if fail:
71+
fout.write(fail + "\n")

0 commit comments

Comments
 (0)