Googletest export
[Fuchsia] Update exception APIs used by death test. Migrates to the new channel-based exception APIs as the port APIs are deprecated and will be removed. PiperOrigin-RevId: 258175830
This commit is contained in:
parent
e4f097b5fb
commit
f38f4d8f27
|
@ -68,6 +68,7 @@
|
|||
# include <lib/fdio/fd.h>
|
||||
# include <lib/fdio/io.h>
|
||||
# include <lib/fdio/spawn.h>
|
||||
# include <lib/zx/channel.h>
|
||||
# include <lib/zx/port.h>
|
||||
# include <lib/zx/process.h>
|
||||
# include <lib/zx/socket.h>
|
||||
|
@ -831,7 +832,7 @@ class FuchsiaDeathTest : public DeathTestImpl {
|
|||
std::string captured_stderr_;
|
||||
|
||||
zx::process child_process_;
|
||||
zx::port port_;
|
||||
zx::channel exception_channel_;
|
||||
zx::socket stderr_socket_;
|
||||
};
|
||||
|
||||
|
@ -876,41 +877,51 @@ class Arguments {
|
|||
int FuchsiaDeathTest::Wait() {
|
||||
const int kProcessKey = 0;
|
||||
const int kSocketKey = 1;
|
||||
const int kExceptionKey = 2;
|
||||
|
||||
if (!spawned())
|
||||
return 0;
|
||||
|
||||
// Register to wait for the child process to terminate.
|
||||
// Create a port to wait for socket/task/exception events.
|
||||
zx_status_t status_zx;
|
||||
status_zx = child_process_.wait_async(
|
||||
port_, kProcessKey, ZX_PROCESS_TERMINATED, ZX_WAIT_ASYNC_ONCE);
|
||||
zx::port port;
|
||||
status_zx = zx::port::create(0, &port);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
// Register to wait for the child process to terminate.
|
||||
status_zx = child_process_.wait_async(
|
||||
port, kProcessKey, ZX_PROCESS_TERMINATED, ZX_WAIT_ASYNC_ONCE);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
// Register to wait for the socket to be readable or closed.
|
||||
status_zx = stderr_socket_.wait_async(
|
||||
port_, kSocketKey, ZX_SOCKET_READABLE | ZX_SOCKET_PEER_CLOSED,
|
||||
port, kSocketKey, ZX_SOCKET_READABLE | ZX_SOCKET_PEER_CLOSED,
|
||||
ZX_WAIT_ASYNC_ONCE);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
// Register to wait for an exception.
|
||||
status_zx = exception_channel_.wait_async(
|
||||
port, kExceptionKey, ZX_CHANNEL_READABLE, ZX_WAIT_ASYNC_ONCE);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
bool process_terminated = false;
|
||||
bool socket_closed = false;
|
||||
do {
|
||||
zx_port_packet_t packet = {};
|
||||
status_zx = port_.wait(zx::time::infinite(), &packet);
|
||||
status_zx = port.wait(zx::time::infinite(), &packet);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
if (packet.key == kProcessKey) {
|
||||
if (ZX_PKT_IS_EXCEPTION(packet.type)) {
|
||||
// Process encountered an exception. Kill it directly rather than
|
||||
// letting other handlers process the event. We will get a second
|
||||
// kProcessKey event when the process actually terminates.
|
||||
status_zx = child_process_.kill();
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
} else {
|
||||
// Process terminated.
|
||||
GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
|
||||
GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_PROCESS_TERMINATED);
|
||||
process_terminated = true;
|
||||
}
|
||||
if (packet.key == kExceptionKey) {
|
||||
// Process encountered an exception. Kill it directly rather than
|
||||
// letting other handlers process the event. We will get a kProcessKey
|
||||
// event when the process actually terminates.
|
||||
status_zx = child_process_.kill();
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
} else if (packet.key == kProcessKey) {
|
||||
// Process terminated.
|
||||
GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
|
||||
GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_PROCESS_TERMINATED);
|
||||
process_terminated = true;
|
||||
} else if (packet.key == kSocketKey) {
|
||||
GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
|
||||
if (packet.signal.observed & ZX_SOCKET_READABLE) {
|
||||
|
@ -930,7 +941,7 @@ int FuchsiaDeathTest::Wait() {
|
|||
} else {
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_ERR_SHOULD_WAIT);
|
||||
status_zx = stderr_socket_.wait_async(
|
||||
port_, kSocketKey, ZX_SOCKET_READABLE | ZX_SOCKET_PEER_CLOSED,
|
||||
port, kSocketKey, ZX_SOCKET_READABLE | ZX_SOCKET_PEER_CLOSED,
|
||||
ZX_WAIT_ASYNC_ONCE);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
}
|
||||
|
@ -1033,12 +1044,11 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
|
|||
child_job, ZX_JOB_POL_RELATIVE, ZX_JOB_POL_BASIC, &policy, 1);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
|
||||
// Create an exception port and attach it to the |child_job|, to allow
|
||||
// Create an exception channel attached to the |child_job|, to allow
|
||||
// us to suppress the system default exception handler from firing.
|
||||
status = zx::port::create(0, &port_);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
status = zx_task_bind_exception_port(
|
||||
child_job, port_.get(), 0 /* key */, 0 /*options */);
|
||||
status =
|
||||
zx_task_create_exception_channel(
|
||||
child_job, 0, exception_channel_.reset_and_get_address());
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
|
||||
// Spawn the child process.
|
||||
|
|
Loading…
Reference in New Issue
Block a user