blob: b189806f7149f114b18a9a56769932d5e33dee66 [file] [log] [blame]
adlr@google.com3defe6a2009-12-04 20:57:17 +00001#!/bin/bash
2
Alex Deymoaea4c1c2015-08-19 20:24:43 -07003#
4# Copyright (C) 2009 The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
adlr@google.com3defe6a2009-12-04 20:57:17 +000018
19# Calculates the test-coverage percentage for non-test files in the
20# update_engine directory. Requires a file 'app.info' to contain the
21# results of running the unittests while collecting coverage data.
22
23cat app.info | awk -F '[,:]' '
24
25BEGIN { OFS = ":"; }
26
27/^SF:/{ FILEN = $2; }
28
29/^end_of_record$/{ FILEN = ""; }
30
31/^DA:/{ print FILEN, $2, $3; }
32
33' | sort | awk -F : '
34BEGIN {
35 OFS = ":";
36 FILEN = "";
37 LINE = "";
38 HITS = 0;
39}
40{
41 NEWFILEN = $1;
42 NEWLINE = $2;
43 if ((NEWFILEN == FILEN) && (NEWLINE == LINE)) {
44 HITS += $3
45 } else {
46 if (FILEN != "") {
47 print FILEN, LINE, HITS;
48 }
49 FILEN = NEWFILEN;
50 LINE = NEWLINE;
51 HITS = $3;
52 }
53}
54' | grep '^.*\/trunk\/src\/platform\/update_engine\/' | \
55fgrep -v '_unittest.cc:' | \
56fgrep -v '/test_utils.' | \
57fgrep -v '/test_http_server.cc' | \
58fgrep -v '/testrunner.cc' | \
59fgrep -v '/mock' | \
60fgrep -v '.pb.cc' | \
61awk -F : '
62
63function printfile() {
64 if (FNAME != "")
65 printf "%-40s %4d / %4d: %5.1f%%\n", FNAME, FILE_GOOD_LINES,
66 (FILE_BAD_LINES + FILE_GOOD_LINES),
67 (FILE_GOOD_LINES * 100) / (FILE_BAD_LINES + FILE_GOOD_LINES);
68}
69
70BEGIN {
71 FNAME = "";
72 FILE_BAD_LINES = 0;
73 FILE_GOOD_LINES = 0;
74}
75{
76 // calc filename
77 ARR_SIZE = split($1, PARTS, "/");
78 NEWFNAME = PARTS[ARR_SIZE];
79 if (NEWFNAME != FNAME) {
80 printfile();
81 FILE_BAD_LINES = 0;
82 FILE_GOOD_LINES = 0;
83 FNAME = NEWFNAME;
84 }
85 if ($3 == "0") {
86 BAD_LINES += 1;
87 FILE_BAD_LINES += 1;
88 } else {
89 GOOD_LINES += 1;
90 FILE_GOOD_LINES += 1;
91 }
92}
93
94END {
95 printfile();
96 print "---\nSummary: tested " GOOD_LINES " / " (BAD_LINES + GOOD_LINES);
Gilad Arnoldab3bb452012-05-22 09:08:12 -070097 printf(
98 "Test coverage: %.1f%%\n",
99 ((GOOD_LINES * 100) / (BAD_LINES + GOOD_LINES)));
adlr@google.com3defe6a2009-12-04 20:57:17 +0000100}
101'