uncovered 2.55 KB
Newer Older
1 2
#! /bin/sh
#
Pekka Pessi's avatar
Pekka Pessi committed
3
# show uncovered lines as errors
4 5 6 7 8 9 10 11 12 13 14
#

#
# Copyright (C) 2007 Nokia Corporation
# Contact: Pekka Pessi <pekka.pessi@nokia.com>
# Licensed under LGPL. See file COPYING.
#

usage()
{
  test X$1 == X0 || exec >&2
Pekka Pessi's avatar
Pekka Pessi committed
15 16 17 18 19 20
  cat <<EOF
usage: uncovered OPTIONS
where OPTIONS are
   --srcdir=DIR                  specify source directory
   --lcov-dir=DIR | -l DIR       specify directory for lcov.info files
EOF
21 22 23
  exit $1;
}

Pekka Pessi's avatar
Pekka Pessi committed
24
GENHTML_OPTIONS= o= ldir=
25 26 27 28

while test $# -gt 0;
do
  case $1 in 
Pekka Pessi's avatar
Pekka Pessi committed
29 30 31 32 33 34 35
  --lcov-dir | -l ) test -z "$2" && usage 1; shift; ldir=$1; shift; ;;
  --lcov-dir=* ) ldir=${1#--ldir=}; shift ;;
  --srcdir | -s )
    test -z "$2" && usage 1; shift; srcdir=$1; shift; ;;
  --srcdir=* )
    srcdir=${1#--srcdir=}; shift ;;
  --help | '-?' | -h ) usage 0 ;;
36 37
  - ) shift; break ;;
  -* ) usage 1; ;;
Pekka Pessi's avatar
Pekka Pessi committed
38
  * ) break ;;
39 40 41
  esac
done

Pekka Pessi's avatar
Pekka Pessi committed
42
cwd=`pwd`
43

Pekka Pessi's avatar
Pekka Pessi committed
44 45
tdir=${TMPDIR:-/tmp}/$USER.uncovered.$$ 
info=${tdir}/lcov.info geninfo=${tdir}/genhtml.info
46

Pekka Pessi's avatar
Pekka Pessi committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60
test -d ${tdir} && { echo ${tdir}: already exists ; exit 2 ; }

mkdir -p ${tdir} &&
{
    # Find all lcov.info0 under -t DIR 
    test -d ${ldir} &&
    find ${ldir} -name lcov.info |
    while read s
    do
      find $cwd -type f -not -newer $s | xargs lcov -q -e $s 
    done
    
    lcov -q -c -d . --compat-libtool
} > ${info}
61

Pekka Pessi's avatar
Pekka Pessi committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75
test -e ${info} || exit 1

{
  # remove system includes with with inlined functions
  lcov -q -l ${info} | grep -v "`cd ${srcdir:-.} && pwd`"
  # remove test programs
  lcov -q -l ${info} | grep "/test\|/torture\|_test[.]c$" 
} | 
cut -d: -f1 |
xargs lcov -q -r ${info} > ${geninfo} &&
cd ${tdir} &&
genhtml -q --prefix=$cwd/ --output-directory . ${geninfo} &&
find . -name '*.gcov.html' |
xargs perl -e '
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 102 103 104 105 106 107
while (<>) {
  if (m:<pre[^>]*>:) { $pre=1; }
  if ($pre && m:</pre[^>]*>:) {
    $pre=0;
    if ($uncovered) {
      print $uncovered;
      $uncovered = "";
    }
  }
  if ($pre) {
    s/<[^>]+>//g;

    s/&lt;/</g; s/&gt;/>/g; s/&quot;/\"/g; s/&amp;/&/g;

    if (m/^ *\d+ *[1-9]\d* :/) {
      if ($uncovered) {
        print $uncovered;
        $uncovered = "";
      }
    }
    else {
      if ($uncovered) {
        if (m/^[^:]+: [{]/) { # Hack: show line number if line starts with {
          s/^ +(\d+)[^:]+:/$1:/;
        }
        else {
          s/^ +(\d+)[^:]+:/sprintf("%*s", 1 + length($1), " ")/e;
        }
        $uncovered .= $f . ":" . $_;
      }
      elsif (m/^ *\d+ *0 :/) {
        for ($f = $ARGV) {
Pekka Pessi's avatar
Pekka Pessi committed
108
          s:^[.]'$cwd/'::o;
109 110 111 112 113 114 115 116 117
          s:[.]gcov[.]html$::;
        } 
        s/^ +(\d+)[^:]+:/$1:/;
        $uncovered = $f . ":" . $_;
      }
    }
  }
}
' /dev/null
Pekka Pessi's avatar
Pekka Pessi committed
118 119 120 121 122

rc=$?
cd /
rm -rf $tdir
exit $rc