Skip to content

Commit a475d6a

Browse files
committed
Add options to CustomCommands.mos to make it possible to generate the directory structure of the MSL regression testing suite
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21254 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 0c605c9 commit a475d6a

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

Examples/BuildModelRecursive.mos

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Note: Run with +g=MetaModelica
2+
// Some examples of CustomCommands.mos files are at the bottom of this file
23

34
setCommandLineOptions("+d=nogen");
45
if not regularFileExists("CustomCommands.mos") then
56
customCommands := "setCommandLineOptions(\"+d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection\");
67
setMatchingAlgorithm(\"PFPlusExt\");
78
setIndexReductionMethod(\"dynamicStateSelection\");";
89
writeFile("CustomCommands.mos",customCommands);
10+
else
11+
customCommands := readFile("CustomCommands.mos");
912
end if;
1013

1114
// May be overridde by CustomCommands.mos
@@ -18,12 +21,17 @@ ulimitExe:="480"; // 8 additional minutes to initialize and run the simulation
1821
ulimitMemory:="16000000"; // ~16GB memory at most
1922
javascript := false;
2023
simFlags := "-abortSlowSimulation -alarm=" + ulimitExe;
24+
customLibrary := false;
2125

2226
runScript("CustomCommands.mos");
2327

2428
customCommandsStr := if regularFileExists("CustomCommands.mos") then ("Flags: <pre>" + escapeXML(readFile("CustomCommands.mos")) + "</pre>") else "";
29+
30+
if not customLibrary then
31+
// It is possible to change library in CustomCommands.mos only if customLibrary := true is set
2532
library:=$TypeName(Modelica);
2633
libraryVersion:="default";
34+
end if;
2735

2836
setCommandLineOptions({"+g=Modelica","+d=nogen"});
2937
OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
@@ -35,14 +43,21 @@ reference_rangeDelta:=1e-3;
3543
loadModel(library,{libraryVersion});
3644
getErrorString();
3745
libraryVersionRevision:=getVersion(library);
38-
libraryVersionRevision := (if libraryVersionRevision == "" then libraryVersion else libraryVersionRevision) + (if regularFileExists(dirname(getSourceFile(library))+".last_change") then (" revision " + readFile(dirname(getSourceFile(library))+".last_change")) else "");
46+
libraryLastChange := "";
47+
if regularFileExists(dirname(getSourceFile(library))+".last_change") then
48+
libraryLastChange := "( revision " + readFile(dirname(getSourceFile(library)))+".last_change";
49+
elseif 0 == system("svn info '" + dirname(getSourceFile(library)) + "' 2>&1 | egrep '^(URL|Last.Changed.Rev)' > svn.info") then
50+
libraryLastChange := " " + readFile("svn.info");
51+
end if;
52+
53+
libraryVersionRevision := (if libraryVersionRevision == "" then libraryVersion else libraryVersionRevision) + libraryLastChange;
3954
libraryString:=typeNameString(library);
4055

4156
system("date +'%Y-%m-%d %H:%M:%S' > tmp.date");
4257
dateAndTime:=readFile("tmp.date");
4358
system("rm -f tmp.date");
4459

45-
loadModelCommand:="\nrunScript(\"CustomCommands.mos\");\nloadModel("+libraryString+",{\""+libraryVersion+"\"});\n";
60+
loadModelCommand:="\n"+customCommands+"\nloadModel("+libraryString+",{\""+libraryVersion+"\"});\n";
4661

4762
omc:=getInstallationDirectoryPath()+"/bin/omc";
4863
dygraphs:=getInstallationDirectoryPath()+"/share/doc/omc/testmodels/dygraph-combined.js";
@@ -119,6 +134,7 @@ writeFile(statFile + \".verify\", testcase(0,false,\"killed\"));getErrorString()
119134

120135
outputFormat:=\"default\";
121136
javascript:="+String(javascript)+";
137+
mslRegressionOutput:=\"\";
122138
"+loadModelCommand+"
123139
reference_reltol:="+String(reference_reltol)+";
124140
reference_reltolDiffMinMax:="+String(reference_reltolDiffMinMax)+";
@@ -130,6 +146,10 @@ referenceFiles := \""+referenceFiles+"\";
130146
referenceCell := if referenceFiles == \"\" then \"\" else \"<td>&nbsp;</td>\";
131147
reference := \""+referenceFiles+"/"+OpenModelica.Scripting.stringReplace(s,".",referenceFileNameDelimiter)+"."+referenceFileExtension+"\";
132148
referenceExists := referenceFiles <> \"\" and regularFileExists(reference);
149+
if not referenceExists then
150+
reference := \""+referenceFiles+"/"+OpenModelica.Scripting.stringReplace(s,".","/")+"/"+basename(OpenModelica.Scripting.stringReplace(s,".","/"))+"."+referenceFileExtension+"\";
151+
referenceExists := referenceFiles <> \"\" and regularFileExists(reference);
152+
end if;
133153

134154
// outputFormat can be overridden in CustomCommands.mos, so we set it to 'default' first
135155
outputFormat := if outputFormat == \"default\" then (if referenceExists then \"mat\" else \"empty\") else outputFormat;
@@ -182,6 +202,33 @@ if buildRes and javascript then
182202
end if;
183203
mdFile := if javascript then \""+s+".md\" else \"\";
184204

205+
if mslRegressionOutput <> \"\" then
206+
mslRegressionOutput := mslRegressionOutput + \"/"+OpenModelica.Scripting.stringReplace(s,".","/")+"/\";
207+
mkdir(mslRegressionOutput);
208+
simFailLog := mslRegressionOutput+\"simulate_failed.log\";
209+
simSuccessLog := mslRegressionOutput+\"simulate_success.log\";
210+
buildFailLog := mslRegressionOutput+\"translate_failed.log\";
211+
buildSuccessLog := mslRegressionOutput+\"translate_success.log\";
212+
213+
system(\"rm -f \"+(if simRes then simFailLog else simSuccessLog));
214+
system(\"rm -f \"+(if buildRes then buildFailLog else buildSuccessLog));
215+
216+
system(\"cp \"+simFile+\" \" + simFile + \".tmp\");
217+
system(\"cp "+s+"_res.csv "+s+".csv\");
218+
system(\"cp "+s+".mos "+s+".mos.tmp\");
219+
220+
if err == \"\" then
221+
system(\"echo > \" + errFile + \".tmp\");
222+
else
223+
system(\"cp \" + errFile + \" \" + errFile + \".tmp\");
224+
end if;
225+
226+
compareFilesAndMove(errFile + \".tmp\", if buildRes then buildSuccessLog else buildFailLog);
227+
compareFilesAndMove(simFile + \".tmp\", if buildRes then simSuccessLog else simFailLog);
228+
compareFilesAndMove(\""+s+".csv\", mslRegressionOutput+\""+s+".csv\");
229+
compareFilesAndMove(\""+s+".mos.tmp\", mslRegressionOutput+\"creation.txt\");
230+
end if;
231+
185232
system(\"sed -i '300,$ d' '\" + simFile + \"'\"); // Only keep the top 300 lines
186233
timeSim := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
187234
if simRes then
@@ -319,3 +366,23 @@ system("chmod -R go+r BuildModelRecursive.html files tidy.err");getErrorString()
319366
system("chmod go+x files");getErrorString();
320367
system("tar czf BuildModelRecursive.tar.gz BuildModelRecursive.html files tidy.err");getErrorString();
321368
system("chmod go+r BuildModelRecursive.tar.gz");
369+
370+
/* Some useful CustomCommands.mos examples:
371+
372+
// MSL regression testing suite:
373+
setCommandLineOptions("+d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection");
374+
setMatchingAlgorithm("PFPlusExt");
375+
setIndexReductionMethod("dynamicStateSelection");
376+
377+
simFlags := "-abortSlowSimulation -alarm=480 -lv LOG_STATS";
378+
setModelicaPath("/home/marsj/dev/v3.2.1+build.2.release");
379+
referenceFileExtension:="csv";
380+
referenceFileNameDelimiter:="/";
381+
referenceFiles:="/path/to/RegressionTesting/ModelicaStandardLibrary/ReferenceResults/v3.2.1+build.2.release/";
382+
outputFormat:="csv";
383+
customLibrary:=true;
384+
library:=$TypeName(Modelica);
385+
libraryVersion:="default";
386+
mslRegressionOutput:="OpenModelica"; // Creates files under ./OpenModelica
387+
388+
*/

0 commit comments

Comments
 (0)