Skip to content

Commit

Permalink
[ci]: Support code coverage (#539)
Browse files Browse the repository at this point in the history
Support code full coverage and diff coverage
  • Loading branch information
xumia authored Oct 21, 2021
1 parent 65bb160 commit e002e40
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
29 changes: 20 additions & 9 deletions .azure-pipelines/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
- job:
displayName: ${{ parameters.arch }}
timeoutInMinutes: ${{ parameters.timeout }}
variables:
DIFF_COVER_CHECK_THRESHOLD: 0
${{ if eq(parameters.run_unit_test, true) }}:
DIFF_COVER_ENABLE: 'true'

pool:
${{ if ne(parameters.pool, 'default') }}:
Expand All @@ -58,9 +62,19 @@ jobs:
- script: |
set -ex
./autogen.sh
fakeroot debian/rules DEB_CONFIGURE_EXTRA_FLAGS='--enable-code-coverage' CFLAGS="" CXXFLAGS="" binary && cp ../*.deb .
fakeroot debian/rules DEB_CONFIGURE_EXTRA_FLAGS='--enable-code-coverage' CFLAGS="" CXXFLAGS="--coverage -fprofile-abs-path" LDFLAGS="--coverage -fprofile-abs-path" binary && cp ../*.deb .
displayName: "Compile sonic swss common with coverage enabled"
- ${{ if eq(parameters.run_unit_test, true) }}:
- script: |
set -ex
git clone https://github.com/Spacetown/gcovr.git
cd gcovr/
git checkout origin/recursive_search_file
sudo pip3 install setuptools
sudo python3 setup.py install
cd ..
sudo rm -rf gcovr
displayName: "Install gcovr 5.0 with recursive fix"
- script: |
set -ex
sudo pip install Pympler==0.8
Expand All @@ -74,12 +88,10 @@ jobs:
sudo dpkg -i libswsscommon_*.deb
sudo dpkg -i python-swsscommon_*.deb
sudo ./tests/tests && redis-cli FLUSHALL && pytest
gcovr -r ./ -x -o coverage.xml
cd common
mkdir -p htmlcov
gcovr -r ./ --html --html-details -o htmlcov/index.html
./tests/tests
redis-cli FLUSHALL
pytest --cov=. --cov-report=xml
gcovr -r ./ --exclude-unreachable-branches --exclude-throw-branches -x --xml-pretty -o tests/coverage.xml
displayName: "Run swss common unit tests"
- publish: $(System.DefaultWorkingDirectory)/
artifact: ${{ parameters.artifact_name }}
Expand All @@ -96,6 +108,5 @@ jobs:
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/common/htmlcov/'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/tests/coverage.xml'
displayName: 'Publish test coverage'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*.lo
*.o
*.swp
*.gcda
*.gcno
*.gcov
*.deb

# Generated Source #
####################
Expand Down

0 comments on commit e002e40

Please sign in to comment.