Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
829402ed
Commit
829402ed
authored
Oct 28, 2011
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds support for detection of running in death test child processes.
parent
83fe024f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
1 deletion
+63
-1
gtest-death-test.h
include/gtest/gtest-death-test.h
+11
-0
gtest-death-test.cc
src/gtest-death-test.cc
+31
-1
gtest-death-test_test.cc
test/gtest-death-test_test.cc
+21
-0
No files found.
include/gtest/gtest-death-test.h
View file @
829402ed
...
@@ -51,6 +51,17 @@ GTEST_DECLARE_string_(death_test_style);
...
@@ -51,6 +51,17 @@ GTEST_DECLARE_string_(death_test_style);
#if GTEST_HAS_DEATH_TEST
#if GTEST_HAS_DEATH_TEST
namespace
internal
{
// 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.
GTEST_API_
bool
InDeathTestChild
();
}
// namespace internal
// The following macros are useful for writing death tests.
// The following macros are useful for writing death tests.
// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
...
...
src/gtest-death-test.cc
View file @
829402ed
...
@@ -109,13 +109,42 @@ GTEST_DEFINE_string_(
...
@@ -109,13 +109,42 @@ GTEST_DEFINE_string_(
"Indicates the file, line number, temporal index of "
"Indicates the file, line number, temporal index of "
"the single death test to run, and a file descriptor to "
"the single death test to run, and a file descriptor to "
"which a success code may be sent, all separated by "
"which a success code may be sent, all separated by "
"
colon
s. This flag is specified if and only if the current "
"
the '|' character
s. This flag is specified if and only if the current "
"process is a sub-process launched for running a thread-safe "
"process is a sub-process launched for running a thread-safe "
"death test. FOR INTERNAL USE ONLY."
);
"death test. FOR INTERNAL USE ONLY."
);
}
// namespace internal
}
// namespace internal
#if GTEST_HAS_DEATH_TEST
#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 constructor.
ExitedWithCode
::
ExitedWithCode
(
int
exit_code
)
:
exit_code_
(
exit_code
)
{
ExitedWithCode
::
ExitedWithCode
(
int
exit_code
)
:
exit_code_
(
exit_code
)
{
}
}
...
@@ -825,6 +854,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
...
@@ -825,6 +854,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
// Event forwarding to the listeners of event listener API mush be shut
// Event forwarding to the listeners of event listener API mush be shut
// down in death test subprocesses.
// down in death test subprocesses.
GetUnitTestImpl
()
->
listeners
()
->
SuppressEventForwarding
();
GetUnitTestImpl
()
->
listeners
()
->
SuppressEventForwarding
();
g_in_fast_death_test_child
=
true
;
return
EXECUTE_TEST
;
return
EXECUTE_TEST
;
}
else
{
}
else
{
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
close
(
pipe_fd
[
1
]));
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
close
(
pipe_fd
[
1
]));
...
...
test/gtest-death-test_test.cc
View file @
829402ed
...
@@ -75,6 +75,7 @@ using testing::internal::DeathTestFactory;
...
@@ -75,6 +75,7 @@ using testing::internal::DeathTestFactory;
using
testing
::
internal
::
FilePath
;
using
testing
::
internal
::
FilePath
;
using
testing
::
internal
::
GetLastErrnoDescription
;
using
testing
::
internal
::
GetLastErrnoDescription
;
using
testing
::
internal
::
GetUnitTestImpl
;
using
testing
::
internal
::
GetUnitTestImpl
;
using
testing
::
internal
::
InDeathTestChild
;
using
testing
::
internal
::
ParseNaturalNumber
;
using
testing
::
internal
::
ParseNaturalNumber
;
using
testing
::
internal
::
String
;
using
testing
::
internal
::
String
;
...
@@ -1345,6 +1346,26 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
...
@@ -1345,6 +1346,26 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
#endif // _MSC_VER
#endif // _MSC_VER
}
}
TEST
(
InDeathTestChildDeathTest
,
ReportsDeathTestCorrectlyInFastStyle
)
{
testing
::
GTEST_FLAG
(
death_test_style
)
=
"fast"
;
EXPECT_FALSE
(
InDeathTestChild
());
EXPECT_DEATH
({
fprintf
(
stderr
,
InDeathTestChild
()
?
"Inside"
:
"Outside"
);
fflush
(
stderr
);
_exit
(
1
);
},
"Inside"
);
}
TEST
(
InDeathTestChildDeathTest
,
ReportsDeathTestCorrectlyInThreadSafeStyle
)
{
testing
::
GTEST_FLAG
(
death_test_style
)
=
"threadsafe"
;
EXPECT_FALSE
(
InDeathTestChild
());
EXPECT_DEATH
({
fprintf
(
stderr
,
InDeathTestChild
()
?
"Inside"
:
"Outside"
);
fflush
(
stderr
);
_exit
(
1
);
},
"Inside"
);
}
// Tests that a test case whose name ends with "DeathTest" works fine
// Tests that a test case whose name ends with "DeathTest" works fine
// on Windows.
// on Windows.
TEST
(
NotADeathTest
,
Test
)
{
TEST
(
NotADeathTest
,
Test
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment