Search in sources :

Example 1 with ActionOwner

use of com.google.devtools.build.lib.actions.ActionOwner in project bazel by bazelbuild.

the class ExperimentalStateTrackerTest method testAggregation.

@Test
public void testAggregation() throws Exception {
    // Assert that actions for the same test are aggregated so that an action afterwards
    // is still shown.
    ManualClock clock = new ManualClock();
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(1234));
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 80);
    Label labelFooTest = Label.parseAbsolute("//foo/bar:footest");
    ConfiguredTarget targetFooTest = Mockito.mock(ConfiguredTarget.class);
    when(targetFooTest.getLabel()).thenReturn(labelFooTest);
    ActionOwner fooOwner = ActionOwner.create(labelFooTest, ImmutableList.<AspectDescriptor>of(), null, null, null, "abcdef", null);
    Label labelBarTest = Label.parseAbsolute("//baz:bartest");
    ConfiguredTarget targetBarTest = Mockito.mock(ConfiguredTarget.class);
    when(targetBarTest.getLabel()).thenReturn(labelBarTest);
    TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class);
    when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(targetFooTest, targetBarTest));
    ActionOwner barOwner = ActionOwner.create(labelBarTest, ImmutableList.<AspectDescriptor>of(), null, null, null, "fedcba", null);
    stateTracker.testFilteringComplete(filteringComplete);
    // First produce 10 actions for footest...
    for (int i = 0; i < 10; i++) {
        clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
        Action action = mockAction("Testing foo, shard " + i, "testlog_foo_" + i);
        when(action.getOwner()).thenReturn(fooOwner);
        stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
    }
    // ...then produce 10 actions for bartest...
    for (int i = 0; i < 10; i++) {
        clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
        Action action = mockAction("Testing bar, shard " + i, "testlog_bar_" + i);
        when(action.getOwner()).thenReturn(barOwner);
        stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
    }
    // ...and finally a completely unrelated action
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
    stateTracker.actionStarted(new ActionStartedEvent(mockAction("Other action", "other/action"), clock.nanoTime()));
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Progress bar should contain ':footest', but was:\n" + output, output.contains(":footest"));
    assertTrue("Progress bar should contain ':bartest', but was:\n" + output, output.contains(":bartest"));
    assertTrue("Progress bar should contain 'Other action', but was:\n" + output, output.contains("Other action"));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) Action(com.google.devtools.build.lib.actions.Action) Label(com.google.devtools.build.lib.cmdline.Label) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) TestFilteringCompleteEvent(com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 2 with ActionOwner

use of com.google.devtools.build.lib.actions.ActionOwner in project bazel by bazelbuild.

the class ExperimentalStateTrackerTest method testSensibleShortening.

@Test
public void testSensibleShortening() throws Exception {
    // Verify that in the typical case, we shorten the progress message by shortening
    // the path implicit in it, that can also be extracted from the label. In particular,
    // the parts
    ManualClock clock = new ManualClock();
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 70);
    Action action = mockAction("Building some/very/very/long/path/for/some/library/directory/foo.jar (42 source files)", "/home/user/bazel/out/abcdef/some/very/very/long/path/for/some/library/directory/foo.jar");
    Label label = Label.parseAbsolute("//some/very/very/long/path/for/some/library/directory:libfoo");
    ActionOwner owner = ActionOwner.create(label, ImmutableList.<AspectDescriptor>of(), null, null, null, "fedcba", null);
    when(action.getOwner()).thenReturn(owner);
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(3));
    stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(5));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Progress bar should contain 'Building ', but was:\n" + output, output.contains("Building "));
    assertTrue("Progress bar should contain 'foo.jar (42 source files)', but was:\n" + output, output.contains("foo.jar (42 source files)"));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) Action(com.google.devtools.build.lib.actions.Action) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) Label(com.google.devtools.build.lib.cmdline.Label) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 3 with ActionOwner

use of com.google.devtools.build.lib.actions.ActionOwner in project bazel by bazelbuild.

the class BlazeExecutor method reportSubcommand.

@Override
public void reportSubcommand(Spawn spawn) {
    String reason;
    ActionOwner owner = spawn.getResourceOwner().getOwner();
    if (owner == null) {
        reason = spawn.getResourceOwner().prettyPrint();
    } else {
        reason = Label.print(owner.getLabel()) + " [" + spawn.getResourceOwner().prettyPrint() + "]";
    }
    String message = Spawns.asShellCommand(spawn, getExecRoot());
    reporter.handle(Event.of(EventKind.SUBCOMMAND, null, "# " + reason + "\n" + message));
}
Also used : ActionOwner(com.google.devtools.build.lib.actions.ActionOwner)

Example 4 with ActionOwner

use of com.google.devtools.build.lib.actions.ActionOwner in project bazel by bazelbuild.

the class AggregatingTestListener method testEvent.

/**
   * Records a new test run result and incrementally updates the target status.
   * This event is sent upon completion of executed test runs.
   */
@Subscribe
@AllowConcurrentEvents
public void testEvent(TestResult result) {
    Preconditions.checkState(statusMap.put(result.getTestStatusArtifact(), result) == null, "Duplicate result reported for an individual test shard");
    ActionOwner testOwner = result.getTestAction().getOwner();
    LabelAndConfiguration targetLabel = LabelAndConfiguration.of(testOwner.getLabel(), result.getTestAction().getConfiguration());
    // executed. Hence report that fact as a cached attempt.
    if (result.isCached()) {
        eventBus.post(TestAttempt.fromCachedTestResult(result));
    }
    TestSummary finalTestSummary = null;
    synchronized (summaryLock) {
        TestSummary.Builder summary = summaries.get(targetLabel);
        preconditionHelper.checkNotNull(summary);
        if (!remainingRuns.remove(targetLabel, result.getTestStatusArtifact())) {
            // This situation is likely to happen if --notest_keep_going is set with multiple targets.
            return;
        }
        summary = analyzer.incrementalAnalyze(summary, result);
        // If all runs are processed, the target is finished and ready to report.
        if (!remainingRuns.containsKey(targetLabel)) {
            finalTestSummary = summary.build();
        }
    }
    // Report finished targets.
    if (finalTestSummary != null) {
        eventBus.post(finalTestSummary);
    }
}
Also used : LabelAndConfiguration(com.google.devtools.build.lib.analysis.LabelAndConfiguration) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

ActionOwner (com.google.devtools.build.lib.actions.ActionOwner)4 Action (com.google.devtools.build.lib.actions.Action)2 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)2 Label (com.google.devtools.build.lib.cmdline.Label)2 ManualClock (com.google.devtools.build.lib.testutil.ManualClock)2 LoggingTerminalWriter (com.google.devtools.build.lib.util.io.LoggingTerminalWriter)2 Test (org.junit.Test)2 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)1 Subscribe (com.google.common.eventbus.Subscribe)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 LabelAndConfiguration (com.google.devtools.build.lib.analysis.LabelAndConfiguration)1 TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)1