Search in sources :

Example 6 with TestExecException

use of com.google.devtools.build.lib.actions.TestExecException 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 7 with TestExecException

use of com.google.devtools.build.lib.actions.TestExecException 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)

Aggregations

TestExecException (com.google.devtools.build.lib.actions.TestExecException)7 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)4 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)2 Executor (com.google.devtools.build.lib.actions.Executor)2 MissingInputFileException (com.google.devtools.build.lib.actions.MissingInputFileException)2 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)2 AbruptExitException (com.google.devtools.build.lib.util.AbruptExitException)2 ExitCode (com.google.devtools.build.lib.util.ExitCode)2 Path (com.google.devtools.build.lib.vfs.Path)2 TestCase (com.google.devtools.build.lib.view.test.TestStatus.TestCase)2 TestResultData (com.google.devtools.build.lib.view.test.TestStatus.TestResultData)2 IOException (java.io.IOException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Stopwatch (com.google.common.base.Stopwatch)1 HashCode (com.google.common.hash.HashCode)1 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)1 Artifact (com.google.devtools.build.lib.actions.Artifact)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