2017-08-04 00:43:05 +02:00
|
|
|
#!/usr/bin/env bash
|
2019-04-18 19:51:19 +02:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
2013-08-01 22:59:01 +02:00
|
|
|
|
|
|
|
# Exit on error.
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ -n "$USE_CLANG" ]; then
|
|
|
|
echo "Error: Coverage test is supported only for gcc."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ROOT=".."
|
|
|
|
# Fetch right version of gcov
|
|
|
|
if [ -d /mnt/gvfs/third-party -a -z "$CXX" ]; then
|
2020-06-02 01:30:45 +02:00
|
|
|
source $ROOT/build_tools/fbcode_config_platform007.sh
|
2014-11-03 23:53:00 +01:00
|
|
|
GCOV=$GCC_BASE/bin/gcov
|
2013-08-01 22:59:01 +02:00
|
|
|
else
|
|
|
|
GCOV=$(which gcov)
|
|
|
|
fi
|
2020-03-25 04:57:53 +01:00
|
|
|
echo -e "Using $GCOV"
|
2013-08-01 22:59:01 +02:00
|
|
|
|
2013-08-14 22:29:05 +02:00
|
|
|
COVERAGE_DIR="$PWD/COVERAGE_REPORT"
|
2013-08-01 22:59:01 +02:00
|
|
|
mkdir -p $COVERAGE_DIR
|
|
|
|
|
|
|
|
# Find all gcno files to generate the coverage report
|
|
|
|
|
2020-03-25 04:57:53 +01:00
|
|
|
PYTHON=${1:-`which python`}
|
|
|
|
echo -e "Using $PYTHON"
|
2013-08-01 22:59:01 +02:00
|
|
|
GCNO_FILES=`find $ROOT -name "*.gcno"`
|
|
|
|
$GCOV --preserve-paths --relative-only --no-output $GCNO_FILES 2>/dev/null |
|
|
|
|
# Parse the raw gcov report to more human readable form.
|
2020-03-25 04:57:53 +01:00
|
|
|
$PYTHON $ROOT/coverage/parse_gcov_output.py |
|
2013-08-01 22:59:01 +02:00
|
|
|
# Write the output to both stdout and report file.
|
|
|
|
tee $COVERAGE_DIR/coverage_report_all.txt &&
|
|
|
|
echo -e "Generated coverage report for all files: $COVERAGE_DIR/coverage_report_all.txt\n"
|
|
|
|
|
|
|
|
# TODO: we also need to get the files of the latest commits.
|
|
|
|
# Get the most recently committed files.
|
|
|
|
LATEST_FILES=`
|
|
|
|
git show --pretty="format:" --name-only HEAD |
|
|
|
|
grep -v "^$" |
|
|
|
|
paste -s -d,`
|
|
|
|
RECENT_REPORT=$COVERAGE_DIR/coverage_report_recent.txt
|
|
|
|
|
|
|
|
echo -e "Recently updated files: $LATEST_FILES\n" > $RECENT_REPORT
|
|
|
|
$GCOV --preserve-paths --relative-only --no-output $GCNO_FILES 2>/dev/null |
|
2020-03-25 04:57:53 +01:00
|
|
|
$PYTHON $ROOT/coverage/parse_gcov_output.py -interested-files $LATEST_FILES |
|
2013-08-01 22:59:01 +02:00
|
|
|
tee -a $RECENT_REPORT &&
|
|
|
|
echo -e "Generated coverage report for recently updated files: $RECENT_REPORT\n"
|
|
|
|
|
2014-02-06 09:11:18 +01:00
|
|
|
# Unless otherwise specified, we'll not generate html report by default
|
|
|
|
if [ -z "$HTML" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2013-08-01 22:59:01 +02:00
|
|
|
# Generate the html report. If we cannot find lcov in this machine, we'll simply
|
|
|
|
# skip this step.
|
|
|
|
echo "Generating the html coverage report..."
|
2013-08-14 22:29:05 +02:00
|
|
|
|
|
|
|
LCOV=$(which lcov || true 2>/dev/null)
|
2013-08-01 22:59:01 +02:00
|
|
|
if [ -z $LCOV ]
|
|
|
|
then
|
|
|
|
echo "Skip: Cannot find lcov to generate the html report."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2013-08-23 01:59:02 +02:00
|
|
|
LCOV_VERSION=$(lcov -v | grep 1.1 || true)
|
|
|
|
if [ $LCOV_VERSION ]
|
|
|
|
then
|
|
|
|
echo "Not supported lcov version. Expect lcov 1.1."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2013-08-01 22:59:01 +02:00
|
|
|
(cd $ROOT; lcov --no-external \
|
|
|
|
--capture \
|
|
|
|
--directory $PWD \
|
|
|
|
--gcov-tool $GCOV \
|
2013-08-23 01:59:02 +02:00
|
|
|
--output-file $COVERAGE_DIR/coverage.info)
|
2013-08-01 22:59:01 +02:00
|
|
|
|
2013-08-23 01:59:02 +02:00
|
|
|
genhtml $COVERAGE_DIR/coverage.info -o $COVERAGE_DIR
|
2013-08-01 22:59:01 +02:00
|
|
|
|
|
|
|
echo "HTML Coverage report is generated in $COVERAGE_DIR"
|