Add tools/run_tests/run_lcov.sh
This is a tool for collecting coverage reports from our tests and
combining them with the open-source tool 'lcov'.
diff --git a/.gitignore b/.gitignore
index 5202b53..192b55f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@
libs
objs
*.pyc
+*.gcno
diff --git a/Makefile b/Makefile
index 35c2d84..ae78f82 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,15 @@
LDFLAGS_msan = -fsanitize=memory
DEFINES_msan = NDEBUG
+VALID_CONFIG_gcov = 1
+CC_gcov = gcc
+CXX_gcov = g++
+LD_gcov = gcc
+LDXX_gcov = g++
+CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
+LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
+DEFINES_gcov = NDEBUG
+
# General settings.
# You may want to change these depending on your system.
diff --git a/tools/run_tests/run_lcov.sh b/tools/run_tests/run_lcov.sh
new file mode 100755
index 0000000..6f22b0e
--- /dev/null
+++ b/tools/run_tests/run_lcov.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+set -ex
+
+out=`realpath ${1:-coverage}`
+
+root=`realpath $(dirname $0)/../..`
+tmp=`mktemp`
+cd $root
+tools/run_tests/run_tests.py -c gcov
+lcov --capture --directory . --output-file $tmp
+genhtml $tmp --output-directory $out
+rm $tmp
+if which xdg-open > /dev/null
+then
+ xdg-open file://$out/index.html
+fi
+
diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py
index 7ddf50c..4cf4422 100755
--- a/tools/run_tests/run_tests.py
+++ b/tools/run_tests/run_tests.py
@@ -37,6 +37,7 @@
'tsan': SimpleConfig('tsan'),
'msan': SimpleConfig('msan'),
'asan': SimpleConfig('asan'),
+ 'gcov': SimpleConfig('gcov'),
'valgrind': ValgrindConfig('dbg'),
}