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.
| 6793 | // status, or 0 if no child process exists. As a side effect, sets the |
| 6794 | // outcome data member. |
| 6795 | int WindowsDeathTest::Wait() { |
| 6796 | if (!spawned()) |
| 6797 | return 0; |
| 6798 | |
| 6799 | // Wait until the child either signals that it has acquired the write end |
| 6800 | // of the pipe or it dies. |
| 6801 | const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() }; |
| 6802 | switch (::WaitForMultipleObjects(2, |
| 6803 | wait_handles, |
| 6804 | FALSE, // Waits for any of the handles. |
| 6805 | INFINITE)) { |
| 6806 | case WAIT_OBJECT_0: |
| 6807 | case WAIT_OBJECT_0 + 1: |
| 6808 | break; |
| 6809 | default: |
| 6810 | GTEST_DEATH_TEST_CHECK_(false); // Should not get here. |
| 6811 | } |
| 6812 | |
| 6813 | // The child has acquired the write end of the pipe or exited. |
| 6814 | // We release the handle on our side and continue. |
| 6815 | write_handle_.Reset(); |
| 6816 | event_handle_.Reset(); |
| 6817 | |
| 6818 | ReadAndInterpretStatusByte(); |
| 6819 | |
| 6820 | // Waits for the child process to exit if it haven't already. This |
| 6821 | // returns immediately if the child has already exited, regardless of |
| 6822 | // whether previous calls to WaitForMultipleObjects synchronized on this |
| 6823 | // handle or not. |
| 6824 | GTEST_DEATH_TEST_CHECK_( |
| 6825 | WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(), |
| 6826 | INFINITE)); |
| 6827 | DWORD status_code; |
| 6828 | GTEST_DEATH_TEST_CHECK_( |
| 6829 | ::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE); |
| 6830 | child_handle_.Reset(); |
| 6831 | set_status(static_cast<int>(status_code)); |
| 6832 | return status(); |
| 6833 | } |
| 6834 | |
| 6835 | // The AssumeRole process for a Windows death test. It creates a child |
| 6836 | // process with the same executable as the current process to run the |