local_coverage_rate 2.3 KB

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