MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / AssumeRole

Method AssumeRole

tests/gtest/gtest-all.cc:8322–8406  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

8320// --gtest_internal_run_death_test flags such that it knows to run the
8321// current death test only.
8322DeathTest::TestRole WindowsDeathTest::AssumeRole() {
8323 const UnitTestImpl* const impl = GetUnitTestImpl();
8324 const InternalRunDeathTestFlag* const flag =
8325 impl->internal_run_death_test_flag();
8326 const TestInfo* const info = impl->current_test_info();
8327 const int death_test_index = info->result()->death_test_count();
8328
8329 if (flag != nullptr) {
8330 // ParseInternalRunDeathTestFlag() has performed all the necessary
8331 // processing.
8332 set_write_fd(flag->write_fd());
8333 return EXECUTE_TEST;
8334 }
8335
8336 // WindowsDeathTest uses an anonymous pipe to communicate results of
8337 // a death test.
8338 SECURITY_ATTRIBUTES handles_are_inheritable = {sizeof(SECURITY_ATTRIBUTES),
8339 nullptr, TRUE};
8340 HANDLE read_handle, write_handle;
8341 GTEST_DEATH_TEST_CHECK_(
8342 ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,
8343 0) // Default buffer size.
8344 != FALSE);
8345 set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle),
8346 O_RDONLY));
8347 write_handle_.Reset(write_handle);
8348 event_handle_.Reset(::CreateEvent(
8349 &handles_are_inheritable,
8350 TRUE, // The event will automatically reset to non-signaled state.
8351 FALSE, // The initial state is non-signalled.
8352 nullptr)); // The even is unnamed.
8353 GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr);
8354 const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
8355 kFilterFlag + "=" + info->test_suite_name() +
8356 "." + info->name();
8357 const std::string internal_flag =
8358 std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
8359 "=" + file_ + "|" + StreamableToString(line_) + "|" +
8360 StreamableToString(death_test_index) + "|" +
8361 StreamableToString(static_cast<unsigned int>(::GetCurrentProcessId())) +
8362 // size_t has the same width as pointers on both 32-bit and 64-bit
8363 // Windows platforms.
8364 // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
8365 "|" + StreamableToString(reinterpret_cast<size_t>(write_handle)) +
8366 "|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
8367
8368 char executable_path[_MAX_PATH + 1]; // NOLINT
8369 GTEST_DEATH_TEST_CHECK_(_MAX_PATH + 1 != ::GetModuleFileNameA(nullptr,
8370 executable_path,
8371 _MAX_PATH));
8372
8373 std::string command_line =
8374 std::string(::GetCommandLineA()) + " " + filter_flag + " \"" +
8375 internal_flag + "\"";
8376
8377 DeathTest::set_last_death_test_message("");
8378
8379 CaptureStderr();

Callers

nothing calls this directly

Calls 15

GetUnitTestImplFunction · 0.85
StreamableToStringFunction · 0.85
CaptureStderrFunction · 0.85
FlushInfoLogFunction · 0.85
GetInjectableArgvsFunction · 0.85
GetThreadCountFunction · 0.85
DeathTestThreadWarningFunction · 0.85
LogToStderrFunction · 0.85
ExecDeathTestSpawnChildFunction · 0.85
ResetMethod · 0.80
GetMethod · 0.80
original_working_dirMethod · 0.80

Tested by

no test coverage detected