-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Support coverage #1118
Comments
From the lcov docs, I'd have gone for lcov -a, not lcov --capture. |
Any update on this? I'm very interested in gathering code coverage using Bazel in the near future. It looks like the 0.6 release is slated for 2016-11 assuming that the roadmap is up to date. How could I gather code coverage metrics for my code in Bazel if I needed it in the next month or two? |
No updates. We'll likely not be able to work on this before October. Java or C++ code? Or some other language? |
C++. I see some support for
|
Is that a build or a test run? Can you give the bazel command lines you're running? |
I made a really simple test workspace to test on:
So, curiously, the build and test passed but the test command exited with 1 because
|
I also found
|
is this being processed? |
Sorry forgot to assign it but @hermione521 is working on it this quarter. |
Also /cc @lberki |
Just in case anybody was wondering or wanted to get some code coverage support before it's fully incorporated into Bazel, I came up with a usable workaround:
I left out a lot of details but that's the general approach that is mostly working for me. |
…and. Progress on #1118. -- MOS_MIGRATED_REVID=140121703
- open source CoverageCommand.java - add a collect-coverage.sh script - update test-setup.sh to be compatible with the coverage collector - update StandaloneTestStrategy to provide the necessary env variables - update StandaloneTestStrategy to set the right command line for coverage - add support for C++ coverage An HTML report can then be generated with genhtml like this: genhtml -o report/ -p "$(readlink -f bazel-<project>)" path/to/coverage.dat Progress on #1118. -- MOS_MIGRATED_REVID=140125715
Progress on #1118. -- MOS_MIGRATED_REVID=140128848
With the above patches, I was able to get C++ coverage results on Linux, with a local install of lcov (it currently uses a hard-coded path to lcov). We have a follow-up change to add support for Java / Jacoco. |
looks like the code is there (thanks!), but I couldn't find any documentation. |
also, I can't find anything to generate HTML reports. Or is there a standard tool to interpret the .dat files that I overlooked? |
I've been testing the C++ coverage with the lcov HTML generator. See here:
http://ltp.sourceforge.net/coverage/lcov.php
Instructions are in the commit description, commit
8829aba.
…On Mon, Jan 30, 2017 at 7:05 PM, Han-Wen Nienhuys ***@***.***> wrote:
also, I can't find anything to generate HTML reports. Or is there a
standard tool to interpret the .dat files that I overlooked?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1118 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHA9YdP4FndI1S_nEUN0F6NW43QK8Zdzks5rXiZngaJpZM4H_9LK>
.
|
I get failing tests without this flag in coverage mode. Workaround is to pass --linkopt=-fprofile-arcs in Bazel. Here are the steps that work at this time (with this change): bazel coverage --strategy=TestRunner=standalone //my/funky:test genhtml -o report-output-directory/ path/to/coverage.dat Some progress on #1118. PiperOrigin-RevId: 193193164
I'm trying to get coverage reports for a C++ project on OS X 10.12.6.
When I try and us either
It appears to occur because bazel/tools/cpp/crosstool_lib.bzl Line 256 in 5cee7f4
This appears related to this issue: #2275 As a work around, I explicitly changed my build rule to be:
with the hope that I could then collect the
Note the double slash. This appears to largely be a permissions issue, but I can't for the life of me figure out how to fix this. By contrast, when I locate the
This is to say that gcov appears to be working fine. I just can't figure out how to get bazel to directly write these files for me, where to find them, or where to get the |
In collect_coverage.sh, path to lcov is hardcoded. Can we make it configurable some how? Maybe just use PATH, or an environment variable. On darwin, it is not easy to install lcov to /usr/bin. Using brew or other package managers will install it in /usr/local/bin or some other location. bazel/tools/test/collect_coverage.sh Line 149 in 1441a3a
|
@siddharthab that's fair. It's not obvious to me how best to do that. We probably need to create a 'coverage toolchain' to put everything in the right place, but we might get away with piggybacking on the cc_configure script for now. |
Actually I realised that on macOS, we will mostly be taking the llvm coverage path. So this might not be that important. I was hitting this only because the stat command in the if clause has an extra flag for bsd stat. |
I made some recent changes that should improve the llvm coverage path. I think they're not released yet. See #5036 (also contains rudimentary instructions for how to use it). Let me know if that works for you. |
Yes, I was able to get coverage reports on macOS with llvm following your instructions with just one patch -- #5162 I also needed to remove sandbox directory segments from the paths in the profdata file but other than that, everything worked as you said. |
A question: do you plan on keeping coverage.dat as lcov intermediate format. Are all languages expected to do the same? I am asking because some of us are trying to pipe coverage information from coverage.dat to end user presentation systems. But I am not sure which format to expect in coverage.dat. |
I'm not sure. @iirina is currently working on this, and we'll send out a proposal soon. |
I'd second @siddharthab's concern from earlier, some environments still don't have |
@eugene-bulkin Note that lcov is only needed when using gcc as the compiler. So if your different environment happens to be macOS and you are using the default toolchain, or if you are using an LLVM toolchain, then you don't really need it. |
@siddharthab My environment, for example, does use gcc as the compiler, so it still might help some people to take it from an environment variable or toolchain. |
There isn't a way to inject the path to lcov at the moment. It is straightforward to add an env variable for this, but I'd like to hear from Irina first. |
I'm currently doing some performance measurements to see if it's worth keeping |
Any indications on whether lcov is here to stay? I'm trying to integrate code coverage into our CI pipeline and wondering if we should wait. |
@iirina has a doc (which she unfortunately hasn't shared yet), where she proposes that we should go with cobertura XML as the format. We've been looking at gcovr to generate it from C/C++ coverage, and there are a lot of other tools available as well. |
Here is the document. Please comment, any feedback is welcomed. We'll gradually change the standard coverage format to Cobertura XML. Both lcov and Cobertura XML will be available for a transitioning period. |
Could the code coverage approach also consider an interface for setting up static analysis tools (e.g. |
Very much looking forward to this. Will this new set of work include collecting baseline coverage? |
I will close this issue since its scope is very wide. To track code coverage progress you can check:
Further issues have the coverage label. |
We've gotten a number of requests to support coverage. Here's an email I wrote in response to one of those requests, which I'm reposting here as a feature request:
Ideally, we'd want blaze coverage to exist and work in Bazel, just as it does in Blaze. The code is mostly there, but not quite. The coverage command itself doesn't actually do a lot of work; it sets --collect_code_coverage and a default --instrumentation_filter, and it optionally runs a tool to generate an HTML report (which is almost never used internally, where we push to a service instead). Otherwise it's identical to the test command, and the two flags can be manually set.
Internally, we have a wrapper script (collect_coverage.sh) that wraps an individual test invocation and uses a tool (lcov_merger.par) to merge the coverage data from that invocation, which both aren't in Bazel, and Bazel also doesn't setup the environment correctly to tell the wrapper script about output locations (StandaloneTestStrategy.java).
If you actually tried, you'd get an error like this one:
ERROR: /usr/local/google/home/ulfjack/Projects/os-bazel/src/test/cpp/BUILD:5:1: output 'src/test/cpp/blaze_util_test/coverage.dat' was not created.
It doesn't seem very hard to make the necessary Bazel changes, but we can't export the scripts as-is.
From my reading of the lcov documentation, lcov --capture looks a lot like what lcov_merger.par does, though I can't be completely certain (the docs are a bit scarce). It may make sense for us to integrate with lcov rather than export lcov_merger.par (or rewrite from scratch).
The text was updated successfully, but these errors were encountered: