Skip to content

Commit 46143ec

Browse files
committed
[WIP] Azure: Publish code coverage results
* Add an Azure Publish Code Coverage Results task * Add `make gcovr-html` to generate a gcovr test coverage report in HTML * Add `make gcovr-xml` to generate a gcovr test coverage report in XML * Remove `test` target dependency from `make lcov-html`; Run the two targets together instead: `make test lcov-html`. Re: #4739 (comment) See: https://externals.io/message/107113, https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-code-coverage-results?view=azure-devops, and #4759.
1 parent f2e8851 commit 46143ec

File tree

4 files changed

+110
-18
lines changed

4 files changed

+110
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ tmp-php.ini
249249
# ------------------------------------------------------------------------------
250250
*.gcda
251251
*.gcno
252+
/gcovr.xml
253+
/gcovr_html/
252254
/lcov_html/
253255
/php_lcov.info
254256

azure-pipelines.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jobs:
2020
parameters:
2121
configurationName: RELEASE_ZTS
2222
configurationParameters: '--disable-debug --enable-maintainer-zts'
23+
- template: azure/coverage_job.yml
24+
parameters:
25+
configurationName: COVERAGE
26+
configurationParameters: '--enable-debug --disable-maintainer-zts'
2327
- template: azure/i386/job.yml
2428
parameters:
2529
configurationName: I386_DEBUG_ZTS

azure/coverage_job.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
parameters:
2+
configurationName: ''
3+
configurationParameters: ''
4+
runTestsParameters: ''
5+
timeoutInMinutes: 60
6+
7+
jobs:
8+
- job: ${{ parameters.configurationName }}
9+
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
10+
pool:
11+
vmImage: 'ubuntu-latest'
12+
steps:
13+
- template: apt.yml
14+
parameters:
15+
packages: lcov
16+
- script: |
17+
sudo -H pip install gcovr
18+
displayName: 'Install gcovr'
19+
- template: configure.yml
20+
parameters:
21+
configurationParameters: --enable-gcov ${{ parameters.configurationParameters }}
22+
- script: make -j$(/usr/bin/nproc) >/dev/null
23+
displayName: 'Make Build'
24+
- script: |
25+
sudo make install
26+
sudo mkdir /etc/php.d
27+
sudo chmod 777 /etc/php.d
28+
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini
29+
echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini
30+
echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini
31+
echo opcache.protect_memory=1 >> /etc/php.d/opcache.ini
32+
displayName: 'Install Build'
33+
- script: |
34+
mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS test"
35+
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
36+
sudo -u postgres psql -c "CREATE DATABASE test;"
37+
displayName: 'Setup'
38+
- template: test.yml
39+
parameters:
40+
configurationName: ${{ parameters.configurationName }}
41+
runTestsParameters: ${{ parameters.runTestsParameters }}
42+
- script: |
43+
rm -f coverage.xml | true
44+
gcovr -sr . -o coverage.xml --xml \
45+
--exclude-directories 'ext/date/lib$$' \
46+
-e 'ext/bcmath/libbcmath/.*' \
47+
-e 'ext/date/lib/.*' \
48+
-e 'ext/fileinfo/libmagic/.*' \
49+
-e 'ext/gd/libgd/.*' \
50+
-e 'ext/hash/sha3/.*' \
51+
-e 'ext/mbstring/libmbfl/.*' \
52+
-e 'ext/opcache/jit/libudis86/.*' \
53+
-e 'ext/pcre/pcre2lib/.*' \
54+
-e 'ext/xmlrpc/libxmlrpc/.*'
55+
displayName: 'Generate ${{ parameters.configurationName }} ${{ parameters.runTestsName }} Test Coverage'
56+
condition: or(succeeded(), failed())
57+
- task: PublishCodeCoverageResults@1
58+
inputs:
59+
codeCoverageTool: 'Cobertura'
60+
summaryFileLocation: coverage.xml
61+
displayName: 'Publish ${{ parameters.configurationName }} ${{ parameters.runTestsName }} Test Coverage'
62+
condition: or(succeeded(), failed())

