-
Notifications
You must be signed in to change notification settings - Fork 298
/
BuildModelRecursive.mos
435 lines (390 loc) · 22.5 KB
/
BuildModelRecursive.mos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
// Note: Run with +g=MetaModelica
// Some examples of CustomCommands.mos files are at the bottom of this file
settings := checkSettings();
configure := settings.CONFIGURE_CMDLINE;
if 0 == system("lsb_release -ds > lsb.release") then
system("uname -p > arch");
systemInfo := stringReplace(readFile("lsb.release") + " " + readFile("arch"), "\n", "");
else
systemInfo := settings.SYSTEM_INFO;
end if;
settingsStr :=
"// OpenModelica " + getVersion() + "\n" +
"// " + configure + "\n" +
"// " + systemInfo
;
setCommandLineOptions("-d=nogen");
if not regularFileExists("CustomCommands.mos") then
customCommands := "setCommandLineOptions(\"-d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection\");
setMatchingAlgorithm(\"PFPlusExt\");
setIndexReductionMethod(\"dynamicStateSelection\");";
writeFile("CustomCommands.mos",customCommands);
else
customCommands := readFile("CustomCommands.mos");
end if;
// May be overridde by CustomCommands.mos
referenceFiles:=getInstallationDirectoryPath()+"/../testsuite/ReferenceFiles/msl32";
referenceFileExtension:="mat";
referenceFileNameDelimiter:=".";
sortFiles:=true;
ulimitOmc:="660"; // 11 minutes to generate the C-code
ulimitExe:="480"; // 8 additional minutes to initialize and run the simulation
ulimitMemory:="16000000"; // ~16GB memory at most
javascript := false;
simFlags := "-abortSlowSimulation -alarm=" + ulimitExe;
customLibrary := false;
runScript("CustomCommands.mos");
customCommandsStr := if regularFileExists("CustomCommands.mos") then ("Flags: <pre>" + escapeXML(readFile("CustomCommands.mos")) + "</pre>") else "";
if not customLibrary then
// It is possible to change library in CustomCommands.mos only if customLibrary := true is set
library:=$TypeName(Modelica);
libraryVersion:="default";
end if;
setCommandLineOptions({"-g=Modelica","-d=nogen"});
OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
log:="BuildModelRecursive.html";
default_tolerance:=1e-6;
reference_reltol:=3e-3;
reference_reltolDiffMinMax:=3e-3;
reference_rangeDelta:=1e-3;
loadModel(library,{libraryVersion});
getErrorString();
libraryVersionRevision:=getVersion(library);
libraryLastChange := "";
print(sum(getSourceFile(l) + "\n" for l in getClassNames()));
if regularFileExists(dirname(getSourceFile(library))+".last_change") then
libraryLastChange := "( revision " + readFile(dirname(getSourceFile(library))+".last_change") + ")";
elseif 0 == system("svn info '" + dirname(getSourceFile(library)) + "' 2>&1 | egrep '^(URL|Last.Changed.Rev)' > svn.info") then
libraryLastChange := " " + readFile("svn.info");
end if;
libraryVersionRevision := (if libraryVersionRevision == "" then libraryVersion else libraryVersionRevision) + libraryLastChange;
libraryString:=typeNameString(library);
system("date +'%Y-%m-%d %H:%M:%S' > tmp.date");
dateAndTime:=readFile("tmp.date");
system("rm -f tmp.date");
loadModelCommand:="\n"+customCommands+"\nloadModel("+libraryString+",{\""+libraryVersion+"\"});\n";
omc:=getInstallationDirectoryPath()+"/bin/omc";
dygraphs:=getInstallationDirectoryPath()+"/share/doc/omc/testmodels/dygraph-combined.js";
a:={typeNameString(x) for x guard isExperiment(x) in getClassNames(library,recursive=true,sort=sortFiles)};
getErrorString();
// writeFile("x",sum(s + "\n" for s in a));
print("Number of classes to build: " + String(size(a,1)));
system("rm -f *.o");
system("rm -f *.c");
system("rm -f *.h");
system("rm -rf "+libraryString+"*");
system("rm -rf files/ "+log);
mkdir("files");
/*** This is the stuff executed for each model ***/
min(writeFile(s + ".mos",settingsStr + "
\""+s+"\";
echo(false);
alarm("+ulimitOmc+");
loadString(\"
function cell
input Real elapsedTime;
input Boolean greenOnOk := false;
input String greenColor := \\\"#00FF00\\\";
input String mdFile := \\\"\\\";
output String str;
algorithm
str := if mdFile == \\\"\\\" then \\\"\\\" else \\\" <a href=\\\\\\\"files/mdpad_local.html?\\\"+mdFile+\\\"\\\\\\\"><img width=\\\\\\\"16px\\\\\\\" src=\\\\\\\"files/Modelica.Icons.Example.svg\\\\\\\"></img></a>\\\";
str := if elapsedTime==-1.0 then \\\"<td bgcolor=\\\\\\\"#FF0000\\\\\\\"> </td>\\\" else ((if greenOnOk then \\\"<td bgcolor=\\\\\\\"\\\" + greenColor + \\\"\\\\\\\">\\\" else \\\"<td>\\\") +
OpenModelica.Scripting.Internal.Time.readableTime(elapsedTime)+str+\\\"</td>\\\");
end cell;
function length input String str; output Integer len; external \\\"C\\\" len=ModelicaStrings_length(str); end length;
function substring input String str; input Integer i1,i2; output String out; external \\\"C\\\" out=ModelicaStrings_substring(str,i1,i2); end substring;
function firstPart input String str; input Integer maxLength := 4096; output String out; algorithm out := if length(str) < maxLength then str else (substring(str,1,maxLength) + \\\"\n... (output truncated, was \\\" + String(length(str)) + \\\" bytes)\\\"); end firstPart;
function csvFileToVariable
input String str;
output String out;
protected
String matches[2];
algorithm
(,matches) := OpenModelica.Scripting.regex(str,\\\"^.*[.]diff[.](.*)$\\\",2);
out := matches[2];
end csvFileToVariable;
function testcase
input Real elapsedTime;
input Boolean success;
input String errNoXMLLong;
output String str;
protected
String errXML;
algorithm
errXML := OpenModelica.Scripting.escapeXML(firstPart(errNoXMLLong,16*1024)); // 16 kB log per test should be enough; increase if there is a good reason to do so
str:=\\\"<testcase name=\\\\\\\""+s+"\\\\\\\" elapsedTime=\\\\\\\"\\\"+String(elapsedTime)+\\\"\\\\\\\">\\\"+(
if not success then \\\"<error type=\\\\\\\"Failure\\\\\\\" />\\\"
else \\\"\\\"
)+(
if errXML <> \\\"\\\" then (\\\"<system-out>\\\" + errXML + \\\"</system-out>\\\")
else \\\"\\\"
)+
\\\"</testcase>\n\\\";
end testcase;
\");getErrorString();
statFile := \""+s+".stat\";
writeFile(\""+log+"\",\""+s+"\n\",append=true);
writeFile(statFile,\"<tr><td bgcolor=\\\"#ff0000\\\">"+s+"</td></tr>\");getErrorString();
writeFile(statFile + \".flat\", testcase(0,false,\"killed\"));getErrorString();
writeFile(statFile + \".compile\", testcase(0,false,\"killed\"));getErrorString();
writeFile(statFile + \".sim\", testcase(0,false,\"killed\"));getErrorString();
writeFile(statFile + \".verify\", testcase(0,false,\"killed\"));getErrorString();
writeFile(\"files/" + s + ".uses\", \"\");getErrorString();
outputFormat:=\"default\";
javascript:="+String(javascript)+";
mslRegressionOutput:=\"\";
"+loadModelCommand+"
reference_reltol:="+String(reference_reltol)+";
reference_reltolDiffMinMax:="+String(reference_reltolDiffMinMax)+";
reference_rangeDelta:="+String(reference_rangeDelta)+";
simFlags:=\""+simFlags+"\";
referenceOK := false;
referenceFiles := \""+referenceFiles+"\";
referenceCell := if referenceFiles == \"\" then \"\" else \"<td> </td>\";
reference := \""+referenceFiles+"/"+OpenModelica.Scripting.stringReplace(s,".",referenceFileNameDelimiter)+"."+referenceFileExtension+"\";
referenceExists := referenceFiles <> \"\" and regularFileExists(reference);
if not referenceExists then
reference := \""+referenceFiles+"/"+OpenModelica.Scripting.stringReplace(s,".","/")+"/"+basename(OpenModelica.Scripting.stringReplace(s,".","/"))+"."+referenceFileExtension+"\";
referenceExists := referenceFiles <> \"\" and regularFileExists(reference);
end if;
// outputFormat can be overridden in CustomCommands.mos, so we set it to 'default' first
outputFormat := if outputFormat == \"default\" then (if referenceExists then \"mat\" else \"empty\") else outputFormat;
compareVarsUri := \"modelica://\" + /*libraryString*/ \"Buildings\" + \"/Resources/Scripts/OpenModelica/compareVars/" + s + ".mos\";
(compareVarsFile,compareVarsFileMessages) := uriToFilename(compareVarsUri);
if regularFileExists(compareVarsFile) then
runScript(compareVarsFile);
vars := compareVars;
variableFilter := sum(stringReplace(stringReplace(s,\"[\",\".\"),\"]\",\".\") + \"|\" for s in vars) + \"time\";
numCompared := size(vars,1);
emit_protected := \" -emit_protected\";
elseif referenceExists then
vars := readSimulationResultVars(reference, readParameters=true, openmodelicaStyle=true);
variableFilter := sum(stringReplace(stringReplace(stringReplace(stringReplace(s,\"[\",\".\"),\"]\",\".\"),\"(\",\".\"),\")\",\".\") + \"|\" for s in vars);
numCompared := size(vars,1);
emit_protected := \" -emit_protected\";
// print(variableFilter + \"\n\");
else
variableFilter := \"\";
outputFormat := \"empty\";
emit_protected := \"\";
end if;
writeFile(\"files/" + s + ".uses\", sum(typeNameString(c) + \"\n\" for c in OpenModelica.Scripting.getUsedClassNames("+s+")));getErrorString();
// Use twice as many output points as the experiment annotation suggests. Else aim for 5000 points.
(startTime,stopTime,tolerance,numberOfIntervals,stepSize):=getSimulationOptions("+s+",defaultTolerance="+String(default_tolerance)+",defaultNumberOfIntervals=2500);
numberOfIntervals := 2*numberOfIntervals;
alarm("+ulimitOmc+"); // Reset the alarm in case the other parts took a long time (reading simulation results)
res:=buildModel("+s+",tolerance=tolerance,outputFormat=outputFormat,numberOfIntervals=numberOfIntervals,variableFilter=variableFilter);
// We built the model fine, so reset the alarm. The simulation executable will also have an alarm, making only result verification a potential to stall.
alarm(0);
greenColor := \"#00FF00\";
errFile:=\"files/"+s+".err\";
simFile:=\"files/"+s+".sim\";
(nmessage,nerror,nwarning) := countMessages();
errorLinkClass := if nerror>0 then \"messagesError\" elseif nwarning>0 then \"messagesWarning\" else \"messagesInfo\";
err:=getErrorString();
system(\"rm -f \" + errFile);
writeFile(simFile,\"\");
if err <> \"\" then
writeFile(errFile,err);
end if;
build :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BUILD_MODEL);
total :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMULATE_TOTAL);
templates:=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_TEMPLATES);
simcode :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_SIMCODE);
backend :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_BACKEND);
frontend :=OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_FRONTEND);
frontend :=if backend <> -1.0 then frontend-backend else frontend;
backend :=if simcode <> -1.0 then backend-simcode else backend;
simcode :=if templates <> -1.0 then simcode-templates else simcode;
templates:=if build <> -1.0 then templates-build else templates;
timeDiff := -1.0;
OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
buildRes := res[1] <> \"\";
simRes := if not buildRes then false else 0 == system(\"./"+s+" \"+simFlags+emit_protected+\" > \"+simFile+\" 2>&1\");
if buildRes and javascript then
system(\"cp " + s + ".js " + s + "_info.xml " + s + "_init.xml " + s + ".md files/\");
end if;
mdFile := if javascript then \""+s+".md\" else \"\";
resFile := \""+s+"_res.\" + outputFormat;
if mslRegressionOutput <> \"\" and referenceExists then
mslRegressionOutput := mslRegressionOutput + \"/"+OpenModelica.Scripting.stringReplace(s,".","/")+"/\";
mkdir(mslRegressionOutput);
simFailLog := mslRegressionOutput+\"simulate_failed.log\";
simSuccessLog := mslRegressionOutput+\"simulate_success.log\";
buildFailLog := mslRegressionOutput+\"translate_failed.log\";
buildSuccessLog := mslRegressionOutput+\"translate_success.log\";
system(\"rm -f \"+(if simRes then simFailLog else simSuccessLog));
system(\"rm -f \"+(if buildRes then buildFailLog else buildSuccessLog));
system(\"cp \"+simFile+\" \" + simFile + \".tmp\");
if simRes then
system(\"cp \"+resFile+\" "+s+".csv\");
compareFilesAndMove(\""+s+".csv\", mslRegressionOutput+\""+s+".csv\");
else
system(\"rm -f \" + mslRegressionOutput + \""+s+".csv\");
end if;
system(\"cp "+s+".mos "+s+".mos.tmp\");
if err == \"\" then
system(\"echo > \" + errFile + \".tmp\");
else
system(\"cp \" + errFile + \" \" + errFile + \".tmp\");
end if;
compareFilesAndMove(errFile + \".tmp\", if buildRes then buildSuccessLog else buildFailLog);
compareFilesAndMove(simFile + \".tmp\", if buildRes then simSuccessLog else simFailLog);
compareFilesAndMove(\""+s+".mos.tmp\", mslRegressionOutput+\"creation.txt\");
end if;
system(\"sed -i '300,$ d' '\" + simFile + \"'\"); // Only keep the top 300 lines
timeSim := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
if simRes then
system(\"touch "+s+".simsuccess\");
prefix := \"files/"+s+".diff\";
if referenceExists then
OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
getErrorString();
(referenceOK,diffVars) := diffSimulationResults(resFile,reference,prefix,relTol=reference_reltol,relTolDiffMinMax=reference_reltolDiffMinMax,rangeDelta=reference_rangeDelta);
errVerify := getErrorString();
if errVerify <> \"\" then
writeFile(errFile, \"\\nVariables in the reference:\"+sum(var+\",\" for var in OpenModelica.Scripting.readSimulationResultVars(reference, openmodelicaStyle=true)), append=true);
writeFile(errFile, \"\\nVariables in the result:\"+sum(var+\",\" for var in OpenModelica.Scripting.readSimulationResultVars(resFile))+\"\\n\" + errVerify, append=true);
end if;
if referenceOK then
system(\"touch "+s+".verifysuccess\");
end if;
timeDiff := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
diffFiles := {prefix + \".\" + var for var in diffVars};
// Create a file containing only the calibrated variables, for easy display
if not referenceOK then
timeDiff := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
referenceCell := \"<td bgcolor=\\\"#FF0000\\\">\"+OpenModelica.Scripting.Internal.Time.readableTime(timeDiff)+\", <a href=\\\"files/"+s+".diff.html\\\">\"+String(size(diffFiles,1))+\"/\"+String(numCompared)+\" signals failed</a></td>\";
writeFile(\"files/"+s+".diff.html\",\"<html><body><h1>"+s+" differences from the reference file</h1><p>startTime: \"+String(startTime)+\"</p><p>stopTime: \"+String(stopTime)+\"</p><p>Simulated using tolerance: \"+String(tolerance)+\"</p><ul>\" + sum(\"<li>\"+csvFileToVariable(file)+\" <a href=\\\"\"+OpenModelica.Scripting.basename(file)+\".html\\\">(javascript)</a> <a href=\\\"\"+OpenModelica.Scripting.basename(file)+\".csv\\\">(csv)</a></li>\" for file in diffFiles) + \"</ul></body></html>\");
{writeFile(prefix + \".\" + var + \".html\",\"<html>
<head>
<script type=\\\"text/javascript\\\" src=\\\"dygraph-combined.js\\\"></script>
<style type=\\\"text/css\\\">
#graphdiv {
position: absolute;
left: 10px;
right: 10px;
top: 40px;
bottom: 10px;
}
</style>
</head>
<body>
<div id=\\\"graphdiv\\\"></div>
<p><input type=checkbox id=\\\"0\\\" checked onClick=\\\"change(this)\\\">
<label for=\\\"0\\\">reference</label>
<input type=checkbox id=\\\"1\\\" checked onClick=\\\"change(this)\\\">
<label for=\\\"1\\\">actual</label>
<input type=checkbox id=\\\"2\\\" checked onClick=\\\"change(this)\\\">
<label for=\\\"2\\\">high</label>
<input type=checkbox id=\\\"3\\\" checked onClick=\\\"change(this)\\\">
<label for=\\\"3\\\">low</label>
<input type=checkbox id=\\\"4\\\" checked onClick=\\\"change(this)\\\">
<label for=\\\"4\\\">error</label>
<input type=checkbox id=\\\"5\\\" onClick=\\\"change(this)\\\">
<label for=\\\"5\\\">actual (original)</label>
Parameters used for the comparison: Relative tolerance \"+String(reference_reltol)+\" (local), \"+String(reference_reltolDiffMinMax)+\" (relative to max-min). Range delta \"+String(reference_rangeDelta)+\".</p>
<script type=\\\"text/javascript\\\">
g = new Dygraph(document.getElementById(\\\"graphdiv\\\"),
\\\"\"+OpenModelica.Scripting.basename(prefix + \".\" + var+\".csv\")+\"\\\",{title: '\"+var+\"',
legend: 'always',
connectSeparatedPoints: true,
xlabel: ['time'],
y2label: ['error'],
series : { 'error': { axis: 'y2' } },
colors: ['blue','red','teal','lightblue','orange','black'],
visibility: [true,true,true,true,true,false]
});
function change(el) {
g.setVisibility(parseInt(el.id), el.checked);
}
</script>
</body>
</html>\") for var in diffVars};
else
referenceCell := \"<td bgcolor=\\\"#00FF00\\\">\"+OpenModelica.Scripting.Internal.Time.readableTime(timeDiff)+\" (\"+String(numCompared)+\" signals)</td>\";
end if;
end if;
end if;
sim:=readFile(simFile);
str:=\"<tr><td>\" + (if err <> \"\" then \"<a class=\\\"\"+errorLinkClass+\"\\\" href=\\\"\"+errFile+\"\\\">"+s+"</a>\" else \""+s+"\") +
(if sim <> \"\" then \" (<a href=\\\"\"+simFile+\"\\\">sim</a>)\" else \"\") +
\"</td>\" + referenceCell +
cell(if simRes then timeSim else -1.0,greenOnOk=true,greenColor=greenColor,mdFile=mdFile) +
\"<td bgcolor=\\\"\"+(if res[1]<>\"\" then greenColor else \"#FF0000\")+\"\\\">\"+OpenModelica.Scripting.Internal.Time.readableTime(total)+\"</td>\" +
sum(cell(d,greenColor=greenColor) for d in {frontend,backend,simcode,templates,build}) + \"</tr>\\n\";getErrorString();
writeFile(statFile,str);getErrorString();
skip:=\"<testcase name=\\\""+s+"\\\"><skipped /></testcase>\";
str:=testcase(frontend,backend <> -1.0,err);
writeFile(statFile + \".flat\", str);getErrorString();
str:=if backend <> -1.0 then testcase(total,buildRes,err) else skip;
writeFile(statFile + \".compile\", str);getErrorString();
str:=if buildRes then testcase(timeSim,simRes,sim) else skip;
writeFile(statFile + \".sim\", str);getErrorString();
str:=if simRes then testcase(timeDiff,referenceOK,if referenceOK then \"\" else \"See the generated report for details\") else skip;
writeFile(statFile + \".verify\", str);getErrorString();
") for s in a);
getErrorString();
if javascript then
system("python " + OpenModelica.Scripting.getInstallationDirectoryPath() + "/share/doc/omc/testmodels/generate_icons.py Modelica.Icons.Example");
system("cp ModelicaIcons/Modelica.Icons.Example.svg files/");
system("cp -a " + OpenModelica.Scripting.getInstallationDirectoryPath() + "/lib/omc/emcc/mdpad/* files/");
end if;
results := system_parallel({"/usr/bin/time -f '"+s+" %es' " + omc + " +n=1 " + s + ".mos" for s in a});
getErrorString();
system("rm -f " + log);
nsucceeded := String(sum(if OpenModelica.Scripting.regularFileExists(s) then 1 else 0 for s in a)) + "/" + String(size(a,1));
nsimsucceeded := String(sum(if OpenModelica.Scripting.regularFileExists(s + ".simsuccess") then 1 else 0 for s in a)) + "/" + String(size(a,1));
nverifysucceeded := String(sum(if OpenModelica.Scripting.regularFileExists(s + ".verifysuccess") then 1 else 0 for s in a)) + "/" + String(size(a,1));
str:="<h1>Recursive BuildModel Test</h1>
<p>BuildModel Results: " + nsucceeded + " succeeded</p>
<p>Simulation Results: " + nsimsucceeded + " succeeded</p>"+(if referenceFiles<> "" then "
<p>Verified Results: " + nverifysucceeded + " succeeded</p>" else "")+"
<p>Total time taken: "+OpenModelica.Scripting.Internal.Time.readableTime(OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED))+"</p>
<p>OpenModelica Version: "+OpenModelica.Scripting.getVersion()+"</p>
<p>Test started: "+dateAndTime+"</p>
<p>Tested Library: "+libraryString+" "+libraryVersionRevision+"</p>
<p>BuildModel time limit: "+ulimitOmc+"s</p>
<p>Simulation time limit: "+ulimitExe+"s</p>
<p>Default tolerance: "+String(default_tolerance)+"</p>"
+ customCommandsStr +
"<p>Links are provided if getErrorString() or the simulation generates output. The links are coded with <font style=\"#FF0000\">red</font> if there were errors, <font style=\"#FFCC66\">yellow</font> if there were warnings, and normal links if there are only notifications.</p>
<p><font style=\"background-color:#00FF00\">Green</font> cells means success. <font style=\"background-color:#FF0000\">Red</font> is bad and in general signifies a failure.</p>
";
writeFile(log,"<html>
<head>
<title>BuildModel Results</title>
<style>
a.messagesError {color:#FF0000;}
a.messagesWarning {color:#FFCC66;}
</style>
</head><body>" + str);
writeFile(log,"<table border=\"1\"><tr><th>Model</th>"+(if referenceFiles == "" then "" else "<th>Verified</th>")+"<th>Simulate</th><th>Total buildModel</th><th>Frontend</th><th>Backend</th><th>SimCode</th><th>Templates</th><th>Compile</th></tr>\n",append=true);getErrorString();
writeFile(log,sum(readFile(s + ".stat") + "\n" for s in a),append=true);getErrorString();
writeFile(log,"</table><hr /><p><a href=\"BuildModelRecursive.tar.gz\">Offline version</a></p></body></html>",append=true);getErrorString();
writeFile("files/" + typeNameString(library) + ".classes",sum(typeNameString(c) + "\n" for c in getClassNames(library, recursive=true)));
{writeFile("BuildModelRecursive." + phase + ".xml.tmp", "<testsuite>\n" + sum(readFile(s + ".stat." + phase) for s in a) + "</testsuite>\n") for phase in {"flat","compile","sim","verify"}};getErrorString();
{system("iconv -f utf8 -t utf8 -c BuildModelRecursive." + phase + ".xml.tmp -o BuildModelRecursive." + phase + ".xml") for phase in {"flat","compile","sim","verify"}};getErrorString();
system("cp '" + dygraphs + "' files/");getErrorString();
system("rm -f tidy.err; for f in files/*.err; do (grep -v 'Duplicate modification of element' $f | sed s,^.*omlibrary/,[, | grep -v 'Error building simulator' | grep -v 'has no value, and is fixed during initialization' | grep -5E '(Warning|Error|Notification):' > tmp.tidy && test -s tmp.tidy && (basename $f && cat tmp.tidy)) >> tidy.err; done");
system("chmod -R go+r BuildModelRecursive.html files tidy.err");getErrorString();
system("chmod go+x files");getErrorString();
system("tar czf BuildModelRecursive.tar.gz BuildModelRecursive.html files tidy.err");getErrorString();
system("chmod go+r BuildModelRecursive.tar.gz");
/* Some useful CustomCommands.mos examples:
// MSL regression testing suite:
setCommandLineOptions("-d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection");
setMatchingAlgorithm("PFPlusExt");
setIndexReductionMethod("dynamicStateSelection");
simFlags := "-abortSlowSimulation -alarm=480 -lv LOG_STATS";
setModelicaPath("/home/marsj/dev/v3.2.1+build.2.release");
referenceFileExtension:="csv";
referenceFileNameDelimiter:="/";
referenceFiles:="/path/to/RegressionTesting/ModelicaStandardLibrary/ReferenceResults/v3.2.1+build.2.release/";
outputFormat:="csv";
customLibrary:=true;
library:=$TypeName(Modelica);
libraryVersion:="default";
mslRegressionOutput:="OpenModelica"; // Creates files under ./OpenModelica
*/