Giter Club home page Giter Club logo

pcov's Introduction

PCOV

Build Status Build status

A self contained CodeCoverage compatible driver for PHP

Requirements and Installation

See INSTALL.md

API

/**
 * Shall start recording coverage information
 */
function \pcov\start() : void;

/**
 * Shall stop recording coverage information
 */
function \pcov\stop() : void;

/**
 * Shall collect coverage information
 *
 * @param integer $type define witch type of information should be collected
 *		 \pcov\all        shall collect coverage information for all files
 *		 \pcov\inclusive  shall collect coverage information for the specified files
 *		 \pcov\exclusive  shall collect coverage information for all but the specified files
 * @param array $filter path of files (realpath) that should be filtered
 *
 * @return array
 */
function \pcov\collect(int $type = \pcov\all, array $filter = []) : array;

/**
 * Shall clear stored information
 *
 * @param bool $files set true to clear file tables
 *
 * Note: clearing the file tables may have surprising consequences
 */
function \pcov\clear(bool $files = false) : void;

/**
 * Shall return list of files waiting to be collected
 */
function \pcov\waiting() : array;

/**
 * Shall return the current size of the trace and cfg arena
 */
function \pcov\memory() : int;

Configuration

PCOV is configured using PHP.ini:

Option Default Changeable Description
pcov.enabled 1 SYSTEM enable or disable zend hooks for pcov
pcov.directory auto SYSTEM,PERDIR restrict collection to files under this path
pcov.exclude unused SYSTEM,PERDIR exclude files under pcov.directory matching this PCRE
pcov.initial.memory 65536 SYSTEM,PERDIR shall set initial size of arena
pcov.initial.files 64 SYSTEM,PERDIR shall set initial size of tables

Notes

The recommended defaults for production should be:

  • pcov.enabled = 0

The recommended defaults for development should be:

  • pcov.enabled = 1
  • pcov.directory = /path/to/your/source/directory

When pcov.directory is left unset, PCOV will attempt to find src, lib or, app in the current working directory, in that order; If none are found the current directory will be used, which may waste resources storing coverage information for the test suite.

If pcov.directory contains test code, it's recommended to set pcov.exclude to avoid wasting resources.

To avoid unnecessary allocation of additional arenas for traces and control flow graphs, pcov.initial.memory should be set according to the memory required by the test suite, which may be discovered with \pcov\memory().

To avoid reallocation of tables, pcov.initial.files should be set to a number higher than the number of files that will be loaded during testing, inclusive of test files.

Note that arenas are allocated in chunks: If the chunk size is set to 65536 and pcov require 65537 bytes, the system will allocate two chunks, each 65536 bytes. When setting arena space therefore, be generous in your estimates.

Interoperability

When PCOV is enabled by configuration pcov.enabled=1:

  • interoperability with Xdebug is not possible
  • interoperability with phpdbg is not possible
  • interoperability with Blackfire profiler is not possible

At an internals level, the executor function is overriden by pcov, so any extension or SAPI which does the same will be broken.

When PCOV is disabled by configuration pcov.enabled=0:

  • PCOV is zero cost - code runs at full speed
  • Xdebug may be loaded
  • phpdbg may be executed
  • Blackfire probe may be loaded

At an internals level, the executor function is untouched, and pcov allocates no memory.

Differences in Reporting

There are subtle differences between Xdebug and PCOV in reporting: Both Xdebug and PCOV perform branch analysis in order to detect executable code. Xdebug has custom written (very mature, proven) analysis, while PCOV uses the very well proven control flow graph from Optimizer. They generate comparably accurate reports, while phpdbg uses less robust detection of executable code and generates reports with known defects. One such defect in phpdbg is this:

/* 2 */ function foo($bar) {
/* 3 */ 	if ($bar) {
/* 4 */			return true;
/* 5 */		}
/* 6 */	}

phpdbg will detect that this function is 100% covered when the first control path is taken, if ($bar), because it cannot correctly detect which implicit return paths inserted by Zend at compile time are executable, and so chooses to ignore them all. While this may seem like a trivial difference to some, it means that the reports generated by phpdbg are not completely trustworthy.

While the accuracy of Xdebug and PCOV are comparable, the reports they generate are not precisely the same, one such example is the switch construct:

/* 2 */ switch ($condition) {
/* 3 */		case 1:
/* 4 */			return "PHP rox!";
/* 5 */	}

From PHP 7.2.15 and PCOV 1.0, PCOV will detect the executability of the cases inside the switch body correctly, but will not detect line 2 (with the switch statement) as executable because Zend didn't output an executable opcode on that line. Xdebug's custom analysis doesn't use the same method and so will show an extra executable line on 2. Pre 7.2.15 and PCOV 1.0, the coverage of some switches is questionable as a result of the way Zend constructs the opcodes in the body of the switch - it may not execute them depending on a jump table optimization.

