aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2022-07-01 21:19:26 +0800
committerLasse Collin <lasse.collin@tukaani.org>2022-07-10 22:42:22 +0300
commitd1bfa3dc703325ecd974167e864a8712fdfe936e (patch)
tree3cc205c618030e84dd8bdb6d3c98808d43fe38e1
parentTests: Add more tests into test_check. (diff)
downloadxz-d1bfa3dc703325ecd974167e864a8712fdfe936e.tar.xz
Created script to generate code coverage reports.
The script uses lcov and genhtml after running the tests to show the code coverage statistics. The script will create a coverage directory where it is run. It can be run both in and out of the source directory.
Diffstat (limited to '')
-rw-r--r--.gitignore4
-rwxr-xr-xtests/code_coverage.sh79
2 files changed, 83 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 782c12cc..3aa4bb8e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,8 @@
.deps
.libs
+*.gcda
+*.gcno
*.la
*.lo
*.o
@@ -32,6 +34,8 @@ build-aux/ltmain.sh
build-aux/missing
build-aux/test-driver
+coverage
+
/src/liblzma/liblzma.pc
/src/lzmainfo/lzmainfo
/src/xz/xz
diff --git a/tests/code_coverage.sh b/tests/code_coverage.sh
new file mode 100755
index 00000000..bf2471b4
--- /dev/null
+++ b/tests/code_coverage.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+###############################################################################
+#
+# This builds xz with special CFLAGS for measuring code coverage and
+# uses lcov and genhtml to create coverage reports.
+#
+# The current directory is used as the build directory so out-of-tree
+# builds are possible. The coverage reports are written to the directory
+# "coverage" under the current directory.
+#
+# Any options passed to this script are passed to "make" so to get
+# faster builds use, for example, "-j4" as an argument to this script.
+#
+# Author: Jia Tan
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+###############################################################################
+
+set -e
+
+COVERAGE_DIR="coverage"
+
+# Test if lcov is installed
+if ! command -v lcov > /dev/null
+then
+ echo "Error: lcov not installed"
+ exit 1
+fi
+
+# Test if genhtml is installed
+if ! command -v genhtml > /dev/null
+then
+ echo "Error: genhtml not installed"
+ exit 1
+fi
+
+top_srcdir=$(cd -- "$(dirname -- "$0")" && cd .. && pwd)
+
+# Run the autogen.sh script if the configure script has not been generated
+if ! test -f "$top_srcdir/configure"
+then
+ ( cd "$top_srcdir" && ./autogen.sh )
+fi
+
+# Execute the configure script if the Makefile is not present
+if ! test -f "Makefile"
+then
+ "$top_srcdir/configure" \
+ --disable-xzdec \
+ --disable-lzmadec \
+ --disable-lzmainfo \
+ --disable-shared \
+ --enable-silent-rules \
+ CFLAGS="$CFLAGS --coverage --no-inline -O0"
+fi
+
+# Run the tests
+make "$@" check
+
+# Re-create the coverage directory
+rm -rf "$COVERAGE_DIR"
+mkdir -p "$COVERAGE_DIR/liblzma"
+mkdir -p "$COVERAGE_DIR/xz"
+
+# Run lcov with src/liblzma as the input directory and write the
+# results out to the coverage directory
+lcov -c -d "src/liblzma" -o "$COVERAGE_DIR/liblzma/liblzma.cov"
+lcov -c -d "src/xz" -o "$COVERAGE_DIR/xz/xz.cov"
+
+# Generate the reports
+genhtml "$COVERAGE_DIR/liblzma/liblzma.cov" -o "$COVERAGE_DIR/liblzma"
+genhtml "$COVERAGE_DIR/xz/xz.cov" -o "$COVERAGE_DIR/xz"
+
+echo "Success! See:"
+echo "file://$PWD/$COVERAGE_DIR/liblzma/index.html"
+echo "file://$PWD/$COVERAGE_DIR/xz/index.html"