Skip to content

Commit

Permalink
Restore partial doc tests.
Browse files Browse the repository at this point in the history
Change-Id: Ia13bac1a502765660dd42900640cf6c2e0f17c05
Reviewed-on: http://gerrit.aldebaran.lan:8080/12699
Reviewed-by: mnottale <[email protected]>
Tested-by: mnottale <[email protected]>
  • Loading branch information
Matthieu Nottale committed Feb 14, 2013
1 parent aa0275a commit 1aed72f
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 36 deletions.
1 change: 0 additions & 1 deletion doc/platforms/jazz-api.tex

This file was deleted.

1 change: 0 additions & 1 deletion doc/platforms/jazz-getting-started.tex

This file was deleted.

1 change: 0 additions & 1 deletion doc/platforms/jazz-hands-on.tex

This file was deleted.

1 change: 0 additions & 1 deletion doc/platforms/jazz-introduction.tex

This file was deleted.

1 change: 0 additions & 1 deletion doc/platforms/jazz-ros.tex

This file was deleted.

1 change: 0 additions & 1 deletion doc/platforms/jazz-troubleshooting.tex

This file was deleted.

1 change: 0 additions & 1 deletion doc/platforms/open-jazz.tex

This file was deleted.

1 change: 0 additions & 1 deletion doc/platforms/p3dx.tex

This file was deleted.

4 changes: 2 additions & 2 deletions doc/specs/code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ \subsection{Slots}
break
}|
jobs;
[00009120] [Job<shell_11>, Job<shell_12>, Job<shell_13>]
[00009120] [Job<shell_6>, Job<shell_7>, Job<shell_8>]
// Wait for the jobs to be done.
jobs.each (function (var j) { j.waitForTermination });
assert (res == [0, 1, 0, 2, 1, 2]);
Expand All @@ -166,7 +166,7 @@ \subsection{Slots}
break
}|
jobs;
[00009120] [Job<shell_14>, Job<shell_15>, Job<shell_16>]
[00009120] [Job<shell_9>, Job<shell_10>, Job<shell_11>]
// Give some time to get the output of the detached expressions.
sleep(100ms);
assert (res == [0, 1, 0]);
Expand Down
4 changes: 2 additions & 2 deletions doc/specs/global.tex
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ \subsection{Slots}

\item[clog] A predefined stream for log messages. Strings are output
escaped.
\begin{urbiscript}
\begin{urbiunchecked}
clog << "Message";
[00015895:clog] "Message"
\end{urbiscript}
\end{urbiunchecked}


\item[Code] See \refObject{Code}.
Expand Down
13 changes: 7 additions & 6 deletions doc/specs/job.tex
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ \subsection{Construction}

\begin{urbiscript}
detach(sleep(10));
[00202654] Job<shell_4>
[00202654] Job<shell_6>

disown(sleep(10));
[00204195] Job<shell_5>
[00204195] Job<shell_7>

function () { sleep(10) }.spawn(false);
[00274160] Job<shell_6>
[00274160] Job<shell_8>
\end{urbiscript}

\subsection{Slots}
Expand Down Expand Up @@ -196,10 +196,11 @@ \subsection{Slots}
// Leave some time for s to be started.
sleep(100ms);
t.dumpState();
[00004295] *** Job: shell_10
[00004295] *** Job: shell_13
[00004295] *** State: sleeping
[00004295] *** Time Shift: 0.003ms
[00004295] *** Tags:
[00004295] *** Tag<Lobby_1>
[00004295] *** Tag<Lobby_3>
[00004297] *** Backtrace:
[00004297] *** file.u:1.16-23: sleep
[00004297] *** file.u:1.9-24: detach
Expand All @@ -220,7 +221,7 @@ \subsection{Slots}
Job.current.name;
[00004293] "shell"
detach(sleep(1)).name;
[00004297] "shell_11"
[00004297] "shell_14"
\end{urbiscript}
Expand Down
2 changes: 1 addition & 1 deletion doc/specs/list.tex
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ \subsection{Slots}
\refObject{List}.

\begin{urbiscript}
var l = ["a", "b", "c"]|;
l = ["a", "b", "c"]|;
var res = []|;
for (var k: l.keys)
res << l[k];
Expand Down
1 change: 0 additions & 1 deletion doc/specs/ros.tex

This file was deleted.

2 changes: 1 addition & 1 deletion doc/tests/test.u → doc/test.u
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
*/

// -*- urbi -*-
load("urbi/test-suite.u");
System.requireFile("urbi/test-suite.u");
1 change: 0 additions & 1 deletion doc/tutorial/ros.tex

This file was deleted.

