]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/coverage/coverage_test.sh
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / coverage / coverage_test.sh
1 #!/usr/bin/env bash
2 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3
4 # Exit on error.
5 set -e
6
7 if [ -n "$USE_CLANG" ]; then
8 echo "Error: Coverage test is supported only for gcc."
9 exit 1
10 fi
11
12 ROOT=".."
13 # Fetch right version of gcov
14 if [ -d /mnt/gvfs/third-party -a -z "$CXX" ]; then
15 source $ROOT/build_tools/fbcode_config_platform007.sh
16 GCOV=$GCC_BASE/bin/gcov
17 else
18 GCOV=$(which gcov)
19 fi
20 echo -e "Using $GCOV"
21
22 COVERAGE_DIR="$PWD/COVERAGE_REPORT"
23 mkdir -p $COVERAGE_DIR
24
25 # Find all gcno files to generate the coverage report
26
27 PYTHON=${1:-`which python`}
28 echo -e "Using $PYTHON"
29 GCNO_FILES=`find $ROOT -name "*.gcno"`
30 $GCOV --preserve-paths --relative-only --no-output $GCNO_FILES 2>/dev/null |
31 # Parse the raw gcov report to more human readable form.
32 $PYTHON $ROOT/coverage/parse_gcov_output.py |
33 # Write the output to both stdout and report file.
34 tee $COVERAGE_DIR/coverage_report_all.txt &&
35 echo -e "Generated coverage report for all files: $COVERAGE_DIR/coverage_report_all.txt\n"
36
37 # TODO: we also need to get the files of the latest commits.
38 # Get the most recently committed files.
39 LATEST_FILES=`
40 git show --pretty="format:" --name-only HEAD |
41 grep -v "^$" |
42 paste -s -d,`
43 RECENT_REPORT=$COVERAGE_DIR/coverage_report_recent.txt
44
45 echo -e "Recently updated files: $LATEST_FILES\n" > $RECENT_REPORT
46 $GCOV --preserve-paths --relative-only --no-output $GCNO_FILES 2>/dev/null |
47 $PYTHON $ROOT/coverage/parse_gcov_output.py -interested-files $LATEST_FILES |
48 tee -a $RECENT_REPORT &&
49 echo -e "Generated coverage report for recently updated files: $RECENT_REPORT\n"
50
51 # Unless otherwise specified, we'll not generate html report by default
52 if [ -z "$HTML" ]; then
53 exit 0
54 fi
55
56 # Generate the html report. If we cannot find lcov in this machine, we'll simply
57 # skip this step.
58 echo "Generating the html coverage report..."
59
60 LCOV=$(which lcov || true 2>/dev/null)
61 if [ -z $LCOV ]
62 then
63 echo "Skip: Cannot find lcov to generate the html report."
64 exit 0
65 fi
66
67 LCOV_VERSION=$(lcov -v | grep 1.1 || true)
68 if [ $LCOV_VERSION ]
69 then
70 echo "Not supported lcov version. Expect lcov 1.1."
71 exit 0
72 fi
73
74 (cd $ROOT; lcov --no-external \
75 --capture \
76 --directory $PWD \
77 --gcov-tool $GCOV \
78 --output-file $COVERAGE_DIR/coverage.info)
79
80 genhtml $COVERAGE_DIR/coverage.info -o $COVERAGE_DIR
81
82 echo "HTML Coverage report is generated in $COVERAGE_DIR"