liblzma: Use LZMA1EXT feature in lzma_alone_decoder().
[xz.git] / tests / code_coverage.sh
blobbf2471b4f129d2cf150d509649614d750d660834
1 #!/bin/sh
3 ###############################################################################
5 # This builds xz with special CFLAGS for measuring code coverage and
6 # uses lcov and genhtml to create coverage reports.
8 # The current directory is used as the build directory so out-of-tree
9 # builds are possible. The coverage reports are written to the directory
10 # "coverage" under the current directory.
12 # Any options passed to this script are passed to "make" so to get
13 # faster builds use, for example, "-j4" as an argument to this script.
15 # Author: Jia Tan
17 # This file has been put into the public domain.
18 # You can do whatever you want with this file.
20 ###############################################################################
22 set -e
24 COVERAGE_DIR="coverage"
26 # Test if lcov is installed
27 if ! command -v lcov > /dev/null
28 then
29 echo "Error: lcov not installed"
30 exit 1
33 # Test if genhtml is installed
34 if ! command -v genhtml > /dev/null
35 then
36 echo "Error: genhtml not installed"
37 exit 1
40 top_srcdir=$(cd -- "$(dirname -- "$0")" && cd .. && pwd)
42 # Run the autogen.sh script if the configure script has not been generated
43 if ! test -f "$top_srcdir/configure"
44 then
45 ( cd "$top_srcdir" && ./autogen.sh )
48 # Execute the configure script if the Makefile is not present
49 if ! test -f "Makefile"
50 then
51 "$top_srcdir/configure" \
52 --disable-xzdec \
53 --disable-lzmadec \
54 --disable-lzmainfo \
55 --disable-shared \
56 --enable-silent-rules \
57 CFLAGS="$CFLAGS --coverage --no-inline -O0"
60 # Run the tests
61 make "$@" check
63 # Re-create the coverage directory
64 rm -rf "$COVERAGE_DIR"
65 mkdir -p "$COVERAGE_DIR/liblzma"
66 mkdir -p "$COVERAGE_DIR/xz"
68 # Run lcov with src/liblzma as the input directory and write the
69 # results out to the coverage directory
70 lcov -c -d "src/liblzma" -o "$COVERAGE_DIR/liblzma/liblzma.cov"
71 lcov -c -d "src/xz" -o "$COVERAGE_DIR/xz/xz.cov"
73 # Generate the reports
74 genhtml "$COVERAGE_DIR/liblzma/liblzma.cov" -o "$COVERAGE_DIR/liblzma"
75 genhtml "$COVERAGE_DIR/xz/xz.cov" -o "$COVERAGE_DIR/xz"
77 echo "Success! See:"
78 echo "file://$PWD/$COVERAGE_DIR/liblzma/index.html"
79 echo "file://$PWD/$COVERAGE_DIR/xz/index.html"