use of com.google.devtools.build.lib.rules.test.TestResult in project bazel by bazelbuild.
the class StandaloneTestStrategy method processFailedTestAttempt.
private void processFailedTestAttempt(int attempt, Executor executor, TestRunnerAction action, Builder dataBuilder, TestResultData data, FileOutErr outErr) throws IOException {
ImmutableList.Builder<Pair<String, Path>> testOutputsBuilder = new ImmutableList.Builder<>();
// Rename outputs
String namePrefix = FileSystemUtils.removeExtension(action.getTestLog().getExecPath().getBaseName());
Path attemptsDir = action.getTestLog().getPath().getParentDirectory().getChild(namePrefix + "_attempts");
attemptsDir.createDirectory();
String attemptPrefix = "attempt_" + attempt;
Path testLog = attemptsDir.getChild(attemptPrefix + ".log");
if (action.getTestLog().getPath().exists()) {
action.getTestLog().getPath().renameTo(testLog);
testOutputsBuilder.add(Pair.of("test.log", testLog));
}
ResolvedPaths resolvedPaths = action.resolve(executor.getExecRoot());
if (resolvedPaths.getXmlOutputPath().exists()) {
Path destinationPath = attemptsDir.getChild(attemptPrefix + ".xml");
resolvedPaths.getXmlOutputPath().renameTo(destinationPath);
testOutputsBuilder.add(Pair.of("test.xml", destinationPath));
}
// Add the test log to the output
dataBuilder.addFailedLogs(testLog.toString());
dataBuilder.addTestTimes(data.getTestTimes(0));
dataBuilder.addAllTestProcessTimes(data.getTestProcessTimesList());
executor.getEventBus().post(new TestAttempt(action, attempt, data.getTestPassed(), data.getRunDurationMillis(), testOutputsBuilder.build(), false));
processTestOutput(executor, outErr, new TestResult(action, data, false), testLog);
}
use of com.google.devtools.build.lib.rules.test.TestResult in project bazel by bazelbuild.
the class TestResultAnalyzerTest method testIncrementalAnalyzeKeepsActionRanTrueWhenAlreadyTrueAndNewCachedResults.
@Test
public void testIncrementalAnalyzeKeepsActionRanTrueWhenAlreadyTrueAndNewCachedResults() {
TestSummary.Builder summaryBuilder = makeTestSummaryBuilder().setActionRan(true);
TestResultData testResultData = TestResultData.newBuilder().setRemotelyCached(true).build();
TestResult result = new TestResult(mock(TestRunnerAction.class), testResultData, /*cached=*/
true);
TestSummary.Builder newSummaryBuilder = underTest.incrementalAnalyze(summaryBuilder, result);
assertTrue(newSummaryBuilder.peek().actionRan());
}
use of com.google.devtools.build.lib.rules.test.TestResult in project bazel by bazelbuild.
the class StandaloneTestStrategy method finalizeTest.
private final void finalizeTest(ActionExecutionContext actionExecutionContext, TestRunnerAction action, TestResultData data) throws IOException, ExecException {
TestResult result = new TestResult(action, data, false);
postTestResult(actionExecutionContext.getExecutor(), result);
processTestOutput(actionExecutionContext.getExecutor(), actionExecutionContext.getFileOutErr(), result, result.getTestLogPath());
if (!executionOptions.testKeepGoing && data.getStatus() != BlazeTestStatus.FLAKY && data.getStatus() != BlazeTestStatus.PASSED) {
throw new TestExecException("Test failed: aborting");
}
}
use of com.google.devtools.build.lib.rules.test.TestResult in project bazel by bazelbuild.
the class TestResultAnalyzer method aggregateAndReportSummary.
/**
* Helper for differential analysis which aggregates the TestSummary
* for an individual target, reporting runs on the EventBus if necessary.
*/
private TestSummary.Builder aggregateAndReportSummary(ConfiguredTarget testTarget, AggregatingTestListener listener) {
// If already reported by the listener, no work remains for this target.
TestSummary.Builder summary = listener.getCurrentSummary(testTarget);
Label testLabel = testTarget.getLabel();
Preconditions.checkNotNull(summary, "%s did not complete test filtering, but has a test result", testLabel);
if (listener.targetReported(testTarget)) {
return summary;
}
Collection<Artifact> incompleteRuns = listener.getIncompleteRuns(testTarget);
Map<Artifact, TestResult> statusMap = listener.getStatusMap();
// will be represented by separate artifacts and will produce exactly one TestResult.
for (Artifact testStatus : TestProvider.getTestStatusArtifacts(testTarget)) {
// When a build is interrupted ( eg. a broken target with --nokeep_going ) runResult could
// be null for an unrelated test because we were not able to even try to execute the test.
// In that case, for tests that were previously passing we return null ( == NO STATUS),
// because checking if the cached test target is up-to-date would require running the
// dependency checker transitively.
TestResult runResult = statusMap.get(testStatus);
boolean isIncompleteRun = incompleteRuns.contains(testStatus);
if (runResult == null) {
summary = markIncomplete(summary);
} else if (isIncompleteRun) {
// Only process results which were not recorded by the listener.
boolean newlyFetched = !statusMap.containsKey(testStatus);
summary = incrementalAnalyze(summary, runResult);
if (newlyFetched) {
eventBus.post(runResult);
}
Preconditions.checkState(listener.getIncompleteRuns(testTarget).contains(testStatus) == isIncompleteRun, "TestListener changed in differential analysis. Ensure it isn't still registered.");
}
}
// The target was not posted by the listener and must be posted now.
eventBus.post(summary.build());
return summary;
}
use of com.google.devtools.build.lib.rules.test.TestResult in project bazel by bazelbuild.
the class TestResultAnalyzerTest method testIncrementalAnalyzeSetsActionRanFalseForRemotelyCachedTests.
@Test
public void testIncrementalAnalyzeSetsActionRanFalseForRemotelyCachedTests() {
TestSummary.Builder summaryBuilder = makeTestSummaryBuilder();
assertFalse(summaryBuilder.peek().actionRan());
TestResultData testResultData = TestResultData.newBuilder().setRemotelyCached(true).build();
TestResult result = new TestResult(mock(TestRunnerAction.class), testResultData, /*cached=*/
false);
TestSummary.Builder newSummaryBuilder = underTest.incrementalAnalyze(summaryBuilder, result);
assertFalse(newSummaryBuilder.peek().actionRan());
}
Aggregations