diff options
author | yusukes <yusukes@chromium.org> | 2015-01-05 22:56:34 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-06 06:57:26 +0000 |
commit | d0329fc964f76d207a2c9f020cea7c324e42d5b1 (patch) | |
tree | 841e3d2553b8e0acdb155a6474acf85318eff1cc /ipc | |
parent | 9ba829d792febd8af5b487f9d4fe1435ecae4d47 (diff) | |
download | chromium_src-d0329fc964f76d207a2c9f020cea7c324e42d5b1.zip chromium_src-d0329fc964f76d207a2c9f020cea7c324e42d5b1.tar.gz chromium_src-d0329fc964f76d207a2c9f020cea7c324e42d5b1.tar.bz2 |
Send more file descriptors in IPCSendFdsTest.DescriptorTest
Previously the test sends 20 IPC messages with sendmsg() to
the other side and each message has one FD. This CL changes
the number of FDs to kMaxDescriptorsPerMessage to make sure
that all POSIX platforms we support including Mac OS X are
able to handle kMaxDescriptorsPerMessage FDs in a single
IPC message.
BUG=nativeclient:3802
TEST=git cl try
Review URL: https://codereview.chromium.org/800463003
Cr-Commit-Position: refs/heads/master@{#310060}
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/ipc_send_fds_test.cc | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/ipc/ipc_send_fds_test.cc b/ipc/ipc_send_fds_test.cc index cf2c680..be95f96 100644 --- a/ipc/ipc_send_fds_test.cc +++ b/ipc/ipc_send_fds_test.cc @@ -26,21 +26,31 @@ extern "C" { #include "ipc/ipc_message_utils.h" #include "ipc/ipc_test_base.h" +#if defined(OS_POSIX) +#include "base/macros.h" +#include "ipc/file_descriptor_set_posix.h" +#endif + namespace { -const unsigned kNumFDsToSend = 20; +const unsigned kNumFDsToSend = 7; // per message +const unsigned kNumMessages = 20; const char* kDevZeroPath = "/dev/zero"; +#if defined(OS_POSIX) +COMPILE_ASSERT(kNumFDsToSend == FileDescriptorSet::kMaxDescriptorsPerMessage, + num_fds_to_send_must_be_the_same_as_the_max_desc_per_message); +#endif + class MyChannelDescriptorListenerBase : public IPC::Listener { public: bool OnMessageReceived(const IPC::Message& message) override { PickleIterator iter(message); - base::FileDescriptor descriptor; - - IPC::ParamTraits<base::FileDescriptor>::Read(&message, &iter, &descriptor); - - HandleFD(descriptor.fd); + while (IPC::ParamTraits<base::FileDescriptor>::Read( + &message, &iter, &descriptor)) { + HandleFD(descriptor.fd); + } return true; } @@ -57,7 +67,7 @@ class MyChannelDescriptorListener : public MyChannelDescriptorListenerBase { } bool GotExpectedNumberOfDescriptors() const { - return num_fds_received_ == kNumFDsToSend; + return num_fds_received_ == kNumFDsToSend * kNumMessages; } void OnChannelError() override { @@ -66,6 +76,7 @@ class MyChannelDescriptorListener : public MyChannelDescriptorListenerBase { protected: void HandleFD(int fd) override { + ASSERT_GE(fd, 0); // Check that we can read from the FD. char buf; ssize_t amt_read = read(fd, &buf, 1); @@ -82,7 +93,7 @@ class MyChannelDescriptorListener : public MyChannelDescriptorListenerBase { ASSERT_EQ(expected_inode_num_, st.st_ino); ++num_fds_received_; - if (num_fds_received_ == kNumFDsToSend) + if (num_fds_received_ == kNumFDsToSend * kNumMessages) base::MessageLoop::current()->Quit(); } @@ -101,14 +112,15 @@ class IPCSendFdsTest : public IPCTestBase { ASSERT_TRUE(ConnectChannel()); ASSERT_TRUE(StartClient()); - for (unsigned i = 0; i < kNumFDsToSend; ++i) { - const int fd = open(kDevZeroPath, O_RDONLY); - ASSERT_GE(fd, 0); - base::FileDescriptor descriptor(fd, true); - + for (unsigned i = 0; i < kNumMessages; ++i) { IPC::Message* message = new IPC::Message(0, 3, IPC::Message::PRIORITY_NORMAL); - IPC::ParamTraits<base::FileDescriptor>::Write(message, descriptor); + for (unsigned j = 0; j < kNumFDsToSend; ++j) { + const int fd = open(kDevZeroPath, O_RDONLY); + ASSERT_GE(fd, 0); + base::FileDescriptor descriptor(fd, true); + IPC::ParamTraits<base::FileDescriptor>::Write(message, descriptor); + } ASSERT_TRUE(sender()->Send(message)); } |