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