Skip to content

Commit

Permalink
Report test exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroPatti committed Oct 17, 2023
1 parent c2761af commit 02bc769
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 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 @@ -362,6 +363,7 @@ protected TestCase parseTestResult(Path resultFile) {
protected void processTestOutput(
ActionExecutionContext actionExecutionContext,
TestResultData testResultData,
TerminationStatus ts,
String testName,
Path testLog)
throws IOException {
Expand Down Expand Up @@ -393,9 +395,10 @@ protected void processTestOutput(
.getEventHandler()
.handle(Event.of(EventKind.CANCELLED, null, testName));
} else {
String message = String.format("%s (%s) (see %s)", testName, ts.toShortString(), testLog);
actionExecutionContext
.getEventHandler()
.handle(Event.of(EventKind.FAIL, null, testName + " (see " + testLog + ")"));
.handle(Event.of(EventKind.FAIL, null, message));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/exec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/shell",
"//src/main/java/com/google/devtools/build/lib/skyframe:tree_artifact_value",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util/io",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.google.devtools.build.lib.server.FailureDetails.Execution.Code;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.server.FailureDetails.TestAction;
import com.google.devtools.build.lib.shell.TerminationStatus;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.FileStatus;
Expand Down Expand Up @@ -272,7 +273,11 @@ private StandaloneFailedAttemptResult processTestAttempt(
.post(
TestAttempt.forExecutedTestResult(
action, data, attemptId, testOutputs, result.executionInfo(), isLastAttempt));
processTestOutput(actionExecutionContext, data, action.getTestName(), renamedTestLog);
TerminationStatus ts = TerminationStatus.builder()
.setWaitResponse(result.spawnResults().get(0).exitCode())
.setTimedOut(data.getStatus() == BlazeTestStatus.TIMEOUT)
.build();
processTestOutput(actionExecutionContext, data, ts, action.getTestName(), renamedTestLog);
return new StandaloneFailedAttemptResult(data);
}

Expand Down
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 02bc769

Please sign in to comment.