-
Notifications
You must be signed in to change notification settings - Fork 3
/
local_coverage_rate
executable file
·101 lines (90 loc) · 2.29 KB
/
local_coverage_rate
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
#!/bin/bash
#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Calculates the test-coverage percentage for non-test files in the
# update_engine directory. Requires a file 'app.info' to contain the
# results of running the unittests while collecting coverage data.
cat app.info | awk -F '[,:]' '
BEGIN { OFS = ":"; }
/^SF:/{ FILEN = $2; }
/^end_of_record$/{ FILEN = ""; }
/^DA:/{ print FILEN, $2, $3; }
' | sort | awk -F : '
BEGIN {
OFS = ":";
FILEN = "";
LINE = "";
HITS = 0;
}
{
NEWFILEN = $1;
NEWLINE = $2;
if ((NEWFILEN == FILEN) && (NEWLINE == LINE)) {
HITS += $3
} else {
if (FILEN != "") {
print FILEN, LINE, HITS;
}
FILEN = NEWFILEN;
LINE = NEWLINE;
HITS = $3;
}
}
' | grep '^.*\/trunk\/src\/platform\/update_engine\/' | \
fgrep -v '_unittest.cc:' | \
fgrep -v '/test_utils.' | \
fgrep -v '/test_http_server.cc' | \
fgrep -v '/testrunner.cc' | \
fgrep -v '/mock' | \
fgrep -v '.pb.cc' | \
awk -F : '
function printfile() {
if (FNAME != "")
printf "%-40s %4d / %4d: %5.1f%%\n", FNAME, FILE_GOOD_LINES,
(FILE_BAD_LINES + FILE_GOOD_LINES),
(FILE_GOOD_LINES * 100) / (FILE_BAD_LINES + FILE_GOOD_LINES);
}
BEGIN {
FNAME = "";
FILE_BAD_LINES = 0;
FILE_GOOD_LINES = 0;
}
{
// calc filename
ARR_SIZE = split($1, PARTS, "/");
NEWFNAME = PARTS[ARR_SIZE];
if (NEWFNAME != FNAME) {
printfile();
FILE_BAD_LINES = 0;
FILE_GOOD_LINES = 0;
FNAME = NEWFNAME;
}
if ($3 == "0") {
BAD_LINES += 1;
FILE_BAD_LINES += 1;
} else {
GOOD_LINES += 1;
FILE_GOOD_LINES += 1;
}
}
END {
printfile();
print "---\nSummary: tested " GOOD_LINES " / " (BAD_LINES + GOOD_LINES);
printf(
"Test coverage: %.1f%%\n",
((GOOD_LINES * 100) / (BAD_LINES + GOOD_LINES)));
}
'