Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TEC Server Config
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MSK-SW
Infrastructure and Support
TEC
TEC Server Config
Commits
9cffabf6
Commit
9cffabf6
authored
2 years ago
by
Martin Christoph Hierholzer
Browse files
Options
Downloads
Patches
Plain Diff
project-template: add python coverage report
parent
b279a860
No related branches found
Branches containing commit
No related tags found
1 merge request
!3
update project template
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmake/make_coverage.sh.in
+75
-25
75 additions, 25 deletions
cmake/make_coverage.sh.in
with
75 additions
and
25 deletions
cmake/make_coverage.sh.in
+
75
−
25
View file @
9cffabf6
...
...
@@ -23,31 +23,81 @@
#
#######################################################################################################################
TESTFILES
=
`
find
-name
CTestTestfile.cmake
`
if
[
-z
"
${
TESTFILES
}
"
]
;
then
echo
"No tests found. Not generating any coverage report."
exit
0
fi
#
# Check whether Python tests are present
#
N_PYTHON
=
0
for
f
in
$TESTFILES
;
do
N_PYTHON
=
$((
N_PYTHON
+
`
grep
-E
'^add_test\([^ ]* "/usr/bin/python3?" '
$f
|
wc
-l
`
))
done
#
# Preparations for C++ coverage report
#
cmake
--build
.
--target
clean-gcda
#
# Preparations for Python coverage report
#
if
((
N_PYTHON
>
0
))
;
then
cp
CTestTestfile.cmake CTestTestfile-backup.cmake
sed
-E
's_"/usr/bin/python(3)?"_"/usr/bin/python\1-coverage" "run" "-a"_'
-i
CTestTestfile.cmake
python3-coverage erase
fi
#
# Execute tests and record coverage data
#
cmake
--build
.
--target
test
lcov
--capture
--directory
.
--output-file
coverage_all.info
--ignore-errors
gcov
#lcov capture also includes external stuff like glibc, boost etc.
#only extract the reports for this project
lcov
--extract
coverage_all.info
"@CMAKE_SOURCE_DIR@*"
-o
coverage_only_source_tree.info
#Some parts of the source code might be excluded. Set EXCLUDE_FROM_COVERAGE to contain
# a list of directories to be excluded from the coverage report.
# Don't worry if this is empty. It just means there is nothing to exclude (the normal case).
for
exclude_dir
in
@EXCLUDE_FROM_COVERAGE@
;
do
echo
lcov
--remove
coverage_only_source_tree.info
"@CMAKE_SOURCE_DIR@/
${
exclude_dir
}
*"
-o
tmp.info
lcov
--remove
coverage_only_source_tree.info
"@CMAKE_SOURCE_DIR@/
${
exclude_dir
}
*"
-o
tmp.info
mv
tmp.info coverage_only_source_tree.info
done
#Some projects install the library and its headers for testing in the build directory
#and compile tests and examples against it. This leads to double
#counting and untested lines in the coverage report. That's why we
#exclude the build directory from the coverage report (needed if the
#build directory is in the source tree).
#Attention: If you make an 'in sorce build' the coverage report will
#be empty!
lcov
--remove
coverage_only_source_tree.info
"@PROJECT_BINARY_DIR@/*"
-o
coverage.info
#finally generate the html page
genhtml coverage.info
--output-directory
coverage_html
#
# Check if C++ report has been generated
#
N_GCDA
=
`
find
-name
*
.gcda |
wc
-l
`
#
# Generate C++ coverage report, if files have been found
#
if
((
N_GCDA
>
0
))
;
then
lcov
--capture
--directory
.
--output-file
coverage_all.info
--ignore-errors
gcov
# lcov capture also includes external stuff like glibc, boost etc.
# only extract the reports for this project
lcov
--extract
coverage_all.info
"@CMAKE_SOURCE_DIR@*"
-o
coverage_only_source_tree.info
# Some parts of the source code might be excluded. Set EXCLUDE_FROM_COVERAGE to contain
# a list of directories to be excluded from the coverage report.
# Don't worry if this is empty. It just means there is nothing to exclude (the normal case).
for
exclude_dir
in
@EXCLUDE_FROM_COVERAGE@
;
do
echo
lcov
--remove
coverage_only_source_tree.info
"@CMAKE_SOURCE_DIR@/
${
exclude_dir
}
*"
-o
tmp.info
lcov
--remove
coverage_only_source_tree.info
"@CMAKE_SOURCE_DIR@/
${
exclude_dir
}
*"
-o
tmp.info
mv
tmp.info coverage_only_source_tree.info
done
# Some projects install the library and its headers for testing in the build directory
# and compile tests and examples against it. This leads to double
# counting and untested lines in the coverage report. That's why we
# exclude the build directory from the coverage report (needed if the
# build directory is in the source tree).
# Attention: If you make an 'in sorce build' the coverage report will
# be empty!
lcov
--remove
coverage_only_source_tree.info
"@PROJECT_BINARY_DIR@/*"
-o
coverage.info
# finally generate the html page
genhtml coverage.info
--output-directory
coverage_html
fi
#
# Generate Python coverage report
#
if
((
N_PYTHON
>
0
))
;
then
python3-coverage html
--omit
=
'/usr/lib/*'
-d
coverage_python_html
python3-coverage xml
--omit
=
'/usr/lib/*'
-o
coverage_python.xml
mv
CTestTestfile-backup.cmake CTestTestfile.cmake
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment