Waits for the child in a death test to exit, returning its exit status, or 0 if no child process exists. As a side effect, sets the outcome data member.
| 7565 | // status, or 0 if no child process exists. As a side effect, sets the |
| 7566 | // outcome data member. |
| 7567 | int WindowsDeathTest::Wait() { |
| 7568 | if (!spawned()) |
| 7569 | return 0; |
| 7570 | |
| 7571 | // Wait until the child either signals that it has acquired the write end |
| 7572 | // of the pipe or it dies. |
| 7573 | const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() }; |
| 7574 | switch (::WaitForMultipleObjects(2, |
| 7575 | wait_handles, |
| 7576 | FALSE, // Waits for any of the handles. |
| 7577 | INFINITE)) { |
| 7578 | case WAIT_OBJECT_0: |
| 7579 | case WAIT_OBJECT_0 + 1: |
| 7580 | break; |
| 7581 | default: |
| 7582 | GTEST_DEATH_TEST_CHECK_(false); // Should not get here. |
| 7583 | } |
| 7584 | |
| 7585 | // The child has acquired the write end of the pipe or exited. |
| 7586 | // We release the handle on our side and continue. |
| 7587 | write_handle_.Reset(); |
| 7588 | event_handle_.Reset(); |
| 7589 | |
| 7590 | ReadAndInterpretStatusByte(); |
| 7591 | |
| 7592 | // Waits for the child process to exit if it haven't already. This |
| 7593 | // returns immediately if the child has already exited, regardless of |
| 7594 | // whether previous calls to WaitForMultipleObjects synchronized on this |
| 7595 | // handle or not. |
| 7596 | GTEST_DEATH_TEST_CHECK_( |
| 7597 | WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(), |
| 7598 | INFINITE)); |
| 7599 | DWORD status_code; |
| 7600 | GTEST_DEATH_TEST_CHECK_( |
| 7601 | ::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE); |
| 7602 | child_handle_.Reset(); |
| 7603 | set_status(static_cast<int>(status_code)); |
| 7604 | return status(); |
| 7605 | } |
| 7606 | |
| 7607 | // The AssumeRole process for a Windows death test. It creates a child |
| 7608 | // process with the same executable as the current process to run the |