Skip to content

Commit

Permalink
BEP: Also report the xml file in cached test
Browse files Browse the repository at this point in the history
When the result of a test is reported from cache, report
the full list of files. This requires knowing the exec
root for, e.g., the xml output file. Therefore, add this
path when constructing a cached TestResult.

--
Change-Id: Id448eacfe3cfd0d36c25a5344874de4dc57acee9
Reviewed-on: https://cr.bazel.build/8934
PiperOrigin-RevId: 147823951
MOS_MIGRATED_REVID=147823951
  • Loading branch information
aehlig authored and dslomov committed Feb 17, 2017
1 parent 1cb5059 commit 4afb4b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,6 @@ private final void finalizeTest(
@Override
public TestResult newCachedTestResult(
Path execRoot, TestRunnerAction action, TestResultData data) {
return new TestResult(action, data, /*cached*/ true);
return new TestResult(action, data, /*cached*/ true, execRoot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.rules.test.TestRunnerAction.ResolvedPaths;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus;
import com.google.devtools.build.lib.view.test.TestStatus.TestResultData;
import java.util.Collection;
import javax.annotation.Nullable;

/**
* This is the event passed from the various test strategies to the {@code RecordingTestListener}
Expand All @@ -38,18 +40,27 @@ public class TestResult {
private final TestRunnerAction testAction;
private final TestResultData data;
private final boolean cached;
@Nullable private final Path execRoot;

/**
* Construct the TestResult for the given test / status.
*
* @param testAction The test that was run.
* @param data test result protobuffer.
* @param cached true if this is a locally cached test result.
* @param execRooot The execution root in which the action was carried out; can be null, in which
* case everything depending on the execution root is ignored.
*/
public TestResult(TestRunnerAction testAction, TestResultData data, boolean cached) {
public TestResult(
TestRunnerAction testAction, TestResultData data, boolean cached, @Nullable Path execRoot) {
this.testAction = Preconditions.checkNotNull(testAction);
this.data = data;
this.cached = cached;
this.execRoot = execRoot;
}

public TestResult(TestRunnerAction testAction, TestResultData data, boolean cached) {
this(testAction, data, cached, null);
}

public static boolean isBlazeTestStatusPassed(BlazeTestStatus status) {
Expand Down Expand Up @@ -143,6 +154,12 @@ public Collection<Pair<String, Path>> getFiles() {
if (testAction.getTestLog().getPath().exists()) {
builder.add(Pair.of("test.log", testAction.getTestLog().getPath()));
}
if (execRoot != null) {
ResolvedPaths resolvedPaths = testAction.resolve(execRoot);
if (resolvedPaths.getXmlOutputPath().exists()) {
builder.add(Pair.of("test.xml", resolvedPaths.getXmlOutputPath()));
}
}
return builder.build();
}
}
2 changes: 2 additions & 0 deletions src/test/shell/integration/build_event_stream_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ function test_cached_test_results() {
|| fail "Clean testing pkg:true failed"
expect_log '^test_result'
expect_log 'name:.*test.log'
expect_log 'name:.*test.xml'
expect_log_once '^progress '
expect_not_log 'aborted'
bazel test --experimental_build_event_text_file=$TEST_log pkg:true \
|| fail "Second testing of pkg:true failed"
expect_log '^test_result'
expect_log 'name:.*test.log'
expect_log 'name:.*test.xml'
expect_log_once '^progress '
expect_not_log 'aborted'
}
Expand Down

0 comments on commit 4afb4b5

Please sign in to comment.