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

[WIP] fix xdebug coverage (part2): support XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE #7900

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xKerman
Copy link
Contributor

@xKerman xKerman commented Jul 2, 2017

description

related to: #1589 and #7888

This pull request adds support for XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE flags to xdebug_start_code_coverage() .

example

With this pull request, code coverage report for moneyphp/money can be generated with HHVM + PHPUnit as following:
https://xkerman.github.io/hhvm-coverage-sample/hhvm/

Contrast coverage report genereated with PHP5.6 + PHPUnit:
https://xkerman.github.io/hhvm-coverage-sample/php56/

Note: In order to generate coverage report with HHVM + PHPUnit, I need to apply the following patch to phpunit/php-code-coverage:

diff --git a/src/Driver/HHVM.php b/src/Driver/HHVM.php
index b35ea81..85dc6a9 100644
--- a/src/Driver/HHVM.php
+++ b/src/Driver/HHVM.php
@@ -24,6 +24,6 @@ class HHVM extends Xdebug
      */
     public function start($determineUnusedAndDead = true)
     {
-        xdebug_start_code_coverage();
+        xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     }

@xKerman
Copy link
Contributor Author

xKerman commented Jul 16, 2017

2 weeks have passed since I submitted this pull request.
@mofarrell could you review this?

@hhvm-bot
Copy link
Contributor

@mofarrell has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@xKerman
Copy link
Contributor Author

xKerman commented Jul 24, 2017

Thanks, but I found there is a conflict. I will rebase this pull request.

@xKerman xKerman force-pushed the feature/xdebug-unused-and-deadcode branch from 800f49a to 318a34c Compare July 24, 2017 20:18
@hhvm-bot
Copy link
Contributor

@xKerman updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@mofarrell has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@xKerman
Copy link
Contributor Author

xKerman commented Aug 14, 2017

@mofarrell It has been over 2 weeks since this pull request was imported to Phabricator.
I would appreciate it if you let me know whether any updates are needed.

@@ -129,6 +160,42 @@ Array CodeCoverage::Report(bool sys /* = true */) {
return ret;
}

Array CodeCoverage::ReportExecutable() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both this and ReportDeadCode could go since all the bookkeeping would happen in m_hits, and be reported by Report.

auto lines = unit->getLinesWithCode();
TI().m_coverage->RecordAsNotDeadCode(filename, std::move(lines));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could go away, and their logic could be performed when initializing a new std::vector for the file in m_hits.

recordNotDeadCode(unit, filename);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be removed. The filter for initializing a new m_hits entry would handle this.
Also this will recompute the DeadCode, and ExecutableLines every time we switch back to a unit.

for (ArrayIter iter(merged); iter; ++iter) {
Array tmp = iter.second().toArray();
tmp->ksort(SORT_REGULAR, true);
ret.set(iter.first(), tmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should all be able to be left the same. Some filtering may need to happen for the DEAD or UNUSED values if the recording was being performed with it, then stopped without throwing away data, then restarted without DEAD and UNUSED data. I don't quite know xdebug's exact behavior there, but it might not show the older DEAD or UNUSED values.

@@ -288,6 +300,8 @@ struct RequestInjectionData {

bool m_debuggerAttached{false};
bool m_coverage{false};
bool m_coverageWithUnused{false};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum with possible states for coverage recording.

m_coverageWithDeadCode = flag;
updateJit();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All unneeded if collapsed with enum.

@mofarrell
Copy link
Contributor

@xKerman Sorry this has taken so long. I kept checking back after test results had expired. This looks like it is working well, but I feel like it would be cleaner to do all the book keeping in a single map. Rather than merging them at the end.

@xKerman
Copy link
Contributor Author

xKerman commented Aug 14, 2017

@mofarrell Thanks for your code review and comments.

it would be cleaner to do all the book keeping in a single map. Rather than merging them at the end.

I see, I will try to change to use a single map (m_hits) for reporting code coverage.

@xKerman xKerman changed the title fix xdebug coverage (part2): support XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE [WIP] fix xdebug coverage (part2): support XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE Aug 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants