MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / ReadAndInterpretStatusByte

Method ReadAndInterpretStatusByte

tests/gtest/gtest-all.cc:8058–8097  ·  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

8056// member, and closes read_fd_. Outputs diagnostics and terminates in
8057// case of unexpected codes.
8058void DeathTestImpl::ReadAndInterpretStatusByte() {
8059 char flag;
8060 int bytes_read;
8061
8062 // The read() here blocks until data is available (signifying the
8063 // failure of the death test) or until the pipe is closed (signifying
8064 // its success), so it's okay to call this in the parent before
8065 // the child process has exited.
8066 do {
8067 bytes_read = posix::Read(read_fd(), &flag, 1);
8068 } while (bytes_read == -1 && errno == EINTR);
8069
8070 if (bytes_read == 0) {
8071 set_outcome(DIED);
8072 } else if (bytes_read == 1) {
8073 switch (flag) {
8074 case kDeathTestReturned:
8075 set_outcome(RETURNED);
8076 break;
8077 case kDeathTestThrew:
8078 set_outcome(THREW);
8079 break;
8080 case kDeathTestLived:
8081 set_outcome(LIVED);
8082 break;
8083 case kDeathTestInternalError:
8084 FailFromInternalError(read_fd()); // Does not return.
8085 break;
8086 default:
8087 GTEST_LOG_(FATAL) << "Death test child process reported "
8088 << "unexpected status byte ("
8089 << static_cast<unsigned int>(flag) << ")";
8090 }
8091 } else {
8092 GTEST_LOG_(FATAL) << "Read from death test child process failed: "
8093 << GetLastErrnoDescription();
8094 }
8095 GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd()));
8096 set_read_fd(-1);
8097}
8098
8099std::string DeathTestImpl::GetErrorLogs() {
8100 return GetCapturedStderr();

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