2 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
7 if [ -n "$USE_CLANG" ]; then
8 echo "Error: Coverage test is supported only for gcc."
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
22 COVERAGE_DIR
="$PWD/COVERAGE_REPORT"
23 mkdir
-p $COVERAGE_DIR
25 # Find all gcno files to generate the coverage report
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"
37 # TODO: we also need to get the files of the latest commits.
38 # Get the most recently committed files.
40 git show --pretty="format:" --name-only HEAD |
43 RECENT_REPORT
=$COVERAGE_DIR/coverage_report_recent.txt
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"
51 # Unless otherwise specified, we'll not generate html report by default
52 if [ -z "$HTML" ]; then
56 # Generate the html report. If we cannot find lcov in this machine, we'll simply
58 echo "Generating the html coverage report..."
60 LCOV
=$
(which lcov || true
2>/dev
/null
)
63 echo "Skip: Cannot find lcov to generate the html report."
67 LCOV_VERSION
=$
(lcov
-v |
grep 1.1 || true
)
70 echo "Not supported lcov version. Expect lcov 1.1."
74 (cd $ROOT; lcov
--no-external \
78 --output-file $COVERAGE_DIR/coverage.info
)
80 genhtml
$COVERAGE_DIR/coverage.info
-o $COVERAGE_DIR
82 echo "HTML Coverage report is generated in $COVERAGE_DIR"