6 if [ -n "$USE_CLANG" ]; then
7 echo "Error: Coverage test is supported only for gcc."
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
20 COVERAGE_DIR
="$PWD/COVERAGE_REPORT"
21 mkdir
-p $COVERAGE_DIR
23 # Find all gcno files to generate the coverage report
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"
33 # TODO: we also need to get the files of the latest commits.
34 # Get the most recently committed files.
36 git show --pretty="format:" --name-only HEAD |
39 RECENT_REPORT
=$COVERAGE_DIR/coverage_report_recent.txt
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"
47 # Unless otherwise specified, we'll not generate html report by default
48 if [ -z "$HTML" ]; then
52 # Generate the html report. If we cannot find lcov in this machine, we'll simply
54 echo "Generating the html coverage report..."
56 LCOV
=$
(which lcov || true
2>/dev
/null
)
59 echo "Skip: Cannot find lcov to generate the html report."
63 LCOV_VERSION
=$
(lcov
-v |
grep 1.1 || true
)
66 echo "Not supported lcov version. Expect lcov 1.1."
70 (cd $ROOT; lcov
--no-external \
74 --output-file $COVERAGE_DIR/coverage.info
)
76 genhtml
$COVERAGE_DIR/coverage.info
-o $COVERAGE_DIR
78 echo "HTML Coverage report is generated in $COVERAGE_DIR"