From 8d25362bcb49286feb546b306657b6453712f2b3 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 2 Nov 2016 17:24:46 +0000 Subject: Also provide test summaries in the build-event stream For each test target, also have a test summary as children to this event. As test summaries are posted on the event bus anyway, it is enough to make then an instance of BuildEvent. -- Change-Id: Id53e5f1760548a1fa621b1667fdb4470f51a52e8 Reviewed-on: https://bazel-review.googlesource.com/#/c/6931 MOS_MIGRATED_REVID=137961100 --- .../build/lib/analysis/TargetCompleteEvent.java | 4 +++ .../build/lib/buildeventstream/BuildEventId.java | 9 +++++ .../proto/build_event_stream.proto | 21 +++++++++++ .../devtools/build/lib/runtime/TestSummary.java | 42 ++++++++++++++++++---- 4 files changed, 69 insertions(+), 7 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java index ae1327d31e..453127c9f7 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.causes.Cause; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; +import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.skyframe.SkyValue; import java.util.Collection; @@ -85,6 +86,9 @@ public final class TargetCompleteEvent implements SkyValue, BuildEvent { for (Cause cause : getRootCauses()) { childrenBuilder.add(BuildEventId.fromCause(cause)); } + if (TargetUtils.isTestRule(target.getTarget())) { + childrenBuilder.add(BuildEventId.testSummary(target.getTarget().getLabel())); + } return childrenBuilder.build(); } diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java index efa7e1c24d..7a1ee66e81 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java @@ -105,4 +105,13 @@ public final class BuildEventId implements Serializable { public static BuildEventId fromCause(Cause cause) { return new BuildEventId(cause.getIdProto()); } + + public static BuildEventId testSummary(Label target) { + BuildEventStreamProtos.BuildEventId.TestSummaryId summaryId = + BuildEventStreamProtos.BuildEventId.TestSummaryId.newBuilder() + .setLabel(target.toString()) + .build(); + return new BuildEventId( + BuildEventStreamProtos.BuildEventId.newBuilder().setTestSummary(summaryId).build()); + } } diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto index c5593f7586..af48728ab1 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto @@ -68,6 +68,11 @@ message BuildEventId { string primary_output = 1; } + // Identifier of an event reporting the summary of a test. + message TestSummaryId { + string label = 1; + } + oneof id { UnknownBuildEventId unknown = 1; ProgressId progress = 2; @@ -75,6 +80,7 @@ message BuildEventId { PatternExpandedId pattern = 4; TargetCompletedId target_completed = 5; ActionCompletedId action_completed = 6; + TestSummaryId test_summary = 7; } } @@ -186,6 +192,20 @@ message TargetComplete { bool success = 1; } +// Payload of the event summarizing a test. +// TODO(aehlig): extend event with additional information as soon as we known +// which additional information we need for test summaries. +message TestSummary { + // Total number of runs + int32 total_run_count = 1; + + // Path to logs of passed runs. + repeated File passed = 3; + + // Path to logs of failed runs; + repeated File failed = 4; +} + // Message describing a build event. Events will have an identifier that // is unique within a given build invocation; they also announce follow-up // events as children. More details, which are specific to the kind of event @@ -201,5 +221,6 @@ message BuildEvent { PatternExpanded expanded = 6; ActionExecuted action = 7; TargetComplete completed = 8; + TestSummary test_summary = 9; }; } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/TestSummary.java b/src/main/java/com/google/devtools/build/lib/runtime/TestSummary.java index b7fb391c94..5b78bef4ff 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/TestSummary.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/TestSummary.java @@ -20,29 +20,32 @@ import com.google.common.collect.Multimap; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.FilesToRunProvider; +import com.google.devtools.build.lib.buildeventstream.BuildEvent; +import com.google.devtools.build.lib.buildeventstream.BuildEventId; +import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; +import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter.Mode; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus; import com.google.devtools.build.lib.view.test.TestStatus.FailedTestCasesStatus; import com.google.devtools.build.lib.view.test.TestStatus.TestCase; - import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.TreeMap; /** - * Test summary entry. Stores summary information for a single test rule. - * Also used to sort summary output by status. + * Test summary entry. Stores summary information for a single test rule. Also used to sort summary + * output by status. * - *

Invariant: - * All TestSummary mutations should be performed through the Builder. - * No direct TestSummary methods (except the constructor) may mutate the object. + *

Invariant: All TestSummary mutations should be performed through the Builder. No direct + * TestSummary methods (except the constructor) may mutate the object. */ @VisibleForTesting // Ideally package-scoped. -public class TestSummary implements Comparable { +public class TestSummary implements Comparable, BuildEvent { /** * Builder class responsible for creating and altering TestSummary objects. */ @@ -446,4 +449,29 @@ public class TestSummary implements Comparable { ? Mode.INFO : (status == BlazeTestStatus.FLAKY ? Mode.WARNING : Mode.ERROR); } + + @Override + public BuildEventId getEventId() { + return BuildEventId.testSummary(target.getTarget().getLabel()); + } + + @Override + public Collection getChildrenEvents() { + return ImmutableList.of(); + } + + @Override + public BuildEventStreamProtos.BuildEvent asStreamProto() { + BuildEventStreamProtos.TestSummary.Builder summaryBuilder = + BuildEventStreamProtos.TestSummary.newBuilder().setTotalRunCount(totalRuns()); + for (Path path : getFailedLogs()) { + summaryBuilder.addFailed( + BuildEventStreamProtos.File.newBuilder().setUri(path.toString()).build()); + } + for (Path path : getPassedLogs()) { + summaryBuilder.addPassed( + BuildEventStreamProtos.File.newBuilder().setUri(path.toString()).build()); + } + return GenericBuildEvent.protoChaining(this).setTestSummary(summaryBuilder.build()).build(); + } } -- cgit v1.2.3