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.
| 6579 | // member, and closes read_fd_. Outputs diagnostics and terminates in |
| 6580 | // case of unexpected codes. |
| 6581 | void DeathTestImpl::ReadAndInterpretStatusByte() { |
| 6582 | char flag; |
| 6583 | int bytes_read; |
| 6584 | |
| 6585 | // The read() here blocks until data is available (signifying the |
| 6586 | // failure of the death test) or until the pipe is closed (signifying |
| 6587 | // its success), so it's okay to call this in the parent before |
| 6588 | // the child process has exited. |
| 6589 | do { |
| 6590 | bytes_read = posix::Read(read_fd(), &flag, 1); |
| 6591 | } while (bytes_read == -1 && errno == EINTR); |
| 6592 | |
| 6593 | if (bytes_read == 0) { |
| 6594 | set_outcome(DIED); |
| 6595 | } else if (bytes_read == 1) { |
| 6596 | switch (flag) { |
| 6597 | case kDeathTestReturned: |
| 6598 | set_outcome(RETURNED); |
| 6599 | break; |
| 6600 | case kDeathTestThrew: |
| 6601 | set_outcome(THREW); |
| 6602 | break; |
| 6603 | case kDeathTestLived: |
| 6604 | set_outcome(LIVED); |
| 6605 | break; |
| 6606 | case kDeathTestInternalError: |
| 6607 | FailFromInternalError(read_fd()); // Does not return. |
| 6608 | break; |
| 6609 | default: |
| 6610 | GTEST_LOG_(FATAL) << "Death test child process reported " |
| 6611 | << "unexpected status byte (" |
| 6612 | << static_cast<unsigned int>(flag) << ")"; |
| 6613 | } |
| 6614 | } else { |
| 6615 | GTEST_LOG_(FATAL) << "Read from death test child process failed: " |
| 6616 | << GetLastErrnoDescription(); |
| 6617 | } |
| 6618 | GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd())); |
| 6619 | set_read_fd(-1); |
| 6620 | } |
| 6621 | |
| 6622 | // Signals that the death test code which should have exited, didn't. |
| 6623 | // Should be called only in a death test child process. |
nothing calls this directly
no test coverage detected