CMake: Add empty lines
[xz/debian.git] / tests / code_coverage.sh
blobb2e06a6ac8e81fb8eaba1f862aebf6863a0e99e8
1 #!/bin/sh
2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
6 # This builds xz with special CFLAGS for measuring code coverage and
7 # uses lcov and genhtml to create coverage reports.
9 # The current directory is used as the build directory so out-of-tree
10 # builds are possible. The coverage reports are written to the directory
11 # "coverage" under the current directory.
13 # Any options passed to this script are passed to "make" so to get
14 # faster builds use, for example, "-j4" as an argument to this script.
16 # Author: Jia Tan
18 ###############################################################################
20 set -e
22 COVERAGE_DIR="coverage"
24 # Test if lcov is installed
25 if ! command -v lcov > /dev/null
26 then
27 echo "Error: lcov not installed"
28 exit 1
31 # Test if genhtml is installed
32 if ! command -v genhtml > /dev/null
33 then
34 echo "Error: genhtml not installed"
35 exit 1
38 top_srcdir=$(cd -- "$(dirname -- "$0")" && cd .. && pwd)
40 # Run the autogen.sh script if the configure script has not been generated
41 if ! test -f "$top_srcdir/configure"
42 then
43 ( cd "$top_srcdir" && ./autogen.sh )
46 # Execute the configure script if the Makefile is not present
47 if ! test -f "Makefile"
48 then
49 "$top_srcdir/configure" \
50 --disable-xzdec \
51 --disable-lzmadec \
52 --disable-lzmainfo \
53 --disable-shared \
54 --enable-silent-rules \
55 CFLAGS="$CFLAGS --coverage --no-inline -O0"
58 # Run the tests
59 make "$@" check
61 # Re-create the coverage directory
62 rm -rf "$COVERAGE_DIR"
63 mkdir -p "$COVERAGE_DIR/liblzma"
64 mkdir -p "$COVERAGE_DIR/xz"
66 # Run lcov with src/liblzma as the input directory and write the
67 # results out to the coverage directory
68 lcov -c -d "src/liblzma" -o "$COVERAGE_DIR/liblzma/liblzma.cov"
69 lcov -c -d "src/xz" -o "$COVERAGE_DIR/xz/xz.cov"
71 # Generate the reports
72 genhtml "$COVERAGE_DIR/liblzma/liblzma.cov" -o "$COVERAGE_DIR/liblzma"
73 genhtml "$COVERAGE_DIR/xz/xz.cov" -o "$COVERAGE_DIR/xz"
75 echo "Success! See:"
76 echo "file://$PWD/$COVERAGE_DIR/liblzma/index.html"
77 echo "file://$PWD/$COVERAGE_DIR/xz/index.html"