forked from tillt/jenkins-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-coverage.pl
105 lines (99 loc) · 2.62 KB
/
check-coverage.pl
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
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl
# Gcov coverage checker with "should never happen" exclusion
# Copyright (C) 2012 Matthew Skala
#
# 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, version 3.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Matthew Skala
# http://ansuz.sooke.bc.ca/
$snherror=0;
$longest=5;
foreach $fn (@ARGV) {
$longest=length($fn) if length($fn)>$longest;
}
$totshouldexec=0;
$totshouldntexec=0;
$totgoodexec=0;
$totbadexec=0;
foreach $fn (@ARGV) {
open(GC,$fn);
$shouldexec=0;
$shouldntexec=0;
$goodexec=0;
$badexec=0;
while (<GC>) {
chomp;
$should=1;
$should=0 if m!/\*\s*SNH\s*\*/!;
$should=0 if m!//\s*SNH\s*$!;
if (/^\s*\d+:\s*\d+:/) {
if ($should) {
$shouldexec++;
$goodexec++;
} else {
$shouldntexec++;
$badexec++;
}
} elsif (/^\s*#####:\s*\d+:/) {
if ($should) {
$shouldexec++;
} else {
$shouldntexec++;
}
}
}
if ($shouldexec==0) {
$goodexecp=1;
$shouldexecp=1;
} else {
$goodexecp=$goodexec;
$shouldexecp=$shouldexec;
}
if ($badexec>0) {
$snherror=1;
printf "%*s: %6d/%6d (%5.01f%%) + %6d/%6d (%5.01f%%) SNH\n",
$longest,$fn,
$goodexec,$shouldexec,100*$goodexecp/$shouldexecp,
$badexec,$shouldntexec,100*$badexec/$shouldntexec;
} else {
$snherror=1 if $goodexec!=$shouldexec;
printf "%*s: %6d/%6d (%5.01f%%)\n",
$longest,$fn,
$goodexec,$shouldexec,100*$goodexecp/$shouldexecp;
}
$totshouldexec+=$shouldexec;
$totshouldntexec+=$shouldntexec;
$totgoodexec+=$goodexec;
$totbadexec+=$badexec;
close(GC);
}
if ($totshouldexec==0) {
$totgoodexecp=1;
$totshouldexecp=1;
$snherror=1;
} else {
$totgoodexecp=$totgoodexec;
$totshouldexecp=$totshouldexec;
}
if ($totbadexec>0) {
printf "\n%*s: %6d/%6d (%5.01f%%) + %6d/%6d (%5.01f%%) SNH\n\n",
$longest,'TOTAL',
$totgoodexec,$totshouldexec,100*$totgoodexecp/$totshouldexecp,
$totbadexec,$totshouldntexec,100*$totbadexec/$totshouldntexec;
} else {
printf "\n%*s: %6d/%6d (%5.01f%%)\n\n",
$longest,'TOTAL',
$totgoodexec,$totshouldexec,100*$totgoodexecp/$totshouldexecp;
}
exit $snherror;