diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-22 01:05:28 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-22 01:05:28 +0000 |
commit | cb80c11a7e7766f77f9fd002959c7548f8548477 (patch) | |
tree | 30f7389dbde3183de897eca492b38edd88ae9d1e /mojo/system | |
parent | 02c1bb2383d86dbee8bc6dc055a615a3c11e8bfd (diff) | |
download | chromium_src-cb80c11a7e7766f77f9fd002959c7548f8548477.zip chromium_src-cb80c11a7e7766f77f9fd002959c7548f8548477.tar.gz chromium_src-cb80c11a7e7766f77f9fd002959c7548f8548477.tar.bz2 |
Revert 252714 "Add some handle read/write helpers to mojo/common..."
> Add some handle read/write helpers to mojo/common/test/test_utils.h
>
> This helps to refactor raw_channel_posix_unittest to run on multiple
> platforms.
>
> TEST=mojo_common_unittests,mojo_system_unittests
> BUG=None
> R=viettrungluu@chromium.org
>
> Review URL: https://codereview.chromium.org/172263006
TBR=yzshen@chromium.org
Review URL: https://codereview.chromium.org/175703004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252718 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/system')
-rw-r--r-- | mojo/system/raw_channel_posix_unittest.cc | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/mojo/system/raw_channel_posix_unittest.cc b/mojo/system/raw_channel_posix_unittest.cc index 5af66c3..4158bb7 100644 --- a/mojo/system/raw_channel_posix_unittest.cc +++ b/mojo/system/raw_channel_posix_unittest.cc @@ -7,7 +7,10 @@ #include "mojo/system/raw_channel.h" +#include <fcntl.h> +#include <stdint.h> #include <sys/socket.h> +#include <unistd.h> #include <vector> @@ -19,13 +22,13 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/message_loop/message_loop.h" +#include "base/posix/eintr_wrapper.h" #include "base/rand_util.h" #include "base/synchronization/lock.h" #include "base/synchronization/waitable_event.h" #include "base/threading/platform_thread.h" // For |Sleep()|. #include "base/threading/simple_thread.h" #include "base/time/time.h" -#include "mojo/common/test/test_utils.h" #include "mojo/system/embedder/platform_channel_pair.h" #include "mojo/system/embedder/platform_handle.h" #include "mojo/system/embedder/scoped_platform_handle.h" @@ -64,10 +67,10 @@ bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle, uint32_t num_bytes) { scoped_ptr<MessageInTransit> message(MakeTestMessage(num_bytes)); - size_t write_size = 0; - mojo::test::BlockingWrite( - handle, message->main_buffer(), message->main_buffer_size(), &write_size); - return write_size == message->main_buffer_size(); + ssize_t write_size = HANDLE_EINTR( + write(handle.fd, message->main_buffer(), message->main_buffer_size())); + bool result = write_size == static_cast<ssize_t>(message->main_buffer_size()); + return result; } // ----------------------------------------------------------------------------- @@ -131,9 +134,12 @@ class TestMessageReaderAndChecker { unsigned char buffer[4096]; for (size_t i = 0; i < kMessageReaderMaxPollIterations;) { - size_t read_size = 0; - CHECK(mojo::test::NonBlockingRead(handle_, buffer, sizeof(buffer), - &read_size)); + ssize_t read_size = HANDLE_EINTR( + read(handle_.fd, buffer, sizeof(buffer))); + if (read_size < 0) { + PCHECK(errno == EAGAIN || errno == EWOULDBLOCK); + read_size = 0; + } // Append newly-read data to |bytes_|. bytes_.insert(bytes_.end(), buffer, buffer + read_size); @@ -279,6 +285,9 @@ class ReadCheckerRawChannelDelegate : public RawChannel::Delegate { // Tests reading (writing using our own custom writer). TEST_F(RawChannelPosixTest, OnReadMessage) { + // We're going to write to |fd(1)|. We'll do so in a blocking manner. + PCHECK(fcntl(handles[1].get().fd, F_SETFL, 0) == 0); + ReadCheckerRawChannelDelegate delegate; scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), &delegate, @@ -472,6 +481,9 @@ class FatalErrorRecordingRawChannelDelegate TEST_F(RawChannelPosixTest, OnFatalError) { const size_t kMessageCount = 5; + // We're going to write to |fd(1)|. We'll do so in a blocking manner. + PCHECK(fcntl(handles[1].get().fd, F_SETFL, 0) == 0); + FatalErrorRecordingRawChannelDelegate delegate(2 * kMessageCount); scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), &delegate, |