copy coverage reporting files from dbus
authorThomas Vander Stichele <thomas@apestaart.org>
Sat, 1 Jul 2006 23:21:52 +0000 (23:21 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Sat, 1 Jul 2006 23:21:52 +0000 (23:21 +0000)
Original commit message from CVS:
* Makefile.am:
* coverage/coverage-report-entry.pl:
* coverage/coverage-report.pl:
* coverage/coverage-report.xsl:
copy coverage reporting files from dbus

ChangeLog
Makefile.am
coverage/coverage-report-entry.pl [new file with mode: 0644]
coverage/coverage-report.pl [new file with mode: 0644]
coverage/coverage-report.xsl [new file with mode: 0644]

index 53bfcf9b6397e01a933c987873dc31dfaea38e83..a6400b99e673a9041a19c4925071ec5e4d452252 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-07-02  Thomas Vander Stichele  <thomas at apestaart dot org>
+
+       * Makefile.am:
+       * coverage/coverage-report-entry.pl:
+       * coverage/coverage-report.pl:
+       * coverage/coverage-report.xsl:
+         copy coverage reporting files from dbus
+
 2006-07-01  Thomas Vander Stichele  <thomas at apestaart dot org>
 
        * m4/gst-args.m4:
index 2f850984e289eca144d30241b6827e5be44cac0a..fd25770fd6aec5542e8821b4be0ffac1a46ccc69 100644 (file)
@@ -8,4 +8,7 @@ EXTRA_DIST = \
        c-to-xml.py gst-xmlinspect.py mangle-tmpl.py scangobj-merge.py \
        gtk-doc-plugins.mak \
        plugins.xsl gstdoc-scangobj \
-       gst.supp check.mak
+       gst.supp check.mak \
+       coverage/coverage-report.pl \
+       coverage/coverage-report.xsl \
+       coverage/coverage-report-entry.pl
diff --git a/coverage/coverage-report-entry.pl b/coverage/coverage-report-entry.pl
new file mode 100644 (file)
index 0000000..8f653af
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+#
+# Copyright (C) 2006 Daniel Berrange
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+print <<EOF;
+<html>
+<head>
+<title>Coverage report for $ARGV[0]</title>
+<style type="text/css">
+          span.perfect {
+            background: rgb(0,255,0);
+          }
+          span.terrible {
+            background: rgb(255,0,0);
+          }
+</style>
+</head>
+<body>
+<h1>Coverage report for $ARGV[0]</h1>
+
+<pre>
+EOF
+
+
+while (<>) {
+    s/&/&amp;/g;
+    s/</&lt;/g;
+    s/>/&gt;/g;
+
+    if (/^\s*function (\S+) called (\d+) returned \d+% blocks executed \d+%/) {
+       my $class = $2 > 0 ? "perfect" : "terrible";
+       $_ = "<span class=\"$class\" id=\"" . $1 . "\">$_</span>";
+    } elsif (/^\s*branch\s+\d+\s+taken\s+(\d+)%\s+.*$/) {
+       my $class = $1 > 0 ? "perfect" : "terrible";
+       $_ = "<span class=\"$class\">$_</span>";
+    } elsif (/^\s*branch\s+\d+\s+never executed.*$/) {
+       my $class = "terrible";
+       $_ = "<span class=\"$class\">$_</span>";
+    } elsif (/^\s*call\s+\d+\s+never executed.*$/) {
+       my $class = "terrible";
+       $_ = "<span class=\"$class\">$_</span>";
+    } elsif (/^\s*call\s+\d+\s+returned\s+(\d+)%.*$/) {
+       my $class = $1 > 0 ? "perfect" : "terrible";
+       $_ = "<span class=\"$class\">$_</span>";
+    }
+    
+
+    print;
+}
+
+print <<EOF;
+</pre>
+</body>
+</html>
+EOF
diff --git a/coverage/coverage-report.pl b/coverage/coverage-report.pl
new file mode 100644 (file)
index 0000000..046bc37
--- /dev/null
@@ -0,0 +1,125 @@
+#!/usr/bin/perl
+#
+# Copyright (C) 2006 Daniel Berrange
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+use warnings;
+use strict;
+
+my %coverage = ( functions => {}, files => {} );
+
+my %filemap;
+
+my $type;
+my $name;
+
+my @functions;
+
+while (<>) {
+    if (/^Function '(.*)'\s*$/) {
+       $type = "function";
+       $name = $1;
+       $coverage{$type}->{$name} = {};
+       push @functions, $name;
+    } elsif (/^File '(.*?)'\s*$/) {
+       $type = "file";
+       $name = $1;
+       $coverage{$type}->{$name} = {};
+       
+       foreach my $func (@functions) {
+           $coverage{"function"}->{$func}->{file} = $name;
+       }
+       @functions = ();
+    } elsif (/^Lines executed:(.*)%\s*of\s*(\d+)\s*$/) {
+       $coverage{$type}->{$name}->{lines} = $2;
+       $coverage{$type}->{$name}->{linesCoverage} = $1;
+    } elsif (/^Branches executed:(.*)%\s*of\s*(\d+)\s*$/) {
+       $coverage{$type}->{$name}->{branches} = $2;
+       $coverage{$type}->{$name}->{branchesCoverage} = $1;
+    } elsif (/^Taken at least once:(.*)%\s*of\s*(\d+)\s*$/) {
+       $coverage{$type}->{$name}->{conds} = $2;
+       $coverage{$type}->{$name}->{condsCoverage} = $1;
+    } elsif (/^Calls executed:(.*)%\s*of\s*(\d+)\s*$/) {
+       $coverage{$type}->{$name}->{calls} = $2;
+       $coverage{$type}->{$name}->{callsCoverage} = $1;
+    } elsif (/^No branches$/) {
+       $coverage{$type}->{$name}->{branches} = 0;
+       $coverage{$type}->{$name}->{branchesCoverage} = "100.00";
+       $coverage{$type}->{$name}->{conds} = 0;
+       $coverage{$type}->{$name}->{condsCoverage} = "100.00";
+    } elsif (/^No calls$/) {
+       $coverage{$type}->{$name}->{calls} = 0;
+       $coverage{$type}->{$name}->{callsCoverage} = "100.00";
+    } elsif (/^\s*(.*):creating '(.*)'\s*$/) {
+       $filemap{$1} = $2;
+    } elsif (/^\s*$/) {
+       # nada
+    } else {
+       warn "Shit [$_]\n";
+    }
+}
+
+my %summary;
+foreach my $type ("function", "file") {
+    $summary{$type} = {};
+    foreach my $m ("lines", "branches", "conds", "calls") {
+       my $totalGot = 0;
+       my $totalMiss = 0;
+       my $count = 0;
+       foreach my $func (keys %{$coverage{function}}) {
+           $count++;
+           my $got = $coverage{function}->{$func}->{$m};
+           $totalGot += $got;
+           my $miss = $got * $coverage{function}->{$func}->{$m ."Coverage"} / 100;
+           $totalMiss += $miss;
+       }
+       $summary{$type}->{$m} = sprintf("%d", $totalGot);
+       $summary{$type}->{$m . "Coverage"} = sprintf("%.2f", $totalMiss / $totalGot * 100);
+    }
+}
+
+
+
+print "<coverage>\n";
+
+foreach my $type ("function", "file") {
+    printf "<%ss>\n", $type;
+    foreach my $name (sort { $a cmp $b } keys %{$coverage{$type}}) {
+       my $rec = $coverage{$type}->{$name};
+       printf "  <entry name=\"%s\" details=\"%s\">\n", $name, ($type eq "file" ? $filemap{$name} : $filemap{$rec->{file}});
+       printf "    <lines count=\"%s\" coverage=\"%s\"/>\n", $rec->{lines}, $rec->{linesCoverage};
+       if (exists $rec->{branches}) {
+           printf "    <branches count=\"%s\" coverage=\"%s\"/>\n", $rec->{branches}, $rec->{branchesCoverage};
+       }
+       if (exists $rec->{conds}) {
+           printf "    <conditions count=\"%s\" coverage=\"%s\"/>\n", $rec->{conds}, $rec->{condsCoverage};
+       }
+       if (exists $rec->{calls}) {
+           printf "    <calls count=\"%s\" coverage=\"%s\"/>\n", $rec->{calls}, $rec->{callsCoverage};
+       }
+       print  "  </entry>\n";
+    }
+    
+    printf "  <summary>\n";
+    printf "    <lines count=\"%s\" coverage=\"%s\"/>\n", $summary{$type}->{lines}, $summary{$type}->{linesCoverage};
+    printf "    <branches count=\"%s\" coverage=\"%s\"/>\n", $summary{$type}->{branches}, $summary{$type}->{branchesCoverage};
+    printf "    <conditions count=\"%s\" coverage=\"%s\"/>\n", $summary{$type}->{conds}, $summary{$type}->{condsCoverage};
+    printf "    <calls count=\"%s\" coverage=\"%s\"/>\n", $summary{$type}->{calls}, $summary{$type}->{callsCoverage};
+    printf  "  </summary>\n";
+    printf "</%ss>\n", $type;
+}
+
+print "</coverage>\n";
diff --git a/coverage/coverage-report.xsl b/coverage/coverage-report.xsl
new file mode 100644 (file)
index 0000000..b19ebb6
--- /dev/null
@@ -0,0 +1,235 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<!--\r
+#\r
+# Copyright (C) 2006 Daniel Berrange\r
+#\r
+# This program is free software; you can redistribute it and/or modify\r
+# it under the terms of the GNU General Public License as published by\r
+# the Free Software Foundation; either version 2 of the License, or\r
+# (at your option) any later version.\r
+#\r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+# GNU General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU General Public License\r
+# along with this program; if not, write to the Free Software\r
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+-->\r
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
+                version="1.0">\r
+\r
+  <xsl:output method="html"/>\r
+\r
+  <xsl:template match="coverage">\r
+    <html>\r
+      <head>\r
+        <title>Coverage report</title>\r
+        <style type="text/css">\r
+          tbody tr.odd td.label {\r
+            border-top: 1px solid rgb(128,128,128);\r
+            border-bottom: 1px solid rgb(128,128,128);\r
+          }\r
+          tbody tr.odd td.label {\r
+            background: rgb(200,200,200);\r
+          }\r
+          \r
+          thead, tfoot {\r
+            background: rgb(60,60,60);\r
+            color: white;\r
+            font-weight: bold;\r
+          }\r
+\r
+          tr td.perfect {\r
+            background: rgb(0,255,0);\r
+            color: black;\r
+          }\r
+          tr td.excellant {\r
+            background: rgb(140,255,140);\r
+            color: black;\r
+          }\r
+          tr td.good {\r
+            background: rgb(160,255,0);\r
+            color: black;\r
+          }\r
+          tr td.poor {\r
+            background: rgb(255,160,0);\r
+            color: black;\r
+          }\r
+          tr td.bad {\r
+            background: rgb(255,140,140);\r
+            color: black;\r
+          }\r
+          tr td.terrible {\r
+            background: rgb(255,0,0);\r
+            color: black;\r
+          }\r
+        </style>\r
+      </head>\r
+      <body>\r
+        <h1>Coverage report</h1>\r
+        <xsl:apply-templates/>\r
+      </body>\r
+    </html>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="functions">\r
+    <h2>Function coverage</h2>\r
+    <xsl:call-template name="content">\r
+      <xsl:with-param name="type" select="'function'"/>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+  \r
+\r
+  <xsl:template match="files">\r
+    <h2>File coverage</h2>\r
+    <xsl:call-template name="content">\r
+      <xsl:with-param name="type" select="'file'"/>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template name="content">\r
+    <xsl:param name="type"/>\r
+    <table>\r
+      <thead>\r
+        <tr>\r
+          <th>Name</th>\r
+          <th>Lines</th>\r
+          <th>Branches</th>\r
+          <th>Conditions</th>\r
+          <th>Calls</th>\r
+        </tr>\r
+      </thead>\r
+      <tbody>\r
+        <xsl:for-each select="entry">\r
+          <xsl:call-template name="entry">\r
+            <xsl:with-param name="type" select="$type"/>\r
+            <xsl:with-param name="class">\r
+              <xsl:choose>\r
+                <xsl:when test="position() mod 2">\r
+                  <xsl:text>odd</xsl:text>\r
+                </xsl:when>\r
+                <xsl:otherwise>\r
+                  <xsl:text>even</xsl:text>\r
+                </xsl:otherwise>\r
+              </xsl:choose>\r
+            </xsl:with-param>\r
+          </xsl:call-template>\r
+        </xsl:for-each>\r
+      </tbody>\r
+      <tfoot>\r
+        <xsl:for-each select="summary">\r
+          <xsl:call-template name="entry">\r
+            <xsl:with-param name="type" select="'summary'"/>\r
+            <xsl:with-param name="class">\r
+              <xsl:choose>\r
+                <xsl:when test="position() mod 2">\r
+                  <xsl:text>odd</xsl:text>\r
+                </xsl:when>\r
+                <xsl:otherwise>\r
+                  <xsl:text>even</xsl:text>\r
+                </xsl:otherwise>\r
+              </xsl:choose>\r
+            </xsl:with-param>\r
+          </xsl:call-template>\r
+        </xsl:for-each>\r
+      </tfoot>\r
+    </table>\r
+  </xsl:template>\r
+  \r
+  <xsl:template name="entry">\r
+    <xsl:param name="type"/>\r
+    <xsl:param name="class"/>\r
+    <tr class="{$class}">\r
+      <xsl:choose>\r
+        <xsl:when test="$type = 'function'">\r
+          <td class="label"><a href="{@details}.html#{@name}"><xsl:value-of select="@name"/></a></td>\r
+        </xsl:when>\r
+        <xsl:when test="$type = 'file'">\r
+          <td class="label"><a href="{@details}.html"><xsl:value-of select="@name"/></a></td>\r
+        </xsl:when>\r
+        <xsl:otherwise>\r
+          <td class="label">Summary</td>\r
+        </xsl:otherwise>\r
+      </xsl:choose>\r
+\r
+      <xsl:if test="count(lines)">\r
+        <xsl:apply-templates select="lines"/>\r
+      </xsl:if>\r
+      <xsl:if test="not(count(lines))">\r
+        <xsl:call-template name="missing"/>\r
+      </xsl:if>\r
+\r
+      <xsl:if test="count(branches)">\r
+        <xsl:apply-templates select="branches"/>\r
+      </xsl:if>\r
+      <xsl:if test="not(count(branches))">\r
+        <xsl:call-template name="missing"/>\r
+      </xsl:if>\r
+\r
+      <xsl:if test="count(conditions)">\r
+        <xsl:apply-templates select="conditions"/>\r
+      </xsl:if>\r
+      <xsl:if test="not(count(conditions))">\r
+        <xsl:call-template name="missing"/>\r
+      </xsl:if>\r
+\r
+      <xsl:if test="count(calls)">\r
+        <xsl:apply-templates select="calls"/>\r
+      </xsl:if>\r
+      <xsl:if test="not(count(calls))">\r
+        <xsl:call-template name="missing"/>\r
+      </xsl:if>\r
+\r
+    </tr>\r
+  </xsl:template>\r
+  \r
+  <xsl:template match="lines">\r
+    <xsl:call-template name="row"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="branches">\r
+    <xsl:call-template name="row"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="conditions">\r
+    <xsl:call-template name="row"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="calls">\r
+    <xsl:call-template name="row"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template name="missing">\r
+    <td></td>\r
+  </xsl:template>\r
+\r
+  <xsl:template name="row">\r
+    <xsl:variable name="quality">\r
+      <xsl:choose>\r
+        <xsl:when test="@coverage = 100">\r
+          <xsl:text>perfect</xsl:text>\r
+        </xsl:when>\r
+        <xsl:when test="@coverage >= 80.0">\r
+          <xsl:text>excellant</xsl:text>\r
+        </xsl:when>\r
+        <xsl:when test="@coverage >= 60.0">\r
+          <xsl:text>good</xsl:text>\r
+        </xsl:when>\r
+        <xsl:when test="@coverage >= 40.0">\r
+          <xsl:text>poor</xsl:text>\r
+        </xsl:when>\r
+        <xsl:when test="@coverage >= 20.0">\r
+          <xsl:text>bad</xsl:text>\r
+        </xsl:when>\r
+        <xsl:otherwise>\r
+          <xsl:text>terrible</xsl:text>\r
+        </xsl:otherwise>\r
+      </xsl:choose>\r
+    </xsl:variable>\r
+    \r
+    <td class="{$quality}"><xsl:value-of select="@coverage"/>% of <xsl:value-of select="@count"/></td>\r
+  </xsl:template>\r
+\r
+</xsl:stylesheet>\r