Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix xdebug coverage (part1): xdebug_get_code_coverage return value format for executed line #7888

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hphp/runtime/base/code-coverage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace HPHP {
struct Array;

struct CodeCoverage {
static constexpr int kLineExecuted = 1;

void Record(const char* filename, int line0, int line1);

/*
Expand Down
20 changes: 17 additions & 3 deletions hphp/runtime/ext/xdebug/ext_xdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,24 @@ static void HHVM_FUNCTION(xdebug_enable) {

static Array HHVM_FUNCTION(xdebug_get_code_coverage) {
auto ti = ThreadInfo::s_threadInfo.getNoCheck();
if (ti->m_reqInjectionData.getCoverage()) {
return ti->m_coverage->Report(false);
if (!ti->m_reqInjectionData.getCoverage()) {
return Array::Create();
}

auto ret = Array::Create();
auto const reports = ti->m_coverage->Report(false);
for (ArrayIter report(reports); report; ++report) {
auto tmp = Array::Create();
auto const lines = report.second().toArray();
for (ArrayIter line(lines); line; ++line) {
auto const count = line.second().toInt64();
if (count > 0) {
tmp.set(line.first(), Variant(CodeCoverage::kLineExecuted));
}
}
ret.set(report.first(), tmp);
}
return Array::Create();
return ret;
}

// TODO(#3704) see xdebug_start_error_collection()
Expand Down
16 changes: 8 additions & 8 deletions hphp/test/slow/ext_xdebug/code_coverage_started.php.expectf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ array(1) {
[5]=>
int(1)
[6]=>
int(3)
int(1)
[8]=>
int(1)
}
Expand All @@ -19,9 +19,9 @@ array(1) {
[11]=>
int(1)
[12]=>
int(3)
int(1)
[14]=>
int(2)
int(1)
[15]=>
int(1)
}
Expand All @@ -32,15 +32,15 @@ array(1) {
[11]=>
int(1)
[12]=>
int(3)
int(1)
[14]=>
int(2)
int(1)
[15]=>
int(3)
int(1)
[16]=>
int(2)
int(1)
[17]=>
int(2)
int(1)
[18]=>
int(1)
}
Expand Down
16 changes: 8 additions & 8 deletions hphp/test/slow/ext_xdebug/get_code_coverage.php.expectf
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ array(1) {
[2]=>
int(1)
[5]=>
int(32)
int(1)
[6]=>
int(16)
int(1)
[9]=>
int(36)
int(1)
[10]=>
int(32)
int(1)
[11]=>
int(18)
int(1)
[12]=>
int(2)
int(1)
[14]=>
int(2)
int(1)
[15]=>
int(2)
int(1)
[17]=>
int(1)
}
Expand Down
18 changes: 9 additions & 9 deletions hphp/test/slow/ext_xdebug/xdebug/coverage.php.expectf
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ array(2) {
["%s/test/slow/ext_xdebug/xdebug/coverage.inc"]=>
array(11) {
[4]=>
int(%d)
int(1)
[7]=>
int(%d)
int(1)
[8]=>
int(1)
[10]=>
int(%d)
int(1)
[11]=>
int(1)
[15]=>
int(2)
int(1)
[17]=>
int(2)
int(1)
[18]=>
int(2)
int(1)
[20]=>
int(1)
[22]=>
int(4)
int(1)
[23]=>
int(3)
int(1)
}
["%s/test/slow/ext_xdebug/xdebug/coverage.php"]=>
array(3) {
[2]=>
int(1)
[3]=>
int(2)
int(1)
[4]=>
int(1)
}
Expand Down