164 changes: 150 additions & 14 deletions share/urbi/run-test.u
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var outClog = Regexp.new("^\\[[0-9]{8}:clog\\]");
var objAddr = Regexp.new("(_0x[0-9a-f]{1,12})([^0-9a-f]|$)");
var objAddr2 = Regexp.new("(uob_[0-9a-f]{2,12})([^0-9a-f]|$)");
var disconnecting = Regexp.new("\\*\\*\\* disconnecting Lobby_");

var timestamp = Regexp.new("^\\[[0-9]{8}");
var errorLocation = Regexp.new("[0-9]+\\.[0-9]+(-[0-9]+)?: ");
function Object.splitNewline(s)
{
var res = []|
Expand All @@ -16,25 +17,94 @@ function Object.splitNewline(s)
l
};

function tex2Chk(filename)
{
var content = File.new(filename).content.data.split("\n");
/*
What to expect:
\begin{urbiscript}
\begin{urbiscript}[firstnumber=1]
\begin{urbiscript}[otherstuff]
\begin{urbiassert}
\begin{urbiassert}[firstnumber=1]
corresponding end
*/
var rBegin = Regexp.new("^\\\\begin\\{(urbiscript|urbiassert|urbicomment)\\}(\\[firstnumber=1\\])?");
var rEnd = Regexp.new("^\\\\end\\{(urbiscript|urbiassert|urbicomment)\\}");
var chk = [];
var isIn = false;
var isAssert = false;
var res = [];
function flush()
{
if (!chk.empty)
res << (["//#line 1"] + chk)| // no file name for those tests
chk = []
};
for| (var l: content)
{
if (!isIn)
{
if (rBegin.match(l))
{
isIn = true;
if (!rBegin.matches[2].empty)
flush();
isAssert = (rBegin.matches[1] == "urbiassert");
if (isAssert)
chk << "assert {";
}
}
else
{
if (rEnd.match(l))
{
isIn = false;
if (isAssert)
chk << "};"
}
else
chk << l
}
}|
flush() |
res
}|;

/* test tex2Chk
var t = tex2Chk(System.arguments[0]);
echo(t.map(function(x) { x.join("\n");}).join("\n---------------\n"));
System._exit(0);
*/

function splitChk(content)
{
var reqs = [];
var sin = [];
var sout = [];
var rOutput = Regexp.new("^\\[[0-9]{8}(:[a-zA-Z0-9_]+)?\\]");
var rVarError = Regexp.new("!!! input.u:@([+-]?[0-9]+)?\\.[0-9]+(-@([+-]?[0-9]+))?");
var rOutputCont = Regexp.new("^\\[:]");
var rOutputCont = Regexp.new("^\\[:] +");
var rDirective = Regexp.new("^//#");
var ignoreStrings = [
"[ Logger ]"
];
var line = 1;
var skipNext = false;
for (var l: content)
{
if (rDirective.match(l))
{
reqs << l[3, 0].trim().split(" ");
echo("Adding directive " + reqs[-1]);
};
if (skipNext)
{
skipNext = false;
++line;
}
// Leave directive go in the file
if (errBacktrace.match(l))
else if (errBacktrace.match(l))
{
sin << "";
++line;
Expand All @@ -58,10 +128,20 @@ function splitChk(content)
{
l = l.replace(objAddr.matches[1], "_0xADDR");
};
if (l[-1] == "\\")
{
var next = content[line];
if (rOutputCont.match(next))
next = next.replace(rOutputCont.matches[0], "");
l = l[0,-1] + next;
skipNext = true;
};
sout << ("[00000000" + l[9, 0]);
sin << "";
++line;
}
else if (ignoreStrings.any(function(x) { l.find(x) != -1}))
{}
else if (rOutputCont.match(l))
{
if (l.size == 3)
Expand Down Expand Up @@ -127,16 +207,37 @@ function startRemote(names)
}|;

function runTest(chkFile)
{
if (Path.new("../tests/" + chkFile).exists())
{
var content = splitNewline(File.new("../tests/" + chkFile).content().data);
runTestContent("../tests/" + chkFile, content);
}
else if (Path.new("../doc/" + chkFile).exists())
{
var ok = true;
var tests = tex2Chk("../doc/" + chkFile);
var i = 0;
for (var t: tests)
{
ok = ok && runTestContent("../doc/" + chkFile + "_" + i.asString(), t);
i++;
}|
ok
}
else throw ("Test " + chkFile + " not found")
}|;

function runTestContent(chkFile, content)
{
var processes = [];
// Tests are run in build dir
System.setenv("URBI_SHARE", (System.urbiRoot / "../../share").asString());
var debug = Logger.new("test");
debug.'<<' = function(x) { this.log(x)};
//debug.level = Logger.level.Dump;
var content = splitNewline(File.new("../tests/" + chkFile).content().data);
(var reqs, var sin, var sout) = splitChk(content);
var testu = fetchTestU("../tests/" + chkFile);
var testu = fetchTestU(chkFile);
debug << ("input: " + sin);
debug << ("expected output: " + sout);
debug << "Creating lobby...";
Expand Down Expand Up @@ -251,7 +352,10 @@ function runTest(chkFile)
l.receive("var Object.test_finished." + ID + "=1|;\n");
debug << "Waiting for test to finish...";
// In fast mode, time of timeout is inpacted too
timeout(1h) waituntil(Object.test_finished.hasLocalSlot(ID));
var waitFor = 1h;
if (System.env["PASS_THROUGH"])
waitFor = 5s;
timeout(waitFor) waituntil(Object.test_finished.hasLocalSlot(ID));
Lobby.write->constant = false;
Lobby.send->constant = false;
Lobby.write = lw;
Expand All @@ -266,7 +370,7 @@ function runTest(chkFile)
//write(p.stderr.content());
write("\nEND REMOTE\n");
};
if (!Object.test_finished.hasLocalSlot(ID))
if (!Object.test_finished.hasLocalSlot(ID)&& !System.env["PASS_THROUGH"])
{
write("EFFECTIVE:\n<< " +eout.join("\n<< ") + "\n\n");
throw "timeout";
Expand Down Expand Up @@ -296,6 +400,8 @@ function runTest(chkFile)
// Compare expected and effective
// Some additional changes may be required, go line by line
var failed = effOut.size != sout.size;
if (failed)
debug << ("SIZE MISMATCH %s %s" % [effOut.size, sout.size]);
var line = 0;
while (!failed && line < effOut.size)
{
Expand All @@ -315,18 +421,48 @@ function runTest(chkFile)
eff = eff.replace(rDouble.matches[0], "<TIMESTAMP>")
}
};
failed = (eff != exp)
// Somehow we still need a layer of timestamp removal
if (timestamp.match(eff) && timestamp.match(exp))
{
eff[0,9] = "[00000000"|
exp[0,9] = "[00000000"|
//eff = eff[9,0]|
//exp = exp[9,0]
};
if (eff != exp)
{
// Some error message in exp lacks a line number, mostly in doc
// for better readability and maintainability
if (errorLocation.match(eff))
{
var m = errorLocation.matches[0]|
var p = eff.find(m)|
eff[p, p+m.length] = ""|
//var remove = eff.replace(errorLocation.matches[0], "")|
//if (remove == exp)
// eff = remove
}
}|
failed = (eff != exp)|
/*if (failed)
{
debug << "FAIL " << eff|
debug << "FAIL " << exp
}*/
};
++line;
};
if (failed)
{
write("SOURCE:\n" + content.join("\n") + "\n\n");
write("INPUT:\n" + sin.join("\n") + "\n");
write("RAW EFFECTIVE:\n" + rawEffOut.join("\n<< ") + "\n\n");
write("EXPECTED:\n>> " + sout.join("\n>> ") + "\n\n");
write("EFFECTIVE:\n<< " +effOut.join("\n<< ") + "\n\n");
write("\n");
if (!System.env["QUIET"])
{
write("SOURCE:\n" + content.join("\n") + "\n\n");
write("INPUT:\n" + sin.join("\n") + "\n");
write("RAW EFFECTIVE:\n" + rawEffOut.join("\n<< ") + "\n\n");
write("EXPECTED:\n>> " + sout.join("\n>> ") + "\n\n");
write("EFFECTIVE:\n<< " +effOut.join("\n<< ") + "\n\n");
write("\n");
};
if (System.getenv("DUMP_TEST_RESULT"))
{
OutputStream.new(File.create("/tmp/out.exp")) << sout.join("\n");
Expand Down
15 changes: 15 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,18 @@ FOREACH(infileName ${tests})
qi_add_test(${_out2} urbi-launch ARGUMENTS -s -- ${_fast} --host 127.0.0.1 --port 0 urbi/run-test.u ${infileName} TIMEOUT 60)
endif()
ENDFOREACH(infileName)

#doc tests
FILE(GLOB_RECURSE doctex RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/../doc ../doc/*.tex)
MESSAGE("Got ${doctex}")
FOREACH(infileName ${doctex})
# Check if there is something
string(REPLACE "." "_" _out ${infileName})
string(REPLACE "/" "_" _out2 ${_out})
file(READ ../doc/${infileName} _fcontent)
string(FIND "${_fcontent}" "begin{urbi" _found)
if (${_found} GREATER -1)
#MESSAGE("adding ${infileName} ${_out} ${_out2} ")
qi_add_test(${_out2} urbi-launch ARGUMENTS -s -- --host 127.0.0.1 --port 0 urbi/run-test.u ${infileName} TIMEOUT 60)
endif()
ENDFOREACH(infileName)

0 comments on commit 1aed72f

Please sign in to comment.