Search in sources :

Example 1 with Builder

use of com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder 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 Builder

use of com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder 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)

Aggregations

Path (com.google.devtools.build.lib.vfs.Path)2 Builder (com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder)2 ImmutableList (com.google.common.collect.ImmutableList)1 EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)1 ExecException (com.google.devtools.build.lib.actions.ExecException)1 Executor (com.google.devtools.build.lib.actions.Executor)1 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)1 TestExecException (com.google.devtools.build.lib.actions.TestExecException)1 TestAttempt (com.google.devtools.build.lib.rules.test.TestAttempt)1 TestResult (com.google.devtools.build.lib.rules.test.TestResult)1 ResolvedPaths (com.google.devtools.build.lib.rules.test.TestRunnerAction.ResolvedPaths)1 Pair (com.google.devtools.build.lib.util.Pair)1 TestCase (com.google.devtools.build.lib.view.test.TestStatus.TestCase)1 TestResultData (com.google.devtools.build.lib.view.test.TestStatus.TestResultData)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1