MCPcopy Create free account
hub / github.com/apache/singa / ReadAndInterpretStatusByte

Method ReadAndInterpretStatusByte

test/gtest/gtest-all.cc:6919–6958  ·  view source on GitHub ↗

Called in the parent process only. Reads the result code of the death test child process via a pipe, interprets it to set the outcome_ member, and closes read_fd_. Outputs diagnostics and terminates in case of unexpected codes.

Source from the content-addressed store, hash-verified

6917// member, and closes read_fd_. Outputs diagnostics and terminates in
6918// case of unexpected codes.
6919void DeathTestImpl::ReadAndInterpretStatusByte() {
6920 char flag;
6921 int bytes_read;
6922
6923 // The read() here blocks until data is available (signifying the
6924 // failure of the death test) or until the pipe is closed (signifying
6925 // its success), so it's okay to call this in the parent before
6926 // the child process has exited.
6927 do {
6928 bytes_read = posix::Read(read_fd(), &flag, 1);
6929 } while (bytes_read == -1 && errno == EINTR);
6930
6931 if (bytes_read == 0) {
6932 set_outcome(DIED);
6933 } else if (bytes_read == 1) {
6934 switch (flag) {
6935 case kDeathTestReturned:
6936 set_outcome(RETURNED);
6937 break;
6938 case kDeathTestThrew:
6939 set_outcome(THREW);
6940 break;
6941 case kDeathTestLived:
6942 set_outcome(LIVED);
6943 break;
6944 case kDeathTestInternalError:
6945 FailFromInternalError(read_fd()); // Does not return.
6946 break;
6947 default:
6948 GTEST_LOG_(FATAL) << "Death test child process reported "
6949 << "unexpected status byte ("
6950 << static_cast<unsigned int>(flag) << ")";
6951 }
6952 } else {
6953 GTEST_LOG_(FATAL) << "Read from death test child process failed: "
6954 << GetLastErrnoDescription();
6955 }
6956 GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd()));
6957 set_read_fd(-1);
6958}
6959
6960// Signals that the death test code which should have exited, didn't.
6961// Should be called only in a death test child process.

Callers

nothing calls this directly

Calls 4

ReadFunction · 0.85
FailFromInternalErrorFunction · 0.85
GetLastErrnoDescriptionFunction · 0.85
CloseFunction · 0.85

Tested by

no test coverage detected