build/Makefile.gcov

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,59 @@
11
#
2-
# LCOV
2+
# GCOV
33
#
44

5-
lcov: lcov-html
5+
LCOV_EXCLUDES = \
6+
'$(top_srcdir)/ext/bcmath/libbcmath/*' \
7+
'$(top_srcdir)/ext/date/lib/*' \
8+
'$(top_srcdir)/ext/fileinfo/libmagic/*' \
9+
'$(top_srcdir)/ext/gd/libgd/*' \
10+
'$(top_srcdir)/ext/hash/sha3/*' \
11+
'$(top_srcdir)/ext/mbstring/libmbfl/*' \
12+
'$(top_srcdir)/ext/opcache/jit/libudis86/*' \
13+
'$(top_srcdir)/ext/pcre/pcre2lib/*' \
14+
'$(top_srcdir)/ext/xmlrpc/libxmlrpc/*'
615

7-
lcov-test: lcov-clean-data test
16+
GCOVR_EXCLUDES = \
17+
'ext/bcmath/libbcmath/.*' \
18+
'ext/date/lib/.*' \
19+
'ext/fileinfo/libmagic/.*' \
20+
'ext/gd/libgd/.*' \
21+
'ext/hash/sha3/.*' \
22+
'ext/mbstring/libmbfl/.*' \
23+
'ext/opcache/jit/libudis86/.*' \
24+
'ext/pcre/pcre2lib/.*' \
25+
'ext/xmlrpc/libxmlrpc/.*'
826

9-
php_lcov.info: lcov-test
27+
php_lcov.info:
1028
@echo "Generating lcov data for $@"
11-
@$(LTP) --capture --no-external --directory . --output-file $@
29+
$(LTP) --capture --no-external --directory . --output-file $@
1230
@echo "Stripping bundled libraries from $@"
13-
@$(LTP) --remove $@ \
14-
'*/<stdout>' \
15-
'$(top_srcdir)/ext/bcmath/libbcmath/*' \
16-
'$(top_srcdir)/ext/date/lib/*' \
17-
'$(top_srcdir)/ext/fileinfo/libmagic/*' \
18-
'$(top_srcdir)/ext/gd/libgd/*' \
19-
'$(top_srcdir)/ext/hash/sha3/*' \
20-
'$(top_srcdir)/ext/mbstring/libmbfl/*' \
21-
'$(top_srcdir)/ext/opcache/jit/libudis86/*' \
22-
'$(top_srcdir)/ext/pcre/pcre2lib/*' \
23-
'$(top_srcdir)/ext/xmlrpc/libxmlrpc/*' \
24-
--output-file $@
31+
$(LTP) --output-file $@ --remove $@ '*/<stdout>' $(LCOV_EXCLUDES)
2532

2633
lcov-html: php_lcov.info
2734
@echo "Generating lcov HTML"
28-
@$(LTP_GENHTML) --legend --output-directory lcov_html/ --title "PHP Code Coverage" php_lcov.info
35+
$(LTP_GENHTML) --legend --output-directory lcov_html/ --title "PHP Code Coverage" php_lcov.info
2936

3037
lcov-clean:
3138
rm -f php_lcov.info
3239
rm -rf lcov_html/
3340

3441
lcov-clean-data:
3542
@find . -name \*.gcda -o -name \*.da -o -name \*.bbg? | xargs rm -f
43+
44+
gcovr-html:
45+
@echo "Generating gcovr HTML"
46+
@rm -rf gcovr_html/
47+
@mkdir gcovr_html
48+
gcovr -sr . -o gcovr_html/index.html --html --html-details \
49+
--exclude-directories 'ext/date/lib$$' \
50+
$(foreach lib, $(GCOVR_EXCLUDES), -e $(lib))
51+
52+
gcovr-xml:
53+
@echo "Generating gcovr XML"
54+
@rm -f gcovr.xml
55+
gcovr -sr . -o gcovr.xml --xml \
56+
--exclude-directories 'ext/date/lib$$' \
57+
$(foreach lib, $(GCOVR_EXCLUDES), -e $(lib))
58+
59+
.PHONY: gcovr-html lcov-html php_lcov.info

0 commit comments

Comments
 (0)