Skip to content

Commit 3dd2b93

Browse files
philsccopybara-github
authored andcommitted
Fix null pointer crash with bazel coverage on only incompatible tests
This is a follow-up to 2f1ff6f. That patch accidentally introduced a crash when running coverage on tests where all tests are incompatible. FATAL: bazel crashed due to an internal error. Printing stack trace: java.lang.NullPointerException: Null reportGenerator at com.google.devtools.build.lib.bazel.coverage.AutoValue_CoverageArgs.<init>(AutoValue_CoverageArgs.java:68) at com.google.devtools.build.lib.bazel.coverage.CoverageArgs.create(CoverageArgs.java:58) at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.createCoverageActionsWrapper(CoverageReportActionBuilder.java:226) at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.createCoverageReportActionsWrapper(BazelCoverageReportModule.java:98) at com.google.devtools.build.lib.analysis.BuildView.createResult(BuildView.java:558) at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:492) at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:227) at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:137) at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:266) at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:506) at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:474) at com.google.devtools.build.lib.runtime.commands.TestCommand.doTest(TestCommand.java:148) at com.google.devtools.build.lib.runtime.commands.TestCommand.exec(TestCommand.java:113) at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:584) at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:231) at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:550) at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$1(GrpcServerImpl.java:614) at io.grpc.Context$1.run(Context.java:566) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) This patch fixes the crash by handling the situation properly. This results in all tests being skipped and reported as being skipped. A new test validates the correct behaviour. Closes #15645. PiperOrigin-RevId: 454132787 Change-Id: Id1cd4109f96d90bbdc114b0bbe7f5c5046d47c27
1 parent c945c16 commit 3dd2b93

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/main/java/com/google/devtools/build/lib/bazel/coverage/CoverageReportActionBuilder.java

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ public CoverageReportActionsWrapper createCoverageActionsWrapper(
212212
reportGenerator = testParams.getCoverageReportGenerator();
213213
}
214214
}
215+
// If all tests are incompatible, there's nothing to do.
216+
if (reportGenerator == null) {
217+
return null;
218+
}
215219
builder.addAll(baselineCoverageArtifacts.toList());
216220

217221
ImmutableList<Artifact> coverageArtifacts = builder.build();

src/test/shell/bazel/bazel_coverage_compatibility_test.sh

+35-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ constraint_setting(name = "incompatible_setting")
2828
constraint_value(
2929
name = "incompatible",
3030
constraint_setting = ":incompatible_setting",
31+
visibility = ["//visibility:public"],
3132
)
3233
3334
sh_test(
@@ -40,6 +41,11 @@ sh_test(
4041
srcs = ["incompatible_test.sh"],
4142
target_compatible_with = [":incompatible"],
4243
)
44+
45+
exports_files([
46+
"compatible_test.sh",
47+
"incompatible_test.sh",
48+
])
4349
EOF
4450
cat <<EOF > compatible_test.sh
4551
#!/bin/bash
@@ -51,17 +57,44 @@ exit 1
5157
EOF
5258
chmod +x compatible_test.sh
5359
chmod +x incompatible_test.sh
60+
61+
mkdir all_incompatible/
62+
cat <<EOF > all_incompatible/BUILD
63+
sh_test(
64+
name = "incompatible1_test",
65+
srcs = ["//:incompatible_test.sh"],
66+
target_compatible_with = ["//:incompatible"],
67+
)
68+
69+
sh_test(
70+
name = "incompatible2_test",
71+
srcs = ["//:incompatible_test.sh"],
72+
target_compatible_with = ["//:incompatible"],
73+
)
74+
EOF
5475
}
5576

56-
# Validates that coverage skips incompatible tests. This is a regression test for
57-
# https://github.com/bazelbuild/bazel/issues/15385.
77+
# Validates that coverage skips incompatible tests. This is a regression test
78+
# for https://github.com/bazelbuild/bazel/issues/15385.
5879
function test_sh_test_coverage() {
5980
set_up_sh_test_coverage
6081
bazel coverage --test_output=all --combined_report=lcov //:all &>$TEST_log \
6182
|| fail "Coverage for //:all failed"
6283
expect_log "INFO: Build completed successfully"
6384
expect_log "//:compatible_test .* PASSED"
6485
expect_log "//:incompatible_test .* SKIPPED"
86+
expect_log "Executed 1 out of 2 tests: 1 were skipped"
87+
}
88+
89+
# Validates that coverage correctly handles all tests being incompatible.
90+
function test_sh_test_coverage() {
91+
set_up_sh_test_coverage
92+
bazel coverage --test_output=all --combined_report=lcov //all_incompatible:all &>$TEST_log \
93+
|| fail "Coverage for //:all failed"
94+
expect_log "INFO: Build completed successfully"
95+
expect_log "//all_incompatible:incompatible1_test .* SKIPPED"
96+
expect_log "//all_incompatible:incompatible2_test .* SKIPPED"
97+
expect_log "Executed 0 out of 2 tests: 2 were skipped"
6598
}
6699

67100
run_suite "test tests"

0 commit comments

Comments
 (0)