layout/tools/reftest/reftest-to-html.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/tools/reftest/reftest-to-html.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +#!/usr/bin/perl
     1.5 +
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +print <<EOD
    1.11 +<html>
    1.12 +<head>
    1.13 +<title>reftest output</title>
    1.14 +<style type="text/css">
    1.15 +/* must be in this order */
    1.16 +.PASS { background-color: green; }
    1.17 +.FAIL { background-color: red; }
    1.18 +.XFAIL { background-color: #999300; }
    1.19 +.WEIRDPASS { background-color: #00FFED; }
    1.20 +.PASSRANDOM { background-color: #598930; }
    1.21 +.FAILRANDOM, td.XFAILRANDOM { background-color: #99402A; }
    1.22 +
    1.23 +.FAILIMAGES { }
    1.24 +img { margin: 5px; width: 80px; height: 100px; }
    1.25 +img.testresult { border: 2px solid red; }
    1.26 +img.testref { border: 2px solid green; }
    1.27 +a { color: inherit; }
    1.28 +.always { display: inline ! important; }
    1.29 +</style>
    1.30 +</head>
    1.31 +<body>
    1.32 +<p>
    1.33 +<span class="PASS always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[0].style; if (s.display == 'none') s.display = null; else s.display = 'none';">PASS</span>&nbsp;
    1.34 +<span class="FAIL always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[1].style; if (s.display == 'none') s.display = null; else s.display = 'none';">UNEXPECTED FAIL</span>&nbsp;
    1.35 +<span class="XFAIL always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[2].style; if (s.display == 'none') s.display = null; else s.display = 'none';">KNOWN FAIL</span>&nbsp;
    1.36 +<span class="WEIRDPASS always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[3].style; if (s.display == 'none') s.display = null; else s.display = 'none';">UNEXPECTED PASS</span>&nbsp;
    1.37 +<span class="PASSRANDOM always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[4].style; if (s.display == 'none') s.display = null; else s.display = 'none';">PASS (Random)</span>&nbsp;
    1.38 +<span class="FAILRANDOM always"><input type="checkbox" checked="true" onclick="var s = document.styleSheets[0].cssRules[5].style; if (s.display == 'none') s.display = null; else s.display = 'none';">FAIL (Random)</span>&nbsp;
    1.39 +</p>
    1.40 +<table>
    1.41 +EOD
    1.42 +;
    1.43 +
    1.44 +sub readcleanline {
    1.45 +  my $l = <>;
    1.46 +  chomp $l;
    1.47 +  chop $l if ($l =~ /\r$/);
    1.48 +  return $l;
    1.49 +}
    1.50 +
    1.51 +sub do_html {
    1.52 +  my ($l) = @_;
    1.53 +
    1.54 +  $l =~ s,(file:[^ ]*),<a href="\1">\1</a>,g;
    1.55 +  $l =~ s,(data:[^ ]*),<a href="\1">\1</a>,g;
    1.56 +
    1.57 +  return $l;
    1.58 +}
    1.59 +
    1.60 +$l = 0;
    1.61 +
    1.62 +while (<>) {
    1.63 +  $l++;
    1.64 +  next unless /^REFTEST/;
    1.65 +
    1.66 +  chomp;
    1.67 +  chop if /\r$/;
    1.68 +
    1.69 +  s/^REFTEST *//;
    1.70 +
    1.71 +  my $randomresult = 0;
    1.72 +  if (/EXPECTED RANDOM/) {
    1.73 +    s/\(EXPECTED RANDOM\)//;
    1.74 +    $randomresult = 1;
    1.75 +  }
    1.76 +
    1.77 +  if (/^TEST-PASS \| (.*)$/) {
    1.78 +    my $class = $randomresult ? "PASSRANDOM" : "PASS";
    1.79 +    print '<tr><td class="' . $class . '">' . do_html($1) . "</td></tr>\n";
    1.80 +  } elsif (/^TEST-UNEXPECTED-(....) \| (.*)$/) {
    1.81 +    if ($randomresult) {
    1.82 +      die "Error on line $l: UNEXPECTED with test marked random?!";
    1.83 +    }
    1.84 +    my $class = ($1 eq "PASS") ? "WEIRDPASS" : "FAIL";
    1.85 +    print '<tr><td class="' . $class . '">' . do_html($2) . "</td></tr>\n";
    1.86 +
    1.87 +    # UNEXPECTED results can be followed by one or two images
    1.88 +    $testline = &readcleanline;
    1.89 +
    1.90 +    print '<tr><td class="FAILIMAGES">';
    1.91 +
    1.92 +    if ($testline =~ /REFTEST   IMAGE: (data:.*)$/) {
    1.93 +      print '<a href="' . $1 . '"><img class="testresult" src="' . $1 . '"></a>';
    1.94 +    } elsif ($testline =~ /REFTEST   IMAGE 1 \(TEST\): (data:.*)$/) {
    1.95 +      $refline = &readcleanline;
    1.96 +      print '<a href="' . $1 . '"><img class="testresult" src="' . $1 . '"></a>';
    1.97 +      {
    1.98 +        die "Error on line $l" unless $refline =~ /REFTEST   IMAGE 2 \(REFERENCE\): (data:.*)$/;
    1.99 +        print '<a href="' . $1 . '"><img class="testref" src="' . $1 . '"></a>';
   1.100 +      }
   1.101 +
   1.102 +    } else {
   1.103 +      die "Error on line $l";
   1.104 +    }
   1.105 +
   1.106 +    print "</td></tr>\n";
   1.107 +  } elsif (/^TEST-KNOWN-FAIL \| (.*$)/) {
   1.108 +    my $class = $randomresult ? "XFAILRANDOM" : "XFAIL";
   1.109 +    print '<tr><td class="' . $class . '">' . do_html($1) . "</td></tr>\n";
   1.110 +  } else {
   1.111 +    print STDERR "Unknown Line: " . $_ . "\n";
   1.112 +    print "<tr><td><pre>" . $_ . "</pre></td></tr>\n";
   1.113 +  }
   1.114 +}
   1.115 +
   1.116 +print <<EOD
   1.117 +</table>
   1.118 +</body>
   1.119 +</html>
   1.120 +EOD
   1.121 +;

mercurial