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 74 #define GTEST_IMPLEMENTATION_ 1 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();
936 extern "C" char** environ;
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);
990 bool StackGrowsDown() {
993 StackLowerThanAddress(&dummy, &result);
1004 static pid_t ExecDeathTestSpawnChild(
char*
const* argv,
int close_fd) {
1005 ExecDeathTestArgs args = { argv, close_fd };
1006 pid_t child_pid = -1;
1011 const int cwd_fd = open(
".", O_RDONLY);
1012 GTEST_DEATH_TEST_CHECK_(cwd_fd != -1);
1013 GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(cwd_fd, F_SETFD, FD_CLOEXEC));
1017 const char*
const original_dir =
1020 if (chdir(original_dir) != 0) {
1021 DeathTestAbort(
std::string(
"chdir(\"") + original_dir +
"\") failed: " +
1022 GetLastErrnoDescription());
1023 return EXIT_FAILURE;
1028 GTEST_DEATH_TEST_CHECK_SYSCALL_(fd_flags = fcntl(close_fd, F_GETFD));
1029 GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(close_fd, F_SETFD,
1030 fd_flags | FD_CLOEXEC));
1031 struct inheritance inherit = {0};
1033 child_pid = spawn(args.argv[0], 0, NULL, &inherit, args.argv, GetEnviron());
1035 GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1);
1036 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
1038 # else // GTEST_OS_QNX 1043 struct sigaction saved_sigprof_action;
1044 struct sigaction ignore_sigprof_action;
1045 memset(&ignore_sigprof_action, 0,
sizeof(ignore_sigprof_action));
1046 sigemptyset(&ignore_sigprof_action.sa_mask);
1047 ignore_sigprof_action.sa_handler = SIG_IGN;
1048 GTEST_DEATH_TEST_CHECK_SYSCALL_(sigaction(
1049 SIGPROF, &ignore_sigprof_action, &saved_sigprof_action));
1050 # endif // GTEST_OS_LINUX 1052 # if GTEST_HAS_CLONE 1053 const bool use_fork =
GTEST_FLAG(death_test_use_fork);
1056 static const bool stack_grows_down = StackGrowsDown();
1057 const size_t stack_size = getpagesize();
1059 void*
const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
1060 MAP_ANON | MAP_PRIVATE, -1, 0);
1061 GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
1069 const size_t kMaxStackAlignment = 64;
1070 void*
const stack_top =
1071 static_cast<char*
>(stack) +
1072 (stack_grows_down ? stack_size - kMaxStackAlignment : 0);
1073 GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment &&
1074 reinterpret_cast<intptr_t>(stack_top) % kMaxStackAlignment == 0);
1076 child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
1078 GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
1081 const bool use_fork =
true;
1082 # endif // GTEST_HAS_CLONE 1084 if (use_fork && (child_pid = fork()) == 0) {
1085 ExecDeathTestChildMain(&args);
1088 # endif // GTEST_OS_QNX 1090 GTEST_DEATH_TEST_CHECK_SYSCALL_(
1091 sigaction(SIGPROF, &saved_sigprof_action, NULL));
1092 # endif // GTEST_OS_LINUX 1094 GTEST_DEATH_TEST_CHECK_(child_pid != -1);
1102 DeathTest::TestRole ExecDeathTest::AssumeRole() {
1104 const InternalRunDeathTestFlag*
const flag =
1105 impl->internal_run_death_test_flag();
1106 const TestInfo*
const info = impl->current_test_info();
1110 set_write_fd(flag->write_fd());
1111 return EXECUTE_TEST;
1115 GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
1118 GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
1129 args.AddArguments(GetArgvsForDeathTestChildProcess());
1130 args.AddArgument(filter_flag.c_str());
1131 args.AddArgument(internal_flag.c_str());
1133 DeathTest::set_last_death_test_message(
"");
1140 const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]);
1141 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
1142 set_child_pid(child_pid);
1143 set_read_fd(pipe_fd[0]);
1145 return OVERSEE_TEST;
1148 # endif // !GTEST_OS_WINDOWS 1155 bool DefaultDeathTestFactory::Create(
const char* statement,
const RE* regex,
1156 const char* file,
int line,
1159 const InternalRunDeathTestFlag*
const flag =
1160 impl->internal_run_death_test_flag();
1161 const int death_test_index = impl->current_test_info()
1162 ->increment_death_test_count();
1165 if (death_test_index > flag->index()) {
1166 DeathTest::set_last_death_test_message(
1168 +
") somehow exceeded expected maximum (" 1173 if (!(flag->file() == file && flag->line() == line &&
1174 flag->index() == death_test_index)) {
1180 # if GTEST_OS_WINDOWS 1182 if (
GTEST_FLAG(death_test_style) ==
"threadsafe" ||
1184 *test =
new WindowsDeathTest(statement, regex, file, line);
1189 if (
GTEST_FLAG(death_test_style) ==
"threadsafe") {
1190 *test =
new ExecDeathTest(statement, regex, file, line);
1191 }
else if (
GTEST_FLAG(death_test_style) ==
"fast") {
1192 *test =
new NoExecDeathTest(statement, regex);
1195 # endif // GTEST_OS_WINDOWS 1198 DeathTest::set_last_death_test_message(
1199 "Unknown death test style \"" +
GTEST_FLAG(death_test_style)
1200 +
"\" encountered");
1211 ::std::vector< ::std::string>* dest) {
1212 ::std::vector< ::std::string> parsed;
1213 ::std::string::size_type pos = 0;
1215 const ::std::string::size_type colon = str.find(delimiter, pos);
1216 if (colon == ::std::string::npos) {
1217 parsed.push_back(str.substr(pos));
1220 parsed.push_back(str.substr(pos, colon - pos));
1227 # if GTEST_OS_WINDOWS 1231 int GetStatusFileDescriptor(
unsigned int parent_process_id,
1232 size_t write_handle_as_size_t,
1233 size_t event_handle_as_size_t) {
1234 AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,
1236 parent_process_id));
1237 if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
1238 DeathTestAbort(
"Unable to open parent process " +
1246 const HANDLE write_handle =
1247 reinterpret_cast<HANDLE
>(write_handle_as_size_t);
1248 HANDLE dup_write_handle;
1253 if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,
1254 ::GetCurrentProcess(), &dup_write_handle,
1258 DUPLICATE_SAME_ACCESS)) {
1259 DeathTestAbort(
"Unable to duplicate the pipe handle " +
1261 " from the parent process " +
1265 const HANDLE event_handle =
reinterpret_cast<HANDLE
>(event_handle_as_size_t);
1266 HANDLE dup_event_handle;
1268 if (!::DuplicateHandle(parent_process_handle.Get(), event_handle,
1269 ::GetCurrentProcess(), &dup_event_handle,
1272 DUPLICATE_SAME_ACCESS)) {
1273 DeathTestAbort(
"Unable to duplicate the event handle " +
1275 " from the parent process " +
1279 const int write_fd =
1280 ::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
1281 if (write_fd == -1) {
1282 DeathTestAbort(
"Unable to convert pipe handle " +
1284 " to a file descriptor");
1289 ::SetEvent(dup_event_handle);
1293 # endif // GTEST_OS_WINDOWS 1298 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
1299 if (
GTEST_FLAG(internal_run_death_test) ==
"")
return NULL;
1305 ::std::vector< ::std::string> fields;
1306 SplitString(
GTEST_FLAG(internal_run_death_test).c_str(),
'|', &fields);
1309 # if GTEST_OS_WINDOWS 1311 unsigned int parent_process_id = 0;
1312 size_t write_handle_as_size_t = 0;
1313 size_t event_handle_as_size_t = 0;
1315 if (fields.size() != 6
1316 || !ParseNaturalNumber(fields[1], &line)
1317 || !ParseNaturalNumber(fields[2], &index)
1318 || !ParseNaturalNumber(fields[3], &parent_process_id)
1319 || !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
1320 || !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
1321 DeathTestAbort(
"Bad --gtest_internal_run_death_test flag: " +
1324 write_fd = GetStatusFileDescriptor(parent_process_id,
1325 write_handle_as_size_t,
1326 event_handle_as_size_t);
1329 if (fields.size() != 4
1330 || !ParseNaturalNumber(fields[1], &line)
1331 || !ParseNaturalNumber(fields[2], &index)
1332 || !ParseNaturalNumber(fields[3], &write_fd)) {
1333 DeathTestAbort(
"Bad --gtest_internal_run_death_test flag: " 1337 # endif // GTEST_OS_WINDOWS 1339 return new InternalRunDeathTestFlag(fields[0], line, index, write_fd);
1344 #endif // GTEST_HAS_DEATH_TEST
class UnitTestImpl * GetUnitTestImpl()
const char * original_working_dir() const
GTEST_API_ std::string GetCapturedStderr()
int death_test_count() const
static const char kDefaultDeathTestStyle[]
const char * StringFromGTestEnv(const char *flag, const char *default_val)
#define GTEST_LOG_(severity)
void SuppressEventForwarding()
UNITTEST_START char * ptr
GTEST_API_ size_t GetThreadCount()
const char kInternalRunDeathTestFlag[]
static bool PartialMatch(const ::std::string &str, const RE &re)
UNITTEST_START int result
GTEST_DEFINE_string_(death_test_style, internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle),"Indicates how to run a death test in a forked child process: ""\"threadsafe\" (child process re-executes the test binary ""from the beginning, running only the specific death test) or ""\"fast\" (child process runs the death test immediately ""after forking).")
std::string StreamableToString(const T &streamable)
int Write(int fd, const void *buf, unsigned int count)
UNITTEST_START char * output
const char * name() const
bool GTEST_FLAG(internal_skip_environment_and_ad_hoc_tests)
#define GTEST_CHECK_(condition)
int Read(int fd, void *buf, unsigned int count)
GTEST_API_ bool AlwaysTrue()
std::string GetString() const
const char * test_case_name() const
bool BoolFromGTestEnv(const char *flag, bool default_val)
GTEST_DEFINE_bool_(death_test_use_fork, internal::BoolFromGTestEnv("death_test_use_fork", false),"Instructs to use fork()/_exit() instead of clone() in death tests. ""Ignored and always uses fork() on POSIX systems where clone() is not ""implemented. Useful when running under valgrind or similar tools if ""those do not support clone(). Valgrind 3.3.1 will just fail if ""it sees an unsupported combination of clone() flags. ""It is not recommended to use this flag w/o valgrind though it will ""work in 99% of the cases. Once valgrind is fixed, this flag will ""most likely be removed.")
TestEventListeners * listeners()
GTEST_API_ void CaptureStderr()
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_ATTRIBUTE_NO_SANITIZE_ADDRESS_
FILE * FDOpen(int fd, const char *mode)
char * StrDup(const char *src)
const char * StrError(int errnum)
TestInfo * current_test_info()
#define GTEST_FLAG_PREFIX_