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.
| 7176 | // --gtest_internal_run_death_test flags such that it knows to run the |
| 7177 | // current death test only. |
| 7178 | DeathTest::TestRole WindowsDeathTest::AssumeRole() { |
| 7179 | const UnitTestImpl* const impl = GetUnitTestImpl(); |
| 7180 | const InternalRunDeathTestFlag* const flag = |
| 7181 | impl->internal_run_death_test_flag(); |
| 7182 | const TestInfo* const info = impl->current_test_info(); |
| 7183 | const int death_test_index = info->result()->death_test_count(); |
| 7184 | |
| 7185 | if (flag != NULL) { |
| 7186 | // ParseInternalRunDeathTestFlag() has performed all the necessary |
| 7187 | // processing. |
| 7188 | set_write_fd(flag->write_fd()); |
| 7189 | return EXECUTE_TEST; |
| 7190 | } |
| 7191 | |
| 7192 | // WindowsDeathTest uses an anonymous pipe to communicate results of |
| 7193 | // a death test. |
| 7194 | SECURITY_ATTRIBUTES handles_are_inheritable = { |
| 7195 | sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; |
| 7196 | HANDLE read_handle, write_handle; |
| 7197 | GTEST_DEATH_TEST_CHECK_( |
| 7198 | ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable, |
| 7199 | 0) // Default buffer size. |
| 7200 | != FALSE); |
| 7201 | set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle), |
| 7202 | O_RDONLY)); |
| 7203 | write_handle_.Reset(write_handle); |
| 7204 | event_handle_.Reset(::CreateEvent( |
| 7205 | &handles_are_inheritable, |
| 7206 | TRUE, // The event will automatically reset to non-signaled state. |
| 7207 | FALSE, // The initial state is non-signalled. |
| 7208 | NULL)); // The even is unnamed. |
| 7209 | GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL); |
| 7210 | const std::string filter_flag = |
| 7211 | std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" + |
| 7212 | info->test_case_name() + "." + info->name(); |
| 7213 | const std::string internal_flag = |
| 7214 | std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + |
| 7215 | "=" + file_ + "|" + StreamableToString(line_) + "|" + |
| 7216 | StreamableToString(death_test_index) + "|" + |
| 7217 | StreamableToString(static_cast<unsigned int>(::GetCurrentProcessId())) + |
| 7218 | // size_t has the same width as pointers on both 32-bit and 64-bit |
| 7219 | // Windows platforms. |
| 7220 | // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx. |
| 7221 | "|" + StreamableToString(reinterpret_cast<size_t>(write_handle)) + |
| 7222 | "|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get())); |
| 7223 | |
| 7224 | char executable_path[_MAX_PATH + 1]; // NOLINT |
| 7225 | GTEST_DEATH_TEST_CHECK_( |
| 7226 | _MAX_PATH + 1 != ::GetModuleFileNameA(NULL, |
| 7227 | executable_path, |
| 7228 | _MAX_PATH)); |
| 7229 | |
| 7230 | std::string command_line = |
| 7231 | std::string(::GetCommandLineA()) + " " + filter_flag + " \"" + |
| 7232 | internal_flag + "\""; |
| 7233 | |
| 7234 | DeathTest::set_last_death_test_message(""); |
| 7235 |
nothing calls this directly
no test coverage detected