Skip to content

Commit 94ac20c

Browse files
authored
Update lcov/gcov scripts (#4)
1 parent eb3f0d1 commit 94ac20c

File tree

4 files changed

+317
-215
lines changed

4 files changed

+317
-215
lines changed

scripts/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
## GCOV/LCOV PROCESSING
3+
4+
- lcov-jenkins.sh: a script used by Jenkins jobs to process test coverage, and output lcov/gcov results.
5+
- lcov-development.sh: almost identical to lcov-jenkins.sh. However the purpose of this script is to test locally in a container, and possibly use this as a location to add new features that will eventually be migrated into the live production in lcov-jenkins.sh. Submit proposed updates here.
6+
- gcov-compare.py: Compares the coverage changes of a pull request, and displays a sort of "chart" indicating if coverage has increased or decreased.
7+
8+

scripts/jenkins.sh

Lines changed: 0 additions & 215 deletions
This file was deleted.

scripts/lcov-development.sh

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/bin/bash
2+
3+
# A script to run lcov and gcovr on a pull request, generating coverage reports.
4+
5+
# Run in a docker container ubuntu:22.04
6+
7+
# ----------------
8+
# First, configuring a few variables and settings that would already be available in a Jenkins job but
9+
# if run in standalone mode would need to be set
10+
# ----------------
11+
12+
set -xe
13+
14+
apt-get update
15+
apt-get install sudo
16+
17+
REPONAME=url
18+
ORGANIZATION=cppalliance
19+
ghprbTargetBranch=develop
20+
JOBFOLDER="${REPONAME}_job_folder"
21+
22+
echo "Initial cleanup. Remove job folder"
23+
rm -rf ${JOBFOLDER}
24+
echo "Remove target folder"
25+
rm -rf ${REPONAME}
26+
echo "Remove boost-root"
27+
rm -rf boost-root
28+
29+
git clone https://github.com/$ORGANIZATION/$REPONAME ${JOBFOLDER}
30+
cd ${JOBFOLDER}
31+
32+
# ----------------
33+
# The main script
34+
# ----------------
35+
36+
set -ex
37+
38+
if [ -z "${REPONAME}" ]; then
39+
echo "Please set the env variable REPONAME"
40+
exit 1
41+
fi
42+
43+
if [ -z "${ORGANIZATION}" ]; then
44+
echo "Please set the env variable ORGANIZATION"
45+
exit 1
46+
fi
47+
48+
# export USER=$(whoami)
49+
# echo "USER is ${USER}"
50+
51+
# these packages are already installed on containers.
52+
sudo apt-get update
53+
sudo apt-get install -y python3-pip sudo git curl jq
54+
55+
# codecov.sh installs perl packages also
56+
# sudo apt-get install -y libcapture-tiny-perl libdatetime-perl libdatetime-format-dateparse-perl
57+
sudo apt-get install -y libdatetime-format-dateparse-perl
58+
59+
export B2_TOOLSET="gcc-11"
60+
export LCOV_VERSION="v2.1"
61+
export LCOV_OPTIONS="--ignore-errors mismatch"
62+
63+
export REPO_NAME=${ORGANIZATION}/${REPONAME}
64+
export PATH=~/.local/bin:/usr/local/bin:$PATH
65+
export BOOST_CI_CODECOV_IO_UPLOAD="skip"
66+
67+
run_coverage_reports () {
68+
69+
git clone https://github.com/boostorg/boost-ci.git boost-ci-cloned --depth 1
70+
cp -prf boost-ci-cloned/ci .
71+
rm -rf boost-ci-cloned
72+
73+
export SELF=`basename $REPO_NAME`
74+
export BOOST_CI_SRC_FOLDER=$(pwd)
75+
76+
. ./ci/common_install.sh
77+
78+
# Formatted such as "cppalliance/buffers cppalliance/http-proto"
79+
for EXTRA_LIB in ${EXTRA_BOOST_LIBRARIES}; do
80+
EXTRA_LIB_REPO=`basename $EXTRA_LIB`
81+
if [ ! -d "$BOOST_ROOT/libs/${EXTRA_LIB_REPO}" ]; then
82+
pushd $BOOST_ROOT/libs
83+
git clone https://github.com/${EXTRA_LIB} -b $BOOST_BRANCH --depth 1
84+
popd
85+
fi
86+
done
87+
88+
cd $BOOST_ROOT/libs/$SELF
89+
ci/travis/codecov.sh
90+
91+
pip3 install --user gcovr
92+
cd $BOOST_CI_SRC_FOLDER
93+
94+
export PATH=/tmp/lcov/bin:$PATH
95+
command -v lcov
96+
lcov --version
97+
98+
lcov --ignore-errors unused --remove coverage.info -o coverage_filtered.info '*/test/*' '*/extra/*'
99+
100+
# Now the tracefile is coverage_filtered.info
101+
genhtml --flat -o genhtml coverage_filtered.info
102+
103+
#########################
104+
#
105+
# gcovr
106+
#
107+
#########################
108+
109+
GCOVRFILTER=".*/$REPONAME/.*"
110+
mkdir gcovr
111+
mkdir -p json
112+
cd ../boost-root
113+
gcovr -p --html-details --exclude '.*/test/.*' --exclude '.*/extra/.*' --filter "$GCOVRFILTER" --html --output $BOOST_CI_SRC_FOLDER/gcovr/index.html
114+
ls -al $BOOST_CI_SRC_FOLDER/gcovr
115+
116+
gcovr -p --json-summary --exclude '.*/test/.*' --exclude '.*/extra/.*' --filter "$GCOVRFILTER" --output $BOOST_CI_SRC_FOLDER/json/summary.json
117+
# jq . $BOOST_CI_SRC_FOLDER/json/summary.json
118+
119+
gcovr -p --json --exclude '.*/test/.*' --exclude '.*/extra/.*' --filter "$GCOVRFILTER" --output $BOOST_CI_SRC_FOLDER/json/coverage.json
120+
# jq . $BOOST_CI_SRC_FOLDER/json/coverage.json
121+
}
122+
123+
run_coverage_reports
124+
125+
#########################################################################
126+
#
127+
# RUN EVERYTHING AGAIN the same way on the target branch, usually develop
128+
#
129+
#########################################################################
130+
131+
# preparation:
132+
133+
# change this to an env variable from pull request builder:
134+
TARGET_BRANCH=$ghprbTargetBranch
135+
136+
cd $BOOST_CI_SRC_FOLDER
137+
BOOST_CI_SRC_FOLDER_ORIG=$BOOST_CI_SRC_FOLDER
138+
rm -rf ../boost-root
139+
cd ..
140+
git clone -b $TARGET_BRANCH https://github.com/$ORGANIZATION/$SELF
141+
cd $SELF
142+
# The "new" BOOST_CI_SRC_FOLDER:
143+
export BOOST_CI_SRC_FOLDER=$(pwd)
144+
export BOOST_CI_SRC_FOLDER_TARGET=$(pwd)
145+
146+
# done with prep, now everything is the same as before
147+
148+
run_coverage_reports
149+
150+
# Done with building target branch. Return everything back.
151+
152+
BOOST_CI_SRC_FOLDER=$BOOST_CI_SRC_FOLDER_ORIG
153+
cd $BOOST_CI_SRC_FOLDER
154+
155+
#########################################
156+
#
157+
# gcov-compare.py. download and run it.
158+
#
159+
#########################################
160+
161+
mkdir -p ~/.local/bin
162+
GITHUB_REPO_URL="https://github.com/cppalliance/ci-automation/raw/master"
163+
DIR="scripts"
164+
FILENAME="gcov-compare.py"
165+
URL="${GITHUB_REPO_URL}/$DIR/$FILENAME"
166+
FILE=~/.local/bin/$FILENAME
167+
if [ ! -f "$FILE" ]; then
168+
curl -s -S --retry 10 -L -o $FILE $URL && chmod 755 $FILE
169+
fi
170+
171+
$FILE $BOOST_CI_SRC_FOLDER_ORIG/json/summary.json $BOOST_CI_SRC_FOLDER_TARGET/json/summary.json > gcovr/coverage_diff.txt

0 commit comments

Comments
 (0)