rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

Code coverage generating empty output

Open rajukrishnamurthy opened this issue 3 years ago • 10 comments

Hi All,

It looks like Kotlin code coverage support started with rules_kotlin v1.5.0, however, bazel coverage only seems to generate empty a coverage.dat file.

bazel: v6.0 rules_kotlin: v1.7.1 arch: Apple M1 OS: Ventura 13.0.1

I'm sure if I'm missing some command line args, but I've tried --combined_report=lcov various versions of --instrumentation_filter=... and --coverage_report_generator=... to no avail. The test target is kt_jvm_test()

Typical output looks like:

INFO: Analyzed 5 targets (86 packages loaded, 4235 targets configured).
INFO: Found 4 targets and 1 test target...
INFO: LCOV coverage report is located at /private/var/tmp/_bazel_rajuk/eef25f2a7f459c920141f1db7bb3e91d/execroot/videoamp/bazel-out/_coverage/_coverage_report.dat
 and execpath is bazel-out/_coverage/_coverage_report.dat
INFO: From Coverage report generation:
Feb 07, 2023 7:26:57 PM com.google.devtools.coverageoutputgenerator.Main getTracefiles
INFO: Found 1 tracefiles.
Feb 07, 2023 7:26:57 PM com.google.devtools.coverageoutputgenerator.Main parseFilesSequentially
INFO: Parsing file bazel-out/darwin_arm64-fastbuild/testlogs/demos/kotlinspark/test/coverage.dat
Feb 07, 2023 7:26:57 PM com.google.devtools.coverageoutputgenerator.Main getGcovInfoFiles
INFO: No gcov info file found.
Feb 07, 2023 7:26:57 PM com.google.devtools.coverageoutputgenerator.Main getGcovJsonInfoFiles
INFO: No gcov json file found.
Feb 07, 2023 7:26:57 PM com.google.devtools.coverageoutputgenerator.Main getProfdataFileOrNull
INFO: No .profdata file found.
Feb 07, 2023 7:26:57 PM com.google.devtools.coverageoutputgenerator.Main runWithArgs
WARNING: There was no coverage found.

Let me know if I can provide more info.

rajukrishnamurthy avatar Feb 09 '23 23:02 rajukrishnamurthy

I confirm that coverage with kotlin is not working

kaskabayev avatar Feb 27 '23 19:02 kaskabayev

My setup is:

(base) ➜  project git:(master) ✗ bazel version
Bazelisk version: v1.11.0
Starting local Bazel server and connecting to it...
Build label: 5.4.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Dec 15 16:22:52 2022 (1671121372)
Build timestamp: 1671121372
Build timestamp as int: 1671121372
rules_kotlin_version = "v1.7.1"

logs of bazel coverage :target:

INFO: LCOV coverage report is located at /private/var/tmp/_bazel_madiyar.kaskabayev/2621012ef60840fd51958fb96a7e2d23/execroot/$PROJECT/bazel-out/_coverage/_coverage_report.dat
 and execpath is bazel-out/_coverage/_coverage_report.dat
INFO: From Coverage report generation:
Feb 28, 2023 5:01:58 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator getTracefiles
INFO: Found 1 tracefiles.
Feb 28, 2023 5:01:58 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator parseFilesSequentially
INFO: Parsing file bazel-out/darwin-fastbuild/testlogs/__PATH__TO__COVERAGE__FILE__OF__TEST
Feb 28, 2023 5:01:58 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator getGcovInfoFiles
INFO: No gcov info file found.
Feb 28, 2023 5:01:58 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator getGcovJsonInfoFiles
INFO: No gcov json file found.
Feb 28, 2023 5:01:58 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator getProfdataFileOrNull
INFO: No .profdata file found.
Feb 28, 2023 5:01:58 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator runWithArgs
WARNING: There was no coverage found.

.bazelrc

...
# coverage
coverage --instrument_test_targets
coverage --combined_report=lcov
coverage --coverage_report_generator=@com_github_zetten_bazel_sonarqube//:sonarqube_coverage_generator

kaskabayev avatar Feb 28 '23 16:02 kaskabayev

I just verified that this is still working for us in our codebase for both JVM and Android targets using the following command:

➜ bazel test //instant-processors/skabbard-ksp/compiler:test --collect_code_coverage --instrument_test_targets=false --instrumentation_filter="^//(todo fill in the target regex you want to be included)/.*[/:]"
...
//instant-processors/skabbard-ksp/compiler:test                          PASSED in 27.2s
  /private/var/tmp/_bazel_blee/499a001013731d09bffd82f8601a3161/execroot/instantandroid/bazel-out/darwin_arm64-dbg/testlogs/instant-processors/skabbard-ksp/compiler/test/coverage.dat
➜ cat /private/var/tmp/_bazel_blee/499a001013731d09bffd82f8601a3161/execroot/instantandroid/bazel-out/darwin_arm64-dbg/testlogs/instant-processors/skabbard-ksp/compiler/test/coverage.dat | wc -l
   18760

Note that this won't work for Android targets unless you have this commit https://github.com/bazelbuild/bazel/pull/15840

Bencodes avatar Mar 06 '23 18:03 Bencodes

@rajukrishnamurthy and @kaskabayev -- are you using android?

restingbull avatar Mar 17 '23 20:03 restingbull

Some more discussion on this topic happened over here that everyone might find useful https://bazelbuild.slack.com/archives/CE6AZ22NR/p1677512521618239

Bencodes avatar Mar 17 '23 20:03 Bencodes

@rajukrishnamurthy and @kaskabayev -- are you using android?

Sorry for the slow response, we are exploring kotlin for developing ETL pipelines and not any android dev.

rajukrishnamurthy avatar Mar 21 '23 15:03 rajukrishnamurthy

@rajukrishnamurthy and @kaskabayev -- are you using android?

hey, sorry for the slow response, no, I am using kotlin, not for android

kaskabayev avatar Mar 21 '23 15:03 kaskabayev

Did you ever get it to work? We have the same issue

fgrosse avatar Aug 18 '23 14:08 fgrosse

Did you ever get it to work? We have the same issue

No I haven't had any luck, it's not urgent for us since we aren't actively writing production code with kotlin.

@restingbull I just noticed that the status was changed to "needs more information", not sure what additional information is required.

rajukrishnamurthy avatar Nov 16 '23 20:11 rajukrishnamurthy

It seems since Bazel 7.0.0 report is no longer empty. However Test files are in the report

geaden avatar Dec 25 '23 07:12 geaden