summaryrefslogtreecommitdiff
path: root/regression.pl
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2013-12-01 21:32:59 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2013-12-01 21:32:59 +0100
commite35be7a971569ce693e9e32a1ac2a6bc74f3c11f (patch)
treec360f7c551d48d225cf2d27650a060ad7a373631 /regression.pl
parent65e5efc7633211d14d660e1089d4c0748fa7b334 (diff)
Add xhtml test
Diffstat (limited to 'regression.pl')
-rwxr-xr-xregression.pl488
1 files changed, 283 insertions, 205 deletions
diff --git a/regression.pl b/regression.pl
index 40e1fac..4250b34 100755
--- a/regression.pl
+++ b/regression.pl
@@ -1,36 +1,44 @@
#!/usr/bin/perl
-my $html = 0; # set to 1 to output a nicely formatted HTML page
+my $html = 0; # set to 1 to output a nicely formatted HTML page
-my $do_vg = 0; # execute the valgrind test (takes a while)
+my $do_vg = 0; # execute the valgrind test (takes a while)
my $pass_colour = "11dd11";
my $fail_colour = "dd1111";
my $warn_colour = "e59800";
my $skip_colour = "9999dd";
-sub DisplayCell
-{
- my ($bgColor, $text) = @_;
+sub DisplayCell {
+ my ( $bgColor, $text ) = @_;
- print "<td style='background-color: #$bgColor;'>$text</td>\n";
+ print "<td style='background-color: #$bgColor;'>$text</td>\n";
}
-sub DiffTest
-{
- my ($command, $file, $extension) = @_;
- my $result = "passed";
- my $comment = "";
-
- my $errPath = $file . ".$extension.err";
- my $rawPath = $file . ".$extension";
- my $newRawPath = $file . ".$extension.new";
- my $diffPath = $file . ".$extension.diff";
-
- # generate a new raw output to compare with
- `$command $file 1> $newRawPath`;
+sub DiffTest {
+ my ( $command, $command2, $command3, $file, $extension ) = @_;
+ my $result = "passed";
+ my $comment = "";
+
+ my $errPath = $file . ".$extension.err";
+ my $rawPath = $file . ".$extension";
+ my $newRawPath = $file . ".$extension.new";
+ my $diffPath = $file . ".$extension.diff";
+
+ # generate a new raw output to compare with
+ `$command $file 1> $newRawPath`;
+ if ($command2) {
+ `mv $newRawPath $newRawPath.tmp`;
+ `$command2 $newRawPath.tmp 1> $newRawPath 2> /dev/null`;
+ `rm $newRawPath.tmp`;
+ }
+ if ($command3) {
+ `mv $newRawPath $newRawPath.tmp`;
+ `$command3 $newRawPath.tmp 1> $newRawPath 2> /dev/null`;
+ `rm $newRawPath.tmp`;
+ }
- # HACK: check if there is a raw file with _some_ contents. If not, we've had a segfault
+# HACK: check if there is a raw file with _some_ contents. If not, we've had a segfault
# my $err = "";
# my $diff = "";
# $newRaw=`cat $newRawPath`;
@@ -39,198 +47,270 @@ sub DiffTest
# `echo $err > $errPath`;
# }
- if ($err ne "") {
- $result = "fail";
- } else {
- # remove the generated (empty) error file
- `rm -f $errPath`;
+ if ( $err ne "" ) {
+ $result = "fail";
+ }
+ else {
+ # remove the generated (empty) error file
+ `rm -f $errPath`;
+
+ # diff the stored raw data with the newly generated raw data
+ `diff -u --minimal -d $rawPath $newRawPath 1>$diffPath 2>$diffPath`;
- # diff the stored raw data with the newly generated raw data
- `diff -u --minimal -d $rawPath $newRawPath 1>$diffPath 2>$diffPath`;
# print "DEBUG: $extension fp:$file ep:$errPath rp:$rawPath nrp:$newRawPath dp:$diffPath\n";
- $diff=`cat $diffPath | grep -v "No differences encountered"`;
+ $diff = `cat $diffPath | grep -v "No differences encountered"`;
- if ($diff ne "") {
- $result = "changed";
- } else {
- `rm -f $diffPath`;
- }
- }
-
- # remove the generated raw file
- `rm -f $newRawPath`;
-
- # DISPLAYING RESULTS
- if ($html) {
- my $bgColor;
- if ($diff eq "" && $err eq "") {
- $bgColor = $pass_colour;
- } elsif ($err ne "") {
- $bgColor = $fail_colour;
- } else {
- $bgColor = $warn_colour;
+ if ( $diff ne "" ) {
+ $result = "changed";
+ }
+ else {
+ `rm -f $diffPath`;
+ }
}
- if ($err ne "" || $diff ne "") {
- $comment = " <a href='" . ($err ne "" ? $errPath : $diffPath) . "'>" . ($err ne "" ? "error" : "diff") . "<a>";
- }
+ # remove the generated raw file
+ `rm -f $newRawPath`;
+
+ # DISPLAYING RESULTS
+ if ($html) {
+ my $bgColor;
+ if ( $diff eq "" && $err eq "" ) {
+ $bgColor = $pass_colour;
+ }
+ elsif ( $err ne "" ) {
+ $bgColor = $fail_colour;
+ }
+ else {
+ $bgColor = $warn_colour;
+ }
- DisplayCell($bgColor, $result . $comment);
- } else {
- if ($err ne "" || $diff ne "") {
- $comment = ($err ne "" ? "(error: " : "(diff: ") . ($err ne "" ? $errPath : $diffPath) . ")";
+ if ( $err ne "" || $diff ne "" ) {
+ $comment =
+ " <a href='"
+ . ( $err ne "" ? $errPath : $diffPath ) . "'>"
+ . ( $err ne "" ? "error" : "diff" ) . "<a>";
+ }
+
+ DisplayCell( $bgColor, $result . $comment );
+ }
+ else {
+ if ( $err ne "" || $diff ne "" ) {
+ $comment = ( $err ne "" ? "(error: " : "(diff: " )
+ . ( $err ne "" ? $errPath : $diffPath ) . ")";
+ }
+ print "! $file diff (using $command): $result $comment\n";
}
- print "! $file diff (using $command): $result $comment\n";
- }
- return $result;
+ return $result;
}
-sub CgTest
-{
- my ($command, $file) = @_;
+sub CgTest {
+ my ( $command, $file ) = @_;
- my $callgraph = `$command $file`;
- chomp($callgraph);
+ my $callgraph = `$command $file`;
+ chomp($callgraph);
- return $callgraph;
+ return $callgraph;
}
-sub RegTest
-{
- my $rawDiffFailures = 0;
- my $vgFailures = 0;
- my $callGraphFailures = 0;
- my $vgCommand = "valgrind --tool=memcheck -v --track-origins=yes";
- my $vgVersionOutput = `valgrind --version`;
- if ($vgVersionOutput =~ /\-2.1/ ||
- $vgVersionOutput =~ /\-2.2/) {
- $vgCommand = "valgrind --tool=memcheck -v --track-origins=yes";
- }
-
- my @cdrVersionList = ( "1", "2", "3", "4", "5", "6", "7", "8", "8b", "9", "10", "11", "12", "13", "14", "15", "16" );
-
- my $cdrVersion;
- foreach $cdrVersion ( @cdrVersionList ) {
- if ($html) {
- print "<b>Regression testing the " . $cdrVersion . " parser</b><br>\n";
- print "<table>\n";
- print "<tr>\n";
- print "<td style='background-color: rgb(204, 204, 255);'><b>File</b></td>\n";
- print "<td style='background-color: rgb(204, 204, 255);'><b>Raw Diff Test<br/>(cdr2raw)</b></td>\n";
- print "<td style='background-color: rgb(204, 204, 255);'><b>Call Graph Test<br/>(cdr2raw)</b></td>\n";
- print "<td style='background-color: rgb(204, 204, 255);'><b>Valgrind Test<br/>(cdr2raw)</b></td>\n";
- print "</tr>\n";
- } else {
- print "Regression testing the " . $cdrVersion . " parser\n";
+sub RegTest {
+ my $rawDiffFailures = 0;
+ my $xhtmlDiffFailures = 0;
+ my $vgFailures = 0;
+ my $callGraphFailures = 0;
+ my $vgCommand = "valgrind --tool=memcheck -v --track-origins=yes";
+ my $vgVersionOutput = `valgrind --version`;
+ if ( $vgVersionOutput =~ /\-2.1/
+ || $vgVersionOutput =~ /\-2.2/ )
+ {
+ $vgCommand = "valgrind --tool=memcheck -v --track-origins=yes";
}
- my $regrInput = 'testset/' . $cdrVersion . '/regression.in';
-
- my @fileList = split(/\n/, `cat $regrInput`);
- foreach $file ( @fileList ) {
-
- my $filePath = 'testset/' . $cdrVersion . '/' . $file;
-
- if ($html) {
- print "<tr>\n";
- print "<td><a href='" . $filePath . "'>" . $file . "</a></td>\n";
- }
-
- # /////////////////////
- # DIFF REGRESSION TESTS
- # /////////////////////
-
- if (DiffTest("cdr2raw", $filePath, "raw") eq "fail") {
- $rawDiffFailures++;
- }
-
- # //////////////////////////
- # CALL GRAPH REGRESSION TEST
- # //////////////////////////
-
- my $cgResult = CgTest("cdr2raw --callgraph", $filePath);
-
- if ($cgResult ne "0") {
- $callGraphFailures++;
- }
- if ($html) {
- ($cgResult eq "0" ? DisplayCell($pass_colour, "passed") :
- DisplayCell($fail_colour, "failed"));
- } else {
- print "! $file call graph: " . ($cgResult eq "0" ? "passed" : "failed") . "\n";
- }
-
-
- # ////////////////////////
- # VALGRIND REGRESSION TEST
- # ////////////////////////
- if ($do_vg) {
- $vgPath = 'testset/' . $cdrVersion . '/' . $file . '.vg';
- $valgrind = 0;
- `$vgCommand --leak-check=yes cdr2raw $filePath 1> $vgPath 2> $vgPath`;
- open VG, "$vgPath";
- my $vgOutput;
- while (<VG>) {
- if (/^\=\=/) {
- $vgOutput .= $_;
- if (/definitely lost: [1-9]/ ||
- /ERROR SUMMARY: [1-9]/ ||
- /Invalid read of/) {
- $valgrind = 1;
- }
- }
- }
- close VG;
-
- `rm -f $vgPath`;
- if ($valgrind) {
- open VG, ">$vgPath";
- print VG $vgOutput;
- close VG;
- $vgFailures++;
- }
- $vgOutput = "";
+ my @cdrVersionList = (
+ "1", "2", "3", "4", "5", "6", "7", "8", "8b", "9",
+ "10", "11", "12", "13", "14", "15", "16"
+ );
+ my $cdrVersion;
+ foreach $cdrVersion (@cdrVersionList) {
if ($html) {
- ($valgrind eq 0 ? DisplayCell($pass_colour, "passed") : DisplayCell($fail_colour, "failed <a href='$vgPath'>log<a>"));
- } else {
- print "! $file valgrind (using cdr2raw): " . ($valgrind eq "0" ? "passed" : "failed") . "\n";
+ print "<b>Regression testing the CDR"
+ . $cdrVersion
+ . " parser</b><br>\n";
+ print "<table>\n";
+ print "<tr>\n";
+ print
+"<td style='background-color: rgb(204, 204, 255);'><b>File</b></td>\n";
+ print
+"<td style='background-color: rgb(204, 204, 255);'><b>Raw Diff Test<br/>(cdr2raw)</b></td>\n";
+ print
+"<td style='background-color: rgb(204, 204, 255);'><b>XHTML Diff Test<br/>(cdr2xhtml)</b></td>\n";
+ print
+"<td style='background-color: rgb(204, 204, 255);'><b>Call Graph Test<br/>(cdr2raw)</b></td>\n";
+ print
+"<td style='background-color: rgb(204, 204, 255);'><b>Valgrind Test<br/>(cdr2raw)</b></td>\n";
+ print "</tr>\n";
}
- } else {
- if ($html) {
- DisplayCell($skip_colour, "skipped");
- } else {
- print "! $file valgrind (using cdr2raw): skipped\n";
+ else {
+ print "Regression testing the CDR" . $cdrVersion . " parser\n";
}
- }
- }
+ my $regrInput = 'testset/' . $cdrVersion . '/regression.in';
- if ($html) {
- print "</table><br>\n";
- }
+ my @fileList = split( /\n/, `cat $regrInput` );
+ foreach $file (@fileList) {
- if ($html) {
- print "<b>Summary</b><br>\n";
- print "Regression test found " . $rawDiffFailures . " raw diff failure(s)<br>\n";
- print "Regression test found " . $callGraphFailures . " call graph failure(s)<br>\n";
- if ($do_vg) {
- print "Regression test found " . $vgFailures . " valgrind failure(s)<br>\n";
- } else {
- print "Valgrind test skipped<br>\n";
- }
- } else {
- print "\nSummary\n";
- print "Regression test found " . $rawDiffFailures . " raw diff failure(s)\n";
- print "Regression test found " . $callGraphFailures . " call graph failure(s)\n";
- if ($do_vg) {
- print "Regression test found " . $vgFailures . " valgrind failure(s)\n";
- } else {
- print "Valgrind test skipped\n";
+ my $filePath = 'testset/' . $cdrVersion . '/' . $file;
+
+ if ($html) {
+ print "<tr>\n";
+ print "<td><a href='"
+ . $filePath . "'>"
+ . $file
+ . "</a></td>\n";
+ }
+
+ # /////////////////////
+ # DIFF REGRESSION TESTS
+ # /////////////////////
+
+ if ( DiffTest( "cdr2raw", 0, 0, $filePath, "raw" ) eq "fail" ) {
+ $rawDiffFailures++;
+ }
+
+ if (
+ DiffTest(
+ "cdr2xhtml", "xmllint --c14n --nonet --dropdtd",
+ "xmllint --format", $filePath,
+ "xhtml"
+ ) eq "fail"
+ )
+ {
+ $xhtmlDiffFailures++;
+ }
+
+ # //////////////////////////
+ # CALL GRAPH REGRESSION TEST
+ # //////////////////////////
+
+ my $cgResult = CgTest( "cdr2raw --callgraph", $filePath );
+
+ if ( $cgResult ne "0" ) {
+ $callGraphFailures++;
+ }
+ if ($html) {
+ (
+ $cgResult eq "0"
+ ? DisplayCell( $pass_colour, "passed" )
+ : DisplayCell( $fail_colour, "failed" )
+ );
+ }
+ else {
+ print "! $file call graph: "
+ . ( $cgResult eq "0" ? "passed" : "failed" ) . "\n";
+ }
+
+ # ////////////////////////
+ # VALGRIND REGRESSION TEST
+ # ////////////////////////
+ if ($do_vg) {
+ $vgPath = 'testset/' . $cdrVersion . '/' . $file . '.vg';
+ $valgrind = 0;
+`$vgCommand --leak-check=yes cdr2raw $filePath 1> $vgPath 2> $vgPath`;
+ open VG, "$vgPath";
+ my $vgOutput;
+ while (<VG>) {
+ if (/^\=\=/) {
+ $vgOutput .= $_;
+ if ( /definitely lost: [1-9]/
+ || /ERROR SUMMARY: [1-9]/
+ || /Invalid read of/ )
+ {
+ $valgrind = 1;
+ }
+ }
+ }
+ close VG;
+
+ `rm -f $vgPath`;
+ if ($valgrind) {
+ open VG, ">$vgPath";
+ print VG $vgOutput;
+ close VG;
+ $vgFailures++;
+ }
+ $vgOutput = "";
+
+ if ($html) {
+ (
+ $valgrind eq 0
+ ? DisplayCell( $pass_colour, "passed" )
+ : DisplayCell(
+ $fail_colour, "failed <a href='$vgPath'>log<a>"
+ )
+ );
+ }
+ else {
+ print "! $file valgrind (using cdr2raw): "
+ . ( $valgrind eq "0" ? "passed" : "failed" ) . "\n";
+ }
+ }
+ else {
+ if ($html) {
+ DisplayCell( $skip_colour, "skipped" );
+ }
+ else {
+ print "! $file valgrind (using cdr2raw): skipped\n";
+ }
+ }
+
+ }
+
+ if ($html) {
+ print "</table><br>\n";
+ }
+
+ if ($html) {
+ print "<b>Summary</b><br>\n";
+ print "Regression test found "
+ . $rawDiffFailures
+ . " raw diff failure(s)<br>\n";
+ print "Regression test found "
+ . $xhtmlDiffFailures
+ . " xhtml diff failure(s)<br>\n";
+ print "Regression test found "
+ . $callGraphFailures
+ . " call graph failure(s)<br>\n";
+ if ($do_vg) {
+ print "Regression test found "
+ . $vgFailures
+ . " valgrind failure(s)<br>\n";
+ }
+ else {
+ print "Valgrind test skipped<br>\n";
+ }
+ }
+ else {
+ print "\nSummary\n";
+ print "Regression test found "
+ . $rawDiffFailures
+ . " raw diff failure(s)\n";
+ print "Regression test found "
+ . $xhtmlDiffFailures
+ . " xhtml diff failure(s)\n";
+ print "Regression test found "
+ . $callGraphFailures
+ . " call graph failure(s)\n";
+ if ($do_vg) {
+ print "Regression test found "
+ . $vgFailures
+ . " valgrind failure(s)\n";
+ }
+ else {
+ print "Valgrind test skipped\n";
+ }
+ }
}
- }
-}
}
sub HtmlHeader {
@@ -243,33 +323,31 @@ sub HtmlFooter {
}
my $confused = 0;
-while (scalar(@ARGV) > 0) {
- my $argument = shift @ARGV;
- if ($argument =~ /--output-html/) {
- $html = 1;
- }
- elsif ($argument =~ /--vg/) {
- $do_vg = 1;
- }
- else {
- $confused = 1;
- }
+while ( scalar(@ARGV) > 0 ) {
+ my $argument = shift @ARGV;
+ if ( $argument =~ /--output-html/ ) {
+ $html = 1;
+ }
+ elsif ( $argument =~ /--vg/ ) {
+ $do_vg = 1;
+ }
+ else {
+ $confused = 1;
+ }
}
if ($confused) {
- print "Usage: regression.pl [ --output-html ] [ --vg ]\n";
- exit;
+ print "Usage: regression.pl [ --output-html ] [ --vg ]\n";
+ exit;
}
# Main function
-if ($html)
-{
+if ($html) {
&HtmlHeader;
}
&RegTest;
-if ($html)
-{
+if ($html) {
&HtmlFooter;
}