aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2016-11-02 17:24:46 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-11-02 17:28:04 +0000
commit8d25362bcb49286feb546b306657b6453712f2b3 (patch)
tree1969c243185b72476f22d6d4f22b511a269b6c78 /src/main/java/com/google/devtools/build/lib
parent2d431b4a80cb702a6538864db762e0956251c0a4 (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto21
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/TestSummary.java42
4 files changed, 69 insertions, 7 deletions
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.
*
- * <p>Invariant:
- * All TestSummary mutations should be performed through the Builder.
- * No direct TestSummary methods (except the constructor) may mutate the object.
+ * <p>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<TestSummary> {
+public class TestSummary implements Comparable<TestSummary>, BuildEvent {
/**
* Builder class responsible for creating and altering TestSummary objects.
*/
@@ -446,4 +449,29 @@ public class TestSummary implements Comparable<TestSummary> {
? Mode.INFO
: (status == BlazeTestStatus.FLAKY ? Mode.WARNING : Mode.ERROR);
}
+
+ @Override
+ public BuildEventId getEventId() {
+ return BuildEventId.testSummary(target.getTarget().getLabel());
+ }
+
+ @Override
+ public Collection<BuildEventId> 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();
+ }
}