-
Notifications
You must be signed in to change notification settings - Fork 18
/
format-gconv-report
executable file
·93 lines (85 loc) · 2.97 KB
/
format-gconv-report
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
#! /usr/bin/env python3
# This file is part of the Green End SFTP Server.
# Copyright (C) 2007, 2018 Richard Kettlewell
#
# 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
import re,sys,os,string
def fatal(msg):
sys.stderr.write("%s\n" % msg)
sys.exit(1)
def sgmlquotechar(c):
if c == '&' or c == '<' or ord(c) < 32 or ord(c) > 126:
return "&#%d;" % ord(c)
else:
return c
def sgmlquote(s):
return string.join(map(sgmlquotechar, s),'')
percent = {}
total_lines = 0
covered_lines = 0
args = sys.argv[1:]
htmldir = None
while len(args) > 0:
if args[0] == "--html":
htmldir = args[1]
args = args[2:]
else:
fatal("unknown option '%s'" % args[0])
name = None
for line in sys.stdin:
line = line[:-1]
r = re.match("File ['`](?:.*/)?([^/]+.c)'", line)
if r:
name = r.group(1)
r = re.match("Lines executed:([0-9\\.]+)% of ([0-9]+)", line)
if r:
if name:
this_pc = float(r.group(1))
this_lines = int(r.group(2))
percent[name] = this_pc
total_lines += this_lines
covered_lines += this_lines * this_pc / 100.0
name = None
keys = list(percent.keys())
keys.sort(key=lambda a: percent[a])
if len(keys):
for k in keys:
print("%20s: %d%%" % (k, percent[k]))
print("Total coverage: %d%%" % (100 * (covered_lines / total_lines)))
if htmldir is not None and len(keys):
index = open(os.path.join(htmldir, "index.html"), "w")
index.write("<html><head><title>gcov report</title>\n")
index.write("<body><h1>gcov report</h1>\n")
index.write("<table><tr><th>File</th><th>Coverage</th></tr>\n")
for k in keys:
index.write("<tr><td><a href=\"%s.html\">%s</a><td>%d%%\n" %
(sgmlquote(k), sgmlquote(k), percent[k]))
index.write("</table>\n")
index.write("<p>Total coverage: %d%%</p>\n" % (100 * (covered_lines / total_lines)))
for k in keys:
html = open(os.path.join(htmldir, "%s.html" % k), "w")
html.write("<html><head><title>%s</title>\n" % sgmlquote(k))
html.write("<body><h1>%s</h1>\n" % sgmlquote(k))
html.write("<pre>")
r = re.compile("^ *#####:.*")
for line in open("%s.gcov" % k, "r"):
if len(line) > 0 and line[-1] == '\n':
line = line[:-1]
if r.match(line):
html.write("<span style='background-color:#ffff00'>%s</span>\n" % sgmlquote(line))
else:
html.write("%s\n" % sgmlquote(line))
html.write("</pre>\n")