Skip to content

Commit

Permalink
- Fixed svg generation for coverage script
Browse files Browse the repository at this point in the history
- Added generation of result verification xml to coverage script
- Some tail recursion optimisations


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17880 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 25, 2013
1 parent 6411e1a commit d26d065
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ protected function traverseIncidenceMatrix1 "author: Frenkel TUD 2010-12"
end FuncType;
algorithm
(outM,outTypeA) := traverseIncidenceMatrix2(inM,func,pos,len,intGt(pos,len),inTypeA);
annotation(__OpenModelica_EarlyInline = true);
end traverseIncidenceMatrix1;

protected function traverseIncidenceMatrix2
Expand All @@ -581,7 +582,6 @@ protected function traverseIncidenceMatrix2
input tuple<BackendDAE.IncidenceMatrixElement,Integer,BackendDAE.IncidenceMatrix,Type_a> inTpl;
output tuple<list<Integer>,BackendDAE.IncidenceMatrix,Type_a> outTpl;
end FuncType;
annotation(__OpenModelica_EarlyInline = true);
algorithm
(outM,outTypeA) := match (inM,func,pos,len,stop,inTypeA)
local
Expand All @@ -597,7 +597,7 @@ algorithm
((eqns,m,extArg)) = func((inM[pos],pos,inM,inTypeA));
eqns1 = List.removeOnTrue(pos,intLt,eqns);
(m1,extArg1) = traverseIncidenceMatrixList(eqns1,m,func,arrayLength(m),pos,extArg);
(m2,extArg2) = traverseIncidenceMatrix1(m1,func,pos+1,len,extArg1);
(m2,extArg2) = traverseIncidenceMatrix2(m1,func,pos+1,len,intGt(pos+1,len),extArg1);
then (m2,extArg2);

end match;
Expand Down
6 changes: 2 additions & 4 deletions Compiler/Util/Flags.mo
Original file line number Diff line number Diff line change
Expand Up @@ -970,17 +970,15 @@ algorithm
case (DEBUG_FLAG(index = index), _)
equation
true = intEq(index, inFlagIndex);
then
inFlagIndex + 1;
then inFlagIndex + 1;

case (DEBUG_FLAG(index = index, name = name), _)
equation
index_str = intString(index);
err_str = "Invalid flag " +& name +& " with index " +& index_str +&
" in Flags.allDebugFlags. Make sure that all flags are present and ordered correctly.";
Error.addMessage(Error.INTERNAL_ERROR, {err_str});
then
fail();
then fail();
end matchcontinue;
end checkDebugFlag;

Expand Down
49 changes: 29 additions & 20 deletions Compiler/Util/List.mo
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,18 @@ algorithm
_ :: outList := inList;
end rest;

public function restCond
"Returns all elements except for the first in a list."
input Boolean cond;
input list<ElementType> inList;
output list<ElementType> outList;
algorithm
outList := match (cond,inList)
case (true,_::outList) then outList;
case (false,_) then inList;
end match;
end restCond;

public function restOrEmpty
"Returns all elements except for the first in a list, or the empty list of the
list is empty."
Expand Down Expand Up @@ -907,8 +919,7 @@ algorithm
(left, right) = split(inList, middle);
left = sort(left, inCompFunc);
right = sort(right, inCompFunc);
then
merge(left, right, inCompFunc);
then merge(left, right, inCompFunc, {});

end match;
end sort;
Expand Down Expand Up @@ -1004,6 +1015,7 @@ protected function merge
input list<ElementType> inLeft;
input list<ElementType> inRight;
input CompareFunc inCompFunc;
input list<ElementType> acc;
output list<ElementType> outList;

partial function CompareFunc
Expand All @@ -1012,30 +1024,27 @@ protected function merge
output Boolean outRes;
end CompareFunc;
algorithm
outList := matchcontinue(inLeft, inRight, inCompFunc)
outList := match (inLeft, inRight, inCompFunc, acc)
local
ElementType l, r;
Boolean b;
ElementType l, r, el;
list<ElementType> l_rest, r_rest, res;

case ({}, {}, _) then {};

case (l :: l_rest, r :: _, _)
/* Tail recursive version */
case (l :: l_rest, r :: r_rest, _, _)
equation
true = inCompFunc(r, l);
res = merge(l_rest, inRight, inCompFunc);
then
l :: res;
b = inCompFunc(r, l);
l_rest = Util.if_(b,l_rest,inLeft);
r_rest = Util.if_(not b,r_rest,inRight);
el = Util.if_(b, listGet(inLeft, 1), listGet(inRight, 1));
res = merge(l_rest, r_rest, inCompFunc, el::acc);
then res;

case (l :: _, r :: r_rest, _)
equation
res = merge(inLeft, r_rest, inCompFunc);
then
r :: res;
case ({}, {}, _, _) then listReverse(acc);
case ({}, _, _, _) then listAppend(listReverse(acc),inRight);
case (_, {}, _, _) then listAppend(listReverse(acc),inLeft);

case ({}, _, _) then inRight;
case (_, {}, _) then inLeft;

end matchcontinue;
end match;
end merge;

