Search in sources :

Example 26 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class TestCaseSummariesBuildingXctestEventHandler method handleEndTestCaseEvent.

@Override
public void handleEndTestCaseEvent(XctestOutputParsing.EndTestCaseEvent event) {
    TestResultSummary testResultSummary = XctestOutputParsing.testResultSummaryForEndTestCaseEvent(event);
    testResultSummariesBuilder.put(Optional.ofNullable(event.className).orElse(Preconditions.checkNotNull(event.test)), testResultSummary);
    testReportingCallback.testDidEnd(testResultSummary);
}
Also used : TestResultSummary(com.facebook.buck.test.TestResultSummary)

Example 27 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class TestCaseSummariesBuildingXctoolEventHandler method handleEndOcunitEvent.

@Override
public void handleEndOcunitEvent(XctoolOutputParsing.EndOcunitEvent event) {
    boolean testsDidEndChangedToTrue = testsDidEnd.compareAndSet(false, true);
    Preconditions.checkState(testsDidEndChangedToTrue, "handleEndOcunitEvent() should not be called twice");
    Optional<TestResultSummary> internalError = XctoolOutputParsing.internalErrorForEndOcunitEvent(event);
    if (internalError.isPresent()) {
        testResultSummariesBuilder.put("Internal error from test runner", internalError.get());
    }
    for (Map.Entry<String, Collection<TestResultSummary>> testCaseSummary : testResultSummariesBuilder.build().asMap().entrySet()) {
        testCaseSummariesBuilder.add(new TestCaseSummary(testCaseSummary.getKey(), ImmutableList.copyOf(testCaseSummary.getValue())));
    }
    testReportingCallback.testsDidEnd(testCaseSummariesBuilder.build());
}
Also used : TestCaseSummary(com.facebook.buck.test.TestCaseSummary) Collection(java.util.Collection) TestResultSummary(com.facebook.buck.test.TestResultSummary) Map(java.util.Map)

Example 28 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class RustTest method parseTestResults.

private ImmutableList<TestResultSummary> parseTestResults() throws IOException {
    Map<String, ResultType> testToResult = new HashMap<>();
    try (BufferedReader reader = Files.newBufferedReader(testOutputFile, Charsets.UTF_8)) {
        String line;
        while ((line = reader.readLine()) != null) {
            String[] resultAndTestName = line.split(" ");
            if (resultAndTestName.length != 2) {
                throw new RuntimeException(String.format("Unknown test output format %s", line));
            }
            ResultType result;
            switch(resultAndTestName[0]) {
                case "ok":
                    result = ResultType.SUCCESS;
                    break;
                case "failed":
                    result = ResultType.FAILURE;
                    break;
                case "ignored":
                    result = ResultType.DISABLED;
                    break;
                default:
                    throw new RuntimeException(String.format("Unknown test status %s", line));
            }
            testToResult.put(resultAndTestName[1], result);
        }
    }
    Map<String, String> testToStdout = new HashMap<>();
    try (BufferedReader reader = Files.newBufferedReader(testStdoutFile, Charsets.UTF_8)) {
        StringBuilder stdout = new StringBuilder();
        String currentStdoutTestName = null;
        BiConsumer<String, String> addTestStdout = (key, value) -> {
            testToStdout.put(key, value);
            stdout.setLength(0);
        };
        String line;
        while ((line = reader.readLine()) != null) {
            Matcher matcher;
            if ((matcher = TEST_STDOUT_PATTERN.matcher(line)).matches()) {
                if (currentStdoutTestName != null) {
                    // Start of stdout output for new test
                    // Save current stdout
                    addTestStdout.accept(currentStdoutTestName, stdout.toString());
                }
                currentStdoutTestName = matcher.group("name");
            } else if (FAILURES_LIST_PATTERN.matcher(line).matches()) {
                if (currentStdoutTestName != null) {
                    addTestStdout.accept(currentStdoutTestName, stdout.toString());
                }
            } else if (currentStdoutTestName != null) {
                stdout.append("\n");
                stdout.append(line);
            }
        }
    }
    ImmutableList.Builder<TestResultSummary> summariesBuilder = ImmutableList.builder();
    for (Map.Entry<String, ResultType> entry : testToResult.entrySet()) {
        summariesBuilder.add(new TestResultSummary("rust_test", entry.getKey(), entry.getValue(), // TODO(StanislavGlebik) time
        0, // message
        "", // stack trace,
        "", testToStdout.get(entry.getKey()), // stderr
        ""));
    }
    return summariesBuilder.build();
}
Also used : BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) ExternalTestRunnerRule(com.facebook.buck.rules.ExternalTestRunnerRule) Step(com.facebook.buck.step.Step) HasRuntimeDeps(com.facebook.buck.rules.HasRuntimeDeps) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ResultType(com.facebook.buck.test.result.type.ResultType) SourcePath(com.facebook.buck.rules.SourcePath) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) Matcher(java.util.regex.Matcher) Label(com.facebook.buck.rules.Label) Tool(com.facebook.buck.rules.Tool) TestResults(com.facebook.buck.test.TestResults) ImmutableList(com.google.common.collect.ImmutableList) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) TestResultSummary(com.facebook.buck.test.TestResultSummary) TestRule(com.facebook.buck.rules.TestRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) Charsets(com.google.common.base.Charsets) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Files(java.nio.file.Files) BuildableContext(com.facebook.buck.rules.BuildableContext) AbstractTestStep(com.facebook.buck.step.AbstractTestStep) IOException(java.io.IOException) BuildTarget(com.facebook.buck.model.BuildTarget) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) Stream(java.util.stream.Stream) BuildContext(com.facebook.buck.rules.BuildContext) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) BuildTargets(com.facebook.buck.model.BuildTargets) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) ResultType(com.facebook.buck.test.result.type.ResultType) TestResultSummary(com.facebook.buck.test.TestResultSummary) BufferedReader(java.io.BufferedReader) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class TestRunningTest method whenSeparateTestFailsThenBuildFails.

