Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci]: Support code coverage #539

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 .
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need a blank before --coverage ? #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not necessary, the blank will be added automatically when using together with the other options.

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