Skip to content

Commit

Permalink
Rearrange lcov scripts (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdarwin authored Jan 14, 2025
1 parent 6d64660 commit 6cf2dc0
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 217 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
pull_request:
push:
branches:
- master
- develop
- feature/**

jobs:
test:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install pre-reqs
run: |
sudo apt-get update
sudo apt-get install black
- name: Shellcheck
run: |
set -xe
shellcheck scripts/lcov-jenkins-gcc-13.sh
- name: Black
run: |
set -xe
black scripts/gcov-compare.py
5 changes: 3 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

## GCOV/LCOV PROCESSING

- lcov-jenkins.sh: a script used by Jenkins jobs to process test coverage, and output lcov/gcov results.
- 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.
- lcov-jenkins-gcc-13.sh: a script used by Jenkins jobs to process test coverage, and output lcov/gcov results.
- gcov-compare.py: Compares the coverage changes of a pull request, and displays a sort of "chart" indicating if coverage has increased or decreased.

Modifying lcov-jenkins-gcc-13.sh affects all current jobs. Therefore, when testing, add scripts such as lcov-jenkins-gcc-16-experimental.sh, etc.

See docs/README.md for instructions about running lcov in a local test environment.
39 changes: 39 additions & 0 deletions scripts/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

## LCOV and GCOVR scripts

Generate coverage reports on pull requests.

## Instructions to test gcovr locally

Run tests in a docker container such as ubuntu:24.04, or the latest LTS Ubuntu.

Configure a few variables and settings that would already be available in a Jenkins job but
if run in standalone mode would need to be set. The following code might be manually
copied into the script. Or run this in a shell first.

```
apt-get update
apt-get install sudo
mkdir -p test
cd test
export REPONAME=url
export ORGANIZATION=cppalliance
ghprbTargetBranch=develop
export JOBFOLDER="${REPONAME}_job_folder"
echo "Initial cleanup. Remove job folder"
rm -rf ${JOBFOLDER}
echo "Remove target folder"
rm -rf ${REPONAME}
echo "Remove boost-root"
rm -rf boost-root
git clone https://github.com/$ORGANIZATION/$REPONAME ${JOBFOLDER}
cd ${JOBFOLDER}
# Then proceed with the lcov processing
./lcov-jenkins-gcc-13.sh # or the name of the current script, which may be gcc-16, etc.
```
56 changes: 30 additions & 26 deletions scripts/gcov-compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,71 @@
from collections import defaultdict

if len(sys.argv) >= 2:
newcoveragefile=sys.argv[1]
newcoveragefile = sys.argv[1]
# print("newcoveragefile is " + newcoveragefile)
else:
# a default
newcoveragefile="summary.pr.json"
# a default
newcoveragefile = "summary.pr.json"
# print("newcoveragefile is using a default value of summary.pr.json")

if len(sys.argv) >= 3:
targetbranchcoveragefile=sys.argv[2]
targetbranchcoveragefile = sys.argv[2]
# print("targetbranchcoveragefile is " + targetbranchcoveragefile)
else:
# a default
targetbranchcoveragefile="summary.develop.json"
targetbranchcoveragefile = "summary.develop.json"
# print("targetbranchcoveragefile is using a default value of summary.targetbranch.json")

json_file = open(newcoveragefile, 'r')
json_file = open(newcoveragefile, "r")
newcoveragedata = json.load(json_file)
json_file.close()
json_file = open(targetbranchcoveragefile, 'r')
json_file = open(targetbranchcoveragefile, "r")
targetbranchcoveragedata = json.load(json_file)
json_file.close()

new_files={}
new_files = {}

for filedict in newcoveragedata["files"]:
filename=filedict["filename"]
new_files[filename]=filedict
filename = filedict["filename"]
new_files[filename] = filedict

targetbranch_files={}
targetbranch_files = {}
for filedict in targetbranchcoveragedata["files"]:
filename=filedict["filename"]
targetbranch_files[filename]=filedict
filename = filedict["filename"]
targetbranch_files[filename] = filedict

diff_files=defaultdict(dict)
diff_files = defaultdict(dict)

for file in new_files:
if file in targetbranch_files:
diff_line_percent=new_files[file]["line_percent"] - targetbranch_files[file]["line_percent"]
diff_line_percent=round(diff_line_percent, 2)
if isinstance(diff_line_percent, float) and diff_line_percent.is_integer():
diff_line_percent=int(diff_line_percent)
diff_line_percent = (
new_files[file]["line_percent"] - targetbranch_files[file]["line_percent"]
)
diff_line_percent = round(diff_line_percent, 2)
if isinstance(diff_line_percent, float) and diff_line_percent.is_integer():
diff_line_percent = int(diff_line_percent)
# print(new_files[file]["line_percent"],targetbranch_files[file]["line_percent"],diff_line_percent)
else:
diff_line_percent=new_files[file]["line_percent"] - 100
diff_line_percent=round(diff_line_percent, 2)
if isinstance(diff_line_percent, float) and diff_line_percent.is_integer():
diff_line_percent=int(diff_line_percent)
diff_line_percent = new_files[file]["line_percent"] - 100
diff_line_percent = round(diff_line_percent, 2)
if isinstance(diff_line_percent, float) and diff_line_percent.is_integer():
diff_line_percent = int(diff_line_percent)
# print(diff_line_percent)

diff_files[file]["diff_line_percent"]=diff_line_percent
diff_files[file]["diff_line_percent"] = diff_line_percent

# Output results

print("")
print('Each number represents a percentage line coverage difference of one file. For example "0" means 0% change in a file, "-7" is 7% less coverage, etc.')
print(
'Each number represents a percentage line coverage difference of one file. For example "0" means 0% change in a file, "-7" is 7% less coverage, etc.'
)
print("")

formatter=0
formatter = 0
for file in diff_files:
print(str(diff_files[file]["diff_line_percent"]).rjust(4) + " ", end="")
formatter=formatter+1
formatter = formatter + 1
if formatter % 20 == 0:
print("")
print("")
171 changes: 0 additions & 171 deletions scripts/lcov-development.sh

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 6cf2dc0

Please sign in to comment.