While Xdebug and PCOV both do the same kind of analysis of code, Xdebug is currently able to do more with that information than just generate accurate line coverage reports, it has path coverage and PCOV does not, although path coverage is not yet implemented (and probably won't be) by CodeCoverage.

Differences in Performance

The differences in performance of Xdebug and PCOV are not slight. Xdebug is first and foremost a debugging extension, and when you load it, you incur the overhead of a debugger even when it's disabled. PCOV is less than 1000 lines of code (not including CFG) and doesn't have anything like the overhead of a debugger.

pcov's People

Contributors

andrewbroberg avatar bcremer avatar cmb69 avatar grahamcampbell avatar krakjoe avatar kubawerlos avatar lolautruche avatar mavimo avatar nikic avatar remicollet avatar ryanjbonnell avatar samnela avatar slamdunk avatar staabm avatar weltling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pcov's Issues

Segmentation fault on 7.4 on macOS with anonymous class

On PHP 7.4 (tested with 7.4.2 and 7.4.3) on macOS collecting code coverage for code that contains an anonymous class segfaults. The same code on Linux doesn't have any problems.

Test script:

<?php
\pcov\start();
$a = new class() {};
\pcov\stop();
var_dump(\pcov\collect());

Expected result (at least that's what one receives with PHP 7.3):

array(1) {
  ["[...redacted...]src/foo.php"]=>
  array(5) {
    [2]=>
    int(-1)
    [3]=>
    int(1)
    [4]=>
    int(1)
    [5]=>
    int(-1)
    [6]=>
    int(-1)
  }
}

Actual result:

[1]    63456 segmentation fault  php src/foo.php

First request display all information, nexts don't

Hello.

First, thanks a lot for this lib :D

Then, I would like to try few things with this lib (more to come) but I'm facing something strange. So I would like to know if this "normal".

I installed the lib as described in the INSTALL.md (BTW you don't tell about loading the extension in the php.ini or with something like -dextension=/home/gregoire/dev/labs/candle/pcov/modules/pcov.so).

Afterwards, I created a fresh Symfony project (composer create-project symfony/website-skeleton demo -s dev master -vvv),
and added a simple entity + controller (CRUD) with the make bundle. Anyway :)

In the frontend controller I did that:

diff --git a/public/index.php b/public/index.php
index e30f90c..fa0c10c 100644
--- a/public/index.php
+++ b/public/index.php
@@ -4,6 +4,8 @@ use App\Kernel;
 use Symfony\Component\Debug\Debug;
 use Symfony\Component\HttpFoundation\Request;

+\pcov\start();
+
 require dirname(__DIR__).'/config/bootstrap.php';

 if ($_SERVER['APP_DEBUG']) {
@@ -23,5 +25,6 @@ if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false
 $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
 $request = Request::createFromGlobals();
 $response = $kernel->handle($request);
+echo json_encode(\pcov\collect());die;
 $response->send();
 $kernel->terminate($request, $response);

If you don't know Symfony, I'm basically starting the coverage report ASAP, and then I dump the report instead if the regular response.

On the very first run, I got something like:

{"\/home\/gregoire\/dev\/labs\/candle\/demo\/src\/Kernel.php":{"49":1,"18":1,"20":1,"21":1,"22":1,"23":1,"26":1,"30":-1,"31":-1,"32":-1,"34":-1,"35":-1,"36":-1,"37":-1,"38":-1,"42":-1,"44":-1,"45":-1,"46":-1,"47":-1},"\/home\/gregoire\/dev\/labs\/candle\/demo\/src\/Controller\/PostController.php":{"97":1,"23":1,"24":1,"33":-1,"34":-1,"35":-1,"37":-1,"38":-1,"39":-1,"40":-1,"42":-1,"45":-1,"46":-1,"47":-1,"56":-1,"57":-1,"66":-1,"67":-1,"69":-1,"70":-1,"72":-1,"73":-1,"77":-1,"78":-1,"79":-1,"88":-1,"89":-1,"90":-1,"91":-1,"94":-1},"\/home\/gregoire\/dev\/labs\/candle\/demo\/src\/Repository\/PostRepository.php":{"51":1,"19":1,"20":1},"\/home\/gregoire\/dev\/labs\/candle\/demo\/src\/Entity\/Post.php":{"58":1,"31":-1,"36":-1,"41":-1,"43":-1,"48":-1,"53":-1,"55":-1}}

This is perfect, and thanks again :D

But, on next runs, I got something like:

[]

At the first glance, I thought it might be caused by OPCache, so I removed it.
But it did not change anything. So I removed Blackfire, and (OH I did not notice
that before) XDebug. Still the same result.

So, to me this is strange, that's why I would like to know what I'm doing wrong.

Note about my arch
# php -v
PHP 7.3.3-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Mar  7 2019 20:31:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies
# release
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic

I'm using the cli-server SAPI through Symfony. But Symfony does not transfer all PHP config to the "server"
I had to manually edit WebsServer.php:

$process = new Process(array_merge(
    [$binary],
    $finder->findArguments(),
    $xdebugArgs,
    ['-dextension=/home/gregoire/dev/labs/candle/pcov/modules/pcov.so'], // I added that
    ['-dpcov.directory=/home/gregoire/dev/labs/candle/demo/src'], // And that
    ['-dvariables_order=EGPCS', '-S', $config->getAddress(), $config->getRouter()],
));

I hope you have all information to solve this issue ❀️

Problem with whitelist and directories

I've created this repo (2 dummy classes, 100% code coverage expected).

Simple structure:

{
    "autoload-dev": {
        "psr-4": {
            "TheFoo\\": "./src",
            "TheFooDev\\": "./dev-code"
        }
    }
}

Whitelist:

    <filter>
        <whitelist>
            <directory>dev-code</directory>
            <directory>src</directory>
        </whitelist>
    </filter>

On master branch this build reports for xdebug and phpdbg 100% coverage (which is correct) and for pcov 50% (one class instead of two).

When I rename src to not-src then suddenly all is good - all 3 jobs reports 100% coverage.

When I rename dev-code to src-code then again, all is [good]https://travis-ci.com/kubawerlos/pcov-bug/builds/129603756) - all 3 jobs reports 100% coverage.

Can it be related to pcov.directory? But the 2nd rename shows that it is not directory, but directory prefix (as both src and src-code are considered).

"malloc_consolidate(): invalid chunk size" with PHP 8.1

The tests for PHPUnit fail with PHP 8.1 on GitHub Actions when PCOV (1.0.6) is used for code coverage because PHP prints

malloc_consolidate(): invalid chunk size
Aborted (core dumped)

which leads to PHPT test failing as their assertions operate on PHP output:

You can see that this is caused by PCOV here: sebastianbergmann/phpunit#4622 (comment)

Tests

Writing phpt tests for pcov is extremely unappealing, and php-code-coverage has a test suite ... need to figure out a way to run the tests in php-code-coverage on CI builds ...

Release v1.0.5

  • Fix #19 fault in 7.2 caused by modification of filename pointer

Waiting for feedback in #19, when that's closed, ready to go ...

Thanks @remicollet

Undefined variable: argv when running

Running PHPUnit on https://github.com/vimeo/psalm I get

> vendor/bin/phpunit
PHPUnit 8.1.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.3.5 with PCOV 1.0.5
Configuration: /xxx/psalm/phpunit.xml.dist

Undefined variable: argv

It works just fine without pcov enabled. Unsure how to proceed.

register_argc_argv = Off

in my php.ini (but setting it to On doesn't help either).

Release v1.0.4

  • Fix #17 Lines not covered when more tests are run
  • Improve perf of clear routine
  • Merge upstream cfg updates (switch block change)
  • Omit ignored opcodes from internal coverage data completely (doesn't effect users, except less memory used)

over to you @remicollet, thanks :)

pcov.exclude syntax

since there are no official examples, i'd like to confirm, would this be a valid syntax to define excluded folders in php.ini?

pcov.exclude="~(vendor|tests|node_modules)~"

Lines not covered when more tests are run

Hello,

I've spot an issue that some lines are not covered when tests are run together with other ones.

Easiest way to reproduce is to clone this repository: git clone [email protected]:kubawerlos/php-cs-fixer-custom-fixers.git.

When running vendor/bin/phpunit tests/Fixer all fixers get covered, which is expected.

But when running vendor/bin/phpunit tests some fixers don't get covered fully (but only some) and always the problematic is function isRisky, e.g. InternalClassCasingFixer::isRisky.

I've tested with PCOV v1.0.3 and phpunit/php-code-coverage 7.0.4.

[WIP] Lines marked as red or white but never green

Hi, I'm having issues on how PCOV reports some lines.

This is a WIP since I know all the following details still aren't enough for you to help me, I need to dig deeper and isolate better where the problem lies, but still I prefer to open an Issue now, maybe you can help me find it.

Env details

  1. Codeception 3.0
  2. PHPUnit 8.3.3
  3. php-code-coverage 7.0.7
  4. PHP 7.3.8
  5. PCOV 1.0.6
  6. OS: Docker, see https://github.com/Slamdunk/docker-php/blob/master/7.3.Dockerfile#L53

1) Executed lines may differ depending on the run

Two different runs, the only change was removing every @covers annotations from unit and functional tests.

Without @covers:
pcov-full

With @covers:
pcov-part

All 3 lines 60, 61 and 62 are executed for sure, as lines 62 is green, but the output differs.

  1. How can lines 60 and 61 marked as red?
  2. How is that executed lines differ?

2) Function parameters may be signed as executed or not

pcov-wut

  1. How can lines 990 and 991 not marked as executed?

Windows DLLs for PHP 8.0

Thanks a lot for the work on this great extension. We probably saved several build hours using PCOV.

I tried to compile pcov on PHP 8.0 branches, and it worked well. Would it be possible to upload Windows DLLs to https://pecl.php.net/package/pcov?

Thank you.

Behaviour change with PHP7.2/PCOV1.0.4

Hi,

I seem to encounter an issue when using PCOV 1.0.4 with PHP 7.2 (CentOS 7 env with packages from Remi repository):

$ /opt/remi/php72/root/usr/bin/php -d pcov.directory=. src/vendor/bin/phpunit --debug --config=tests/phpunit/phpunit.xml --coverage-clover=/tmp/coverage.xml tests/phpunit/common/Include/
PHPUnit 8.2.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.19 with PCOV 1.0.4
Configuration: /tuleap/tests/phpunit/phpunit.xml

Test 'Tuleap\CookieManagerTest::testCookiePrefixIsSet' started
Test 'Tuleap\CookieManagerTest::testCookiePrefixIsSet' ended
Test 'Tuleap\CookieManagerTest::testItDoesNotSetCookiePrefixIfHTTPSIsNotAvailable' started
Test 'Tuleap\CookieManagerTest::testItDoesNotSetCookiePrefixIfHTTPSIsNotAvailable' ended
Test 'Tuleap\CookieManagerTest::testCookiesRemoval' started
Test 'Tuleap\CookieManagerTest::testCookiesRemoval' ended
Test 'Tuleap\CookieManagerTest::testItDeterminesIfACookieCanUseSecureFlag' started
Test 'Tuleap\CookieManagerTest::testItDeterminesIfACookieCanUseSecureFlag' ended
PHP Fatal error:  Uncaught TypeError: is_file() expects parameter 1 to be a valid path, string given in /tuleap/src/vendor/phpunit/phpunit/src/Util/GlobalState.php:72
Stack trace:
#0 /tuleap/src/vendor/phpunit/phpunit/src/Util/GlobalState.php(72): is_file('\x00filtertestcase...')
#1 /tuleap/src/vendor/phpunit/phpunit/src/Util/GlobalState.php(37): PHPUnit\Util\GlobalState::processIncludedFilesAsString(Array)
#2 /tuleap/src/vendor/phpunit/phpunit/src/Framework/TestCase.php(736): PHPUnit\Util\GlobalState::getIncludedFilesAsString()
#3 /tuleap/src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(568): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult))
#4 /tuleap/src/vendor/phpunit/phpunit/src/Framework/TestSuite.php(568): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#5 /tuleap/src/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(619): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#6 /tuleap/src/vendor/phpunit/phpunit/src/TextUI/Command.php(201): PHPUnit\TextUI in /tuleap/src/vendor/phpunit/phpunit/src/Util/GlobalState.php on line 72

The same tests run fine when using PHP 7.2/PCOV1.0.3 or PHP 7.3/PCOV1.0.4.

The issue seems to be caused by the usage of the PHPUnit feature @runInSeparateProcess in the next test the testsuite is supposed to execute (https://github.com/Enalean/tuleap/blob/d03d01a75616907f55c4317370861679850b4741/tests/phpunit/common/Include/LoaderSchedulerTest.php#L52).

I also tried to reproduce the issue on a smaller repository than my usual codebase without luck so I'm guessing the number of files covered also play a role.

I have setup a repository to play the tests on Travis to try to ease the reproduction, I got a different output on the failure (different defaults?) but still, it only fails when using PHP7.2/PCOV1.0.4:
https://travis-ci.com/LeSuisse/issue-php72-pcov104/builds/114996334
https://github.com/LeSuisse/issue-php72-pcov104

$ php -d pcov.directory=. src/vendor/bin/phpunit --debug --config=tests/phpunit/phpunit.xml --coverage-clover=coverage.xml tests/phpunit/common/Include/
PHPUnit 8.2.0 by Sebastian Bergmann and contributors.
Runtime:       PHP 7.2.16 with PCOV 1.0.4
Configuration: /home/travis/build/LeSuisse/issue-php72-pcov104/tuleap/tests/phpunit/phpunit.xml
Test 'Tuleap\CookieManagerTest::testCookiePrefixIsSet' started
/home/travis/.travis/functions: line 104: 10129 Segmentation fault      (core dumped) php -d pcov.directory=. src/vendor/bin/phpunit --debug --config=tests/phpunit/phpunit.xml --coverage-clover=coverage.xml tests/phpunit/common/Include/

'No code coverage driver available' although php reports pcov enabled

Hi,

It's very, very likely I'm doing something wrong - so apologies in advance! I've installed the extension using pecl and added an ini entry with pcov.enabled = 1 just to be sure. When I run phpunit I get the above exception message back from the code coverage driver though. Things look ok to me :

$ php --version
PHP 7.2.17 (cli) (built: Apr  6 2019 03:22:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

$ php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gmp
hash
iconv
json
ldap
libxml
mbstring
mysqlnd
openssl
pcntl
pcov
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
sysvmsg
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

$ php --ri pcov

pcov

PCOV support => Enabled
PCOV version => 1.0.2
pcov.directory => auto
pcov.exclude => none
pcov.initial.memory => 65336 bytes
pcov.initial.files => 64

$ php vendor/bin/phpunit --coverage-text --colors=never

PHPUnit 7.5.9 by Sebastian Bergmann and contributors.

Fatal error: Uncaught SebastianBergmann\CodeCoverage\RuntimeException: No code coverage driver available in /builds/ohffs/glasgow_projects/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:908
Stack trace:
#0 /builds/ohffs/glasgow_projects/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(146): SebastianBergmann\CodeCoverage\CodeCoverage->selectDriver(Object(SebastianBergmann\CodeCoverage\Filter))
#1 /builds/ohffs/glasgow_projects/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(528): SebastianBergmann\CodeCoverage\CodeCoverage->__construct(NULL, Object(SebastianBergmann\CodeCoverage\Filter))
#2 /builds/ohffs/glasgow_projects/vendor/phpunit/phpunit/src/TextUI/Command.php(206): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#3 /builds/ohffs/glasgow_projects/vendor/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\TextUI\Command->run(Array, true)
#4 /builds/ohffs/glasgow_projects/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#5 {main}
  thrown in /builds/ohffs/glasgow_projects/vendor/phpunit/php-code-coverage/src/CodeCoverage.php on line 908
ERROR: Job failed: exit code 1

Release 1.0.0

Hi Remi :)

I know you're afk at the moment ... whenever you've time ...

Release v1.0.0 is ready for PECL ... I know I said the API was stable, but I changed it, hence version bump.

I think I've removed all the unused stuff, but if you could cast your eye over it, that'd be good.

The changelog should be brief, just "Import Zend CFG" or something. Probably still go with beta, even though the CFG is probably some of the best tested code in the ecosystem, let us be cautious ...

Thanks in advance, hope you're enjoying conference :)

Problem with installation PCOV on php 7.3.8

git clone ....
git checkout release (not develop)

-rw-r--r--   1 pvsaintpe  staff     0B  8 ΠΎΠΊΡ‚ 14:35 missing
-rw-r--r--   1 pvsaintpe  staff     0B  8 ΠΎΠΊΡ‚ 14:35 mkinstalldirs
drwxr-xr-x   2 pvsaintpe  staff    64B  8 ΠΎΠΊΡ‚ 14:10 modules
-rw-r--r--   1 pvsaintpe  staff   5,1K  8 ΠΎΠΊΡ‚ 14:35 package.xml
-rw-r--r--   1 pvsaintpe  staff    21K  8 ΠΎΠΊΡ‚ 14:35 pcov.c
-rw-r--r--   1 root       staff   221B  8 ΠΎΠΊΡ‚ 14:38 pcov.loT
-rw-r--r--   1 pvsaintpe  staff   2,5K  8 ΠΎΠΊΡ‚ 14:35 php_pcov.h
-rw-r--r--   1 pvsaintpe  staff    85K  8 ΠΎΠΊΡ‚ 14:35 run-tests.php
drwxr-xr-x   6 pvsaintpe  staff   192B  8 ΠΎΠΊΡ‚ 14:09 tests
pvsaintpe@UMB-0049 pcov % make 
/bin/sh /Users/pvsaintpe/pcov/libtool --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/Users/pvsaintpe/pcov -DPHP_ATOM_INC -I/Users/pvsaintpe/pcov/include -I/Users/pvsaintpe/pcov/main -I/Users/pvsaintpe/pcov -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/Users/pvsaintpe/pcov/cfg/703  -DHAVE_CONFIG_H  -g -O2   -c /Users/pvsaintpe/pcov/pcov.c -o pcov.lo 
 cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/Users/pvsaintpe/pcov -DPHP_ATOM_INC -I/Users/pvsaintpe/pcov/include -I/Users/pvsaintpe/pcov/main -I/Users/pvsaintpe/pcov -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/Users/pvsaintpe/pcov/cfg/703 -DHAVE_CONFIG_H -g -O2 -c /Users/pvsaintpe/pcov/pcov.c  -fno-common -DPIC -o .libs/pcov.o
/Users/pvsaintpe/pcov/pcov.c:25:10: fatal error: 'php.h' file not found
#include "php.h"
         ^~~~~~~
1 error generated.
make: *** [pcov.lo] Error 1

OS: MacOS Catalina (official release) 10.15
PEAR Version: 1.10.9
PHP Version: 7.3.8
Zend Engine Version: 3.3.8

Installation via pecl also got errors.

What am I doing wrong?

PCOV doesn't work with paratest?

I can’t understand if my configuration error or if pcov cannot be started with paratest.
I execute the command:

/usr/bin/php -d memory_limit=2G -d pcov.enabled=1 -d pcov.directory=/srv/http/api.zp.ru/scripts/Job /srv/http/api.zp.ru/vendor/bin/phpunit -c /srv/http/api.zp.ru/tests/functional/phpunit.xml --coverage-text /srv/http/api.zp.ru/tests/functional/scripts/Job/Users

and get result

Code Coverage Report:
2019-11-24 14:16:14

Summary:
Classes: 2.51% (46/1831)
Methods: 7.02% (727/10361)
Lines: 7.45% (4754/63852)

so, when run :

/usr/bin/php -d memory_limit=2G -d pcov.enabled=1 -d pcov.directory=/srv/http/api.zp.ru/scripts/Job /srv/http/api.zp.ru/vendor/bin/paratest -p 4 -c /srv/http/api.zp.ru/tests/functional/phpunit.xml --coverage-text /srv/http/api.zp.ru/tests/functional/scripts/Job/Users

we get zero result =(

Code Coverage Report:
2019-11-24 14:18:38

Summary:
Classes: 0.00% (0/1831)
Methods: 0.00% (0/10362)
Lines: 0.00% (0/110095)

Am I missing something?

.cov files are generated but are essentially empty

I am trying to run pcov in a Jenkins CI/CD environment.

I think I have everything wired up correctly because I am seeing that .cov files are generated as expected.

However, these generated files contain no coverage data. They all look like this:

<?php
$coverage = new SebastianBergmann\CodeCoverage\CodeCoverage;
$coverage->setData(array (
));
$coverage->setTests(array (
));

$filter = $coverage->filter();
$filter->setWhitelistedFiles(array (
  '/var/www/html/app/code/Foo/Bar/baz.php' => true,
  ...
  1000 more files here
  ...
));

return $coverage;

Notice setData() and setTests() are being passed an empty array, so therefore the coverage report is empty.

Does anyone have any ideas of things to try or investigate?
Thanks for any help you can offer!

Config.w32

Hi @weltling, me again :)

I did make config.w32 work for 7.1-7.3, but it won't work for 7.4 because 7.3/7.4 share the same cfg currently.

I wonder if you could just fixup config.w32 so it matches config.m4 for me, please ?

Release v1.0.1

Changelog:

  • Release memory from building CFG as early as possible
  • Compat with 7.4/8.0 changes

At the moment, the PHP builds on travis are out of date, so I'm not sure if it's a good idea to push this release out right now ? I opened a ticket/started a thread here to have this resolved.

Occassional segmentation fault on PHP 7.4.0

First of all: Thanks a lot for this amazing project. It really saves time and headaches!

In my brand new PCOV 1.0.6 / Symfony 4.4.0 / Behat 3.5 setup I occassionally run into a segfault that mentions pcov. See the coredump and the backtrace below.

Unfortunately I am not able to trigger it with a small reproducer.

Is this something that can be caused by userland? Or is it perhaps a small bug in pcov or even PHP ?

Core was generated by `php -d extension=pcov -d pcov.enabled=1 vendor/bin/behat --profile no-bootstrap'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f554a4b4d76 in zend_mark_reachable (opcodes=0x7f554544ec00, cfg=0x7ffef075d260, b=0x7f5541250a50) at /tmp/pear/temp/pcov/cfg/703/zend_cfg.c:91
91                              zend_basic_block *succ = blocks + b->successors[i];
(gdb) bt
#0  0x00007f554a4b4d76 in zend_mark_reachable (opcodes=0x7f554544ec00, cfg=0x7ffef075d260, b=0x7f5541250a50) at /tmp/pear/temp/pcov/cfg/703/zend_cfg.c:91
#1  0x00007f554a4b4f91 in zend_mark_reachable (opcodes=0x7f554544ec00, cfg=0x7ffef075d260, b=0x7f5541053650) at /tmp/pear/temp/pcov/cfg/703/zend_cfg.c:148
#2  0x00007f554a4b4f91 in zend_mark_reachable (opcodes=0x7f554544ec00, cfg=0x7ffef075d260, b=0x7f55410535d0) at /tmp/pear/temp/pcov/cfg/703/zend_cfg.c:148
#3  0x00007f554a4b4f91 in zend_mark_reachable (opcodes=0x7f554544ec00, cfg=0x7ffef075d260, b=0x7f5541053510) at /tmp/pear/temp/pcov/cfg/703/zend_cfg.c:148
#4  0x00007f554a4b5010 in zend_mark_reachable_blocks (op_array=0x7f5544579690, cfg=0x7ffef075d260, start=0) at /tmp/pear/temp/pcov/cfg/703/zend_cfg.c:161
#5  0x00007f554a4b71a3 in zend_build_cfg (arena=0x7ffef075d2e8, op_array=0x7f5544579690, build_flags=2147483648, cfg=0x7ffef075d260)
    at /tmp/pear/temp/pcov/cfg/703/zend_cfg.c:639
#6  0x00007f554a4b3abd in php_pcov_discover_code (arena=0x7ffef075d2e8, ops=0x7f5544579690, return_value=0x7ffef075d2f0) at /tmp/pear/temp/pcov/pcov.c:544
#7  0x00007f554a4b3ecf in php_pcov_discover_file (file=0x7f55447bb180, return_value=0x7f554a8175c0) at /tmp/pear/temp/pcov/pcov.c:624
#8  0x00007f554a4b4259 in php_pcov_collect (execute_data=0x7f554a8175f0, return_value=0x7f554a8175c0) at /tmp/pear/temp/pcov/pcov.c:691
#9  0x000055f0882a57fc in ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1525
#10 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a817510) at /usr/src/php/Zend/zend_vm_execute.h:61485
#11 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a817510) at /tmp/pear/temp/pcov/pcov.c:252
#12 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a817510) at /tmp/pear/temp/pcov/pcov.c:291
#13 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#14 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a8173e0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#15 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a8173e0) at /tmp/pear/temp/pcov/pcov.c:252
#16 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a8173e0) at /tmp/pear/temp/pcov/pcov.c:291
#17 0x000055f0882a5b39 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1601
#18 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a817350) at /usr/src/php/Zend/zend_vm_execute.h:61485
#19 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a817350) at /tmp/pear/temp/pcov/pcov.c:252
#20 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a817350) at /tmp/pear/temp/pcov/pcov.c:291
#21 0x000055f088219184 in zend_call_function (fci=0x7ffef075d960, fci_cache=0x7ffef075d940) at /usr/src/php/Zend/zend_execute_API.c:811
#22 0x000055f0880439a0 in zif_call_user_func_array (execute_data=0x7f554a8172e0, return_value=0x7f554a817270) at /usr/src/php/ext/standard/basic_functions.c:4960
#23 0x000055f0882a60a5 in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1729
#24 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a817140) at /usr/src/php/Zend/zend_vm_execute.h:61485
#25 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a817140) at /tmp/pear/temp/pcov/pcov.c:252
#26 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a817140) at /tmp/pear/temp/pcov/pcov.c:291
#27 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#28 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a817090) at /usr/src/php/Zend/zend_vm_execute.h:61485
#29 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a817090) at /tmp/pear/temp/pcov/pcov.c:252
#30 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a817090) at /tmp/pear/temp/pcov/pcov.c:291
#31 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#32 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a816f80) at /usr/src/php/Zend/zend_vm_execute.h:61485
#33 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a816f80) at /tmp/pear/temp/pcov/pcov.c:252
#34 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a816f80) at /tmp/pear/temp/pcov/pcov.c:291
#35 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#36 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a816db0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#37 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a816db0) at /tmp/pear/temp/pcov/pcov.c:252
#38 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a816db0) at /tmp/pear/temp/pcov/pcov.c:291
#39 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#40 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a816d00) at /usr/src/php/Zend/zend_vm_execute.h:61485
#41 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a816d00) at /tmp/pear/temp/pcov/pcov.c:252
#42 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a816d00) at /tmp/pear/temp/pcov/pcov.c:291
#43 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#44 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a816c00) at /usr/src/php/Zend/zend_vm_execute.h:61485
#45 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a816c00) at /tmp/pear/temp/pcov/pcov.c:252
#46 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a816c00) at /tmp/pear/temp/pcov/pcov.c:291
#47 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#48 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a816a80) at /usr/src/php/Zend/zend_vm_execute.h:61485
#49 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a816a80) at /tmp/pear/temp/pcov/pcov.c:252
#50 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a816a80) at /tmp/pear/temp/pcov/pcov.c:291
#51 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#52 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a8168d0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#53 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a8168d0) at /tmp/pear/temp/pcov/pcov.c:252
#54 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a8168d0) at /tmp/pear/temp/pcov/pcov.c:291
#55 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#56 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a816690) at /usr/src/php/Zend/zend_vm_execute.h:61485
#57 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a816690) at /tmp/pear/temp/pcov/pcov.c:252
#58 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a816690) at /tmp/pear/temp/pcov/pcov.c:291
#59 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#60 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a8163f0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#61 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a8163f0) at /tmp/pear/temp/pcov/pcov.c:252
#62 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a8163f0) at /tmp/pear/temp/pcov/pcov.c:291
#63 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#64 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a816350) at /usr/src/php/Zend/zend_vm_execute.h:61485
#65 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a816350) at /tmp/pear/temp/pcov/pcov.c:252
#66 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a816350) at /tmp/pear/temp/pcov/pcov.c:291
#67 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#68 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a8162b0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#69 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a8162b0) at /tmp/pear/temp/pcov/pcov.c:252
#70 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a8162b0) at /tmp/pear/temp/pcov/pcov.c:291
#71 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#72 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a816050) at /usr/src/php/Zend/zend_vm_execute.h:61485
#73 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a816050) at /tmp/pear/temp/pcov/pcov.c:252
#74 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a816050) at /tmp/pear/temp/pcov/pcov.c:291
#75 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#76 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815fb0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#77 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815fb0) at /tmp/pear/temp/pcov/pcov.c:252
--Type <RET> for more, q to quit, c to continue without paging--c
#78 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815fb0) at /tmp/pear/temp/pcov/pcov.c:291
#79 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#80 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815f10) at /usr/src/php/Zend/zend_vm_execute.h:61485
#81 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815f10) at /tmp/pear/temp/pcov/pcov.c:252
#82 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815f10) at /tmp/pear/temp/pcov/pcov.c:291
#83 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#84 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815c60) at /usr/src/php/Zend/zend_vm_execute.h:61485
#85 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815c60) at /tmp/pear/temp/pcov/pcov.c:252
#86 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815c60) at /tmp/pear/temp/pcov/pcov.c:291
#87 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#88 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815bd0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#89 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815bd0) at /tmp/pear/temp/pcov/pcov.c:252
#90 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815bd0) at /tmp/pear/temp/pcov/pcov.c:291
#91 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#92 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815b30) at /usr/src/php/Zend/zend_vm_execute.h:61485
#93 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815b30) at /tmp/pear/temp/pcov/pcov.c:252
#94 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815b30) at /tmp/pear/temp/pcov/pcov.c:291
#95 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#96 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815910) at /usr/src/php/Zend/zend_vm_execute.h:61485
#97 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815910) at /tmp/pear/temp/pcov/pcov.c:252
#98 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815910) at /tmp/pear/temp/pcov/pcov.c:291
#99 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#100 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815780) at /usr/src/php/Zend/zend_vm_execute.h:61485
#101 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815780) at /tmp/pear/temp/pcov/pcov.c:252
#102 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815780) at /tmp/pear/temp/pcov/pcov.c:291
#103 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#104 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815640) at /usr/src/php/Zend/zend_vm_execute.h:61485
#105 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815640) at /tmp/pear/temp/pcov/pcov.c:252
#106 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815640) at /tmp/pear/temp/pcov/pcov.c:291
#107 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#108 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a815260) at /usr/src/php/Zend/zend_vm_execute.h:61485
#109 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a815260) at /tmp/pear/temp/pcov/pcov.c:252
#110 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a815260) at /tmp/pear/temp/pcov/pcov.c:291
#111 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#112 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a814f00) at /usr/src/php/Zend/zend_vm_execute.h:61485
#113 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a814f00) at /tmp/pear/temp/pcov/pcov.c:252
#114 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a814f00) at /tmp/pear/temp/pcov/pcov.c:291
#115 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#116 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a8148e0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#117 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a8148e0) at /tmp/pear/temp/pcov/pcov.c:252
#118 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a8148e0) at /tmp/pear/temp/pcov/pcov.c:291
#119 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#120 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a8146c0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#121 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a8146c0) at /tmp/pear/temp/pcov/pcov.c:252
#122 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a8146c0) at /tmp/pear/temp/pcov/pcov.c:291
#123 0x000055f0882a5fea in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1713
#124 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a8141e0) at /usr/src/php/Zend/zend_vm_execute.h:61485
#125 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a8141e0) at /tmp/pear/temp/pcov/pcov.c:252
#126 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a8141e0) at /tmp/pear/temp/pcov/pcov.c:291
#127 0x000055f0882a5b39 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1601
#128 0x000055f08830e917 in zend_vm_call_opcode_handler (ex=0x7f554a814020) at /usr/src/php/Zend/zend_vm_execute.h:61485
#129 0x00007f554a4b2f32 in php_pcov_trace (execute_data=0x7f554a814020) at /tmp/pear/temp/pcov/pcov.c:252
#130 0x00007f554a4b3065 in php_pcov_execute_ex (execute_data=0x7f554a814020) at /tmp/pear/temp/pcov/pcov.c:291
#131 0x000055f08830d9e5 in zend_execute (op_array=0x7f554a88c300, return_value=0x0) at /usr/src/php/Zend/zend_vm_execute.h:57651
#132 0x000055f088232435 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/php/Zend/zend.c:1663
#133 0x000055f088192377 in php_execute_script (primary_file=0x7ffef0761920) at /usr/src/php/main/main.c:2619
#134 0x000055f0883105be in do_cli (argc=10, argv=0x55f08919f030) at /usr/src/php/sapi/cli/php_cli.c:961
#135 0x000055f088311728 in main (argc=10, argv=0x55f08919f030) at /usr/src/php/sapi/cli/php_cli.c:1352

Issue about whitelist/multiple directory coverage zero

Coverage always 0.00% files for ./config directory even if dpcov.directory option used

This is a bug or am i missing something? πŸ€”

.travis.yml

install:
   ...
  - composer require --no-interaction --ignore-platform-reqs "phpunit/phpunit:^7" "friendsofphp/php-cs-fixer" "pcov/clobber"
   ...

script:
    php -dpcov.enabled=1 -dpcov.directory=./config ./src ./vendor/bin/pcov clobber; ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml

Also tried

script:
  - php -dpcov.directory=. -dpcov.exclude="~vendor~" ./vendor/bin/pcov clobber; ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml

phpunit.xml.dist

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    bootstrap="tests/bootstrap.php"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    stopOnFailure="true"
    stderr="true"
    colors="true"
    verbose="true">

    <filter>
        <whitelist>
            <directory>./config</directory>
            <directory>./src</directory>
        </whitelist>
    </filter>

    <testsuites>
        <testsuite name="Classes">
            <directory>./tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

pcov not reporting on ./tests directory

Not sure if this is the best place to ask but...

I'm looking to move my PHPUnit coverage reports to pcov from phpdbg to get around some issue with the latter not covering case statements.

When using xdebug or phpdbg I get 100% coverage on both my src and tests folders. When I use pcov I get 0% for tests.

My phpunit.xml file contains:

<filter>
    <whitelist  processUncoveredFilesFromWhitelist="false">
        <directory suffix=".php">src</directory>
        <directory suffix=".php">tests/Integration</directory>
        <directory suffix=".php">tests/Unit</directory>
    </whitelist>
</filter>
<logging>
    <log type="coverage-html" target="build/coverage"/>
</logging>

tests in all cases are run with ./vendor/bin/phpunit.

Am I missing something?

Could you explain how PCOV calculates coverage

Hello.

We have a big discrepancies in code coverage using xDebug and PCOV in our project. For example there is 15% difference for covered lines.

There is a small part of README describes the difference, but I'm not 100% clear on that.

Π ere on this example

image

I'm confused that lines 90 and 91 are not covered according PCOV?

Built-in server source discovery

In the codeception test suite the built-in server is used to test getting remote coverage.
While trying to switch over to pcov I discovered that pcov does not take into account the root directory passed into php via -t.

In my opinion it makes more sense to, in this case, default to the webroot than to the calling directory.
The 3 invocations below should result in the same coverage being shown.

> php -S 127.0.0.1:1234 -t /test/cool/stuff
> cd /test/cool php -S 127.0.0.1:1234 -t stuff
> cd /test/cool/stuff php -S 127.0.0.1:1234 -t .

Because of the auto discovery this is not the case.
To aid in debugging this, it might also make sense to somehow expose the discovered directory in use.

Missing Code Coverage When Phpunit's Process Isolation Is False

  • PHP 7.3.17
  • PHPUnit 8.5.5
  • pcov 1.0.6

Steps to reproduce:

  1. Download attached code: pcov-bug-report.zip
  2. composer install
  3. ./vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover clover.xml

Expected: Accurate code coverage

Actual: Missing coverage in switch statements using consts

Workaround: If I open tests/phpunit.xml and change processIsolation="false" to processIsolation="true" the coverage is accurate.

Screen Shot 2020-06-09 at 1 56 09 PM
Screen Shot 2020-06-09 at 1 56 51 PM


Zip file contains:

.
β”œβ”€β”€ clover-processIsolation-false.xml
β”œβ”€β”€ clover-processIsolation-true.xml
β”œβ”€β”€ composer.json
β”œβ”€β”€ composer.lock
β”œβ”€β”€ src
β”‚Β Β  β”œβ”€β”€ One
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ SupportedCountriesISO2.php
β”‚Β Β  β”‚Β Β  └── SupportedCountriesISO3.php
β”‚Β Β  └── Two
β”‚Β Β      └── Example.php
└── tests
    β”œβ”€β”€ Unit
    β”‚Β Β  └── ExampleTest.php
    └── phpunit.xml

Issue with faulty line coverage

Hi, I noticed something strange when running PHPUnit in a new repository, I got reports that tests were risky because they executed methods that they in reality didn't, because of me using beStrictAboutCoversAnnotation.

When I ran it multiple times, it displayed different methods not being covered by @covers annotations as a result of PHPUnit triggering the tests that were reported risky first.

I think the issue might be with the clear method, but that's just a wild guess after looking at the PHPUnit coverage driver for PCOV.

A minimal repository recreating my issue can be found here.

Add installation instructions to README

I think you should add installation instructions to the README.

Not everyone might be aware that it's a PECL package that can easily be installed with pecl install.
I think for wider adoption proper installation instructions are important.

PS: Thank you for the package! Keep up the good work. πŸ‘

phpunit8 not wroking...

test code:https://github.com/shanliu/tmp_test
xdebug ouput:(success)
PHPUnit 8.0.6 by Sebastian Bergmann and contributors.

.. 2 / 2 (100%)

Time: 149 ms, Memory: 6.00 MB

OK (2 tests, 2 assertions)

Code Coverage Report:
2019-05-05 07:50:41

Summary:
Classes: 100.00% (1/1)
Methods: 100.00% (2/2)
Lines: 100.00% (4/4)

Mycode
Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 4/ 4)
PCOV output:(fail)
PHPUnit 8.0.6 by Sebastian Bergmann and contributors.

.. 2 / 2 (100%)

Time: 130 ms, Memory: 6.00 MB

OK (2 tests, 2 assertions)

Code Coverage Report:
2019-05-05 07:50:28

Summary:
Classes: 0.00% (0/1)
Methods: 0.00% (0/2)
Lines: 0.00% (0/6)

Mycode
Methods: 0.00% ( 0/ 2) Lines: 0.00% ( 0/ 6) (not working...)

Question about generating coverage report

Hi,

I'm using:

  • PHPUnit 9.2
  • PHP 7.4.6 with PCOV 1.0.6

When I used XDebug, when my tests fail, no coverage report would be generated. But when I use PCOV, it still generated coverage report and I don't really want it.

image

How could I stop it?
Many thanks.

pcov.enabled=1 does not enable PCOV

I'm having trouble enabling PCOV via INI.

In php.ini, I have set pcov.enabled=1. When I run PHPUnit, I get an error that no code coverage driver is available, and php -m reports that PCOV is loaded. but php --ri pcov says PCOV support => Disabled.

The configuration file is loaded and parsed correctly though, as if I set extension=pcov.so PHP will warn about the extension already being loaded. If I set pcov.initial.memory=1.5G, I get a segfault/coredump (not sure if this is a bug or intentional).

It is only the enabled option which does not work for some reason.

When I invoke PHPUnit using

$ php -dpcov.enabled=1 phpunit --coverage-text --whitelist=src ./testsdir/

everything seems to work and code coverage is generated properly to stdout.

  • PHP version is latest 7.3.8
  • PHPUnit version is 8.3.4, installed with Composer to project
  • PCOV version is 1.0.6, installed from PECL
  • Xdebug and similar are not loaded at the same time

Let me know if there are steps I can take to get more information visible to help with solving this.

Wrong coverage report

Hello, I created a full reproducer here.
I made it as small as possible. I hope it will help you.

But basically, The faulty code:

class Sut
{
    public function compute()
    {
        if (true) {
            if (true) {
                $newConfig = [
                    'here' => 'yes',
                ];
            } else {
                $newConfig = [
                    'here' => 'no',
                ];
            }
        } else {
            throw new \RuntimeException('oups');
        }

        return $newConfig;
    }
}

When I execute:

./vendor/bin/phpunit test/ --coverage-html cov

It get the following report:

^ array:1 [
  "/home/gregoire/dev/github.com/lyrixx/test/src/Sut.php" => array:7 [
    24 => -1
    7 => 1
    8 => 1
    10 => 1
    14 => 1
    18 => -1
    21 => 1
  ]
]

image

This is not possible to go through line 10 and 14, right ?

And we can go even crazier with the following code:

image


PHP:

PHP 7.4.4 (cli) (built: Mar 20 2020 13:47:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies
    with blackfire v1.32.0~linux-x64-non_zts74, https://blackfire.io, by Blackfire

pcov: 1.0.6


Note, I also tested with minimal setup, and I got the same issue:

php -n -d extension=dom -d extension=pcov -d extension=tokenizer -d extension=json  ./vendor/bin/phpunit test/ --coverage-html cov

Reporting method curly braces ( `{` and `}`) as not covered, but method content as covered

Hi !

Very weird : since a few weeks/months, method curly braces ( { and }) are reported as not covered , even if the method declaration and content are reported as covered (and they are actually covered).

Command used :

php \
            -d pcov.enabled=1 \
            -d pcov.directory=src \
            -d pcov.initial.files=2048	\
            -d memory_limit=-1 \
            bin/phpunit --log-junit junit.xml --coverage-clover clover.xml -c phpunit.xml.dist

The coverage is then sent to SonarCloud, and the uncovered lines break our Quality Gate.

Fro example, this DTO :

image

What's going on ?
How can I fix this ?
Is it a configuration issue or a bug ?

Thanks for your help !

It would be nice if pcov and phpunit's php-code-coverage communicated over directory filtering

With the default setting of not setting pcov.directory, pcov will latch onto either ./src, ./lib or, ./app. Leaving the end user confused why adding extra directories in phpunit.xml doesn't do anything:

sebastianbergmann/php-code-coverage#741

It would be nice if in some way, the directories whitelisted in phpunit.xml or --whitelist <dir> would change a pcov.directory-like filter, according to the Rule of Least Surprise.


For now I'll try to see if I can move CentOS and Ubuntu or Debian to write pcov.directory=. in /etc/php/7.*/mods-available/pcov.ini, but that is less optimal and takes a bit of luck to find someone who just had their breakfast and coffee and is in a good mood to apply such a change. It also doesn't 'solve' it anywhere else. Neither is it really a proper solution.


Hedging my bets: https://youtrack.jetbrains.com/issue/WI-52914

Getting Segmentation Fault Errors

While running phpunit 8.5.6 with PHP 7.4.14 with PCOV 1.0.6 I keep getting segmentations fault.
We just upgraded our php to 7.4 when we noticed this error.
While running Xdebug, the coverage collection is completed as expected.
image

When the tests are not run in random, the segmentation fault always happens during the same test.

Code that is not executed is reported as being executed

When I run the tests for the diff test suite with code coverage reporting based on PCOV then I get two tests marked as risky:

There were 2 risky tests:

1) SebastianBergmann\Diff\DifferTest::testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation with data set #0 (array(array('a', 2), array('b', 1)), 'a', 'b')
This test executed code that is not listed as code to be covered or used:
- SebastianBergmann\Diff\Chunk::__construct
- SebastianBergmann\Diff\Diff::__construct
- SebastianBergmann\Diff\Diff::getChunks
- SebastianBergmann\Diff\Diff::setChunks

2) SebastianBergmann\Diff\MemoryEfficientImplementationTest::testBothEmpty
This test executed code that is not listed as code to be covered or used:
- SebastianBergmann\Diff\Line::__construct
- SebastianBergmann\Diff\Line::getContent

These tests are not marked as risky when code coverage is reported using Xdebug or PHPDBG.

When I add an exit statement to the constructor of Chunk like so

diff --git a/src/Chunk.php b/src/Chunk.php
index d030954..21f3367 100644
--- a/src/Chunk.php
+++ b/src/Chunk.php
@@ -39,6 +39,7 @@ final class Chunk
 
     public function __construct(int $start = 0, int $startRange = 1, int $end = 0, int $endRange = 1, array $lines = [])
     {
+        exit;
         $this->start      = $start;
         $this->startRange = $startRange;
         $this->end        = $end;

and run the testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation test (./vendor/bin/phpunit --filter testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation) then it works, meaning the exit statement is not reached, meaning that Chunk is not used.

When I add an exit statement to the constructor of Diff like so

diff --git a/src/Diff.php b/src/Diff.php
index 3029e59..ea5c15d 100644
--- a/src/Diff.php
+++ b/src/Diff.php
@@ -34,6 +34,7 @@ final class Diff
      */
     public function __construct(string $from, string $to, array $chunks = [])
     {
+        exit;
         $this->from   = $from;
         $this->to     = $to;
         $this->chunks = $chunks;

and run the testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation test (./vendor/bin/phpunit --filter testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation) then it works, meaning the exit statement is not reached, meaning that Diff is not used.

When I add an exit statement to the constructor of Line like so

diff --git a/src/Line.php b/src/Line.php
index 125bafd..0ec4266 100644
--- a/src/Line.php
+++ b/src/Line.php
@@ -28,6 +28,7 @@ final class Line
 
     public function __construct(int $type = self::UNCHANGED, string $content = '')
     {
+        exit;
         $this->type    = $type;
         $this->content = $content;
     }

and run the testBothEmpty test (./vendor/bin/phpunit --filter testBothEmpty) then it works, meaning the exit statement is not reached, meaning that Line is not used.

How to run the tests where I see the problem

git clone https://github.com/sebastianbergmann/diff.git
cd diff
composer install
./vendor/bin/phpunit

Empty results

Tests run and report is generated as normal, however, the coverage report shows 0% all the way through.

If I run the same config using phpdbg or Xdebug, it takes a lot longer, but it yields correct results.

I suspect it may be related to processIsolation? Here is my config

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap                   = "tests/bootstrap.php"
         backupGlobals               = "false"
         backupStaticAttributes      = "false"
         colors                      = "true"
         convertErrorsToExceptions   = "true"
         convertNoticesToExceptions  = "true"
         convertWarningsToExceptions = "true"
         processIsolation            = "true"
         stopOnFailure               = "false">
    <php>
        <env name="APP_ENV" value="test"/>
    </php>
    
    <testsuites>
        <testsuite name="Unit Tests">
            <directory>tests/unit</directory>
        </testsuite>
    </testsuites>

    <logging>
        <log type="coverage-html" target=".output/report" />
    </logging>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
</phpunit>

Relative paths in clover file

When running pcov in docker it outputs the docker absolute paths in clover file. But when I want to use them in PhpStorm to show coverage, it obviously does not work, because the absolute paths are not available. Would it be possible to resolve the absolute paths relative to the current working directory?

Memory usage with php7.4

Hi

I want to use pcov with php7.4 but i saw that memory usage increased

tests with php7.3
551.00 MB

tests with php7.4
more than 1gb

Do you have any idea how to reduce used memory?

Best regards

PCOV and Webdriver

Hello,

I have a project with phpunit 6.5. I'm using the Krakjoe/pcov driver (pcov clobber).
Everything work fine except for tests running with php-webdriver/webdriver.

Am I missing something ? When I was using xdebug code coverage I had to prepend code in the htaccess, I thought I didn't had to do so with PCOV but maybe I'm wrong.

Thanks in advance for your help

Best regards

Release 1.0.6

Hi @remicollet, this is just to fix compat with 7.4.0alpha1 ...

I'm not sure when it's best to make this release, same as parallel, if you think it's worth delaying until alpha2, that's cool with me, do what you think is best ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.