34 #include "gtest/gtest-death-test.h" 35 #include "gtest/internal/gtest-port.h" 37 #if GTEST_HAS_DEATH_TEST 40 # include <crt_externs.h> 41 # endif // GTEST_OS_MAC 49 # endif // GTEST_OS_LINUX 56 # include <sys/mman.h> 57 # include <sys/wait.h> 58 # endif // GTEST_OS_WINDOWS 62 # endif // GTEST_OS_QNX 64 #endif // GTEST_HAS_DEATH_TEST 66 #include "gtest/gtest-message.h" 67 #include "gtest/internal/gtest-string.h" 74 #define GTEST_IMPLEMENTATION_ 1 75 #include "src/gtest-internal-inl.h" 76 #undef GTEST_IMPLEMENTATION_ 88 "Indicates how to run a death test in a forked child process: " 89 "\"threadsafe\" (child process re-executes the test binary " 90 "from the beginning, running only the specific death test) or " 91 "\"fast\" (child process runs the death test immediately " 97 "Instructs to use fork()/_exit() instead of clone() in death tests. " 98 "Ignored and always uses fork() on POSIX systems where clone() is not " 99 "implemented. Useful when running under valgrind or similar tools if " 100 "those do not support clone(). Valgrind 3.3.1 will just fail if " 101 "it sees an unsupported combination of clone() flags. " 102 "It is not recommended to use this flag w/o valgrind though it will " 103 "work in 99% of the cases. Once valgrind is fixed, this flag will " 104 "most likely be removed.");
108 internal_run_death_test,
"",
109 "Indicates the file, line number, temporal index of " 110 "the single death test to run, and a file descriptor to " 111 "which a success code may be sent, all separated by " 112 "the '|' characters. This flag is specified if and only if the current " 113 "process is a sub-process launched for running a thread-safe " 114 "death test. FOR INTERNAL USE ONLY.");
117 #if GTEST_HAS_DEATH_TEST 123 static bool g_in_fast_death_test_child =
false;
130 bool InDeathTestChild() {
131 # if GTEST_OS_WINDOWS 135 return !
GTEST_FLAG(internal_run_death_test).empty();
139 if (
GTEST_FLAG(death_test_style) ==
"threadsafe")
140 return !
GTEST_FLAG(internal_run_death_test).empty();
142 return g_in_fast_death_test_child;
149 ExitedWithCode::ExitedWithCode(
int exit_code) : exit_code_(exit_code) {
153 bool ExitedWithCode::operator()(
int exit_status)
const {
154 # if GTEST_OS_WINDOWS 156 return exit_status == exit_code_;
160 return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_;
162 # endif // GTEST_OS_WINDOWS 165 # if !GTEST_OS_WINDOWS 167 KilledBySignal::KilledBySignal(
int signum) : signum_(signum) {
171 bool KilledBySignal::operator()(
int exit_status)
const {
172 return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
174 # endif // !GTEST_OS_WINDOWS 185 # if GTEST_OS_WINDOWS 187 m <<
"Exited with exit status " << exit_code;
191 if (WIFEXITED(exit_code)) {
192 m <<
"Exited with exit status " << WEXITSTATUS(exit_code);
193 }
else if (WIFSIGNALED(exit_code)) {
194 m <<
"Terminated by signal " << WTERMSIG(exit_code);
197 if (WCOREDUMP(exit_code)) {
198 m <<
" (core dumped)";
201 # endif // GTEST_OS_WINDOWS 208 bool ExitedUnsuccessfully(
int exit_status) {
209 return !ExitedWithCode(0)(exit_status);
212 # if !GTEST_OS_WINDOWS 217 static std::string DeathTestThreadWarning(
size_t thread_count) {
219 msg <<
"Death tests use fork(), which is unsafe particularly" 220 <<
" in a threaded context. For this test, " <<
GTEST_NAME_ <<
" ";
221 if (thread_count == 0)
222 msg <<
"couldn't detect the number of threads.";
224 msg <<
"detected " << thread_count <<
" threads.";
227 # endif // !GTEST_OS_WINDOWS 230 static const char kDeathTestLived =
'L';
231 static const char kDeathTestReturned =
'R';
232 static const char kDeathTestThrew =
'T';
233 static const char kDeathTestInternalError =
'I';
244 enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
255 const InternalRunDeathTestFlag*
const flag =
259 fputc(kDeathTestInternalError, parent);
260 fprintf(parent,
"%s", message.c_str());
264 fprintf(stderr,
"%s", message.c_str());
272 # define GTEST_DEATH_TEST_CHECK_(expression) \ 274 if (!::testing::internal::IsTrue(expression)) { \ 276 ::std::string("CHECK failed: File ") + __FILE__ + ", line " \ 277 + ::testing::internal::StreamableToString(__LINE__) + ": " \ 280 } while (::testing::internal::AlwaysFalse()) 289 # define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \ 293 gtest_retval = (expression); \ 294 } while (gtest_retval == -1 && errno == EINTR); \ 295 if (gtest_retval == -1) { \ 297 ::std::string("CHECK failed: File ") + __FILE__ + ", line " \ 298 + ::testing::internal::StreamableToString(__LINE__) + ": " \ 299 + #expression + " != -1"); \ 301 } while (::testing::internal::AlwaysFalse()) 312 static void FailFromInternalError(
int fd) {
318 while ((num_read =
posix::Read(fd, buffer, 255)) > 0) {
319 buffer[num_read] =
'\0';
322 }
while (num_read == -1 && errno == EINTR);
327 const int last_error = errno;
328 GTEST_LOG_(FATAL) <<
"Error while reading death test internal: " 329 << GetLastErrnoDescription() <<
" [" << last_error <<
"]";
335 DeathTest::DeathTest() {
338 DeathTestAbort(
"Cannot run a death test outside of a TEST or " 345 bool DeathTest::Create(
const char* statement,
const RE* regex,
346 const char* file,
int line, DeathTest**
test) {
348 statement, regex, file, line, test);
351 const char* DeathTest::LastMessage() {
352 return last_death_test_message_.c_str();
355 void DeathTest::set_last_death_test_message(
const std::string& message) {
356 last_death_test_message_ =
message;
362 class DeathTestImpl :
public DeathTest {
364 DeathTestImpl(
const char* a_statement,
const RE* a_regex)
365 : statement_(a_statement),
369 outcome_(IN_PROGRESS),
374 ~DeathTestImpl() { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
376 void Abort(AbortReason reason);
377 virtual bool Passed(
bool status_ok);
379 const char* statement()
const {
return statement_; }
380 const RE* regex()
const {
return regex_; }
381 bool spawned()
const {
return spawned_; }
382 void set_spawned(
bool is_spawned) { spawned_ = is_spawned; }
383 int status()
const {
return status_; }
384 void set_status(
int a_status) { status_ = a_status; }
385 DeathTestOutcome outcome()
const {
return outcome_; }
386 void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; }
387 int read_fd()
const {
return read_fd_; }
388 void set_read_fd(
int fd) { read_fd_ = fd; }
389 int write_fd()
const {
return write_fd_; }
390 void set_write_fd(
int fd) { write_fd_ = fd; }
396 void ReadAndInterpretStatusByte();
401 const char*
const statement_;
404 const RE*
const regex_;
410 DeathTestOutcome outcome_;
425 void DeathTestImpl::ReadAndInterpretStatusByte() {
435 }
while (bytes_read == -1 && errno == EINTR);
437 if (bytes_read == 0) {
439 }
else if (bytes_read == 1) {
441 case kDeathTestReturned:
442 set_outcome(RETURNED);
444 case kDeathTestThrew:
447 case kDeathTestLived:
450 case kDeathTestInternalError:
451 FailFromInternalError(read_fd());
454 GTEST_LOG_(FATAL) <<
"Death test child process reported " 455 <<
"unexpected status byte (" 456 <<
static_cast<unsigned int>(flag) <<
")";
459 GTEST_LOG_(FATAL) <<
"Read from death test child process failed: " 460 << GetLastErrnoDescription();
462 GTEST_DEATH_TEST_CHECK_SYSCALL_(
posix::Close(read_fd()));
474 const char status_ch =
475 reason == TEST_DID_NOT_DIE ? kDeathTestLived :
476 reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned;
478 GTEST_DEATH_TEST_CHECK_SYSCALL_(
posix::Write(write_fd(), &status_ch, 1));
495 for (
size_t at = 0; ; ) {
496 const size_t line_end = output.find(
'\n', at);
498 if (line_end == ::std::string::npos) {
499 ret += output.substr(at);
502 ret += output.substr(at, line_end + 1 - at);
530 bool DeathTestImpl::Passed(
bool status_ok) {
536 bool success =
false;
539 buffer <<
"Death test: " << statement() <<
"\n";
542 buffer <<
" Result: failed to die.\n" 543 <<
" Error msg:\n" << FormatDeathTestOutput(error_message);
546 buffer <<
" Result: threw an exception.\n" 547 <<
" Error msg:\n" << FormatDeathTestOutput(error_message);
550 buffer <<
" Result: illegal return in test statement.\n" 551 <<
" Error msg:\n" << FormatDeathTestOutput(error_message);
559 buffer <<
" Result: died but not with expected error.\n" 560 <<
" Expected: " << regex()->pattern() <<
"\n" 561 <<
"Actual msg:\n" << FormatDeathTestOutput(error_message);
564 buffer <<
" Result: died but not with expected exit code:\n" 565 <<
" " << ExitSummary(status()) <<
"\n" 566 <<
"Actual msg:\n" << FormatDeathTestOutput(error_message);
572 <<
"DeathTest::Passed somehow called before conclusion of test";
575 DeathTest::set_last_death_test_message(buffer.
GetString());
579 # if GTEST_OS_WINDOWS 608 class WindowsDeathTest :
public DeathTestImpl {
610 WindowsDeathTest(
const char* a_statement,
614 : DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
618 virtual TestRole AssumeRole();
622 const char*
const file_;
626 AutoHandle write_handle_;
628 AutoHandle child_handle_;
633 AutoHandle event_handle_;
639 int WindowsDeathTest::Wait() {
645 const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() };
646 switch (::WaitForMultipleObjects(2,
651 case WAIT_OBJECT_0 + 1:
654 GTEST_DEATH_TEST_CHECK_(
false);
659 write_handle_.Reset();
660 event_handle_.Reset();
662 ReadAndInterpretStatusByte();
668 GTEST_DEATH_TEST_CHECK_(
669 WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(),
672 GTEST_DEATH_TEST_CHECK_(
673 ::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE);
674 child_handle_.Reset();
675 set_status(static_cast<int>(status_code));
684 DeathTest::TestRole WindowsDeathTest::AssumeRole() {
686 const InternalRunDeathTestFlag*
const flag =
687 impl->internal_run_death_test_flag();
688 const TestInfo*
const info = impl->current_test_info();
694 set_write_fd(flag->write_fd());
700 SECURITY_ATTRIBUTES handles_are_inheritable = {
701 sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
702 HANDLE read_handle, write_handle;
703 GTEST_DEATH_TEST_CHECK_(
704 ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,
707 set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle),
709 write_handle_.Reset(write_handle);
710 event_handle_.Reset(::CreateEvent(
711 &handles_are_inheritable,
715 GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);
730 char executable_path[_MAX_PATH + 1];
731 GTEST_DEATH_TEST_CHECK_(
732 _MAX_PATH + 1 != ::GetModuleFileNameA(NULL,
737 std::string(::GetCommandLineA()) +
" " + filter_flag +
" \"" +
738 internal_flag +
"\"";
740 DeathTest::set_last_death_test_message(
"");
747 STARTUPINFOA startup_info;
748 memset(&startup_info, 0,
sizeof(STARTUPINFO));
749 startup_info.dwFlags = STARTF_USESTDHANDLES;
750 startup_info.hStdInput = ::GetStdHandle(STD_INPUT_HANDLE);
751 startup_info.hStdOutput = ::GetStdHandle(STD_OUTPUT_HANDLE);
752 startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE);
754 PROCESS_INFORMATION process_info;
755 GTEST_DEATH_TEST_CHECK_(::CreateProcessA(
757 const_cast<char*>(command_line.c_str()),
765 &process_info) != FALSE);
766 child_handle_.Reset(process_info.hProcess);
767 ::CloseHandle(process_info.hThread);
771 # else // We are not on Windows. 776 class ForkingDeathTest :
public DeathTestImpl {
778 ForkingDeathTest(
const char* statement,
const RE* regex);
784 void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }
792 ForkingDeathTest::ForkingDeathTest(
const char* a_statement,
const RE* a_regex)
793 : DeathTestImpl(a_statement, a_regex),
799 int ForkingDeathTest::Wait() {
803 ReadAndInterpretStatusByte();
806 GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_value, 0));
807 set_status(status_value);
813 class NoExecDeathTest :
public ForkingDeathTest {
815 NoExecDeathTest(
const char* a_statement,
const RE* a_regex) :
816 ForkingDeathTest(a_statement, a_regex) { }
817 virtual TestRole AssumeRole();
822 DeathTest::TestRole NoExecDeathTest::AssumeRole() {
824 if (thread_count != 1) {
825 GTEST_LOG_(WARNING) << DeathTestThreadWarning(thread_count);
829 GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
831 DeathTest::set_last_death_test_message(
"");
842 const pid_t child_pid = fork();
843 GTEST_DEATH_TEST_CHECK_(child_pid != -1);
844 set_child_pid(child_pid);
845 if (child_pid == 0) {
846 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[0]));
847 set_write_fd(pipe_fd[1]);
855 g_in_fast_death_test_child =
true;
858 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
859 set_read_fd(pipe_fd[0]);
868 class ExecDeathTest :
public ForkingDeathTest {
870 ExecDeathTest(
const char* a_statement,
const RE* a_regex,
871 const char* file,
int line) :
872 ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
873 virtual TestRole AssumeRole();
875 static ::std::vector<testing::internal::string>
876 GetArgvsForDeathTestChildProcess() {
877 ::std::vector<testing::internal::string> args = GetInjectableArgvs();
881 const char*
const file_;
890 args_.push_back(NULL);
894 for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
899 void AddArgument(
const char* argument) {
903 template <
typename Str>
904 void AddArguments(const ::std::vector<Str>& arguments) {
905 for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
906 i != arguments.end();
911 char*
const* Argv() {
916 std::vector<char*> args_;
921 struct ExecDeathTestArgs {
927 inline char** GetEnviron() {
931 return *_NSGetEnviron();
937 inline char** GetEnviron() {
return environ; }
938 # endif // GTEST_OS_MAC 944 static int ExecDeathTestChildMain(
void* child_arg) {
945 ExecDeathTestArgs*
const args =
static_cast<ExecDeathTestArgs*
>(child_arg);
946 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd));
951 const char*
const original_dir =
954 if (chdir(original_dir) != 0) {
955 DeathTestAbort(
std::string(
"chdir(\"") + original_dir +
"\") failed: " +
956 GetLastErrnoDescription());
965 execve(args->argv[0], args->argv, GetEnviron());
966 DeathTestAbort(
std::string(
"execve(") + args->argv[0] +
", ...) in " +
967 original_dir +
" failed: " +
968 GetLastErrnoDescription());
971 # endif // !GTEST_OS_QNX 983 void StackLowerThanAddress(
const void* ptr,
bool* result) {
985 *result = (&dummy < ptr);
988 bool StackGrowsDown() {
991 StackLowerThanAddress(&dummy, &result);
1002 static pid_t ExecDeathTestSpawnChild(
char*
const* argv,
int close_fd) {
1003 ExecDeathTestArgs args = { argv, close_fd };
1004 pid_t child_pid = -1;
1009 const int cwd_fd = open(
".", O_RDONLY);
1010 GTEST_DEATH_TEST_CHECK_(cwd_fd != -1);
1011 GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(cwd_fd, F_SETFD, FD_CLOEXEC));
1015 const char*
const original_dir =
1018 if (chdir(original_dir) != 0) {
1019 DeathTestAbort(
std::string(
"chdir(\"") + original_dir +
"\") failed: " +
1020 GetLastErrnoDescription());
1021 return EXIT_FAILURE;
1026 GTEST_DEATH_TEST_CHECK_SYSCALL_(fd_flags = fcntl(close_fd, F_GETFD));
1027 GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(close_fd, F_SETFD,
1028 fd_flags | FD_CLOEXEC));
1029 struct inheritance inherit = {0};
1031 child_pid = spawn(args.argv[0], 0, NULL, &inherit, args.argv, GetEnviron());
1033 GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1);
1034 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
1036 # else // GTEST_OS_QNX 1041 struct sigaction saved_sigprof_action;
1042 struct sigaction ignore_sigprof_action;
1043 memset(&ignore_sigprof_action, 0,
sizeof(ignore_sigprof_action));
1044 sigemptyset(&ignore_sigprof_action.sa_mask);
1045 ignore_sigprof_action.sa_handler = SIG_IGN;
1046 GTEST_DEATH_TEST_CHECK_SYSCALL_(sigaction(
1047 SIGPROF, &ignore_sigprof_action, &saved_sigprof_action));
1048 # endif // GTEST_OS_LINUX 1050 # if GTEST_HAS_CLONE 1051 const bool use_fork =
GTEST_FLAG(death_test_use_fork);
1054 static const bool stack_grows_down = StackGrowsDown();
1057 void*
const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
1058 MAP_ANON | MAP_PRIVATE, -1, 0);
1059 GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
1067 const size_t kMaxStackAlignment = 64;
1068 void*
const stack_top =
1069 static_cast<char*
>(stack) +
1070 (stack_grows_down ? stack_size - kMaxStackAlignment : 0);
1071 GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment &&
1072 reinterpret_cast<intptr_t>(stack_top) % kMaxStackAlignment == 0);
1074 child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
1076 GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
1079 const bool use_fork =
true;
1080 # endif // GTEST_HAS_CLONE 1082 if (use_fork && (child_pid = fork()) == 0) {
1083 ExecDeathTestChildMain(&args);
1086 # endif // GTEST_OS_QNX 1088 GTEST_DEATH_TEST_CHECK_SYSCALL_(
1089 sigaction(SIGPROF, &saved_sigprof_action, NULL));
1090 # endif // GTEST_OS_LINUX 1092 GTEST_DEATH_TEST_CHECK_(child_pid != -1);
1100 DeathTest::TestRole ExecDeathTest::AssumeRole() {
1102 const InternalRunDeathTestFlag*
const flag =
1103 impl->internal_run_death_test_flag();
1104 const TestInfo*
const info = impl->current_test_info();
1108 set_write_fd(flag->write_fd());
1109 return EXECUTE_TEST;
1113 GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
1116 GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
1127 args.AddArguments(GetArgvsForDeathTestChildProcess());
1128 args.AddArgument(filter_flag.c_str());
1129 args.AddArgument(internal_flag.c_str());
1131 DeathTest::set_last_death_test_message(
"");
1138 const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]);
1139 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
1140 set_child_pid(child_pid);
1141 set_read_fd(pipe_fd[0]);
1143 return OVERSEE_TEST;
1146 # endif // !GTEST_OS_WINDOWS 1153 bool DefaultDeathTestFactory::Create(
const char* statement,
const RE* regex,
1154 const char* file,
int line,
1157 const InternalRunDeathTestFlag*
const flag =
1158 impl->internal_run_death_test_flag();
1159 const int death_test_index = impl->current_test_info()
1160 ->increment_death_test_count();
1163 if (death_test_index > flag->index()) {
1164 DeathTest::set_last_death_test_message(
1166 +
") somehow exceeded expected maximum (" 1171 if (!(flag->file() == file && flag->line() == line &&
1172 flag->index() == death_test_index)) {
1178 # if GTEST_OS_WINDOWS 1180 if (
GTEST_FLAG(death_test_style) ==
"threadsafe" ||
1182 *test =
new WindowsDeathTest(statement, regex, file, line);
1187 if (
GTEST_FLAG(death_test_style) ==
"threadsafe") {
1188 *test =
new ExecDeathTest(statement, regex, file, line);
1189 }
else if (
GTEST_FLAG(death_test_style) ==
"fast") {
1190 *test =
new NoExecDeathTest(statement, regex);
1193 # endif // GTEST_OS_WINDOWS 1196 DeathTest::set_last_death_test_message(
1197 "Unknown death test style \"" +
GTEST_FLAG(death_test_style)
1198 +
"\" encountered");
1209 ::std::vector< ::std::string>* dest) {
1210 ::std::vector< ::std::string> parsed;
1211 ::std::string::size_type pos = 0;
1213 const ::std::string::size_type colon = str.find(delimiter, pos);
1214 if (colon == ::std::string::npos) {
1215 parsed.push_back(str.substr(pos));
1218 parsed.push_back(str.substr(pos, colon - pos));
1225 # if GTEST_OS_WINDOWS 1229 int GetStatusFileDescriptor(
unsigned int parent_process_id,
1230 size_t write_handle_as_size_t,
1231 size_t event_handle_as_size_t) {
1232 AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,
1234 parent_process_id));
1235 if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
1236 DeathTestAbort(
"Unable to open parent process " +
1244 const HANDLE write_handle =
1245 reinterpret_cast<HANDLE
>(write_handle_as_size_t);
1246 HANDLE dup_write_handle;
1251 if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,
1252 ::GetCurrentProcess(), &dup_write_handle,
1256 DUPLICATE_SAME_ACCESS)) {
1257 DeathTestAbort(
"Unable to duplicate the pipe handle " +
1259 " from the parent process " +
1263 const HANDLE event_handle =
reinterpret_cast<HANDLE
>(event_handle_as_size_t);
1264 HANDLE dup_event_handle;
1266 if (!::DuplicateHandle(parent_process_handle.Get(), event_handle,
1267 ::GetCurrentProcess(), &dup_event_handle,
1270 DUPLICATE_SAME_ACCESS)) {
1271 DeathTestAbort(
"Unable to duplicate the event handle " +
1273 " from the parent process " +
1277 const int write_fd =
1278 ::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
1279 if (write_fd == -1) {
1280 DeathTestAbort(
"Unable to convert pipe handle " +
1282 " to a file descriptor");
1287 ::SetEvent(dup_event_handle);
1291 # endif // GTEST_OS_WINDOWS 1296 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
1297 if (
GTEST_FLAG(internal_run_death_test) ==
"")
return NULL;
1303 ::std::vector< ::std::string> fields;
1304 SplitString(
GTEST_FLAG(internal_run_death_test).c_str(),
'|', &fields);
1307 # if GTEST_OS_WINDOWS 1309 unsigned int parent_process_id = 0;
1310 size_t write_handle_as_size_t = 0;
1311 size_t event_handle_as_size_t = 0;
1313 if (fields.size() != 6
1314 || !ParseNaturalNumber(fields[1], &line)
1315 || !ParseNaturalNumber(fields[2], &index)
1316 || !ParseNaturalNumber(fields[3], &parent_process_id)
1317 || !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
1318 || !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
1319 DeathTestAbort(
"Bad --gtest_internal_run_death_test flag: " +
1322 write_fd = GetStatusFileDescriptor(parent_process_id,
1323 write_handle_as_size_t,
1324 event_handle_as_size_t);
1327 if (fields.size() != 4
1328 || !ParseNaturalNumber(fields[1], &line)
1329 || !ParseNaturalNumber(fields[2], &index)
1330 || !ParseNaturalNumber(fields[3], &write_fd)) {
1331 DeathTestAbort(
"Bad --gtest_internal_run_death_test flag: " 1335 # endif // GTEST_OS_WINDOWS 1337 return new InternalRunDeathTestFlag(fields[0], line, index, write_fd);
1342 #endif // GTEST_HAS_DEATH_TEST
UnitTestImpl * GetUnitTestImpl()
const char * original_working_dir() const
std::string GetCapturedStderr()
int death_test_count() const
char * StrDup(const char *src)
static const char kDefaultDeathTestStyle[]
bool BoolFromGTestEnv(const char *flag, bool default_value)
void SuppressEventForwarding()
GTEST_DEFINE_bool_(also_run_disabled_tests, internal::BoolFromGTestEnv("also_run_disabled_tests", false),"Run disabled tests too, in addition to the tests normally being run.")
static bool PartialMatch(const ::std::string &str, const RE &re)
std::string StreamableToString(const T &streamable)
const char * StringFromGTestEnv(const char *flag, const char *default_value)
int Write(int fd, const void *buf, unsigned int count)
const char * name() const
int Read(int fd, void *buf, unsigned int count)
std::string GetString() const
const char * test_case_name() const
FILE * FDOpen(int fd, const char *mode)
const char kInternalRunDeathTestFlag[]
TestEventListeners * listeners()
const char * StrError(int errnum)
#define GTEST_FLAG_PREFIX_
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
const TestResult * result() const
static UnitTest * GetInstance()
GTEST_DEFINE_string_(internal_run_death_test,"","Indicates the file, line number, temporal index of ""the single death test to run, and a file descriptor to ""which a success code may be sent, all separated by ""the '|' characters. This flag is specified if and only if the current ""process is a sub-process launched for running a thread-safe ""death test. FOR INTERNAL USE ONLY.")
#define GTEST_CHECK_(condition)
#define GTEST_LOG_(severity)
TestInfo * current_test_info()
GTEST_DEFINE_string_(color, internal::StringFromGTestEnv("color","auto"),"Whether to use colors in the output. Valid values: yes, no, ""and auto. 'auto' means to use colors if the output is ""being sent to a terminal and the TERM environment variable ""is set to a terminal type that supports colors.")