Skip to content

Commit

Permalink
feat(gcov coverage): added a check to handel gcov8 output
Browse files Browse the repository at this point in the history
Gcov 8 changes the way the outputs work, this requires a differnt way of gerring the files. As the
versions prior to 8 need to be processed in the older manner a version check has been added to
select between these to options.

feat(coverage): changed the gcov command

Change the GCOV command to the command used in the other parts of the script

feat(coverage): moved the GCOV call and updated the description

The GCOV call was moved to in the version check to allow gcov 8.0.0 to generate branch information.
The description for this gcov call in 8.0.0 or higher is updated to comply with the executed
command.

feat(coverage): change version check

feat(coverage): updated the description

feat(coverage): added a check for the 9.1.0 version

in the 9.1.0 version the file name changes form <name>.gcov to <name>.gcov.json.gz
  • Loading branch information
AxelZvb committed Oct 30, 2019
1 parent 386b25b commit 418e7f0
Showing 1 changed file with 70 additions and 35 deletions.
105 changes: 70 additions & 35 deletions tools/test/collect_cc_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,41 +98,76 @@ function gcov_coverage() {
mkdir -p "${COVERAGE_DIR}/$(dirname ${gcno_path})"
cp "$ROOT/${gcno_path}" "${COVERAGE_DIR}/${gcno_path}"
fi
# Invoke gcov to generate a code coverage report with the flags:
# -i Output gcov file in an intermediate text format.
# The output is a single .gcov file per .gcda file.
# No source code is required.
# -o directory The directory containing the .gcno and
# .gcda data files.
# "${gcda"} The input file name. gcov is looking for data files
# named after the input filename without its extension.
# gcov produces files called <source file name>.gcov in the current
# directory. These contain the coverage information of the source file
# they correspond to. One .gcov file is produced for each source
# (or header) file containing code which was compiled to produce the
# .gcda files.
# Don't generate branch coverage (-b) because of a gcov issue that
# segfaults when both -i and -b are used (see
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84879).
"${GCOV}" -i -o "$(dirname ${gcda})" "${gcda}" &> "$gcov_log"

# Go through all the files that were created by the gcov command above
# and append their content to the output .gcov file.
#
# For each source file gcov outputs to stdout something like this:
#
# File 'examples/cpp/hello-lib.cc'
# Lines executed:100.00% of 8
# Creating 'hello-lib.cc.gcov'
#
# We grep the names of the files that were created from that output.
cat "$gcov_log" | grep "Creating" | cut -d " " -f 2 | cut -d"'" -f2 | \
while read gcov_file; do
echo "Processing $gcov_file"
cat "$gcov_file" >> "$output_file"
# Remove the intermediate gcov file because it is not useful anymore.
rm -f "$gcov_file"
done

# check the gcov version
version=$("${GCOV}" --version | sed -n -r -e 's/^.*\s([0-9]\.[0-9]\.[0-9])\s?.*$/\1/p')

# Check the version to run branches if the version is 8+
if [ "$(printf '%s\n%s' "8.0.0" "$version" | sort -V | head -n 1)" != "$version" ]; then
# Invoke gcov to generate a code coverage report with the flags:
# -i Output gcov file in an intermediate text format.
# The output is a single .gcov file per .gcda file.
# No source code is required.
# -b Generate branch coverage information in the output.
# -o directory The directory containing the .gcno and
# .gcda data files.
# "${gcda"} The input file name. gcov is looking for data files
# named after the input filename without its extension.
"${GCOV}" -i -b -o "$(dirname ${gcda})" "${gcda}" &> "$gcov_log"

else
# Invoke gcov to generate a code coverage report with the flags:
# -i Output gcov file in an intermediate text format.
# The output is a single .gcov file per .gcda file.
# No source code is required.
# -o directory The directory containing the .gcno and
# .gcda data files.
# "${gcda"} The input file name. gcov is looking for data files
# named after the input filename without its extension.
# gcov produces files called <source file name>.gcov in the current
# directory. These contain the coverage information of the source file
# they correspond to. One .gcov file is produced for each source
# (or header) file containing code which was compiled to produce the
# .gcda files.
# Don't generate branch coverage (-b) because of a gcov issue that
# segfaults when both -i and -b are used (see
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84879).
"${GCOV}" -i -o "$(dirname ${gcda})" "${gcda}" &> "$gcov_log"

fi

# Check the gcov version again to use the correct processing on the data
if [ "$(printf '%s\n%s' "5.4.0" "$version" | sort -V | head -n 1)" != "$version" ]; then
# The version in 5.4.0 or higher
# The output is generated into only one file: "$(basename ${gcda}).gcov"
cat "$(basename ${gcda}).gcov" >> "$output_file"
rm -f "$(basename ${gcda}).gcov"

elif [ "$(printf '%s\n%s' "9.1.0" "$version" | sort -V | head -n 1)" != "$version" ]; then
# The version in 9.1.0 or higher
# The output is generated into only one file: "$(basename ${gcda}).gcov"
cat "$(basename ${gcda}).gcov.json.gz" >> "$output_file"
rm -f "$(basename ${gcda}).gcov.json.gz"

else
# Go through all the files that were created by the gcov command above
# and append their content to the output .gcov file.
#
# For each source file gcov outputs to stdout something like this:
#
# File 'examples/cpp/hello-lib.cc'
# Lines executed:100.00% of 8
# Creating 'hello-lib.cc.gcov'
#
# We grep the names of the files that were created from that output.
cat "$gcov_log" | grep "Creating" | cut -d " " -f 2 | cut -d"'" -f2 | \
while read gcov_file; do
echo "Processing $gcov_file"
cat "$gcov_file" >> "$output_file"
# Remove the intermediate gcov file because it is not useful anymore.
rm -f "$gcov_file"
done
fi
fi
fi
done < "${COVERAGE_MANIFEST}"
Expand Down

0 comments on commit 418e7f0

Please sign in to comment.