Page MenuHomePhabricator

Use -fdebug-compilation-dir to form absolute paths in coverage mappings
ClosedPublic

Authored by rnk on Oct 9 2019, 2:43 PM.

Diff Detail

Event Timeline

rnk created this revision.Oct 9 2019, 2:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 9 2019, 2:43 PM
Herald added a subscriber: dexonsmith. · View Herald Transcript
vsk accepted this revision.Oct 9 2019, 4:34 PM

Thanks, lgtm!

In PR43614 I mentioned adding an extra argument to llvm-cov to specify the base directory. On second thought, the existing -path-equivalence option should make that unnecessary.

clang/test/CoverageMapping/debug-dir.cpp
15

Does the "[^/]" check work on Windows, or is something like "[^/\\]" necessary?

This revision is now accepted and ready to land.Oct 9 2019, 4:34 PM
rnk marked an inline comment as done.Oct 9 2019, 4:59 PM
rnk added inline comments.
clang/test/CoverageMapping/debug-dir.cpp
15

It is insufficient on Windows, but the full string looks like "\01\0Dfoobar\5Cdebug-dir.cpp, so [^/\\] would match the \0D. If the \0D is the same across all systems, I could match that and it would suffice. As is, this will catch absolute paths on Unix only, which could be enough coverage.

This revision was automatically updated to reflect the committed changes.
In D68733#1702609, @vsk wrote:

Thanks, lgtm!

In PR43614 I mentioned adding an extra argument to llvm-cov to specify the base directory. On second thought, the existing -path-equivalence option should make that unnecessary.

I just tested out this CL, and I don't think it's working correctly (even with -path-equivalence flag)

The command I used is:
/usr/local/google/home/liaoyuke/chromium/src/third_party/llvm-build/Release+Asserts/bin/llvm-cov show -format=html -output-dir=/usr/local/google/home/liaoyuke/chromium/src/out/output_test_path -instr-profile=/usr/local/google/home/liaoyuke/chromium/src/out/output_test_path/linux/coverage.profdata -path-equivalence=../..,/usr/local/google/home/liaoyuke/chromium/src out/coverage/base_unittests

And the generated html files are as following: https://imgur.com/gallery/dlgQXhy
Specifically, there are a few problems:

  1. The index.html files still show relative paths, but I'm expecting an absolute path given that I passed in the -path-equivalence flag.
  2. The file level line-by-line view's styling is completely off, there is no table and no highlights.
  3. I also tried the "llvm-cov export" command, it seems that it doesn't respect the -path-equivalence flag at all, and the produced json still uses relative paths in them. (I'm guessing the root cause is the same as 1)

Am I using the -path-equivalence flag correctly? And any other suggestions to work this around?

vsk added a comment.Tue, Oct 29, 10:25 AM
In D68733#1702609, @vsk wrote:

Thanks, lgtm!

In PR43614 I mentioned adding an extra argument to llvm-cov to specify the base directory. On second thought, the existing -path-equivalence option should make that unnecessary.

I just tested out this CL, and I don't think it's working correctly (even with -path-equivalence flag)

The command I used is:
/usr/local/google/home/liaoyuke/chromium/src/third_party/llvm-build/Release+Asserts/bin/llvm-cov show -format=html -output-dir=/usr/local/google/home/liaoyuke/chromium/src/out/output_test_path -instr-profile=/usr/local/google/home/liaoyuke/chromium/src/out/output_test_path/linux/coverage.profdata -path-equivalence=../..,/usr/local/google/home/liaoyuke/chromium/src out/coverage/base_unittests

Hi @liaoyuke, thanks for trying this out.

And the generated html files are as following: https://imgur.com/gallery/dlgQXhy
Specifically, there are a few problems:

  1. The index.html files still show relative paths, but I'm expecting an absolute path given that I passed in the -path-equivalence flag.

I have a question about the option you passed: -path-equivalence=../..,<local-path>. If I read this patch correctly, the final coverage mapping will contain (what looks like) absolute paths which are just rooted at the debug compilation dir. So, why remap ../.. instead of <debug-compilation-dir>?

  1. The file level line-by-line view's styling is completely off, there is no table and no highlights.

Interesting. Have you confirmed that the issue does not reproduce without -fdebug-compilation-dir/-path-equivalence?

  1. I also tried the "llvm-cov export" command, it seems that it doesn't respect the -path-equivalence flag at all, and the produced json still uses relative paths in them. (I'm guessing the root cause is the same as 1)

Hm, actually this could be a bug in llvm-cov. Reading through the source, it looks like the path remapping is done before the exporter is created, but perhaps I've missed something.

Am I using the -path-equivalence flag correctly? And any other suggestions to work this around?