adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 3 | # |
| 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.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 18 | |
| 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 | |
| 23 | cat app.info | awk -F '[,:]' ' |
| 24 | |
| 25 | BEGIN { OFS = ":"; } |
| 26 | |
| 27 | /^SF:/{ FILEN = $2; } |
| 28 | |
| 29 | /^end_of_record$/{ FILEN = ""; } |
| 30 | |
| 31 | /^DA:/{ print FILEN, $2, $3; } |
| 32 | |
| 33 | ' | sort | awk -F : ' |
| 34 | BEGIN { |
| 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\/' | \ |
| 55 | fgrep -v '_unittest.cc:' | \ |
| 56 | fgrep -v '/test_utils.' | \ |
| 57 | fgrep -v '/test_http_server.cc' | \ |
| 58 | fgrep -v '/testrunner.cc' | \ |
| 59 | fgrep -v '/mock' | \ |
| 60 | fgrep -v '.pb.cc' | \ |
| 61 | awk -F : ' |
| 62 | |
| 63 | function 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 | |
| 70 | BEGIN { |
| 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 | |
| 94 | END { |
| 95 | printfile(); |
| 96 | print "---\nSummary: tested " GOOD_LINES " / " (BAD_LINES + GOOD_LINES); |
Gilad Arnold | ab3bb45 | 2012-05-22 09:08:12 -0700 | [diff] [blame] | 97 | printf( |
| 98 | "Test coverage: %.1f%%\n", |
| 99 | ((GOOD_LINES * 100) / (BAD_LINES + GOOD_LINES))); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 100 | } |
| 101 | ' |