The AssumeRole process for a Windows death test. It creates a child process with the same executable as the current process to run the death test. The child process is given the --gtest_filter and --gtest_internal_run_death_test flags such that it knows to run the current death test only.
| 6838 | // --gtest_internal_run_death_test flags such that it knows to run the |
| 6839 | // current death test only. |
| 6840 | DeathTest::TestRole WindowsDeathTest::AssumeRole() { |
| 6841 | const UnitTestImpl* const impl = GetUnitTestImpl(); |
| 6842 | const InternalRunDeathTestFlag* const flag = |
| 6843 | impl->internal_run_death_test_flag(); |
| 6844 | const TestInfo* const info = impl->current_test_info(); |
| 6845 | const int death_test_index = info->result()->death_test_count(); |
| 6846 | |
| 6847 | if (flag != NULL) { |
| 6848 | // ParseInternalRunDeathTestFlag() has performed all the necessary |
| 6849 | // processing. |
| 6850 | set_write_fd(flag->write_fd()); |
| 6851 | return EXECUTE_TEST; |
| 6852 | } |
| 6853 | |
| 6854 | // WindowsDeathTest uses an anonymous pipe to communicate results of |
| 6855 | // a death test. |
| 6856 | SECURITY_ATTRIBUTES handles_are_inheritable = { |
| 6857 | sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; |
| 6858 | HANDLE read_handle, write_handle; |
| 6859 | GTEST_DEATH_TEST_CHECK_( |
| 6860 | ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable, |
| 6861 | 0) // Default buffer size. |
| 6862 | != FALSE); |
| 6863 | set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle), |
| 6864 | O_RDONLY)); |
| 6865 | write_handle_.Reset(write_handle); |
| 6866 | event_handle_.Reset(::CreateEvent( |
| 6867 | &handles_are_inheritable, |
| 6868 | TRUE, // The event will automatically reset to non-signaled state. |
| 6869 | FALSE, // The initial state is non-signalled. |
| 6870 | NULL)); // The even is unnamed. |
| 6871 | GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL); |
| 6872 | const String filter_flag = String::Format("--%s%s=%s.%s", |
| 6873 | GTEST_FLAG_PREFIX_, kFilterFlag, |
| 6874 | info->test_case_name(), |
| 6875 | info->name()); |
| 6876 | const String internal_flag = String::Format( |
| 6877 | "--%s%s=%s|%d|%d|%u|%Iu|%Iu", |
| 6878 | GTEST_FLAG_PREFIX_, |
| 6879 | kInternalRunDeathTestFlag, |
| 6880 | file_, line_, |
| 6881 | death_test_index, |
| 6882 | static_cast<unsigned int>(::GetCurrentProcessId()), |
| 6883 | // size_t has the same with as pointers on both 32-bit and 64-bit |
| 6884 | // Windows platforms. |
| 6885 | // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx. |
| 6886 | reinterpret_cast<size_t>(write_handle), |
| 6887 | reinterpret_cast<size_t>(event_handle_.Get())); |
| 6888 | |
| 6889 | char executable_path[_MAX_PATH + 1]; // NOLINT |
| 6890 | GTEST_DEATH_TEST_CHECK_( |
| 6891 | _MAX_PATH + 1 != ::GetModuleFileNameA(NULL, |
| 6892 | executable_path, |
| 6893 | _MAX_PATH)); |
| 6894 | |
| 6895 | String command_line = String::Format("%s %s \"%s\"", |
| 6896 | ::GetCommandLineA(), |
| 6897 | filter_flag.c_str(), |
nothing calls this directly
no test coverage detected