chiark / gitweb /
Macroize submit buttons so we can mess with them more easily
[disorder] / scripts / format-gcov-report
... / ...
CommitLineData
1#! /usr/bin/env python
2#
3# This file is part of DisOrder.
4# Copyright (C) 2007 Richard Kettlewell
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19# USA
20#
21import re,sys,os,string
22
23def fatal(msg):
24 sys.stderr.write("%s\n" % msg)
25 sys.exit(1)
26
27def sgmlquotechar(c):
28 if c == '&' or c == '<' or ord(c) < 32 or ord(c) > 126:
29 return "&#%d;" % ord(c)
30 else:
31 return c
32
33def sgmlquote(s):
34 return string.join(map(sgmlquotechar, s),'')
35
36missing = {}
37percent = {}
38total_lines = 0
39covered_lines = 0
40args = sys.argv[1:]
41htmldir = None
42while len(args) > 0 and re.match("^--", args[0]):
43 if args[0] == "--html":
44 htmldir = args[1]
45 args = args[2:]
46 else:
47 fatal("unknown option '%s'" % args[0])
48for s in args:
49 missing[s] = True
50
51name = None
52for line in sys.stdin:
53 line = line[:-1]
54 r = re.match("File ['`](?:.*/)?([^/]+.c)'", line)
55 if r:
56 name = r.group(1)
57 if name in missing:
58 del missing[name]
59 r = re.match("Lines executed:([0-9\\.]+)% of ([0-9]+)", line)
60 if r:
61 if name:
62 this_pc = float(r.group(1))
63 this_lines = int(r.group(2))
64 percent[name] = this_pc
65 total_lines += this_lines
66 covered_lines += this_lines * this_pc / 100.0
67 name = None
68
69def cmp(a,b):
70 if percent[a] < percent[b]: return -1
71 elif percent[a] > percent[b]: return 1
72 else: return 0
73
74keys = percent.keys()
75keys.sort(cmp)
76
77if len(keys):
78 for k in keys:
79 print "%20s: %d%%" % (k, percent[k])
80 print "Total coverage: %d%%" % (100 * (covered_lines / total_lines))
81
82if htmldir is not None and len(keys):
83 index = open(os.path.join(htmldir, "index.html"), "w")
84 index.write("<html><head><title>gcov report</title>\n")
85 index.write("<body><h1>gcov report</h1>\n")
86 index.write("<table><tr><th>File</th><th>Coverage</th></tr>\n")
87 for k in keys:
88 index.write("<tr><td><a href=\"%s.html\">%s</a><td>%d%%\n" %
89 (sgmlquote(k), sgmlquote(k), percent[k]))
90 index.write("</table>\n")
91 index.write("<p>Total coverage: %d%%</p>\n" % (100 * (covered_lines / total_lines)))
92 missing_files = missing.keys()
93 missing_files.sort()
94 if len(missing_files) > 0:
95 index.write("<p>Missing files:</p>\n")
96 index.write("<ul>\n")
97 for mf in missing_files:
98 index.write("<li><a href=\"%s\">%s</a></li>\n" % (mf, mf))
99 index.write("</lu>\n")
100 for k in keys:
101 html = open(os.path.join(htmldir, "%s.html" % k), "w")
102 html.write("<html><head><title>%s</title>\n" % sgmlquote(k))
103 html.write("<body><h1>%s</h1>\n" % sgmlquote(k))
104 html.write("<pre>")
105 r = re.compile("^ *#####:.*")
106 for line in open("%s.gcov" % k, "r"):
107 if len(line) > 0 and line[-1] == '\n':
108 line = line[:-1]
109 if r.match(line):
110 html.write("<span style='background-color:#ffff00'>%s</span>\n" % sgmlquote(line))
111 else:
112 html.write("%s\n" % sgmlquote(line))
113 html.write("</pre>\n")