-
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
genhtml can't find Java source files when generating a coverage report #2528
Comments
this is on ubuntu (google laptop version) |
on my workstation $ bazel coverage --test_strategy=standalone --test_output=streamed //gerrit-common:auto_value_tests OK (1 test) BazelTestRunner exiting with a return value of 0 -- JVM shutdown starting at 2017-02-13 15:43:31 -- Feb 13, 2017 3:43:31 PM com.google.devtools.lcovmerger.LcovMerger merge |
in the latter case, there is a coverage.dat file, but it is empty. Do we need to tweak the test runner somehow to generate the coverage file? |
(i'm sorry, these are really two bugs. I'm personally more interested in the latter problem.) |
quick update: it's not supported now bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java Line 291 in 67f0f4b
I'll check how to make it happen. |
for now, I'd be satisfied if we could just skip the srcjar. They're only used for autovalue, so they shouldn't affect the coverage much. |
ping? could you provide a time estimate and/or a workaround? |
Sorry, I'm focused on benchmark now. But I will do it before I leave! (which means next month) |
The auto_value_tests doesn't have any code for which Bazel could collect coverage. I'm not sure why we report an error if there's no coverage, I think in Blaze we're only reporting a warning. In any case, I looked for a test that does have sources:
This gives more interesting output. The test is marked as passed, but there's a stack trace in the log: Exception in thread "Thread-0" java.lang.VerifyError: Bad type on operand stack
That's certainly a bug, but I have no idea where that might be coming from. |
Somehow, Bazel built from HEAD ends up with a broken JacocoCoverage_deploy.jar. Dunno why, but I get better results with a JacocoCoverage_deploy.jar built from head. JUnit4 Test Runner OK (2 tests) BazelTestRunner exiting with a return value of 0 -- JVM shutdown starting at 2017-03-10 12:03:32 -- Mar 10, 2017 12:03:33 PM com.google.devtools.lcovmerger.LcovMerger merge |
Ah, my bad. I didn't delete the old lcov files. I got coverage results now. |
I filed #2663 for the deploy jar issue. With that fixed, I get coverage results for //gerrit-sshd:sshd_tests. |
I can get an HTML coverage report with:
Source doesn't work because the file names are all wrong. It would be good if we could fix that. |
Ulf, this is still broken for me in 0.4.5, which is newer than your update. hanwen@han-wen: OK (2 tests) BazelTestRunner exiting with a return value of 0 -- JVM shutdown starting at 2017-04-27 12:55:53 -- Exception in thread "Thread-0" java.lang.VerifyError: Bad type on operand stack
Target //gerrit-sshd:sshd_tests up-to-date: Executed 1 out of 1 test: 1 test passes. |
I can get some output using 0.5.0rc3. Is there a blessed way to get genhtml to find source code, or do I have to piece together a source tree by myself? $ genhtml -o report/ -p "$(readlink -f bazel-gerrit)" bazel-testlogs/gerrit-sshd/sshd_tests/coverage.dat |
Progress! Unfortunately, Javac doesn't put the full relative path into the class files, which is not ideal, and on top of that, genhtml doesn't support looking for files under a custom prefix (or a list of prefixes), and, even if it did, we wouldn't know which prefixes. Ideally, we'd hack Javac to output the relative path, although it's technically in violation of the spec. @cushon Suggestions? |
genhtml is a Perl script (shudder), and reads files serially (sigh.). Do you know of any newer tools to process this data? Is there maybe documentation for the file format of the .dat files so I can whip up my own? |
I think it would be easiest to get all srcjars and then look inside them for the filenames. That also sidesteps the problem of how to deal with generated source code. |
The .dat files are in gcov format, I think, which is not difficult to parse. There are dozens of tools, but I'm not aware of any good tools to generate a report. We've had other reports about genhtml that make it sound like we may have to open source the tool we're using internally or write a new one from scratch. Note that we currently never collect coverage for generated files. |
@ulfjack - JVMS 4.7.10 makes it clear that's deliberate, so if it's possible to handle another way that'd be better. We're already writing a
|
see https://gerrit-review.googlesource.com/c/106471/ . From my perspective we can close this now |
I've changed the title and will reuse this bug for the problem that genhtml can't find the Java source files with the default configuration. It's great that you found a workaround, but it's not ideal in the medium term. |
@cushon we need to know the relative path to the source file for each class file, ideally even if there are multiple classes with the same name. Ideally, the coverage tool will output the correct relative path, which means we need to pass this information to the coverage tool itself. It would seem cleaner to put this information into the class file itself. If we can't use SourceName, that's fine, as long as we can put it somewhere - maybe SourceDebugExtension? Or maybe we could add a custom tag? |
After recent work, this command will generate a beautiful combined coverage
But if suffers from all the issues here.
Is there a now-recommended way to visualize the coverage output? |
Running coverage with [1]:
|
For me:
followed by
followed by
|
That's great to hear @dhalperi! I will close this issue. If anyone is still having troubles with |
Please provide the following information. The more we know about your system and use case, the more easily and likely we can help.
Description of the problem / feature request / question:
$ git clone --recursive https://gerrit.googlesource.com/gerrit
$ cd gerrit
$ bazel version
Build label: 0.4.4
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Feb 1 18:54:21 2017 (1485975261)
Build timestamp: 1485975261
Build timestamp as int: 1485975261
$ bazel coverage --test_output=streamed //gerrit-common:auto_value_tests
.........
WARNING: Streamed test output requested so all tests will be run locally, without sharding, one at a time.
INFO: Using default value for --instrumentation_filter: "//gerrit-common".
INFO: Override the above default with --instrumentation_filter
INFO: Found 1 test target...
JUnit4 Test Runner
.
Time: 0.027
OK (1 test)
BazelTestRunner exiting with a return value of 0
JVM shutdown hooks (if any) will run now.
The JVM will exit once they complete.
-- JVM shutdown starting at 2017-02-13 15:38:40 --
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/devtools/lcovmerger/Main : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
FAIL: //gerrit-common:auto_value_tests (see /home/hanwen/.cache/bazel/_bazel_hanwen/9590700e58e6cc9bff046cc6a346bc64/execroot/gerrit/bazel-out/local-fastbuild/testlogs/gerrit-common/auto_value_tests/test.log).
Target //gerrit-common:auto_value_tests up-to-date:
bazel-bin/gerrit-common/auto_value_tests.jar
bazel-bin/gerrit-common/auto_value_tests
If asking a question or requesting a feature, also tell us about the underlying problem you're trying to solve.
If possible, provide a minimal example to reproduce the problem:
Environment info
Operating System:
Bazel version (output of
bazel info release
):If
bazel info release
returns "development version" or "(@non-git)", please tell us what source tree you compiled Bazel from; git commit hash is appreciated (git rev-parse HEAD
):Have you found anything relevant by searching the web? (e.g. GitHub issues, email threads in the bazel-discuss@googlegroups.com archive)
Anything else, information or logs or outputs that would be helpful?
(If they are large, please upload as attachment or provide link).
The text was updated successfully, but these errors were encountered: