Search in sources :

Example 6 with TestCase

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

the class TestSummaryTest method testTestCaseNamesOrdered.

@Test
public void testTestCaseNamesOrdered() throws Exception {
    TestCase[] details = { newDetail("apple", TestCase.Status.FAILED, 1000L), newDetail("banana", TestCase.Status.FAILED, 1000L), newDetail("cranberry", TestCase.Status.FAILED, 1000L) };
    // The exceedingly dumb approach: writing all the permutations down manually
    // is simply easier than any way of generating them.
    int[][] permutations = { { 0, 1, 2 }, { 0, 2, 1 }, { 1, 0, 2 }, { 1, 2, 0 }, { 2, 0, 1 }, { 2, 1, 0 } };
    for (int[] permutation : permutations) {
        List<TestCase> permutatedDetails = new ArrayList<>();
        for (int element : permutation) {
            permutatedDetails.add(details[element]);
        }
        TestSummary summary = createTestSummaryWithDetails(BlazeTestStatus.FAILED, permutatedDetails);
        // A mock that checks the ordering of method calls
        AnsiTerminalPrinter printer = Mockito.mock(AnsiTerminalPrinter.class);
        TestSummaryPrinter.print(summary, printer, true, true);
        InOrder order = Mockito.inOrder(printer);
        order.verify(printer).print(contains("//package:name"));
        order.verify(printer).print(find("FAILED.*apple"));
        order.verify(printer).print(find("FAILED.*banana"));
        order.verify(printer).print(find("FAILED.*cranberry"));
    }
}
Also used : InOrder(org.mockito.InOrder) AnsiTerminalPrinter(com.google.devtools.build.lib.util.io.AnsiTerminalPrinter) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with TestCase

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

the class StandaloneTestStrategy method executeTest.

protected TestResultData executeTest(TestRunnerAction action, Spawn spawn, ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException, IOException {
    Executor executor = actionExecutionContext.getExecutor();
    Closeable streamed = null;
    Path testLogPath = action.getTestLog().getPath();
    TestResultData.Builder builder = TestResultData.newBuilder();
    long startTime = executor.getClock().currentTimeMillis();
    SpawnActionContext spawnActionContext = executor.getSpawnActionContext(action.getMnemonic());
    try {
        try {
            if (executionOptions.testOutput.equals(TestOutputFormat.STREAMED)) {
                streamed = new StreamedTestOutput(Reporter.outErrForReporter(actionExecutionContext.getExecutor().getEventHandler()), testLogPath);
            }
            spawnActionContext.exec(spawn, actionExecutionContext);
            builder.setTestPassed(true).setStatus(BlazeTestStatus.PASSED).setCachable(true).setPassedLog(testLogPath.getPathString());
        } catch (ExecException e) {
            // Execution failed, which we consider a test failure.
            // TODO(bazel-team): set cachable==true for relevant statuses (failure, but not for
            // timeout, etc.)
            builder.setTestPassed(false).setStatus(e.hasTimedOut() ? BlazeTestStatus.TIMEOUT : BlazeTestStatus.FAILED).addFailedLogs(testLogPath.getPathString());
            if (spawnActionContext.shouldPropagateExecException()) {
                throw e;
            }
        } finally {
            long duration = executor.getClock().currentTimeMillis() - startTime;
            builder.addTestTimes(duration);
            builder.addTestProcessTimes(duration);
            builder.setRunDurationMillis(duration);
            if (streamed != null) {
                streamed.close();
            }
        }
        TestCase details = parseTestResult(action.resolve(actionExecutionContext.getExecutor().getExecRoot()).getXmlOutputPath());
        if (details != null) {
            builder.setTestCase(details);
        }
        if (action.isCoverageMode()) {
            builder.setHasCoverage(true);
        }
        return builder.build();
    } catch (IOException e) {
        throw new TestExecException(e.getMessage());
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Executor(com.google.devtools.build.lib.actions.Executor) TestResultData(com.google.devtools.build.lib.view.test.TestStatus.TestResultData) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) Closeable(java.io.Closeable) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) TestExecException(com.google.devtools.build.lib.actions.TestExecException) ExecException(com.google.devtools.build.lib.actions.ExecException) Builder(com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder) IOException(java.io.IOException) SpawnActionContext(com.google.devtools.build.lib.actions.SpawnActionContext) TestExecException(com.google.devtools.build.lib.actions.TestExecException)

Example 8 with TestCase

use of com.google.devtools.build.lib.view.test.TestStatus.TestCase 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 9 with TestCase

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

the class TestSummaryTest method testCollectingFailedDetails.

@Test
public void testCollectingFailedDetails() throws Exception {
    TestCase rootCase = TestCase.newBuilder().setName("tests").setRunDurationMillis(5000L).addChild(newDetail("apple", TestCase.Status.FAILED, 1000L)).addChild(newDetail("banana", TestCase.Status.PASSED, 1000L)).addChild(newDetail("cherry", TestCase.Status.ERROR, 1000L)).build();
    TestSummary summary = getTemplateBuilder().collectFailedTests(rootCase).setStatus(BlazeTestStatus.FAILED).build();
    AnsiTerminalPrinter printer = Mockito.mock(AnsiTerminalPrinter.class);
    TestSummaryPrinter.print(summary, printer, true, true);
    verify(printer).print(contains("//package:name"));
    verify(printer).print(find("FAILED.*apple"));
    verify(printer).print(find("ERROR.*cherry"));
}
Also used : AnsiTerminalPrinter(com.google.devtools.build.lib.util.io.AnsiTerminalPrinter) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) Test(org.junit.Test)

Aggregations

TestCase (com.google.devtools.build.lib.view.test.TestStatus.TestCase)9 AnsiTerminalPrinter (com.google.devtools.build.lib.util.io.AnsiTerminalPrinter)6 Test (org.junit.Test)6 Path (com.google.devtools.build.lib.vfs.Path)3 IOException (java.io.IOException)3 Executor (com.google.devtools.build.lib.actions.Executor)2 TestExecException (com.google.devtools.build.lib.actions.TestExecException)2 TestResultData (com.google.devtools.build.lib.view.test.TestStatus.TestResultData)2 HashCode (com.google.common.hash.HashCode)1 EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)1 ExecException (com.google.devtools.build.lib.actions.ExecException)1 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 BlazeTestStatus (com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus)1 Builder (com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder)1 WorkRequest (com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest)1 WorkResponse (com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse)1 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 InOrder (org.mockito.InOrder)1