Search in sources :

Example 1 with BlazeTestStatus

use of com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus in project bazel by bazelbuild.

the class TestResultAnalyzer method markIncomplete.

private TestSummary.Builder markIncomplete(TestSummary.Builder summaryBuilder) {
    // TODO(bazel-team): (2010) Make NotRunTestResult support both tests failed to built and
    // tests with no status and post it here.
    TestSummary summary = summaryBuilder.peek();
    BlazeTestStatus status = summary.getStatus();
    if (skipTargetsOnFailure) {
        status = BlazeTestStatus.NO_STATUS;
    } else if (status != BlazeTestStatus.NO_STATUS) {
        status = aggregateStatus(status, BlazeTestStatus.INCOMPLETE);
    }
    return summaryBuilder.setStatus(status);
}
Also used : BlazeTestStatus(com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus)

Example 2 with BlazeTestStatus

use of com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus in project bazel by bazelbuild.

the class TestSummaryPrinter method print.

/**
   * Prints summary status for a single test.
   * @param terminalPrinter The printer to print to
   */
public static void print(TestSummary summary, AnsiTerminalPrinter terminalPrinter, boolean verboseSummary, boolean printFailedTestCases) {
    BlazeTestStatus status = summary.getStatus();
    // Skip output for tests that failed to build.
    if (status == BlazeTestStatus.FAILED_TO_BUILD || status == BlazeTestStatus.BLAZE_HALTED_BEFORE_TESTING) {
        return;
    }
    String message = getCacheMessage(summary) + statusString(summary.getStatus());
    terminalPrinter.print(Strings.padEnd(summary.getTarget().getLabel().toString(), 78 - message.length(), ' ') + " " + TestSummary.getStatusMode(summary.getStatus()) + message + Mode.DEFAULT + (verboseSummary ? getAttemptSummary(summary) + getTimeSummary(summary) : "") + "\n");
    if (printFailedTestCases && summary.getStatus() == BlazeTestStatus.FAILED) {
        if (summary.getFailedTestCasesStatus() == FailedTestCasesStatus.NOT_AVAILABLE) {
            terminalPrinter.print(Mode.WARNING + "    (individual test case information not available) " + Mode.DEFAULT + "\n");
        } else {
            for (TestCase testCase : summary.getFailedTestCases()) {
                if (testCase.getStatus() != TestCase.Status.PASSED) {
                    TestSummaryPrinter.printTestCase(terminalPrinter, testCase);
                }
            }
            if (summary.getFailedTestCasesStatus() != FailedTestCasesStatus.FULL) {
                terminalPrinter.print(Mode.WARNING + "    (some shards did not report details, list of failed test" + " cases incomplete)\n" + Mode.DEFAULT);
            }
        }
    }
    if (!printFailedTestCases) {
        for (String warning : summary.getWarnings()) {
            terminalPrinter.print("  " + AnsiTerminalPrinter.Mode.WARNING + "WARNING: " + AnsiTerminalPrinter.Mode.DEFAULT + warning + "\n");
        }
        for (Path path : summary.getFailedLogs()) {
            if (path.exists()) {
                // Don't use getPrettyPath() here - we want to print the absolute path,
                // so that it cut and paste into a different terminal, and we don't
                // want to use the blaze-bin etc. symbolic links because they could be changed
                // by a subsequent build with different options.
                terminalPrinter.print("  " + path.getPathString() + "\n");
            }
        }
    }
    for (Path path : summary.getCoverageFiles()) {
        // Print only non-trivial coverage files.
        try {
            if (path.exists() && path.getFileSize() > 0) {
                terminalPrinter.print("  " + path.getPathString() + "\n");
            }
        } catch (IOException e) {
            LoggingUtil.logToRemote(Level.WARNING, "Error while reading coverage data file size", e);
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) BlazeTestStatus(com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus) IOException(java.io.IOException)

Example 3 with BlazeTestStatus

use of com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus in project bazel by bazelbuild.

the class TestResultAnalyzer method incrementalAnalyze.

/**
   * Incrementally updates a TestSummary given an existing summary
   * and a new TestResult. Only call on built targets.
   *
   * @param summaryBuilder Existing unbuilt test summary associated with a target.
   * @param result New test result to aggregate into the summary.
   * @return The updated TestSummary.
   */
public TestSummary.Builder incrementalAnalyze(TestSummary.Builder summaryBuilder, TestResult result) {
    // Cache retrieval should have been performed already.
    Preconditions.checkNotNull(result);
    Preconditions.checkNotNull(summaryBuilder);
    TestSummary existingSummary = Preconditions.checkNotNull(summaryBuilder.peek());
    TransitiveInfoCollection target = existingSummary.getTarget();
    Preconditions.checkNotNull(target, "The existing TestSummary must be associated with a target");
    BlazeTestStatus status = existingSummary.getStatus();
    int numCached = existingSummary.numCached();
    int numLocalActionCached = existingSummary.numLocalActionCached();
    // If a test was neither cached locally nor remotely we say action was taken.
    if (!(result.isCached() || result.getData().getRemotelyCached())) {
        summaryBuilder.setActionRan(true);
    } else {
        numCached++;
    }
    if (result.isCached()) {
        numLocalActionCached++;
    }
    PathFragment coverageData = result.getCoverageData();
    if (coverageData != null) {
        summaryBuilder.addCoverageFiles(Collections.singletonList(execRoot.getRelative(coverageData)));
    }
    if (!executionOptions.runsPerTestDetectsFlakes) {
        status = aggregateStatus(status, result.getData().getStatus());
    } else {
        int shardNumber = result.getShardNum();
        int runsPerTestForLabel = target.getProvider(TestProvider.class).getTestParams().getRuns();
        List<BlazeTestStatus> singleShardStatuses = summaryBuilder.addShardStatus(shardNumber, result.getData().getStatus());
        if (singleShardStatuses.size() == runsPerTestForLabel) {
            BlazeTestStatus shardStatus = BlazeTestStatus.NO_STATUS;
            int passes = 0;
            for (BlazeTestStatus runStatusForShard : singleShardStatuses) {
                shardStatus = aggregateStatus(shardStatus, runStatusForShard);
                if (TestResult.isBlazeTestStatusPassed(runStatusForShard)) {
                    passes++;
                }
            }
            // If all results pass or fail, aggregate the passing/failing shardStatus.
            if (passes == 0 || passes == runsPerTestForLabel) {
                status = aggregateStatus(status, shardStatus);
            } else {
                status = aggregateStatus(status, BlazeTestStatus.FLAKY);
            }
        }
    }
    List<Path> passed = new ArrayList<>();
    if (result.getData().hasPassedLog()) {
        passed.add(result.getTestAction().getTestLog().getPath().getRelative(result.getData().getPassedLog()));
    }
    List<Path> failed = new ArrayList<>();
    for (String path : result.getData().getFailedLogsList()) {
        failed.add(result.getTestAction().getTestLog().getPath().getRelative(path));
    }
    summaryBuilder.addTestTimes(result.getData().getTestTimesList()).addPassedLogs(passed).addFailedLogs(failed).addWarnings(result.getData().getWarningList()).collectFailedTests(result.getData().getTestCase()).setRanRemotely(result.getData().getIsRemoteStrategy());
    List<String> warnings = new ArrayList<>();
    if (status == BlazeTestStatus.PASSED && shouldEmitTestSizeWarningInSummary(summaryOptions.testVerboseTimeoutWarnings, warnings, result.getData().getTestProcessTimesList(), target)) {
        summaryBuilder.setWasUnreportedWrongSize(true);
    }
    return summaryBuilder.setStatus(status).setNumCached(numCached).setNumLocalActionCached(numLocalActionCached).addWarnings(warnings);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BlazeTestStatus(com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ArrayList(java.util.ArrayList) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Aggregations

BlazeTestStatus (com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus)3 Path (com.google.devtools.build.lib.vfs.Path)2 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 TestCase (com.google.devtools.build.lib.view.test.TestStatus.TestCase)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1