From 664381ee570887b7c7a8585e16da92078bce197f Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 19 Oct 2018 20:38:20 +0300 Subject: [PATCH] Enable code coverage report (#1675) * Enable code coverage report * Correct ExitDieTest * Correct ExitDieTest (2) --- .gitignore | 2 - .travis.yml | 14 +++-- unit-tests/Extension/ExitDieTest.php | 5 ++ unit-tests/ci/after-success.sh | 29 ++++++++++ .../ci/{install-re2c => install-re2c.sh} | 56 +++++++++---------- unit-tests/ci/install-test-ext.sh | 33 ++++++++++- unit-tests/ci/run-unit-tests.sh | 3 +- unit-tests/ci/test.ini | 1 - unit-tests/fixtures/exit.php | 6 +- unit-tests/fixtures/exit_int.php | 6 +- unit-tests/fixtures/exit_string.php | 6 +- unit-tests/output/.gitignore | 2 + 12 files changed, 117 insertions(+), 46 deletions(-) create mode 100755 unit-tests/ci/after-success.sh rename unit-tests/ci/{install-re2c => install-re2c.sh} (54%) delete mode 100644 unit-tests/ci/test.ini diff --git a/.gitignore b/.gitignore index 9b83aad50d..f7ba966a49 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,6 @@ build/ phpunit.xml phpcs.xml -coverage.xml -clover.xml # Ignore for all projects based on Zephir .temp/ diff --git a/.travis.yml b/.travis.yml index 26e4c1c63b..88201e2ea5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ addons: apt: packages: - gdb + - lcov env: global: @@ -29,6 +30,7 @@ env: - ZEPHIR_PARSER_VERSION="v1.1.2" - DEFAULT_ZFLAGS="-Wnonexistent-function -Wnonexistent-class -Wunused-variable" - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest" + - REPORT_COVERAGE=1 matrix: fast_finish: true @@ -55,8 +57,9 @@ before_install: - phpenv config-add ./unit-tests/ci/999-default.ini install: - - composer install $DEFAULT_COMPOSER_FLAGS - - ./unit-tests/ci/install-re2c $RE2C_VERSION + - travis_retry composer install $DEFAULT_COMPOSER_FLAGS + - travis_retry gem install coveralls-lcov + - ./unit-tests/ci/install-re2c.sh $RE2C_VERSION - ./unit-tests/ci/install-zephir-parser.sh - ./install @@ -77,22 +80,21 @@ jobs: compiler: clang env: - CC=clang + - REPORT_COVERAGE=0 before_script: - - $(phpenv which php) compiler.php generate $DEFAULT_ZFLAGS - ./unit-tests/ci/install-test-ext.sh script: - ./unit-tests/ci/run-unit-tests.sh - stage: Benchmark php: 7.2 before_script: - - $(phpenv which php) compiler.php generate $DEFAULT_ZFLAGS - ./unit-tests/ci/install-test-ext.sh script: - phpenv config-rm xdebug.ini || true - - $(phpenv which php) unit-tests/microbench.php + - $(phpenv which php) -d extension=ext/modules/test.so unit-tests/microbench.php after_success: - - if [[ ! -z "${CODECOV_TOKEN}" ]]; then bash <(curl -s https://codecov.io/bash); fi; + - ./unit-tests/ci/after-success.sh after_failure: - ./unit-tests/ci/after-failure.sh diff --git a/unit-tests/Extension/ExitDieTest.php b/unit-tests/Extension/ExitDieTest.php index 5f1ce36124..d480314eb3 100644 --- a/unit-tests/Extension/ExitDieTest.php +++ b/unit-tests/Extension/ExitDieTest.php @@ -45,6 +45,11 @@ public function setUp() } $this->phpBinary .= " -d 'enable_dl=true'"; + $extension = realpath( __DIR__ . '/../../ext/modules/test.so'); + + if (file_exists($extension)) { + $this->phpBinary .= sprintf(" -d 'extension=%s'", $extension); + } parent::setUp(); } diff --git a/unit-tests/ci/after-success.sh b/unit-tests/ci/after-success.sh new file mode 100755 index 0000000000..80ba99e6d2 --- /dev/null +++ b/unit-tests/ci/after-success.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# +# This file is part of the Zephir. +# +# (c) Zephir Team +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. + +if [ "${CI}" != "true" ]; then + echo "This script is designed to run inside a CI container only. Stop." + exit 1 +fi + +PROJECT_ROOT=$(readlink -enq "$(dirname $0)/../../") + +if [ "x${REPORT_COVERAGE}" = "x1" ]; then + output=${PROJECT_ROOT}/unit-tests/output/coverage.info + + lcov --no-checksum --directory ${PROJECT_ROOT}/ext --capture --compat-libtool --output-file ${output} + lcov \ + --remove ${output} "/usr*" \ + --remove ${output} "*/.phpenv/*" \ + --remove ${output} "${HOME}/build/include/*" \ + --compat-libtool \ + --output-file ${output} + + coveralls-lcov ${output} +fi diff --git a/unit-tests/ci/install-re2c b/unit-tests/ci/install-re2c.sh similarity index 54% rename from unit-tests/ci/install-re2c rename to unit-tests/ci/install-re2c.sh index 87b062249b..8f34ef9e50 100755 --- a/unit-tests/ci/install-re2c +++ b/unit-tests/ci/install-re2c.sh @@ -31,45 +31,45 @@ prefix="${HOME}/.local/opt/${pkgname}/${pkgname}-${RE2C_VERSION}" bindir="${prefix}/bin" if [ ! -f "${bindir}/re2c" ]; then - if [ ! -d `dirname ${downloaddir}` ]; then - mkdir -p `dirname ${downloaddir}` - fi + if [ ! -d `dirname ${downloaddir}` ]; then + mkdir -p `dirname ${downloaddir}` + fi - cd `dirname ${downloaddir}` + cd `dirname ${downloaddir}` - if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then - curl -sSL "$source" -o "${pkgname}-${RE2C_VERSION}.tar.gz" - fi + if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then + curl -sSL "$source" -o "${pkgname}-${RE2C_VERSION}.tar.gz" + fi - if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then - echo "Unable to locate ${pkgname}-${RE2C_VERSION}.tar.gz file. Stop." - exit 1 - fi + if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then + echo "Unable to locate ${pkgname}-${RE2C_VERSION}.tar.gz file. Stop." + exit 1 + fi - if [ ! -d "${downloaddir}" ]; then - mkdir -p "${downloaddir}" - tar -zxf "${pkgname}-${RE2C_VERSION}.tar.gz" - fi + if [ ! -d "${downloaddir}" ]; then + mkdir -p "${downloaddir}" + tar -zxf "${pkgname}-${RE2C_VERSION}.tar.gz" + fi - if [ ! -d "${downloaddir}" ]; then - echo "Unable to locate re2c source. Stop." - exit 1 - fi + if [ ! -d "${downloaddir}" ]; then + echo "Unable to locate re2c source. Stop." + exit 1 + fi - if [ ! -d "${prefix}" ]; then - mkdir -p "${prefix}" - fi + if [ ! -d "${prefix}" ]; then + mkdir -p "${prefix}" + fi - cd "${downloaddir}" - ./configure --prefix="${prefix}" + cd "${downloaddir}" + ./configure --prefix="${prefix}" - make -j"$(getconf _NPROCESSORS_ONLN)" - make install + make -j"$(getconf _NPROCESSORS_ONLN)" + make install fi if [ ! -x "${bindir}/re2c" ]; then - echo "Unable to locate re2c executable. Stop." - exit 1 + echo "Unable to locate re2c executable. Stop." + exit 1 fi mkdir -p ${HOME}/bin diff --git a/unit-tests/ci/install-test-ext.sh b/unit-tests/ci/install-test-ext.sh index a08c2be425..023ee7c207 100755 --- a/unit-tests/ci/install-test-ext.sh +++ b/unit-tests/ci/install-test-ext.sh @@ -36,10 +36,39 @@ phpenv config-rm zephir-parser.ini || true $(phpenv which phpize) -./configure --with-php-config=$(phpenv which php-config) --enable-test +# However, the version of libtool that claims to no longer remove .gcno profiler information is libtool 2.2.6. +# The fix is probably in later libtool versions as well. +if [ -f /etc/gentoo-release ]; then + # Gentoo Linux + LIBTOOLIZE_BIN=$(command -v libtoolize 2>/dev/null) + aclocal && ${LIBTOOLIZE_BIN} --copy --force && autoheader && autoconf +elif [ "$(uname -s 2>/dev/null)" = "Darwin" ]; then + # macOS + LIBTOOLIZE_BIN=$(command -v glibtoolize 2>/dev/null) + aclocal && ${LIBTOOLIZE_BIN} --copy --force && autoheader && autoconf +else + # Linux + aclocal && libtoolize --copy --force && autoheader && autoconf +fi + +CFLAGS="${CFLAGS}" +LDFLAGS="${LDFLAGS}" + +if [ "${REPORT_COVERAGE}" = "1" ]; then + CFLAGS="--coverage -fprofile-arcs -ftest-coverage $CFLAGS" + LDFLAGS="--coverage ${LDFLAGS}" +fi + +./configure --with-php-config=$(phpenv which php-config) --enable-test CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" make -j"$(getconf _NPROCESSORS_ONLN)" -make install + +if [ "x${REPORT_COVERAGE}" = "x1" ]; then + output=${PROJECT_ROOT}/unit-tests/output/coverage.info + + lcov --directory ${PROJECT_ROOT}/ext --zerocounters + lcov --directory ${PROJECT_ROOT}/ext --capture --compat-libtool --initial --output-file ${output} +fi popd diff --git a/unit-tests/ci/run-unit-tests.sh b/unit-tests/ci/run-unit-tests.sh index 81085cfbc4..b43131b9e9 100755 --- a/unit-tests/ci/run-unit-tests.sh +++ b/unit-tests/ci/run-unit-tests.sh @@ -25,7 +25,8 @@ if [ "${PHP_MAJOR}.${PHP_MINOR}" = "7.3" ] || [ "${PHP_MAJOR}.${PHP_MINOR}" = "7 fi $(phpenv which php) -d extension=ext/modules/test.so unit-tests/phpunit -c ${confing_file} +status=$? popd -exit $? +exit ${status} diff --git a/unit-tests/ci/test.ini b/unit-tests/ci/test.ini deleted file mode 100644 index 3128f5c4bf..0000000000 --- a/unit-tests/ci/test.ini +++ /dev/null @@ -1 +0,0 @@ -extension=test.so diff --git a/unit-tests/fixtures/exit.php b/unit-tests/fixtures/exit.php index 5f122ad002..a0df138251 100644 --- a/unit-tests/fixtures/exit.php +++ b/unit-tests/fixtures/exit.php @@ -15,10 +15,12 @@ if (ini_get('enable_dl') == '1') { $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : ''; dl($prefix . 'test.' . PHP_SHLIB_SUFFIX); - } else { - exit('"test" extension not loaded; cannot run tests without it'); } } +if (!extension_loaded('test')) { + exit('"test" extension not loaded; cannot run tests without it'); +} + $t = new ExitDie(); $t->testExit(); diff --git a/unit-tests/fixtures/exit_int.php b/unit-tests/fixtures/exit_int.php index 6fef642401..ee1b44d359 100644 --- a/unit-tests/fixtures/exit_int.php +++ b/unit-tests/fixtures/exit_int.php @@ -15,11 +15,13 @@ if (ini_get('enable_dl') == '1') { $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : ''; dl($prefix . 'test.' . PHP_SHLIB_SUFFIX); - } else { - exit('"test" extension not loaded; cannot run tests without it'); } } +if (!extension_loaded('test')) { + exit('"test" extension not loaded; cannot run tests without it'); +} + $argv = $_SERVER['argv']; if (isset($argv[1])) { diff --git a/unit-tests/fixtures/exit_string.php b/unit-tests/fixtures/exit_string.php index 0614a10330..e8ab3a4672 100644 --- a/unit-tests/fixtures/exit_string.php +++ b/unit-tests/fixtures/exit_string.php @@ -15,11 +15,13 @@ if (ini_get('enable_dl') == '1') { $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : ''; dl($prefix . 'test.' . PHP_SHLIB_SUFFIX); - } else { - exit('"test" extension not loaded; cannot run tests without it'); } } +if (!extension_loaded('test')) { + exit('"test" extension not loaded; cannot run tests without it'); +} + $argv = $_SERVER['argv']; if (isset($argv[1])) { $t = new ExitDie(); diff --git a/unit-tests/output/.gitignore b/unit-tests/output/.gitignore index e69de29bb2..d6b7ef32c8 100644 --- a/unit-tests/output/.gitignore +++ b/unit-tests/output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore