#!/usr/bin/perl my $html = 0; # set to 1 to output a nicely formatted HTML page my $do_odg = 0; # execute the vs?2odg diff test 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 ) = @_; print "$text\n"; } 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"; `$command $file 1> $newRawPath 2>/dev/null`; 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`; } 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 = `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 = " " . ( $err ne "" ? "error" : "diff" ) . ""; } 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 = `$command $file`; chomp($callgraph); return $callgraph; } sub RegTest { my $rawDiffFailures = 0; my $xhtmlDiffFailures = 0; my $odgDiffFailures = 0; my $vgFailures = 0; my $callGraphFailures = 0; my $vgCommand = "valgrind --tool=memcheck -v"; my @vsdVersionList = ( "1", "2", "5", "6", "11", "vdx", "vsdx" ); my $vsdVersion; foreach $vsdVersion (@vsdVersionList) { if ($html) { print "Regression testing the " . $vsdVersion . " parser
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } else { print "Regression testing the " . $vsdVersion . " parser\n"; } my $regrInput = 'testset/' . $vsdVersion . '/regression.in'; my @fileList = split( /\n/, `cat $regrInput` ); foreach $file (@fileList) { my $filePath = 'testset/' . $vsdVersion . '/' . $file; if ($html) { print "\n"; print "\n"; } # ///////////////////// # DIFF REGRESSION TESTS # ///////////////////// if ( DiffTest( "vsd2raw", 0, 0, $filePath, "raw" ) eq "fail" ) { $rawDiffFailures++; } if ( DiffTest( "vsd2xhtml", "xmllint --c14n --nonet --dropdtd", "xmllint --format", $filePath, "xhtml" ) eq "fail" ) { $xhtmlDiffFailures++; } if ($do_odg) { if ( DiffTest( "vsd2odg --stdout", "xmllint --c14n", "xmllint --format", $filePath, "odg" ) eq "fail" ) { $odgDiffFailures++; } } else { if ($html) { DisplayCell( $skip_colour, "skipped" ); } else { print "! $file ODG: skipped\n"; } } # ////////////////////////// # CALL GRAPH REGRESSION TEST # ////////////////////////// my $cgResult = CgTest( "vsd2raw --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/' . $vsdVersion . '/' . $file . '.vg'; $valgrind = 0; `$vgCommand --leak-check=yes vsd2raw $filePath 1> $vgPath 2> $vgPath`; open VG, "$vgPath"; my $vgOutput; while () { 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 log" ) ); } else { print "! $file valgrind (using vsd2raw): " . ( $valgrind eq "0" ? "passed" : "failed" ) . "\n"; } } else { if ($html) { DisplayCell( $skip_colour, "skipped" ); } else { print "! $file valgrind (using vsd2raw): skipped\n"; } } if ( $do_vg && $do_odg ) { $vgPath = 'testset/' . $vsdVersion . '/' . $file . '.odgvg'; $odgvalgrind = 0; `$vgCommand --leak-check=yes vsd2odg --stdout $filePath 1> $vgPath 2> $vgPath`; open VG, "$vgPath"; my $vgOutput; while () { if (/^\=\=/) { $vgOutput .= $_; if ( /definitely lost: [1-9]/ || /ERROR SUMMARY: [1-9]/ || /Invalid read of/ ) { $odgvalgrind = 1; } } } close VG; `rm -f $vgPath`; if ($odgvalgrind) { open VG, ">$vgPath"; print VG $vgOutput; close VG; $odgvgFailures++; } $vgOutput = ""; if ($html) { ( $odgvalgrind eq 0 ? DisplayCell( $pass_colour, "passed" ) : DisplayCell( $fail_colour, "failed log" ) ); } else { print "! $file odg valgrind: " . ( $odgvalgrind eq "0" ? "passed" : "failed" ) . "\n"; } } else { if ($html) { DisplayCell( $skip_colour, "skipped" ); } else { print "! $file odg valgrind: skipped\n"; } } # ///////////////////////// # VSS DIFF REGRESSION TESTS # ///////////////////////// if ( DiffTest( "vss2raw", 0, 0, $filePath, "sraw" ) eq "fail" ) { $rawDiffFailures++; } if ( DiffTest( "vss2xhtml", "xmllint --c14n --nonet --dropdtd", "xmllint --format", $filePath, "sxhtml" ) eq "fail" ) { $xhtmlDiffFailures++; } if ($do_odg) { if ( DiffTest( "vss2odg --stdout", "xmllint --c14n", "xmllint --format", $filePath, "sodg" ) eq "fail" ) { $odgDiffFailures++; } } else { if ($html) { DisplayCell( $skip_colour, "skipped" ); } else { print "! $file ODG: skipped\n"; } } # ////////////////////////////// # VSS CALL GRAPH REGRESSION TEST # ////////////////////////////// my $cgResult = CgTest( "vss2raw --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"; } # //////////////////////////// # VSS VALGRIND REGRESSION TEST # //////////////////////////// if ($do_vg) { $vgPath = 'testset/' . $vsdVersion . '/' . $file . '.vgs'; $valgrind = 0; `$vgCommand --leak-check=yes vss2raw $filePath 1> $vgPath 2> $vgPath`; open VG, "$vgPath"; my $vgOutput; while () { 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 log" ) ); } else { print "! $file valgrind (using vss2raw): " . ( $valgrind eq "0" ? "passed" : "failed" ) . "\n"; } } else { if ($html) { DisplayCell( $skip_colour, "skipped" ); } else { print "! $file valgrind (using vss2raw): skipped\n"; } } if ( $do_vg && $do_odg ) { $vgPath = 'testset/' . $vsdVersion . '/' . $file . '.odgvgs'; $odgvalgrind = 0; `$vgCommand --leak-check=yes vss2odg --stdout $filePath 1> $vgPath 2> $vgPath`; open VG, "$vgPath"; my $vgOutput; while () { if (/^\=\=/) { $vgOutput .= $_; if ( /definitely lost: [1-9]/ || /ERROR SUMMARY: [1-9]/ || /Invalid read of/ ) { $odgvalgrind = 1; } } } close VG; `rm -f $vgPath`; if ($odgvalgrind) { open VG, ">$vgPath"; print VG $vgOutput; close VG; $odgvgFailures++; } $vgOutput = ""; if ($html) { ( $odgvalgrind eq 0 ? DisplayCell( $pass_colour, "passed" ) : DisplayCell( $fail_colour, "failed log" ) ); print "\n"; } else { print "! $file odg valgrind: " . ( $odgvalgrind eq "0" ? "passed" : "failed" ) . "\n"; } } else { if ($html) { DisplayCell( $skip_colour, "skipped" ); } else { print "! $file odg valgrind: skipped\n"; } } } if ($html) { print "
FileRaw Diff Test
(vsd2raw)
XHTML Diff Test
(vsd2xhtml)
ODG Test
(vsd2odg)
Call Graph Test
(vsd2raw)
Valgrind Test
(vsd2raw)
ODG Valgrind Test
(vsd2odg)
Raw Diff Test
(vss2raw)
XHTML Diff Test
(vss2xhtml)
ODG Test
(vss2odg)
Call Graph Test
(vss2raw)
Valgrind Test
(vss2raw)
ODG Valgrind Test
(vss2odg)
" . $file . "

\n"; } if ($html) { print "Summary
\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_odg) { print "Regression test found " . $odgDiffFailures . " odg diff failure(s)
\n"; } else { print "ODG diff test skipped
\n"; } if ($do_vg) { print "Regression test found " . $vgFailures . " valgrind failure(s)
\n"; } else { print "Valgrind test skipped
\n"; } if ($do_vg && $do_odg) { print "Regression test found " . $odgvgFailures . "ODG valgrind failure(s)

\n"; } else { print "ODG valgrind test skipped

\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_odg) { print "Regression test found " . $odgDiffFailures . " odg diff failure(s)\n"; } else { print "ODG test skipped\n"; } if ($do_vg) { print "Regression test found " . $vgFailures . " valgrind failure(s)\n"; } else { print "Valgrind test skipped\n"; } if ($do_vg && $do_odg) { print "Regression test found " . $odgvgFailures . " ODG valgrind failure(s)\n"; } else { print "ODG valgrind test skipped\n"; } } } } sub HtmlHeader { print "\n\n\n\n"; print "

libvisio Regression Test Suite

\n"; } sub HtmlFooter { print "\n\n"; } my $confused = 0; while ( scalar(@ARGV) > 0 ) { my $argument = shift @ARGV; if ( $argument =~ /--output-html/ ) { $html = 1; } elsif ( $argument =~ /--vg/ ) { $do_vg = 1; } elsif ( $argument =~ /--odg/ ) { $do_odg = 1; } else { $confused = 1; } } if ($confused) { print "Usage: regression.pl [ --output-html ] [ --vg ] [ --odg ]\n"; exit; } # Main function if ($html) { &HtmlHeader; } &RegTest; if ($html) { &HtmlFooter; }