public function mergeSorted
Expand Down
34 changes: 19 additions & 15 deletions Examples/BuildModelRecursive.mos
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OpenModelica.Scripting.Internal.Time.timerTick(OpenModelica.Scripting.Internal.T
log:="BuildModelRecursive.html";
ulimitOmc:="1200"; // 20 minutes to generate the C-code
ulimitExe:="480"; // 8 minutes to initialize and run the simulation
default_tolerance:=1e-10;
default_tolerance:=1e-5;
reference_reltol:=1e-3;
reference_rangeDelta:=2e-3;
loadModel(library,{libraryVersion});
Expand Down Expand Up @@ -47,17 +47,6 @@ mkdir("files");
min(writeFile(s + ".mos","
\""+s+"\";
echo(false);
statFile := \""+s+".stat\";
writeFile(\""+log+"\",\""+s+"\n\",append=true);
writeFile(statFile,\"<tr><td bgcolor=\\\"#ff0000\\\">"+s+"</td></tr>\");getErrorString();
writeFile(statFile + \".flat\", \"killed\");getErrorString();
writeFile(statFile + \".compile\", \"killed\");getErrorString();
writeFile(statFile + \".sim\", \"killed\");getErrorString();
"+loadModelCommand+"
reference_reltol:="+String(reference_reltol)+";
reference_rangeDelta:="+String(reference_rangeDelta)+";
(startTime,stopTime,tolerance):=getSimulationOptions("+s+",defaultTolerance="+String(default_tolerance)+");
setCommandLineOptions(\"+d=nogen,initialization\"); setMatchingAlgorithm(\"PFPlusExt\"); setIndexReductionMethod(\"dynamicStateSelection\");
loadString(\"
function cell
input Real time;
Expand Down Expand Up @@ -99,6 +88,18 @@ algorithm
\\\"</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();
"+loadModelCommand+"
reference_reltol:="+String(reference_reltol)+";
reference_rangeDelta:="+String(reference_rangeDelta)+";
(startTime,stopTime,tolerance):=getSimulationOptions("+s+",defaultTolerance="+String(default_tolerance)+");
setCommandLineOptions(\"+d=nogen,initialization\"); setMatchingAlgorithm(\"PFPlusExt\"); setIndexReductionMethod(\"dynamicStateSelection\");
res:=buildModel("+s+",tolerance=tolerance);
greenColor := \"#00FF00\";
if res[1] == \"\" then
Expand Down Expand Up @@ -133,6 +134,7 @@ simRes := if not buildRes then false else 0 == system(\"ulimit -t "+ulimitExe+"
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);
referenceExists := false;
referenceOK := false;
referenceFiles := \""+referenceFiles+"\";
referenceCell := if referenceFiles == \"\" then \"\" else \"<td>&nbsp;</td>\";
if simRes then
Expand All @@ -156,7 +158,7 @@ set samples 300
set title \\\"Result difference of \"+csvFileToVariable(file)+\"\\\"
# Skip setting xrange; it removes too many lines
set xrange [\"+String(startTime)+\":\"+String(stopTime)+\"]
plot \\\"\"+file+\".csv\\\" using 1:2 title 'reference' with lines, \\\"\"+file+\".csv\\\" using 5:6 title 'actual' with lines, \\\"\"+file+\".csv\\\" using 1:3 title 'high' with lines, \\\"\"+file+\".csv\\\" using 1:4 title 'low' with lines
plot \\\"\"+file+\".csv\\\" using 1:2 title 'reference' with lines, \\\"\"+file+\".csv\\\" using 1:3 title 'actual' with lines, \\\"\"+file+\".csv\\\" using 1:4 title 'high' with lines, \\\"\"+file+\".csv\\\" using 1:5 title 'low' with lines
\" for file in diffFiles));
system(\"gnuplot '"+s+".gnuplot'\");
timeDiff := OpenModelica.Scripting.Internal.Time.timerTock(OpenModelica.Scripting.Internal.Time.RT_CLOCK_USER_RESERVED);
Expand Down Expand Up @@ -212,6 +214,8 @@ str:=if backend <> -1.0 then testcase(total,buildRes,errXML) else skip;
writeFile(statFile + \".compile\", str);getErrorString();
str:=if buildRes then testcase(timeSim,simRes,escapeXML(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();
results := system_parallel({"ulimit -t "+ulimitOmc+" ; " + omc + " " + s + ".mos" for s in a});
Expand All @@ -238,8 +242,8 @@ writeFile(log,"<table><tr><th>Model</th>"+(if referenceFiles == "" then "" else
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("BuildModelRecursive." + phase + ".xml.tmp", "<testsuite>\n" + sum(readFile(s + ".stat." + phase) for s in a) + "</testsuite>\n") for phase in {"flat","compile","sim"}};getErrorString();
{system("iconv -f utf8 -t utf8 -c BuildModelRecursive." + phase + ".xml.tmp -o BuildModelRecursive." + phase + ".xml") for phase in {"flat","compile","sim"}};getErrorString();
{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");
Expand Down

0 comments on commit d26d065

Please sign in to comment.