11// Note: Run with +g=MetaModelica
2+ // Some examples of CustomCommands.mos files are at the bottom of this file
23
34setCommandLineOptions("+d=nogen");
45if not regularFileExists("CustomCommands.mos") then
56 customCommands := "setCommandLineOptions(\"+d=nogen,initialization,backenddaeinfo,discreteinfo,stateselection\");
67setMatchingAlgorithm(\"PFPlusExt\");
78setIndexReductionMethod(\"dynamicStateSelection\");";
89 writeFile("CustomCommands.mos",customCommands);
10+ else
11+ customCommands := readFile("CustomCommands.mos");
912end if;
1013
1114// May be overridde by CustomCommands.mos
@@ -18,12 +21,17 @@ ulimitExe:="480"; // 8 additional minutes to initialize and run the simulation
1821ulimitMemory:="16000000"; // ~16GB memory at most
1922javascript := false;
2023simFlags := "-abortSlowSimulation -alarm=" + ulimitExe;
24+ customLibrary := false;
2125
2226runScript("CustomCommands.mos");
2327
2428customCommandsStr := 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
2532library:=$TypeName(Modelica);
2633libraryVersion:="default";
34+ end if;
2735
2836setCommandLineOptions({"+g=Modelica","+d=nogen"});
2937OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
@@ -35,14 +43,21 @@ reference_rangeDelta:=1e-3;
3543loadModel(library,{libraryVersion});
3644getErrorString();
3745libraryVersionRevision:=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;
3954libraryString:=typeNameString(library);
4055
4156system("date +'%Y-%m-%d %H:%M:%S' > tmp.date");
4257dateAndTime:=readFile("tmp.date");
4358system("rm -f tmp.date");
4459
45- loadModelCommand:="\nrunScript(\"CustomCommands.mos\"); \nloadModel("+libraryString+",{\""+libraryVersion+"\"});\n";
60+ loadModelCommand:="\n"+customCommands+" \nloadModel("+libraryString+",{\""+libraryVersion+"\"});\n";
4661
4762omc:=getInstallationDirectoryPath()+"/bin/omc";
4863dygraphs:=getInstallationDirectoryPath()+"/share/doc/omc/testmodels/dygraph-combined.js";
@@ -119,6 +134,7 @@ writeFile(statFile + \".verify\", testcase(0,false,\"killed\"));getErrorString()
119134
120135outputFormat:=\"default\";
121136javascript:="+String(javascript)+";
137+ mslRegressionOutput:=\"\";
122138"+loadModelCommand+"
123139reference_reltol:="+String(reference_reltol)+";
124140reference_reltolDiffMinMax:="+String(reference_reltolDiffMinMax)+";
@@ -130,6 +146,10 @@ referenceFiles := \""+referenceFiles+"\";
130146referenceCell := if referenceFiles == \"\" then \"\" else \"<td> </td>\";
131147reference := \""+referenceFiles+"/"+OpenModelica.Scripting.stringReplace(s,".",referenceFileNameDelimiter)+"."+referenceFileExtension+"\";
132148referenceExists := 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
135155outputFormat := if outputFormat == \"default\" then (if referenceExists then \"mat\" else \"empty\") else outputFormat;
@@ -182,6 +202,33 @@ if buildRes and javascript then
182202end if;
183203mdFile := 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+
185232system(\"sed -i '300,$ d' '\" + simFile + \"'\"); // Only keep the top 300 lines
186233timeSim := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
187234if simRes then
@@ -319,3 +366,23 @@ system("chmod -R go+r BuildModelRecursive.html files tidy.err");getErrorString()
319366system("chmod go+x files");getErrorString();
320367system("tar czf BuildModelRecursive.tar.gz BuildModelRecursive.html files tidy.err");getErrorString();
321368system("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