38 #if GTEST_HAS_DEATH_TEST
41 # include <crt_externs.h>
42 # endif // GTEST_OS_MAC
50 # endif // GTEST_OS_LINUX
57 # include <sys/mman.h>
58 # include <sys/wait.h>
59 # endif // GTEST_OS_WINDOWS
63 # endif // GTEST_OS_QNX
65 #endif // GTEST_HAS_DEATH_TEST
75 #define GTEST_IMPLEMENTATION_ 1
77 #undef GTEST_IMPLEMENTATION_
89 "Indicates how to run a death test in a forked child process: "
90 "\"threadsafe\" (child process re-executes the test binary "
91 "from the beginning, running only the specific death test) or "
92 "\"fast\" (child process runs the death test immediately "
98 "Instructs to use fork()/_exit() instead of clone() in death tests. "
99 "Ignored and always uses fork() on POSIX systems where clone() is not "
100 "implemented. Useful when running under valgrind or similar tools if "
101 "those do not support clone(). Valgrind 3.3.1 will just fail if "
102 "it sees an unsupported combination of clone() flags. "
103 "It is not recommended to use this flag w/o valgrind though it will "
104 "work in 99% of the cases. Once valgrind is fixed, this flag will "
105 "most likely be removed.");
109 internal_run_death_test,
"",
110 "Indicates the file, line number, temporal index of "
111 "the single death test to run, and a file descriptor to "
112 "which a success code may be sent, all separated by "
113 "the '|' characters. This flag is specified if and only if the current "
114 "process is a sub-process launched for running a thread-safe "
115 "death test. FOR INTERNAL USE ONLY.");
118 #if GTEST_HAS_DEATH_TEST
124 # if !GTEST_OS_WINDOWS
125 static bool g_in_fast_death_test_child =
false;
133 bool InDeathTestChild() {
134 # if GTEST_OS_WINDOWS
138 return !
GTEST_FLAG(internal_run_death_test).empty();
142 if (
GTEST_FLAG(death_test_style) ==
"threadsafe")
143 return !
GTEST_FLAG(internal_run_death_test).empty();
145 return g_in_fast_death_test_child;
152 ExitedWithCode::ExitedWithCode(
int exit_code) : exit_code_(exit_code) {
156 bool ExitedWithCode::operator()(
int exit_status)
const {
157 # if GTEST_OS_WINDOWS
159 return exit_status == exit_code_;
163 return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_;
165 # endif // GTEST_OS_WINDOWS
168 # if !GTEST_OS_WINDOWS
170 KilledBySignal::KilledBySignal(
int signum) : signum_(signum) {
174 bool KilledBySignal::operator()(
int exit_status)
const {
175 # if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
178 if (GTEST_KILLED_BY_SIGNAL_OVERRIDE_(signum_, exit_status, &result)) {
182 # endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
183 return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
185 # endif // !GTEST_OS_WINDOWS
196 # if GTEST_OS_WINDOWS
198 m <<
"Exited with exit status " << exit_code;
202 if (WIFEXITED(exit_code)) {
203 m <<
"Exited with exit status " << WEXITSTATUS(exit_code);
204 }
else if (WIFSIGNALED(exit_code)) {
205 m <<
"Terminated by signal " << WTERMSIG(exit_code);
208 if (WCOREDUMP(exit_code)) {
209 m <<
" (core dumped)";
212 # endif // GTEST_OS_WINDOWS
214 return m.GetString();
219 bool ExitedUnsuccessfully(
int exit_status) {
220 return !ExitedWithCode(0)(exit_status);
223 # if !GTEST_OS_WINDOWS
228 static std::string DeathTestThreadWarning(
size_t thread_count) {
230 msg <<
"Death tests use fork(), which is unsafe particularly"
231 <<
" in a threaded context. For this test, " <<
GTEST_NAME_ <<
" ";
232 if (thread_count == 0)
233 msg <<
"couldn't detect the number of threads.";
235 msg <<
"detected " << thread_count <<
" threads.";
236 return msg.GetString();
238 # endif // !GTEST_OS_WINDOWS
241 static const char kDeathTestLived =
'L';
242 static const char kDeathTestReturned =
'R';
243 static const char kDeathTestThrew =
'T';
244 static const char kDeathTestInternalError =
'I';
255 enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
266 const InternalRunDeathTestFlag*
const flag =
270 fputc(kDeathTestInternalError, parent);
271 fprintf(parent,
"%s", message.c_str());
275 fprintf(stderr,
"%s", message.c_str());
283 # define GTEST_DEATH_TEST_CHECK_(expression) \
285 if (!::testing::internal::IsTrue(expression)) { \
287 ::std::string("CHECK failed: File ") + __FILE__ + ", line " \
288 + ::testing::internal::StreamableToString(__LINE__) + ": " \
291 } while (::testing::internal::AlwaysFalse())
300 # define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \
304 gtest_retval = (expression); \
305 } while (gtest_retval == -1 && errno == EINTR); \
306 if (gtest_retval == -1) { \
308 ::std::string("CHECK failed: File ") + __FILE__ + ", line " \
309 + ::testing::internal::StreamableToString(__LINE__) + ": " \
310 + #expression + " != -1"); \
312 } while (::testing::internal::AlwaysFalse())
323 static void FailFromInternalError(
int fd) {
329 while ((num_read =
posix::Read(fd, buffer, 255)) > 0) {
330 buffer[num_read] =
'\0';
333 }
while (num_read == -1 && errno == EINTR);
338 const int last_error = errno;
340 << GetLastErrnoDescription() <<
" [" << last_error <<
"]";
346 DeathTest::DeathTest() {
349 DeathTestAbort(
"Cannot run a death test outside of a TEST or "
356 bool DeathTest::Create(
const char* statement,
const RE* regex,
359 statement, regex, file, line, test);
362 const char* DeathTest::LastMessage() {
363 return last_death_test_message_.c_str();
366 void DeathTest::set_last_death_test_message(
const std::string& message) {
367 last_death_test_message_ =
message;
373 class DeathTestImpl :
public DeathTest {
375 DeathTestImpl(
const char* a_statement,
const RE* a_regex)
376 : statement_(a_statement),
380 outcome_(IN_PROGRESS),
385 ~DeathTestImpl() { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
387 void Abort(AbortReason reason);
388 virtual bool Passed(
bool status_ok);
390 const char* statement()
const {
return statement_; }
391 const RE* regex()
const {
return regex_; }
392 bool spawned()
const {
return spawned_; }
393 void set_spawned(
bool is_spawned) { spawned_ = is_spawned; }
394 int status()
const {
return status_; }
395 void set_status(
int a_status) { status_ = a_status; }
396 DeathTestOutcome outcome()
const {
return outcome_; }
397 void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; }
398 int read_fd()
const {
return read_fd_; }
399 void set_read_fd(
int fd) { read_fd_ =
fd; }
400 int write_fd()
const {
return write_fd_; }
401 void set_write_fd(
int fd) { write_fd_ =
fd; }
407 void ReadAndInterpretStatusByte();
412 const char*
const statement_;
415 const RE*
const regex_;
421 DeathTestOutcome outcome_;
436 void DeathTestImpl::ReadAndInterpretStatusByte() {
446 }
while (bytes_read == -1 && errno == EINTR);
448 if (bytes_read == 0) {
450 }
else if (bytes_read == 1) {
452 case kDeathTestReturned:
453 set_outcome(RETURNED);
455 case kDeathTestThrew:
458 case kDeathTestLived:
461 case kDeathTestInternalError:
462 FailFromInternalError(read_fd());
466 <<
"unexpected status byte ("
467 <<
static_cast<unsigned int>(flag) <<
")";
471 << GetLastErrnoDescription();
473 GTEST_DEATH_TEST_CHECK_SYSCALL_(
posix::Close(read_fd()));
485 const char status_ch =
486 reason == TEST_DID_NOT_DIE ? kDeathTestLived :
487 reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned;
489 GTEST_DEATH_TEST_CHECK_SYSCALL_(
posix::Write(write_fd(), &status_ch, 1));
506 for (
size_t at = 0; ; ) {
507 const size_t line_end = output.find(
'\n',
at);
509 if (line_end == ::std::string::npos) {
510 ret += output.substr(
at);
513 ret += output.substr(
at, line_end + 1 -
at);
541 bool DeathTestImpl::Passed(
bool status_ok) {
547 bool success =
false;
550 buffer <<
"Death test: " << statement() <<
"\n";
553 buffer <<
" Result: failed to die.\n"
554 <<
" Error msg:\n" << FormatDeathTestOutput(error_message);
557 buffer <<
" Result: threw an exception.\n"
558 <<
" Error msg:\n" << FormatDeathTestOutput(error_message);
561 buffer <<
" Result: illegal return in test statement.\n"
562 <<
" Error msg:\n" << FormatDeathTestOutput(error_message);
566 const bool matched = RE::PartialMatch(error_message.c_str(), *regex());
570 buffer <<
" Result: died but not with expected error.\n"
571 <<
" Expected: " << regex()->pattern() <<
"\n"
572 <<
"Actual msg:\n" << FormatDeathTestOutput(error_message);
575 buffer <<
" Result: died but not with expected exit code:\n"
576 <<
" " << ExitSummary(
status()) <<
"\n"
577 <<
"Actual msg:\n" << FormatDeathTestOutput(error_message);
583 <<
"DeathTest::Passed somehow called before conclusion of test";
586 DeathTest::set_last_death_test_message(buffer.GetString());
590 # if GTEST_OS_WINDOWS
619 class WindowsDeathTest :
public DeathTestImpl {
621 WindowsDeathTest(
const char* a_statement,
625 : DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
629 virtual TestRole AssumeRole();
633 const char*
const file_;
637 AutoHandle write_handle_;
639 AutoHandle child_handle_;
644 AutoHandle event_handle_;
650 int WindowsDeathTest::Wait() {
656 const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() };
657 switch (::WaitForMultipleObjects(2,
662 case WAIT_OBJECT_0 + 1:
665 GTEST_DEATH_TEST_CHECK_(
false);
670 write_handle_.Reset();
671 event_handle_.Reset();
673 ReadAndInterpretStatusByte();
679 GTEST_DEATH_TEST_CHECK_(
680 WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(),
683 GTEST_DEATH_TEST_CHECK_(
684 ::GetExitCodeProcess(child_handle_.Get(), &status_code) !=
FALSE);
685 child_handle_.Reset();
686 set_status(static_cast<int>(status_code));
695 DeathTest::TestRole WindowsDeathTest::AssumeRole() {
697 const InternalRunDeathTestFlag*
const flag =
698 impl->internal_run_death_test_flag();
699 const TestInfo*
const info = impl->current_test_info();
700 const int death_test_index = info->result()->death_test_count();
705 set_write_fd(flag->write_fd());
711 SECURITY_ATTRIBUTES handles_are_inheritable = {
712 sizeof(SECURITY_ATTRIBUTES), NULL,
TRUE };
713 HANDLE read_handle, write_handle;
714 GTEST_DEATH_TEST_CHECK_(
715 ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,
718 set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle),
720 write_handle_.Reset(write_handle);
721 event_handle_.Reset(::CreateEvent(
722 &handles_are_inheritable,
726 GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);
729 info->test_case_name() +
"." + info->name();
741 char executable_path[_MAX_PATH + 1];
742 GTEST_DEATH_TEST_CHECK_(
743 _MAX_PATH + 1 != ::GetModuleFileNameA(NULL,
748 std::string(::GetCommandLineA()) +
" " + filter_flag +
" \"" +
749 internal_flag +
"\"";
751 DeathTest::set_last_death_test_message(
"");
758 STARTUPINFOA startup_info;
759 memset(&startup_info, 0,
sizeof(STARTUPINFO));
760 startup_info.dwFlags = STARTF_USESTDHANDLES;
761 startup_info.hStdInput = ::GetStdHandle(STD_INPUT_HANDLE);
762 startup_info.hStdOutput = ::GetStdHandle(STD_OUTPUT_HANDLE);
763 startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE);
765 PROCESS_INFORMATION process_info;
766 GTEST_DEATH_TEST_CHECK_(::CreateProcessA(
768 const_cast<char*>(command_line.c_str()),
774 UnitTest::GetInstance()->original_working_dir(),
776 &process_info) !=
FALSE);
777 child_handle_.Reset(process_info.hProcess);
778 ::CloseHandle(process_info.hThread);
782 # else // We are not on Windows.
787 class ForkingDeathTest :
public DeathTestImpl {
789 ForkingDeathTest(
const char* statement,
const RE* regex);
795 void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }
803 ForkingDeathTest::ForkingDeathTest(
const char* a_statement,
const RE* a_regex)
804 : DeathTestImpl(a_statement, a_regex),
810 int ForkingDeathTest::Wait() {
814 ReadAndInterpretStatusByte();
817 GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_value, 0));
818 set_status(status_value);
824 class NoExecDeathTest :
public ForkingDeathTest {
826 NoExecDeathTest(
const char* a_statement,
const RE* a_regex) :
827 ForkingDeathTest(a_statement, a_regex) { }
828 virtual TestRole AssumeRole();
833 DeathTest::TestRole NoExecDeathTest::AssumeRole() {
835 if (thread_count != 1) {
840 GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
842 DeathTest::set_last_death_test_message(
"");
853 const pid_t child_pid = fork();
854 GTEST_DEATH_TEST_CHECK_(child_pid != -1);
855 set_child_pid(child_pid);
856 if (child_pid == 0) {
857 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[0]));
858 set_write_fd(pipe_fd[1]);
866 g_in_fast_death_test_child =
true;
869 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
870 set_read_fd(pipe_fd[0]);
879 class ExecDeathTest :
public ForkingDeathTest {
881 ExecDeathTest(
const char* a_statement,
const RE* a_regex,
882 const char* file,
int line) :
883 ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
884 virtual TestRole AssumeRole();
886 static ::std::vector<testing::internal::string>
887 GetArgvsForDeathTestChildProcess() {
888 ::std::vector<testing::internal::string>
args = GetInjectableArgvs();
889 # if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
890 ::std::vector<testing::internal::string> extra_args =
891 GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_();
892 args.insert(args.end(), extra_args.begin(), extra_args.end());
893 # endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
897 const char*
const file_;
906 args_.push_back(NULL);
910 for (std::vector<char*>::iterator
i = args_.begin();
i != args_.end();
915 void AddArgument(
const char* argument) {
919 template <
typename Str>
920 void AddArguments(const ::std::vector<Str>& arguments) {
921 for (typename ::std::vector<Str>::const_iterator
i = arguments.begin();
922 i != arguments.end();
927 char*
const* Argv() {
932 std::vector<char*> args_;
937 struct ExecDeathTestArgs {
943 inline char** GetEnviron() {
947 return *_NSGetEnviron();
953 inline char** GetEnviron() {
return environ; }
954 # endif // GTEST_OS_MAC
960 static int ExecDeathTestChildMain(
void* child_arg) {
961 ExecDeathTestArgs*
const args =
static_cast<ExecDeathTestArgs*
>(child_arg);
962 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd));
967 const char*
const original_dir =
968 UnitTest::GetInstance()->original_working_dir();
970 if (chdir(original_dir) != 0) {
971 DeathTestAbort(
std::string(
"chdir(\"") + original_dir +
"\") failed: " +
972 GetLastErrnoDescription());
981 execve(args->argv[0], args->argv, GetEnviron());
982 DeathTestAbort(
std::string(
"execve(") + args->argv[0] +
", ...) in " +
983 original_dir +
" failed: " +
984 GetLastErrnoDescription());
987 # endif // !GTEST_OS_QNX
999 void StackLowerThanAddress(
const void* ptr,
bool* result) {
1001 *result = (&dummy < ptr);
1006 bool StackGrowsDown() {
1009 StackLowerThanAddress(&dummy, &result);
1020 static pid_t ExecDeathTestSpawnChild(
char*
const* argv,
int close_fd) {
1021 ExecDeathTestArgs args = { argv, close_fd };
1022 pid_t child_pid = -1;
1027 const int cwd_fd =
open(
".", O_RDONLY);
1028 GTEST_DEATH_TEST_CHECK_(cwd_fd != -1);
1029 GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(cwd_fd, F_SETFD, FD_CLOEXEC));
1033 const char*
const original_dir =
1034 UnitTest::GetInstance()->original_working_dir();
1036 if (chdir(original_dir) != 0) {
1037 DeathTestAbort(
std::string(
"chdir(\"") + original_dir +
"\") failed: " +
1038 GetLastErrnoDescription());
1039 return EXIT_FAILURE;
1044 GTEST_DEATH_TEST_CHECK_SYSCALL_(fd_flags = fcntl(close_fd, F_GETFD));
1045 GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(close_fd, F_SETFD,
1046 fd_flags | FD_CLOEXEC));
1047 struct inheritance inherit = {0};
1049 child_pid = spawn(args.argv[0], 0, NULL, &inherit, args.argv, GetEnviron());
1051 GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1);
1052 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
1054 # else // GTEST_OS_QNX
1059 struct sigaction saved_sigprof_action;
1060 struct sigaction ignore_sigprof_action;
1061 memset(&ignore_sigprof_action, 0,
sizeof(ignore_sigprof_action));
1062 sigemptyset(&ignore_sigprof_action.sa_mask);
1063 ignore_sigprof_action.sa_handler = SIG_IGN;
1064 GTEST_DEATH_TEST_CHECK_SYSCALL_(sigaction(
1065 SIGPROF, &ignore_sigprof_action, &saved_sigprof_action));
1066 # endif // GTEST_OS_LINUX
1068 # if GTEST_HAS_CLONE
1069 const bool use_fork =
GTEST_FLAG(death_test_use_fork);
1072 static const bool stack_grows_down = StackGrowsDown();
1073 const size_t stack_size = getpagesize();
1075 void*
const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
1076 MAP_ANON | MAP_PRIVATE, -1, 0);
1077 GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
1085 const size_t kMaxStackAlignment = 64;
1086 void*
const stack_top =
1087 static_cast<char*
>(stack) +
1088 (stack_grows_down ? stack_size - kMaxStackAlignment : 0);
1089 GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment &&
1090 reinterpret_cast<intptr_t>(stack_top) % kMaxStackAlignment == 0);
1092 child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
1094 GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
1097 const bool use_fork =
true;
1098 # endif // GTEST_HAS_CLONE
1100 if (use_fork && (child_pid = fork()) == 0) {
1101 ExecDeathTestChildMain(&args);
1104 # endif // GTEST_OS_QNX
1106 GTEST_DEATH_TEST_CHECK_SYSCALL_(
1107 sigaction(SIGPROF, &saved_sigprof_action, NULL));
1108 # endif // GTEST_OS_LINUX
1110 GTEST_DEATH_TEST_CHECK_(child_pid != -1);
1118 DeathTest::TestRole ExecDeathTest::AssumeRole() {
1120 const InternalRunDeathTestFlag*
const flag =
1121 impl->internal_run_death_test_flag();
1122 const TestInfo*
const info = impl->current_test_info();
1123 const int death_test_index = info->result()->death_test_count();
1126 set_write_fd(flag->write_fd());
1127 return EXECUTE_TEST;
1131 GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
1134 GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
1138 + info->test_case_name() +
"." + info->name();
1145 args.AddArguments(GetArgvsForDeathTestChildProcess());
1146 args.AddArgument(filter_flag.c_str());
1147 args.AddArgument(internal_flag.c_str());
1149 DeathTest::set_last_death_test_message(
"");
1156 const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]);
1157 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
1158 set_child_pid(child_pid);
1159 set_read_fd(pipe_fd[0]);
1161 return OVERSEE_TEST;
1164 # endif // !GTEST_OS_WINDOWS
1171 bool DefaultDeathTestFactory::Create(
const char* statement,
const RE* regex,
1172 const char* file,
int line,
1175 const InternalRunDeathTestFlag*
const flag =
1176 impl->internal_run_death_test_flag();
1177 const int death_test_index = impl->current_test_info()
1178 ->increment_death_test_count();
1181 if (death_test_index > flag->index()) {
1182 DeathTest::set_last_death_test_message(
1184 +
") somehow exceeded expected maximum ("
1189 if (!(flag->file() == file && flag->line() == line &&
1190 flag->index() == death_test_index)) {
1196 # if GTEST_OS_WINDOWS
1198 if (
GTEST_FLAG(death_test_style) ==
"threadsafe" ||
1200 *test =
new WindowsDeathTest(statement, regex, file, line);
1205 if (
GTEST_FLAG(death_test_style) ==
"threadsafe") {
1206 *test =
new ExecDeathTest(statement, regex, file, line);
1207 }
else if (
GTEST_FLAG(death_test_style) ==
"fast") {
1208 *test =
new NoExecDeathTest(statement, regex);
1211 # endif // GTEST_OS_WINDOWS
1214 DeathTest::set_last_death_test_message(
1215 "Unknown death test style \"" +
GTEST_FLAG(death_test_style)
1216 +
"\" encountered");
1223 # if GTEST_OS_WINDOWS
1227 int GetStatusFileDescriptor(
unsigned int parent_process_id,
1228 size_t write_handle_as_size_t,
1229 size_t event_handle_as_size_t) {
1230 AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,
1232 parent_process_id));
1233 if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
1234 DeathTestAbort(
"Unable to open parent process " +
1242 const HANDLE write_handle =
1243 reinterpret_cast<HANDLE
>(write_handle_as_size_t);
1244 HANDLE dup_write_handle;
1249 if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,
1250 ::GetCurrentProcess(), &dup_write_handle,
1254 DUPLICATE_SAME_ACCESS)) {
1255 DeathTestAbort(
"Unable to duplicate the pipe handle " +
1257 " from the parent process " +
1261 const HANDLE event_handle =
reinterpret_cast<HANDLE
>(event_handle_as_size_t);
1262 HANDLE dup_event_handle;
1264 if (!::DuplicateHandle(parent_process_handle.Get(), event_handle,
1265 ::GetCurrentProcess(), &dup_event_handle,
1268 DUPLICATE_SAME_ACCESS)) {
1269 DeathTestAbort(
"Unable to duplicate the event handle " +
1271 " from the parent process " +
1275 const int write_fd =
1276 ::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
1277 if (write_fd == -1) {
1278 DeathTestAbort(
"Unable to convert pipe handle " +
1280 " to a file descriptor");
1285 ::SetEvent(dup_event_handle);
1289 # endif // GTEST_OS_WINDOWS
1294 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
1295 if (
GTEST_FLAG(internal_run_death_test) ==
"")
return NULL;
1301 ::std::vector< ::std::string> fields;
1305 # if GTEST_OS_WINDOWS
1307 unsigned int parent_process_id = 0;
1308 size_t write_handle_as_size_t = 0;
1309 size_t event_handle_as_size_t = 0;
1311 if (fields.size() != 6
1312 || !ParseNaturalNumber(fields[1], &line)
1313 || !ParseNaturalNumber(fields[2], &index)
1314 || !ParseNaturalNumber(fields[3], &parent_process_id)
1315 || !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
1316 || !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
1317 DeathTestAbort(
"Bad --gtest_internal_run_death_test flag: " +
1320 write_fd = GetStatusFileDescriptor(parent_process_id,
1321 write_handle_as_size_t,
1322 event_handle_as_size_t);
1325 if (fields.size() != 4
1326 || !ParseNaturalNumber(fields[1], &line)
1327 || !ParseNaturalNumber(fields[2], &index)
1328 || !ParseNaturalNumber(fields[3], &write_fd)) {
1329 DeathTestAbort(
"Bad --gtest_internal_run_death_test flag: "
1333 # endif // GTEST_OS_WINDOWS
1335 return new InternalRunDeathTestFlag(fields[0], line, index, write_fd);
1340 #endif // GTEST_HAS_DEATH_TEST