Skip to content

Commit

Permalink
Report test exit code
Browse files Browse the repository at this point in the history
Actions already report their exit code on the UI. After this change, the same applies to test failures.

Closes bazelbuild#19841.

PiperOrigin-RevId: 586681853
Change-Id: I140f09e254d82b4cd12b4bdded2e05b386e82c17
  • Loading branch information
AlessandroPatti authored and copybara-github committed Nov 30, 2023
1 parent c49fa45 commit 9f167a9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.server.FailureDetails.TestAction;
import com.google.devtools.build.lib.server.FailureDetails.TestAction.Code;
import com.google.devtools.build.lib.shell.TerminationStatus;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.util.io.OutErr;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -393,9 +394,13 @@ protected void processTestOutput(
.getEventHandler()
.handle(Event.of(EventKind.CANCELLED, null, testName));
} else {
actionExecutionContext
.getEventHandler()
.handle(Event.of(EventKind.FAIL, null, testName + " (see " + testLog + ")"));
TerminationStatus ts =
TerminationStatus.builder()
.setWaitResponse(testResultData.getExitCode())
.setTimedOut(testResultData.getStatus() == BlazeTestStatus.TIMEOUT)
.build();
String message = String.format("%s (%s) (see %s)", testName, ts.toShortString(), testLog);
actionExecutionContext.getEventHandler().handle(Event.of(EventKind.FAIL, null, message));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ private StandaloneFailedAttemptResult processTestAttempt(
dataBuilder.addFailedLogs(renamedTestLog.toString());
}

if (!result.spawnResults().isEmpty()) {
dataBuilder.setExitCode(result.spawnResults().get(0).exitCode());
}

// Add the test log to the output
TestResultData data = dataBuilder.build();
actionExecutionContext
Expand Down
25 changes: 13 additions & 12 deletions src/main/protobuf/test_status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ option java_package = "com.google.devtools.build.lib.view.test";

// Status data of test cases which failed (used only for printing test summary)
enum FailedTestCasesStatus {
/** Information about every test case is available. */
FULL = 1;
/** Information about some test cases may be missing. */
PARTIAL = 2;
/** No information about individual test cases. */
NOT_AVAILABLE = 3;
/** This is an empty object still without data. */
EMPTY = 4;
};
/** Information about every test case is available. */
FULL = 1;
/** Information about some test cases may be missing. */
PARTIAL = 2;
/** No information about individual test cases. */
NOT_AVAILABLE = 3;
/** This is an empty object still without data. */
EMPTY = 4;
}

// Detailed status data for a TestRunnerAction execution.
enum BlazeTestStatus {
Expand All @@ -41,7 +41,7 @@ enum BlazeTestStatus {
REMOTE_FAILURE = 6;
FAILED_TO_BUILD = 7;
BLAZE_HALTED_BEFORE_TESTING = 8;
};
}

// TestCase contains detailed data about all tests (cases/suites/decorators)
// ran, structured in a tree. This data will be later used to present the tests
Expand All @@ -68,7 +68,7 @@ message TestCase {
optional Type type = 6;
optional Status status = 7;
optional bool run = 8 [default = true];
};
}

// TestResultData holds the outcome data for a single test action (A
// single test rule can result in multiple actions due to sharding and
Expand All @@ -83,6 +83,7 @@ message TestResultData {
// Following data is informational.
optional BlazeTestStatus status = 3 [default = NO_STATUS];
optional string status_details = 16;
optional int32 exit_code = 17;
repeated string failed_logs = 4;
repeated string warning = 5;
optional bool has_coverage = 6;
Expand Down Expand Up @@ -111,4 +112,4 @@ message TestResultData {
// Additional build info
optional TestCase test_case = 13;
optional FailedTestCasesStatus failed_status = 14;
};
}
10 changes: 10 additions & 0 deletions src/test/shell/integration/ui_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,14 @@ EOF
expect_log_n "INFO: Build completed successfully, [456] total actions" 1
}

function test_exit_code_reported() {
bazel build --curses=yes --color=yes error:failwitherror 2>$TEST_log \
&& fail "${PRODUCT_NAME} build passed"
expect_log '//error:failwitherror failed: (Exit 1): '

bazel test --curses=yes --color=yes pkg:false 2>$TEST_log \
&& fail "${PRODUCT_NAME} test passed"
expect_log '//pkg:false (Exit 1) (see'
}

run_suite "Integration tests for ${PRODUCT_NAME}'s UI"

0 comments on commit 9f167a9

Please sign in to comment.