3
# Copyright (C) 2006 Daniel Berrange
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
my %coverage = ( functions => {}, files => {} );
32
if (/^Function '(.*)'\s*$/) {
35
$coverage{$type}->{$name} = {};
36
push @functions, $name;
37
} elsif (/^File '(.*?)'\s*$/) {
40
$coverage{$type}->{$name} = {};
42
foreach my $func (@functions) {
43
$coverage{"function"}->{$func}->{file} = $name;
46
} elsif (/^Lines executed:(.*)%\s*of\s*(\d+)\s*$/) {
47
$coverage{$type}->{$name}->{lines} = $2;
48
$coverage{$type}->{$name}->{linesCoverage} = $1;
49
} elsif (/^Branches executed:(.*)%\s*of\s*(\d+)\s*$/) {
50
$coverage{$type}->{$name}->{branches} = $2;
51
$coverage{$type}->{$name}->{branchesCoverage} = $1;
52
} elsif (/^Taken at least once:(.*)%\s*of\s*(\d+)\s*$/) {
53
$coverage{$type}->{$name}->{conds} = $2;
54
$coverage{$type}->{$name}->{condsCoverage} = $1;
55
} elsif (/^Calls executed:(.*)%\s*of\s*(\d+)\s*$/) {
56
$coverage{$type}->{$name}->{calls} = $2;
57
$coverage{$type}->{$name}->{callsCoverage} = $1;
58
} elsif (/^No branches$/) {
59
$coverage{$type}->{$name}->{branches} = 0;
60
$coverage{$type}->{$name}->{branchesCoverage} = "100.00";
61
$coverage{$type}->{$name}->{conds} = 0;
62
$coverage{$type}->{$name}->{condsCoverage} = "100.00";
63
} elsif (/^No calls$/) {
64
$coverage{$type}->{$name}->{calls} = 0;
65
$coverage{$type}->{$name}->{callsCoverage} = "100.00";
66
} elsif (/^\s*(.*):creating '(.*)'\s*$/) {
76
foreach my $type ("function", "file") {
78
foreach my $m ("lines", "branches", "conds", "calls") {
82
foreach my $func (keys %{$coverage{function}}) {
84
my $got = $coverage{function}->{$func}->{$m};
86
my $miss = $got * $coverage{function}->{$func}->{$m ."Coverage"} / 100;
89
$summary{$type}->{$m} = sprintf("%d", $totalGot);
90
$summary{$type}->{$m . "Coverage"} = sprintf("%.2f", $totalMiss / $totalGot * 100);
98
foreach my $type ("function", "file") {
99
printf "<%ss>\n", $type;
100
foreach my $name (sort { $a cmp $b } keys %{$coverage{$type}}) {
101
my $rec = $coverage{$type}->{$name};
102
printf " <entry name=\"%s\" details=\"%s\">\n", $name, ($type eq "file" ? $filemap{$name} : $filemap{$rec->{file}});
103
printf " <lines count=\"%s\" coverage=\"%s\"/>\n", $rec->{lines}, $rec->{linesCoverage};
104
if (exists $rec->{branches}) {
105
printf " <branches count=\"%s\" coverage=\"%s\"/>\n", $rec->{branches}, $rec->{branchesCoverage};
107
if (exists $rec->{conds}) {
108
printf " <conditions count=\"%s\" coverage=\"%s\"/>\n", $rec->{conds}, $rec->{condsCoverage};
110
if (exists $rec->{calls}) {
111
printf " <calls count=\"%s\" coverage=\"%s\"/>\n", $rec->{calls}, $rec->{callsCoverage};
116
printf " <summary>\n";
117
printf " <lines count=\"%s\" coverage=\"%s\"/>\n", $summary{$type}->{lines}, $summary{$type}->{linesCoverage};
118
printf " <branches count=\"%s\" coverage=\"%s\"/>\n", $summary{$type}->{branches}, $summary{$type}->{branchesCoverage};
119
printf " <conditions count=\"%s\" coverage=\"%s\"/>\n", $summary{$type}->{conds}, $summary{$type}->{condsCoverage};
120
printf " <calls count=\"%s\" coverage=\"%s\"/>\n", $summary{$type}->{calls}, $summary{$type}->{callsCoverage};
121
printf " </summary>\n";
122
printf "</%ss>\n", $type;
125
print "</coverage>\n";