Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
96c3c422
Commit
96c3c422
authored
May 02, 2018
by
Fabrice de Gans-Riberi
Browse files
Get all the things to work.
parent
b6cb5c3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
35 deletions
+45
-35
googletest/src/gtest-death-test.cc
googletest/src/gtest-death-test.cc
+45
-35
No files found.
googletest/src/gtest-death-test.cc
View file @
96c3c422
...
@@ -245,6 +245,13 @@ static const char kDeathTestReturned = 'R';
...
@@ -245,6 +245,13 @@ static const char kDeathTestReturned = 'R';
static
const
char
kDeathTestThrew
=
'T'
;
static
const
char
kDeathTestThrew
=
'T'
;
static
const
char
kDeathTestInternalError
=
'I'
;
static
const
char
kDeathTestInternalError
=
'I'
;
#if GTEST_OS_FUCHSIA
// File descriptor used for the pipe in the child process.
static
const
int
kFuchsiaReadPipeFd
=
3
;
#endif
// An enumeration describing all of the possible ways that a death test can
// An enumeration describing all of the possible ways that a death test can
// conclude. DIED means that the process died while executing the test
// conclude. DIED means that the process died while executing the test
// code; LIVED means that process lived beyond the end of the test code;
// code; LIVED means that process lived beyond the end of the test code;
...
@@ -544,9 +551,7 @@ bool DeathTestImpl::Passed(bool status_ok) {
...
@@ -544,9 +551,7 @@ bool DeathTestImpl::Passed(bool status_ok) {
if
(
!
spawned
())
if
(
!
spawned
())
return
false
;
return
false
;
// FIXME: This isn't working.
const
std
::
string
error_message
=
GetCapturedStderr
();
//const std::string error_message = GetCapturedStderr();
const
std
::
string
error_message
=
""
;
bool
success
=
false
;
bool
success
=
false
;
Message
buffer
;
Message
buffer
;
...
@@ -811,7 +816,6 @@ class FuchsiaDeathTest : public DeathTestImpl {
...
@@ -811,7 +816,6 @@ class FuchsiaDeathTest : public DeathTestImpl {
const
int
line_
;
const
int
line_
;
zx_handle_t
child_process_
;
zx_handle_t
child_process_
;
zx_handle_t
pipe_handle_
;
};
};
// Utility class for accumulating command-line arguments.
// Utility class for accumulating command-line arguments.
...
@@ -868,16 +872,16 @@ int FuchsiaDeathTest::Wait() {
...
@@ -868,16 +872,16 @@ int FuchsiaDeathTest::Wait() {
&
signals
);
&
signals
);
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
// Close the pipe.
status_zx
=
zx_handle_close
(
pipe_handle_
);
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
ReadAndInterpretStatusByte
();
ReadAndInterpretStatusByte
();
zx_info_process_t
buffer
;
zx_info_process_t
buffer
;
size_t
actual
;
status_zx
=
zx_object_get_info
(
size_t
avail
;
child_process_
,
status_zx
=
zx_object_get_info
(
child_process_
,
ZX_INFO_PROCESS
,
&
buffer
,
sizeof
(
buffer
),
&
actual
,
&
avail
);
ZX_INFO_PROCESS
,
&
buffer
,
sizeof
(
buffer
),
nullptr
,
nullptr
);
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
GTEST_DEATH_TEST_CHECK_
(
buffer
.
exited
);
GTEST_DEATH_TEST_CHECK_
(
buffer
.
exited
);
...
@@ -900,53 +904,49 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
...
@@ -900,53 +904,49 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
if
(
flag
!=
NULL
)
{
if
(
flag
!=
NULL
)
{
// ParseInternalRunDeathTestFlag() has performed all the necessary
// ParseInternalRunDeathTestFlag() has performed all the necessary
// processing.
// processing.
set_write_fd
(
flag
->
write_fd
()
);
set_write_fd
(
kFuchsiaReadPipeFd
);
return
EXECUTE_TEST
;
return
EXECUTE_TEST
;
}
}
// FIXME: This isn't working on Fuchsia.
CaptureStderr
();
// CaptureStderr();
// Flush the log buffers since the log streams are shared with the child.
// Flush the log buffers since the log streams are shared with the child.
FlushInfoLog
();
FlushInfoLog
();
// Create the pipe
zx_status_t
status
;
uint32_t
id
;
status
=
fdio_pipe_half
(
&
pipe_handle_
,
&
id
);
GTEST_DEATH_TEST_CHECK_
(
status
>=
0
);
set_read_fd
(
status
);
// Build the child process launcher.
launchpad_t
*
lp
;
status
=
launchpad_create
(
ZX_HANDLE_INVALID
,
"processname"
,
&
lp
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
// Build the writing pipe for the child.
int
write_fd
;
status
=
launchpad_add_pipe
(
lp
,
&
write_fd
,
read_fd
());
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
// Build the child process command line.
// Build the child process command line.
const
std
::
string
filter_flag
=
const
std
::
string
filter_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kFilterFlag
+
"="
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kFilterFlag
+
"="
+
info
->
test_case_name
()
+
"."
+
info
->
name
();
+
info
->
test_case_name
()
+
"."
+
info
->
name
();
const
std
::
string
internal_flag
=
const
std
::
string
internal_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kInternalRunDeathTestFlag
+
"="
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kInternalRunDeathTestFlag
+
"="
+
file_
+
"|"
+
StreamableToString
(
line_
)
+
"|"
+
file_
+
"|"
+
StreamableToString
(
death_test_index
)
+
"|"
+
StreamableToString
(
line_
)
+
"|"
+
StreamableToString
(
write_fd
);
+
StreamableToString
(
death_test_index
);
Arguments
args
;
Arguments
args
;
args
.
AddArguments
(
GetInjectableArgvs
());
args
.
AddArguments
(
GetInjectableArgvs
());
args
.
AddArgument
(
filter_flag
.
c_str
());
args
.
AddArgument
(
filter_flag
.
c_str
());
args
.
AddArgument
(
internal_flag
.
c_str
());
args
.
AddArgument
(
internal_flag
.
c_str
());
// Build the child process launcher.
zx_status_t
status
;
launchpad_t
*
lp
;
status
=
launchpad_create
(
ZX_HANDLE_INVALID
,
args
.
Argv
()[
0
],
&
lp
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
// Build the pipe for communication with the child.
int
read_fd
;
status
=
launchpad_add_pipe
(
lp
,
&
read_fd
,
3
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
set_read_fd
(
read_fd
);
// Set the command line arguments.
// Set the command line arguments.
status
=
launchpad_load_from_file
(
lp
,
args
.
Argv
()[
0
]);
status
=
launchpad_load_from_file
(
lp
,
args
.
Argv
()[
0
]);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
status
=
launchpad_set_args
(
lp
,
args
.
size
(),
args
.
Argv
());
status
=
launchpad_set_args
(
lp
,
args
.
size
(),
args
.
Argv
());
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
// Clone all the things (environment, stdio, namespace, ...).
launchpad_clone
(
lp
,
LP_CLONE_ALL
);
// Launch the child process.
// Launch the child process.
status
=
launchpad_go
(
lp
,
&
child_process_
,
nullptr
);
status
=
launchpad_go
(
lp
,
&
child_process_
,
nullptr
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
...
@@ -1505,6 +1505,16 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
...
@@ -1505,6 +1505,16 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
write_fd
=
GetStatusFileDescriptor
(
parent_process_id
,
write_fd
=
GetStatusFileDescriptor
(
parent_process_id
,
write_handle_as_size_t
,
write_handle_as_size_t
,
event_handle_as_size_t
);
event_handle_as_size_t
);
# elif GTEST_OS_FUCHSIA
if
(
fields
.
size
()
!=
3
||
!
ParseNaturalNumber
(
fields
[
1
],
&
line
)
||
!
ParseNaturalNumber
(
fields
[
2
],
&
index
))
{
DeathTestAbort
(
"Bad --gtest_internal_run_death_test flag: "
+
GTEST_FLAG
(
internal_run_death_test
));
}
# else
# else
if
(
fields
.
size
()
!=
4
if
(
fields
.
size
()
!=
4
...
...
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