1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
#!/usr/bin/perl
my $html = 0; # set to 1 to output a nicely formatted HTML page
my %toDo=("csv"=>0, "epub"=>0, "html"=>0, "odf"=>0, "raw"=>1, "svg"=>0, "valgrind"=>0 );
my $pass_colour = "11dd11";
my $fail_colour = "dd1111";
my $warn_colour = "e59800";
my $skip_colour = "9999dd";
sub DisplayCell
{
my ($bgColor, $text) = @_;
print "<td style='background-color: #$bgColor;'>$text</td>\n";
}
sub DiffTest
{
my ($command, $command2, $file, $extension, $condition) = @_;
my $result = "passed";
my $comment = "";
if (!$condition) {
DisplayCell($skip_colour, "skipped") if ($html);
return "skipped";
}
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`;
`rm $newRawPath.tmp`;
}
# 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`;
if ($newRaw eq "") {
$err = "Segmentation fault";
`echo $err > $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 $rawPath $newRawPath 1>$diffPath 2>$diffPath`;
$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 ($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";
}
return $result;
}
sub CgTest
{
my ($command, $file) = @_;
my $callgraph = `sd2raw -c $file`;
chomp($callgraph);
return $callgraph;
}
sub CheckVg
{
my ($file,$msg) = @_;
open VG, "$vgPath";
my $result = "passed";
my $valgrind = 0;
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;
$result="fail";
$valgrind = 1;
}
if ($html) {
($valgrind eq 0 ? DisplayCell($pass_colour, "passed") : DisplayCell($fail_colour, "failed <a href='$vgPath'>log<a>"));
} else {
print $msg. " " . ($valgrind eq "0" ? "passed" : "failed (see '$vgPath')") . "\n";
}
return $result;
}
sub RegTest
{
my $i;
# basic raw/html endOfLine
my $endLine=($html?"<br>\n":"\n");
# list of directories containing test files
my @listDirectory = ( "Calc3.1", "Calc4", "Calc5", "Draw3.1", "Draw4", "Draw5", "Pres5", "Text3.1", "Text4", "Text5" );
# list of commands to test
# type => [ "name", "extension", "array of accepted types", "command", "filter" ]
my @commands=("raw", "csv", "epub", "html", "svg", "odf");
my %listCommand = (
"csv" => [ "CSV", "csv", ["S"], "sdc2csv", 0 ],
"epub" => [ "Epub", "epub", ["G", "P", "S", "T"], "sd2epub", 0],
"html" => [ "Html", "html", ["T"], "sdw2html", 0],
"odf" => ["WriterPerfect", "writerperfect", ["G", "P", "S", "T"], "sd2odf", "xmllint --format"],
"raw"=>["Raw", "raw", ["G", "P", "S", "T"], "sd2raw", 0],
"svg" => ["SVG", "svg", ["G", "P"], "sd2svg", 0]
);
# valgrind command
my $vgVersionOutput = `valgrind --version`;
my $vgCommand=( ($vgVersionOutput =~ /\-2.1/ || $vgVersionOutput =~ /\-2.2/) ? "valgrind --tool=memcheck" : "valgrind" );
# init failures
my $callGraphFailures = 0;
my %diffFailures, %valgrindFailures;
foreach $i ( @commands ) {
$diffFailures{$i}=0;
$valgrindFailures{$i}=0;
}
foreach my $directory ( @listDirectory ) {
if ($html) {
print "<b>Regression testing the " . $directory . " 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>Call Graph Test</b></td>\n";
foreach $i ( @commands ) {
print "<td style='background-color: rgb(204, 204, 255);'><b>$listCommand{$i}[0] Diff Test</b></td>\n" if ($toDo{$i});
}
if (!$toDo{"valgrind"}) {
print "<td style='background-color: rgb(204, 204, 255);'><b>Valgrind Tests</b></td>\n";
}
else {
foreach $i ( @commands ) {
print "<td style='background-color: rgb(204, 204, 255);'><b>$listCommand{$i}[0]<br> Valgrind Test</b></td>\n" if ($toDo{$i});
}
}
print "</tr>\n";
} else {
print "Regression testing the " . $directory . " parser\n";
}
my $regrInput = $directory . '/regression.in';
my @fileList = split(/\n/, `cat $regrInput`);
foreach $_ ( @fileList ) {
if (!/^([GPST]):(.*)/) {
print "Skip ".$_.": unknown type\n";
next;
}
$file=$2;
$fileType=$1;
my $filePath = $directory . '/' . $file;
if ($html) {
print "<tr>\n";
print "<td><a href='" . $filePath . "'>" . $file . "</a></td>\n";
}
# //////////////////////////
# CALL GRAPH REGRESSION TEST
# //////////////////////////
my $cgResult = CgTest("sd2raw --callgraph", $filePath);
$callGraphFailures++ if ($cgResult ne "0");
if ($html) {
($cgResult eq "0" ? DisplayCell($pass_colour, "passed") :
DisplayCell($fail_colour, "failed"));
} else {
print "! $file call graph: " . ($cgResult eq "0" ? "passed" : "failed") . "\n";
}
# /////////////////////
# DIFF REGRESSION TESTS
# /////////////////////
foreach $i ( @commands ) {
next if (!$toDo{$i});
$diffFailures{$i}++ if (DiffTest($listCommand{$i}[3], $listCommand{$i}[4], $filePath, $listCommand{$i}[1], ($fileType ~~ $listCommand{$i}[2]) ) eq "fail");
}
# ////////////////////////
# VALGRIND REGRESSION TEST
# ////////////////////////
if (!$toDo{"valgrind"}) {
if (!$html) {
print "! $file valgrind: skipped all tests\n";
}
else {
DisplayCell($skip_colour, "skipped");
print "</tr>\n"
}
next;
}
foreach $i ( @commands ) {
next if (!$toDo{$i});
if ($fileType ~~ $listCommand{$i}[2]) {
$vgPath = $directory . '/' . $file . '.' . $listCommand{$i}[1] . 'vg';
`$vgCommand --leak-check=yes $listCommand{$i}[3] $filePath 1> $vgPath 2> $vgPath`;
$valgrindFailures{$i}++ if (CheckVg($vgPath, "! $file $listCommand{$i}[0] valgrind:") eq "fail");
}
elsif ($html) {
DisplayCell($skip_colour, "skipped");
}
}
print "</tr>\n" if ($html);
}
print "</table><br>\n" if ($html);
}
#
# Summary
#
if ($html) {
print "<b>Summary</b>".$endLine;
} else {
print "\nSummary".$endLine;
}
## callgraph errors
print "Regression test found " . $callGraphFailures . " call graph failure(s)".$endLine;
# diff errors
foreach $i ( @commands ) {
if ($toDo{$i}) {
print "Regression test found $diffFailures{$i} $listCommand{$i}[0] diff failure(s)".$endLine;
} else {
print "$listCommand{$i}[0] test skipped".$endLine;
}
}
## valgrind errors
if (!$toDo{"valgrind"}) {
print "Valgrind test skipped".$endLine;
}
else {
foreach $i ( @commands ) {
if ($toDo{$i}) {
print "Regression test found $valgrindFailures{$i} $listCommand{$i}[0] valgrind failure(s)".$endLine;
} else {
print "$listCommand{$i}[0] valgrind test skipped".$endLine;
}
}
}
}
my $confused = 0;
while (scalar(@ARGV) > 0) {
my $argument = shift @ARGV;
if ($argument =~ /--output-html/) {
$html = 1;
next;
}
$find=0;
foreach $key (keys %toDo) {
if ($argument =~ /--$key/) {
$find=1;
$toDo{$key} = 1;
break;
}
}
$confused = 1 if (!$find);
}
if ($confused) {
print "Usage: regression.pl [--output-html] [--valgrind] [--csv] [--epub] [--html] [--odf] [--svg]\n";
exit;
}
# Main function
if ($html)
{
print "<html>\n<head>\n</head>\n<body>\n";
print "<h2>libstoff Regression Test Suite</h2>\n";
}
&RegTest;
if ($html)
{
print "</body>\n</html>\n";
}
|