@Test
public void whenSeparateTestFailsThenBuildFails() throws Exception {
    CommandRunnerParams commandRunnerParams = CommandRunnerParamsForTesting.builder().build();
    final TestResults failingTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "failTest", ResultType.FAILURE, 5000, null, null, null, null)))));
    BuildTarget failingTestTarget = BuildTargetFactory.newInstance("//:failingtest");
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    FakeTestRule failingTest = new FakeTestRule(new FakeBuildRuleParamsBuilder(failingTestTarget).build(), resolver, ImmutableSet.of(), Optional.of(Paths.get("failingTestStep1OutputDir")), // runTestSeparately
    true, ImmutableList.of(), () -> failingTestResults);
    ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3));
    FakeBuildEngine fakeBuildEngine = new FakeBuildEngine(ImmutableMap.of(failingTestTarget, BuildResult.success(failingTest, BUILT_LOCALLY, CacheResult.miss())), ImmutableMap.of(failingTestTarget, new RuleKey("00")));
    ExecutionContext fakeExecutionContext = TestExecutionContext.newInstance();
    DefaultStepRunner stepRunner = new DefaultStepRunner();
    int ret = TestRunning.runTests(commandRunnerParams, ImmutableList.of(failingTest), fakeExecutionContext, DEFAULT_OPTIONS, service, fakeBuildEngine, stepRunner, resolver, ruleFinder);
    assertThat(ret, equalTo(TestRunning.TEST_FAILURES_EXIT_CODE));
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) TestResults(com.facebook.buck.test.TestResults) FakeTestResults(com.facebook.buck.test.FakeTestResults) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) FakeBuildEngine(com.facebook.buck.rules.FakeBuildEngine) Test(org.junit.Test)

Example 30 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class TestRunningTest method whenSomeTestsAreSeparateThenSeparateTestsRunAtEnd.

