[dconf/wip/reorg] Add script to trim bogus lcov data



commit eea502023950db2cccdb1d4fa563b05316b64419
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Jul 10 12:33:46 2012 -0400

    Add script to trim bogus lcov data
    
    There is no (apparent) way to trim branch or line coverage data from
    lcov output based on expression matching against the source file.  This
    means that we get coverage results that tell us (for example) that we
    failed to test lines like 'g_assert_not_reached ();' or didn't test all
    branches of a g_assert().
    
    Add a script to read the lcov output and remove line or branch coverage
    data according to a list of symbols that are known to have incomplete
    coverage when operating as expected.

 .gitignore   |    2 ++
 Makefile.am  |    2 +-
 trim-lcov.py |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 6538832..8679fda 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,5 @@ Makefile
 /autom4te.cache
 /aclocal.m4
 /stamp-h1
+/dconf-lcov.info
+/lcov-html
diff --git a/Makefile.am b/Makefile.am
index 270b8e1..cf81afb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,7 +14,7 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
 # use recursive makes in order to ignore errors during check
 lcov: lcov-clean
 	-$(MAKE) $(AM_MAKEFLAGS) -k check
-	lcov --directory $(top_builddir) --capture --output-file dconf-lcov.info --test-name dconf --no-checksum --compat-libtool
+	lcov --directory $(top_builddir) --capture --test-name dconf | $(top_srcdir)/trim-lcov.py > dconf-lcov.info
 	LANG=C genhtml --prefix $(top_builddir) --output-directory lcov-html --legend --show-details dconf-lcov.info
 	@echo
 	@echo "     file://$(abs_top_builddir)/lcov-html/index.html"
diff --git a/trim-lcov.py b/trim-lcov.py
new file mode 100755
index 0000000..c1709c3
--- /dev/null
+++ b/trim-lcov.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+
+# This script removes branch and/or line coverage data for lines that
+# contain a particular substring.
+#
+# In the interest of "fairness" it removes all branch or coverage data
+# when a match is found -- not just negative data.  It is therefore
+# likely that running this script will actually reduce the total number
+# of lines and branches that are marked as covered (in absolute terms).
+#
+# This script intentionally avoids checking for errors.  Any exceptions
+# will trigger make to fail.
+#
+# Author: Ryan Lortie <desrt desrt ca>
+
+import sys
+
+line_suppress = ['g_assert_not_reached']
+branch_suppress = ['g_assert', 'g_return_if_fail', 'g_return_val_if_fail', 'G_DEFINE_TYPE']
+
+def check_suppress(suppressions, source, data):
+    line, _, rest = data.partition(',')
+    line = int(line) - 1
+
+    assert line < len(source)
+
+    for suppression in suppressions:
+        if suppression in source[line]:
+            return True
+
+    return False
+
+source = []
+for line in sys.stdin:
+    line = line[:-1]
+
+    keyword, _, rest = line.partition(':')
+
+    # Source file
+    if keyword == 'SF':
+        source = file(rest).readlines()
+
+    # Branch coverage data
+    elif keyword == 'BRDA':
+        if check_suppress(branch_suppress, source, rest):
+            continue
+
+    # Line coverage data
+    elif keyword == 'DA':
+        if check_suppress(line_suppress, source, rest):
+            continue
+
+    print line



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]