2
0

uncovered 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #! /bin/sh
  2. #
  3. # show uncovered lines as errors
  4. #
  5. #
  6. # Copyright (C) 2007 Nokia Corporation
  7. # Contact: Pekka Pessi <pekka.pessi@nokia.com>
  8. # Licensed under LGPL. See file COPYING.
  9. #
  10. usage()
  11. {
  12. test X$1 = X0 || exec >&2
  13. cat <<EOF
  14. usage: uncovered OPTIONS
  15. where OPTIONS are
  16. --srcdir=DIR specify source directory
  17. --lcov-dir=DIR | -l DIR specify directory for lcov.info files
  18. EOF
  19. exit $1;
  20. }
  21. GENHTML_OPTIONS= o= ldir=
  22. while test $# -gt 0;
  23. do
  24. case $1 in
  25. --lcov-dir | -l ) test -z "$2" && usage 1; shift; ldir=$1; shift; ;;
  26. --lcov-dir=* ) ldir=${1#--ldir=}; shift ;;
  27. --srcdir | -s )
  28. test -z "$2" && usage 1; shift; srcdir=$1; shift; ;;
  29. --srcdir=* )
  30. srcdir=${1#--srcdir=}; shift ;;
  31. --help | '-?' | -h ) usage 0 ;;
  32. - ) shift; break ;;
  33. -* ) usage 1; ;;
  34. * ) break ;;
  35. esac
  36. done
  37. cwd=`pwd`
  38. tdir=${TMPDIR:-/tmp}/$USER.uncovered.$$
  39. info=${tdir}/lcov.info geninfo=${tdir}/genhtml.info
  40. test -d ${tdir} && { echo ${tdir}: already exists ; exit 2 ; }
  41. mkdir -p ${tdir} &&
  42. {
  43. # Find all lcov.info0 under -t DIR
  44. test -d ${ldir} &&
  45. find ${ldir} -name lcov.info |
  46. while read s
  47. do
  48. find $cwd -type f -not -newer $s | xargs lcov -q -e $s
  49. done
  50. lcov -q -c -d . --compat-libtool
  51. } > ${info}
  52. test -e ${info} || exit 1
  53. {
  54. # remove system includes with with inlined functions
  55. lcov -q -l ${info} | grep -v "`cd ${srcdir:-.} && pwd`"
  56. # remove test programs
  57. lcov -q -l ${info} | grep "/test\|/torture\|_test[.]c$"
  58. } |
  59. cut -d: -f1 |
  60. xargs lcov -q -r ${info} > ${geninfo} &&
  61. cd ${tdir} &&
  62. genhtml -q --prefix=$cwd/ --output-directory . ${geninfo} &&
  63. find . -name '*.gcov.html' |
  64. xargs perl -e '
  65. while (<>) {
  66. if (m:<pre[^>]*>:) { $pre=1; }
  67. if ($pre && m:</pre[^>]*>:) {
  68. $pre=0;
  69. if ($uncovered) {
  70. print $uncovered;
  71. $uncovered = "";
  72. }
  73. }
  74. if ($pre) {
  75. s/<[^>]+>//g;
  76. s/&lt;/</g; s/&gt;/>/g; s/&quot;/\"/g; s/&amp;/&/g;
  77. if (m/^ *\d+ *[1-9]\d* :/) {
  78. if ($uncovered) {
  79. print $uncovered;
  80. $uncovered = "";
  81. }
  82. }
  83. else {
  84. if ($uncovered) {
  85. if (m/^[^:]+: [{]/) { # Hack: show line number if line starts with {
  86. s/^ +(\d+)[^:]+:/$1:/;
  87. }
  88. else {
  89. s/^ +(\d+)[^:]+:/sprintf("%*s", 1 + length($1), " ")/e;
  90. }
  91. $uncovered .= $f . ":" . $_;
  92. }
  93. elsif (m/^ *\d+ *0 :/) {
  94. for ($f = $ARGV) {
  95. s:^[.]'$cwd/'::o;
  96. s:[.]gcov[.]html$::;
  97. }
  98. s/^ +(\d+)[^:]+:/$1:/;
  99. $uncovered = $f . ":" . $_;
  100. }
  101. }
  102. }
  103. }
  104. ' /dev/null
  105. rc=$?
  106. cd /
  107. rm -rf $tdir
  108. exit $rc