diff options
author | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-10-28 16:19:04 +0000 |
---|---|---|
committer | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-10-28 16:19:04 +0000 |
commit | f46f3eaf059b7b3ca00a3428c594bd477bc1839c (patch) | |
tree | 9724f34e4e4a728238047ca1bd974b3c030e1d8f /src | |
parent | 9781f5467fadad9b15a0beb983b123049dc6d5a2 (diff) | |
download | gtest-f46f3eaf059b7b3ca00a3428c594bd477bc1839c.tar.gz gtest-f46f3eaf059b7b3ca00a3428c594bd477bc1839c.tar.bz2 gtest-f46f3eaf059b7b3ca00a3428c594bd477bc1839c.tar.xz |
Adds support for detection of running in death test child processes.
git-svn-id: http://googletest.googlecode.com/svn/trunk@606 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'src')
-rw-r--r-- | src/gtest-death-test.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc index 76aa168..0a0f83b 100644 --- a/src/gtest-death-test.cc +++ b/src/gtest-death-test.cc @@ -109,13 +109,42 @@ GTEST_DEFINE_string_( "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 " - "colons. This flag is specified if and only if the current " + "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."); } // namespace internal #if GTEST_HAS_DEATH_TEST +namespace internal { + +// Valid only for fast death tests. Indicates the code is running in the +// child process of a fast style death test. +static bool g_in_fast_death_test_child = false; + +// Returns a Boolean value indicating whether the caller is currently +// executing in the context of the death test child process. Tools such as +// Valgrind heap checkers may need this to modify their behavior in death +// tests. IMPORTANT: This is an internal utility. Using it may break the +// implementation of death tests. User code MUST NOT use it. +bool InDeathTestChild() { +# if GTEST_OS_WINDOWS + + // On Windows, death tests are thread-safe regardless of the value of the + // death_test_style flag. + return !GTEST_FLAG(internal_run_death_test).empty(); + +# else + + if (GTEST_FLAG(death_test_style) == "threadsafe") + return !GTEST_FLAG(internal_run_death_test).empty(); + else + return g_in_fast_death_test_child; +#endif +} + +} // namespace internal + // ExitedWithCode constructor. ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) { } @@ -825,6 +854,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() { // Event forwarding to the listeners of event listener API mush be shut // down in death test subprocesses. GetUnitTestImpl()->listeners()->SuppressEventForwarding(); + g_in_fast_death_test_child = true; return EXECUTE_TEST; } else { GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1])); |