From 31c5ff869c4261b25f940c113d28cf6e65be5582 Mon Sep 17 00:00:00 2001 From: Gerard Roche Date: Wed, 25 Sep 2019 19:13:17 +0100 Subject: [PATCH 1/5] [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: https://github.com/php/php-src/pull/4739#issuecomment-534911441 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 https://github.com/php/php-src/pull/4759. --- .gitignore | 2 ++ azure-pipelines.yml | 4 +++ azure/coverage_job.yml | 62 ++++++++++++++++++++++++++++++++++++++++++ build/Makefile.gcov | 62 ++++++++++++++++++++++++++++++------------ 4 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 azure/coverage_job.yml diff --git a/.gitignore b/.gitignore index 20c97ef302f72..cd6e779831254 100644 --- a/.gitignore +++ b/.gitignore @@ -249,6 +249,8 @@ tmp-php.ini # ------------------------------------------------------------------------------ *.gcda *.gcno +/gcovr.xml +/gcovr_html/ /lcov_html/ /php_lcov.info diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 82531f278680c..e4042f077a0ab 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -20,6 +20,10 @@ jobs: parameters: configurationName: RELEASE_ZTS configurationParameters: '--disable-debug --enable-maintainer-zts' + - template: azure/coverage_job.yml + parameters: + configurationName: COVERAGE + configurationParameters: '--enable-debug --disable-maintainer-zts' - template: azure/i386/job.yml parameters: configurationName: I386_DEBUG_ZTS diff --git a/azure/coverage_job.yml b/azure/coverage_job.yml new file mode 100644 index 0000000000000..5cbf7857e72de --- /dev/null +++ b/azure/coverage_job.yml @@ -0,0 +1,62 @@ +parameters: + configurationName: '' + configurationParameters: '' + runTestsParameters: '' + timeoutInMinutes: 60 + +jobs: + - job: ${{ parameters.configurationName }} + timeoutInMinutes: ${{ parameters.timeoutInMinutes }} + pool: + vmImage: 'ubuntu-latest' + steps: + - template: apt.yml + parameters: + packages: lcov + - script: | + sudo -H pip install gcovr + displayName: 'Install gcovr' + - template: configure.yml + parameters: + configurationParameters: --enable-gcov ${{ parameters.configurationParameters }} + - script: make -j$(/usr/bin/nproc) >/dev/null + displayName: 'Make Build' + - script: | + sudo make install + sudo mkdir /etc/php.d + sudo chmod 777 /etc/php.d + echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini + echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini + echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini + echo opcache.protect_memory=1 >> /etc/php.d/opcache.ini + displayName: 'Install Build' + - script: | + mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS test" + sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" + sudo -u postgres psql -c "CREATE DATABASE test;" + displayName: 'Setup' + - template: test.yml + parameters: + configurationName: ${{ parameters.configurationName }} + runTestsParameters: ${{ parameters.runTestsParameters }} + - script: | + rm -f coverage.xml | true + gcovr -sr . -o coverage.xml --xml \ + --exclude-directories 'ext/date/lib$$' \ + -e 'ext/bcmath/libbcmath/.*' \ + -e 'ext/date/lib/.*' \ + -e 'ext/fileinfo/libmagic/.*' \ + -e 'ext/gd/libgd/.*' \ + -e 'ext/hash/sha3/.*' \ + -e 'ext/mbstring/libmbfl/.*' \ + -e 'ext/opcache/jit/libudis86/.*' \ + -e 'ext/pcre/pcre2lib/.*' \ + -e 'ext/xmlrpc/libxmlrpc/.*' + displayName: 'Generate ${{ parameters.configurationName }} ${{ parameters.runTestsName }} Test Coverage' + condition: or(succeeded(), failed()) + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: 'Cobertura' + summaryFileLocation: coverage.xml + displayName: 'Publish ${{ parameters.configurationName }} ${{ parameters.runTestsName }} Test Coverage' + condition: or(succeeded(), failed()) diff --git a/build/Makefile.gcov b/build/Makefile.gcov index 944739aff3309..a206523061eab 100644 --- a/build/Makefile.gcov +++ b/build/Makefile.gcov @@ -1,34 +1,43 @@ # -# LCOV +# GCOV # LTP = lcov LTP_GENHTML = genhtml -lcov: lcov-html +LCOV_EXCLUDES = \ + '$(top_srcdir)/ext/bcmath/libbcmath/*' \ + '$(top_srcdir)/ext/date/lib/*' \ + '$(top_srcdir)/ext/fileinfo/libmagic/*' \ + '$(top_srcdir)/ext/gd/libgd/*' \ + '$(top_srcdir)/ext/hash/sha3/*' \ + '$(top_srcdir)/ext/mbstring/libmbfl/*' \ + '$(top_srcdir)/ext/opcache/jit/libudis86/*' \ + '$(top_srcdir)/ext/pcre/pcre2lib/*' \ + '$(top_srcdir)/ext/xmlrpc/libxmlrpc/*' + +GCOVR_EXCLUDES = \ + 'ext/bcmath/libbcmath/.*' \ + 'ext/date/lib/.*' \ + 'ext/fileinfo/libmagic/.*' \ + 'ext/gd/libgd/.*' \ + 'ext/hash/sha3/.*' \ + 'ext/mbstring/libmbfl/.*' \ + 'ext/opcache/jit/libudis86/.*' \ + 'ext/pcre/pcre2lib/.*' \ + 'ext/xmlrpc/libxmlrpc/.*' -lcov-test: lcov-clean-data test +lcov: lcov-html -php_lcov.info: lcov-test +php_lcov.info: @echo "Generating lcov data for $@" - @$(LTP) --capture --no-external --directory . --output-file $@ + $(LTP) --capture --no-external --directory . --output-file $@ @echo "Stripping bundled libraries from $@" - @$(LTP) --remove $@ \ - '*/' \ - '$(top_srcdir)/ext/bcmath/libbcmath/*' \ - '$(top_srcdir)/ext/date/lib/*' \ - '$(top_srcdir)/ext/fileinfo/libmagic/*' \ - '$(top_srcdir)/ext/gd/libgd/*' \ - '$(top_srcdir)/ext/hash/sha3/*' \ - '$(top_srcdir)/ext/mbstring/libmbfl/*' \ - '$(top_srcdir)/ext/opcache/jit/libudis86/*' \ - '$(top_srcdir)/ext/pcre/pcre2lib/*' \ - '$(top_srcdir)/ext/xmlrpc/libxmlrpc/*' \ - --output-file $@ + $(LTP) --output-file $@ --remove $@ '*/' $(LCOV_EXCLUDES) lcov-html: php_lcov.info @echo "Generating lcov HTML" - @$(LTP_GENHTML) --legend --output-directory lcov_html/ --title "PHP Code Coverage" php_lcov.info + $(LTP_GENHTML) --legend --output-directory lcov_html/ --title "PHP Code Coverage" php_lcov.info lcov-clean: rm -f php_lcov.info @@ -36,3 +45,20 @@ lcov-clean: lcov-clean-data: @find . -name \*.gcda -o -name \*.da -o -name \*.bbg? | xargs rm -f + +gcovr-html: + @echo "Generating gcovr HTML" + @rm -rf gcovr_html/ + @mkdir gcovr_html + gcovr -sr . -o gcovr_html/index.html --html --html-details \ + --exclude-directories 'ext/date/lib$$' \ + $(foreach lib, $(GCOVR_EXCLUDES), -e $(lib)) + +gcovr-xml: + @echo "Generating gcovr XML" + @rm -f gcovr.xml + gcovr -sr . -o gcovr.xml --xml \ + --exclude-directories 'ext/date/lib$$' \ + $(foreach lib, $(GCOVR_EXCLUDES), -e $(lib)) + +.PHONY: gcovr-html lcov-html php_lcov.info From 3e5e98d719d5e88a5fb9496f384cce7ccccb2b1c Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 11 Oct 2019 16:55:10 +0200 Subject: [PATCH 2/5] Enable only coverage job --- azure-pipelines.yml | 70 --------------------------------------------- 1 file changed, 70 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e4042f077a0ab..0432fee21299f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,77 +12,7 @@ trigger: - UPGRADING.INTERNALS jobs: - - template: azure/job.yml - parameters: - configurationName: DEBUG_NTS - configurationParameters: '--enable-debug --disable-maintainer-zts' - - template: azure/job.yml - parameters: - configurationName: RELEASE_ZTS - configurationParameters: '--disable-debug --enable-maintainer-zts' - template: azure/coverage_job.yml parameters: configurationName: COVERAGE configurationParameters: '--enable-debug --disable-maintainer-zts' - - template: azure/i386/job.yml - parameters: - configurationName: I386_DEBUG_ZTS - configurationParameters: '--enable-debug --enable-maintainer-zts' - - template: azure/macos/job.yml - parameters: - configurationName: MACOS_DEBUG_NTS - configurationParameters: '--enable-debug --disable-maintainer-zts' - - ${{ if eq(variables['Build.Reason'], 'Schedule') }}: - - template: azure/job.yml - parameters: - configurationName: DEBUG_ZTS - configurationParameters: '--enable-debug --enable-maintainer-zts' - - template: azure/job.yml - parameters: - configurationName: RELEASE_NTS - configurationParameters: '--disable-debug --disable-maintainer-zts' - - template: azure/i386/job.yml - parameters: - configurationName: I386_DEBUG_NTS - configurationParameters: '--enable-debug --disable-maintainer-zts' - - template: azure/i386/job.yml - parameters: - configurationName: I386_RELEASE_NTS - configurationParameters: '--disable-debug --disable-maintainer-zts' - - template: azure/i386/job.yml - parameters: - configurationName: I386_RELEASE_ZTS - configurationParameters: '--disable-debug --enable-maintainer-zts' - - template: azure/macos/job.yml - parameters: - configurationName: MACOS_DEBUG_ZTS - configurationParameters: '--enable-debug --enable-maintainer-zts' - - template: azure/macos/job.yml - parameters: - configurationName: MACOS_RELEASE_NTS - configurationParameters: '--disable-debug --disable-maintainer-zts' - - template: azure/macos/job.yml - parameters: - configurationName: MACOS_RELEASE_ZTS - configurationParameters: '--disable-debug --enable-maintainer-zts' - - template: azure/job.yml - parameters: - configurationName: DEBUG_ZTS_ASAN_UBSAN - configurationParameters: >- - --enable-debug --enable-maintainer-zts - CFLAGS='-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC' - LDFLAGS='-fsanitize=undefined,address' - runTestsParameters: --asan - timeoutInMinutes: 120 - - template: azure/msan_job.yml - parameters: - configurationName: DEBUG_ZTS_MSAN - configurationParameters: '--enable-debug --enable-maintainer-zts' - runTestsParameters: --asan - - template: azure/community_job.yml - parameters: - configurationName: COMMUNITY - configurationParameters: >- - --enable-debug --enable-maintainer-zts - CFLAGS='-fsanitize=undefined,address -fno-sanitize-recover -DZEND_TRACK_ARENA_ALLOC' - LDFLAGS='-fsanitize=undefined,address' From bd27cf9d0e45688cd89ecbdf87d26d6441af1789 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 11 Oct 2019 16:56:07 +0200 Subject: [PATCH 3/5] Don't install lcov (no longer needed) --- azure/coverage_job.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/azure/coverage_job.yml b/azure/coverage_job.yml index 5cbf7857e72de..5cd1d4ad686c3 100644 --- a/azure/coverage_job.yml +++ b/azure/coverage_job.yml @@ -11,8 +11,6 @@ jobs: vmImage: 'ubuntu-latest' steps: - template: apt.yml - parameters: - packages: lcov - script: | sudo -H pip install gcovr displayName: 'Install gcovr' From 310bd519c67d31ab5ee94ee90cd94e7fd3e741fe Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 11 Oct 2019 16:57:55 +0200 Subject: [PATCH 4/5] Share install step across jobs --- azure/coverage_job.yml | 10 +--------- azure/install.yml | 10 ++++++++++ azure/job.yml | 10 +--------- 3 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 azure/install.yml diff --git a/azure/coverage_job.yml b/azure/coverage_job.yml index 5cd1d4ad686c3..4976846ed074c 100644 --- a/azure/coverage_job.yml +++ b/azure/coverage_job.yml @@ -19,15 +19,7 @@ jobs: configurationParameters: --enable-gcov ${{ parameters.configurationParameters }} - script: make -j$(/usr/bin/nproc) >/dev/null displayName: 'Make Build' - - script: | - sudo make install - sudo mkdir /etc/php.d - sudo chmod 777 /etc/php.d - echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini - echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini - echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini - echo opcache.protect_memory=1 >> /etc/php.d/opcache.ini - displayName: 'Install Build' + - template: install.yml - script: | mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS test" sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" diff --git a/azure/install.yml b/azure/install.yml new file mode 100644 index 0000000000000..7f5bf4b68fda9 --- /dev/null +++ b/azure/install.yml @@ -0,0 +1,10 @@ +steps: + - script: | + sudo make install + sudo mkdir /etc/php.d + sudo chmod 777 /etc/php.d + echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini + echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini + echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini + echo opcache.protect_memory=1 >> /etc/php.d/opcache.ini + displayName: 'Install Build' diff --git a/azure/job.yml b/azure/job.yml index e4af6d631e039..afe1d99e80122 100644 --- a/azure/job.yml +++ b/azure/job.yml @@ -16,15 +16,7 @@ jobs: configurationParameters: ${{ parameters.configurationParameters }} - script: make -j$(/usr/bin/nproc) >/dev/null displayName: 'Make Build' - - script: | - sudo make install - sudo mkdir /etc/php.d - sudo chmod 777 /etc/php.d - echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini - echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini - echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini - echo opcache.protect_memory=1 >> /etc/php.d/opcache.ini - displayName: 'Install Build' + - template: install.yml - script: | mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS test" sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" From d1f0eb8fd88bd588670fc693878c0e65ddaa5ca8 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 11 Oct 2019 17:01:16 +0200 Subject: [PATCH 5/5] Reuse "make gcovr-xml" in azure job --- azure/coverage_job.yml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/azure/coverage_job.yml b/azure/coverage_job.yml index 4976846ed074c..217b5d664a3e3 100644 --- a/azure/coverage_job.yml +++ b/azure/coverage_job.yml @@ -30,23 +30,13 @@ jobs: configurationName: ${{ parameters.configurationName }} runTestsParameters: ${{ parameters.runTestsParameters }} - script: | - rm -f coverage.xml | true - gcovr -sr . -o coverage.xml --xml \ - --exclude-directories 'ext/date/lib$$' \ - -e 'ext/bcmath/libbcmath/.*' \ - -e 'ext/date/lib/.*' \ - -e 'ext/fileinfo/libmagic/.*' \ - -e 'ext/gd/libgd/.*' \ - -e 'ext/hash/sha3/.*' \ - -e 'ext/mbstring/libmbfl/.*' \ - -e 'ext/opcache/jit/libudis86/.*' \ - -e 'ext/pcre/pcre2lib/.*' \ - -e 'ext/xmlrpc/libxmlrpc/.*' - displayName: 'Generate ${{ parameters.configurationName }} ${{ parameters.runTestsName }} Test Coverage' + make gcovr-xml + mv gcovr.xml coverage.xml + displayName: 'Generate ${{ parameters.configurationName }} Test Coverage' condition: or(succeeded(), failed()) - task: PublishCodeCoverageResults@1 inputs: codeCoverageTool: 'Cobertura' summaryFileLocation: coverage.xml - displayName: 'Publish ${{ parameters.configurationName }} ${{ parameters.runTestsName }} Test Coverage' + displayName: 'Publish ${{ parameters.configurationName }} Test Coverage' condition: or(succeeded(), failed())