Search in sources :

Example 1 with TestResult

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);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ImmutableList(com.google.common.collect.ImmutableList) Builder(com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder) TestAttempt(com.google.devtools.build.lib.rules.test.TestAttempt) TestResult(com.google.devtools.build.lib.rules.test.TestResult) ResolvedPaths(com.google.devtools.build.lib.rules.test.TestRunnerAction.ResolvedPaths) Pair(com.google.devtools.build.lib.util.Pair)

Example 2 with TestResult

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());
}
Also used : TestResultData(com.google.devtools.build.lib.view.test.TestStatus.TestResultData) TestResult(com.google.devtools.build.lib.rules.test.TestResult) TestRunnerAction(com.google.devtools.build.lib.rules.test.TestRunnerAction) Test(org.junit.Test)

Example 3 with TestResult

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");
    }
}
Also used : TestResult(com.google.devtools.build.lib.rules.test.TestResult) TestExecException(com.google.devtools.build.lib.actions.TestExecException)

Example 4 with TestResult

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;
}
Also used : Label(com.google.devtools.build.lib.cmdline.Label) TestResult(com.google.devtools.build.lib.rules.test.TestResult) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 5 with TestResult

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());
}
Also used : TestResultData(com.google.devtools.build.lib.view.test.TestStatus.TestResultData) TestResult(com.google.devtools.build.lib.rules.test.TestResult) TestRunnerAction(com.google.devtools.build.lib.rules.test.TestRunnerAction) Test(org.junit.Test)

Aggregations

TestResult (com.google.devtools.build.lib.rules.test.TestResult)7 TestRunnerAction (com.google.devtools.build.lib.rules.test.TestRunnerAction)4 TestResultData (com.google.devtools.build.lib.view.test.TestStatus.TestResultData)4 Test (org.junit.Test)4 ImmutableList (com.google.common.collect.ImmutableList)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 TestExecException (com.google.devtools.build.lib.actions.TestExecException)1 Label (com.google.devtools.build.lib.cmdline.Label)1 TestAttempt (com.google.devtools.build.lib.rules.test.TestAttempt)1 ResolvedPaths (com.google.devtools.build.lib.rules.test.TestRunnerAction.ResolvedPaths)1 Pair (com.google.devtools.build.lib.util.Pair)1 Path (com.google.devtools.build.lib.vfs.Path)1 Builder (com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder)1