@Test
public void whenSomeTestsAreSeparateThenSeparateTestsRunAtEnd() throws Exception {
    CommandRunnerParams commandRunnerParams = CommandRunnerParamsForTesting.builder().build();
    AtomicInteger atomicExecutionOrder = new AtomicInteger(0);
    ExecutionOrderAwareFakeStep separateTestStep1 = new ExecutionOrderAwareFakeStep("teststep1", "teststep1", 0, atomicExecutionOrder);
    final TestResults fakeTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.SUCCESS, 5000, null, null, null, null)))));
    BuildTarget separateTest1Target = BuildTargetFactory.newInstance("//:test1");
    FakeTestRule separateTest1 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest1Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep1OutputDir")), // runTestSeparately
    true, ImmutableList.of(separateTestStep1), () -> fakeTestResults);
    ExecutionOrderAwareFakeStep separateTestStep2 = new ExecutionOrderAwareFakeStep("teststep2", "teststep2", 0, atomicExecutionOrder);
    BuildTarget separateTest2Target = BuildTargetFactory.newInstance("//:test2");
    FakeTestRule separateTest2 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest2Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep2OutputDir")), // runTestSeparately
    true, ImmutableList.of(separateTestStep2), () -> fakeTestResults);
    ExecutionOrderAwareFakeStep separateTestStep3 = new ExecutionOrderAwareFakeStep("teststep3", "teststep3", 0, atomicExecutionOrder);
    BuildTarget separateTest3Target = BuildTargetFactory.newInstance("//:test3");
    FakeTestRule separateTest3 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest3Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep3OutputDir")), // runTestSeparately
    true, ImmutableList.of(separateTestStep3), () -> fakeTestResults);
    ExecutionOrderAwareFakeStep parallelTestStep1 = new ExecutionOrderAwareFakeStep("parallelteststep1", "parallelteststep1", 0, atomicExecutionOrder);
    BuildTarget parallelTest1Target = BuildTargetFactory.newInstance("//:paralleltest1");
    FakeTestRule parallelTest1 = new FakeTestRule(new FakeBuildRuleParamsBuilder(parallelTest1Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("parallelTestStep1OutputDir")), // runTestSeparately
    false, ImmutableList.of(parallelTestStep1), () -> fakeTestResults);
    ExecutionOrderAwareFakeStep parallelTestStep2 = new ExecutionOrderAwareFakeStep("parallelteststep2", "parallelteststep2", 0, atomicExecutionOrder);
    BuildTarget parallelTest2Target = BuildTargetFactory.newInstance("//:paralleltest2");
    FakeTestRule parallelTest2 = new FakeTestRule(new FakeBuildRuleParamsBuilder(parallelTest2Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("parallelTestStep2OutputDir")), // runTestSeparately
    false, ImmutableList.of(parallelTestStep2), () -> fakeTestResults);
    ExecutionOrderAwareFakeStep parallelTestStep3 = new ExecutionOrderAwareFakeStep("parallelteststep3", "parallelteststep3", 0, atomicExecutionOrder);
    BuildTarget parallelTest3Target = BuildTargetFactory.newInstance("//:paralleltest3");
    FakeTestRule parallelTest3 = new FakeTestRule(new FakeBuildRuleParamsBuilder(parallelTest3Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("parallelTestStep3OutputDir")), // runTestSeparately
    false, ImmutableList.of(parallelTestStep3), () -> fakeTestResults);
    // We explicitly use an actual thread pool here; the logic should ensure the
    // separate tests are run in the correct order.
    ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3));
    FakeBuildEngine fakeBuildEngine = new FakeBuildEngine(ImmutableMap.<BuildTarget, BuildResult>builder().put(separateTest1Target, BuildResult.success(separateTest1, BUILT_LOCALLY, CacheResult.miss())).put(separateTest2Target, BuildResult.success(separateTest2, BUILT_LOCALLY, CacheResult.miss())).put(separateTest3Target, BuildResult.success(separateTest3, BUILT_LOCALLY, CacheResult.miss())).put(parallelTest1Target, BuildResult.success(parallelTest1, BUILT_LOCALLY, CacheResult.miss())).put(parallelTest2Target, BuildResult.success(parallelTest2, BUILT_LOCALLY, CacheResult.miss())).put(parallelTest3Target, BuildResult.success(parallelTest3, BUILT_LOCALLY, CacheResult.miss())).build(), ImmutableMap.<BuildTarget, RuleKey>builder().put(separateTest1Target, new RuleKey("00")).put(separateTest2Target, new RuleKey("00")).put(separateTest3Target, new RuleKey("00")).put(parallelTest1Target, new RuleKey("00")).put(parallelTest2Target, new RuleKey("00")).put(parallelTest3Target, new RuleKey("00")).build());
    ExecutionContext fakeExecutionContext = TestExecutionContext.newInstance();
    DefaultStepRunner stepRunner = new DefaultStepRunner();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    int ret = TestRunning.runTests(commandRunnerParams, ImmutableList.of(separateTest1, parallelTest1, separateTest2, parallelTest2, separateTest3, parallelTest3), fakeExecutionContext, DEFAULT_OPTIONS, service, fakeBuildEngine, stepRunner, new SourcePathResolver(ruleFinder), ruleFinder);
    assertThat(ret, equalTo(0));
    // The tests not marked as separate could run in any order -- but they must run
    // before the separate test steps.
    ImmutableSet<Optional<Integer>> expectedParallelStepExecutionOrderSet = ImmutableSet.<Optional<Integer>>builder().add(Optional.of(0)).add(Optional.of(1)).add(Optional.of(2)).add(Optional.of(3)).add(Optional.of(4)).add(Optional.of(5)).build();
    ImmutableSet<Optional<Integer>> actualParallelStepExecutionOrderSet = ImmutableSet.<Optional<Integer>>builder().add(parallelTestStep1.getExecutionBeginOrder()).add(parallelTestStep1.getExecutionEndOrder()).add(parallelTestStep2.getExecutionBeginOrder()).add(parallelTestStep2.getExecutionEndOrder()).add(parallelTestStep3.getExecutionBeginOrder()).add(parallelTestStep3.getExecutionEndOrder()).build();
    LOG.debug("Expected parallel execution order: %s Actual parallel execution order: %s", expectedParallelStepExecutionOrderSet, actualParallelStepExecutionOrderSet);
    // We allow the parallel steps to begin and end in any order (note the thread
    // pool of size 3 above), so we use a set.
    assertThat(actualParallelStepExecutionOrderSet, equalTo(expectedParallelStepExecutionOrderSet));
    // The separate test steps must begin and end in a specific order, so we use a list.
    ImmutableList<Optional<Integer>> expectedSeparateStepExecutionOrderList = ImmutableList.<Optional<Integer>>builder().add(Optional.of(6)).add(Optional.of(7)).add(Optional.of(8)).add(Optional.of(9)).add(Optional.of(10)).add(Optional.of(11)).build();
    ImmutableList<Optional<Integer>> actualSeparateStepExecutionOrderList = ImmutableList.<Optional<Integer>>builder().add(separateTestStep1.getExecutionBeginOrder()).add(separateTestStep1.getExecutionEndOrder()).add(separateTestStep2.getExecutionBeginOrder()).add(separateTestStep2.getExecutionEndOrder()).add(separateTestStep3.getExecutionBeginOrder()).add(separateTestStep3.getExecutionEndOrder()).build();
    LOG.debug("Expected separate execution order: %s Actual separate execution order: %s", expectedSeparateStepExecutionOrderList, actualSeparateStepExecutionOrderList);
    assertThat(actualSeparateStepExecutionOrderList, equalTo(expectedSeparateStepExecutionOrderList));
}
Also used : Optional(java.util.Optional) ExecutionOrderAwareFakeStep(com.facebook.buck.step.ExecutionOrderAwareFakeStep) RuleKey(com.facebook.buck.rules.RuleKey) TestResults(com.facebook.buck.test.TestResults) FakeTestResults(com.facebook.buck.test.FakeTestResults) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BuildResult(com.facebook.buck.rules.BuildResult) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) FakeBuildEngine(com.facebook.buck.rules.FakeBuildEngine) Test(org.junit.Test)

Aggregations

TestResultSummary (com.facebook.buck.test.TestResultSummary)34 TestCaseSummary (com.facebook.buck.test.TestCaseSummary)17 Test (org.junit.Test)16 TestResults (com.facebook.buck.test.TestResults)11 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)10 BuildTarget (com.facebook.buck.model.BuildTarget)9 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)9 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 Path (java.nio.file.Path)8 ExecutionContext (com.facebook.buck.step.ExecutionContext)7 FakeTestResults (com.facebook.buck.test.FakeTestResults)7 ImmutableList (com.google.common.collect.ImmutableList)7 RuleKey (com.facebook.buck.rules.RuleKey)6 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)5 ResultType (com.facebook.buck.test.result.type.ResultType)5 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)4 BufferedReader (java.io.BufferedReader)4 Matcher (java.util.regex.Matcher)4 Document (org.w3c.dom.Document)4