Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: mojo/system/multiprocess_message_pipe_unittest.cc

Issue 134373005: Mojo: Refactor PlatformChannel stuff. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/common/test/multiprocess_test_base_unittest.cc ('k') | mojo/system/platform_channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(vtl): Enable this on non-POSIX once we have a non-POSIX implementation. 5 // TODO(vtl): Enable this on non-POSIX once we have a non-POSIX implementation.
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 MultiprocessMessagePipeTest() {} 115 MultiprocessMessagePipeTest() {}
116 virtual ~MultiprocessMessagePipeTest() {} 116 virtual ~MultiprocessMessagePipeTest() {}
117 117
118 virtual void TearDown() OVERRIDE { 118 virtual void TearDown() OVERRIDE {
119 if (io_thread_wrapper_.is_initialized()) 119 if (io_thread_wrapper_.is_initialized())
120 io_thread_wrapper_.Shutdown(); 120 io_thread_wrapper_.Shutdown();
121 mojo::test::MultiprocessTestBase::TearDown(); 121 mojo::test::MultiprocessTestBase::TearDown();
122 } 122 }
123 123
124 void Init(scoped_refptr<MessagePipe> mp) { 124 void Init(scoped_refptr<MessagePipe> mp) {
125 io_thread_wrapper_.Init(platform_server_channel.get(), mp); 125 io_thread_wrapper_.Init(server_platform_channel.get(), mp);
126 } 126 }
127 127
128 private: 128 private:
129 IOThreadWrapper io_thread_wrapper_; 129 IOThreadWrapper io_thread_wrapper_;
130 130
131 DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTest); 131 DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTest);
132 }; 132 };
133 133
134 MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp, MojoWaitFlags flags) { 134 MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp, MojoWaitFlags flags) {
135 Waiter waiter; 135 Waiter waiter;
136 waiter.Init(); 136 waiter.Init();
137 137
138 MojoResult add_result = mp->AddWaiter(0, &waiter, flags, MOJO_RESULT_OK); 138 MojoResult add_result = mp->AddWaiter(0, &waiter, flags, MOJO_RESULT_OK);
139 if (add_result != MOJO_RESULT_OK) { 139 if (add_result != MOJO_RESULT_OK) {
140 return (add_result == MOJO_RESULT_ALREADY_EXISTS) ? MOJO_RESULT_OK : 140 return (add_result == MOJO_RESULT_ALREADY_EXISTS) ? MOJO_RESULT_OK :
141 add_result; 141 add_result;
142 } 142 }
143 143
144 MojoResult wait_result = waiter.Wait(MOJO_DEADLINE_INDEFINITE); 144 MojoResult wait_result = waiter.Wait(MOJO_DEADLINE_INDEFINITE);
145 mp->RemoveWaiter(0, &waiter); 145 mp->RemoveWaiter(0, &waiter);
146 return wait_result; 146 return wait_result;
147 } 147 }
148 148
149 // For each message received, sends a reply message with the same contents 149 // For each message received, sends a reply message with the same contents
150 // repeated twice, until the other end is closed or it receives "quitquitquit" 150 // repeated twice, until the other end is closed or it receives "quitquitquit"
151 // (which it doesn't reply to). It'll return the number of messages received, 151 // (which it doesn't reply to). It'll return the number of messages received,
152 // not including any "quitquitquit" message, modulo 100. 152 // not including any "quitquitquit" message, modulo 100.
153 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { 153 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
154 IOThreadWrapper io_thread_wrapper; 154 IOThreadWrapper io_thread_wrapper;
155 PlatformClientChannel* const platform_client_channel = 155 PlatformChannel* const client_platform_channel =
156 MultiprocessMessagePipeTest::platform_client_channel.get(); 156 MultiprocessMessagePipeTest::client_platform_channel.get();
157 CHECK(platform_client_channel); 157 CHECK(client_platform_channel);
158 CHECK(platform_client_channel->is_valid()); 158 CHECK(client_platform_channel->is_valid());
159 scoped_refptr<MessagePipe> mp(new MessagePipe( 159 scoped_refptr<MessagePipe> mp(new MessagePipe(
160 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), 160 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()),
161 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); 161 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint())));
162 io_thread_wrapper.Init(platform_client_channel, mp); 162 io_thread_wrapper.Init(client_platform_channel, mp);
163 163
164 const std::string quitquitquit("quitquitquit"); 164 const std::string quitquitquit("quitquitquit");
165 int rv = 0; 165 int rv = 0;
166 for (;; rv = (rv + 1) % 100) { 166 for (;; rv = (rv + 1) % 100) {
167 // Wait for our end of the message pipe to be readable. 167 // Wait for our end of the message pipe to be readable.
168 MojoResult result = WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE); 168 MojoResult result = WaitIfNecessary(mp, MOJO_WAIT_FLAG_READABLE);
169 if (result != MOJO_RESULT_OK) { 169 if (result != MOJO_RESULT_OK) {
170 // It was closed, probably. 170 // It was closed, probably.
171 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); 171 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION);
172 break; 172 break;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 mp->Close(0); 289 mp->Close(0);
290 290
291 EXPECT_EQ(static_cast<int>(kNumMessages % 100), WaitForChildShutdown()); 291 EXPECT_EQ(static_cast<int>(kNumMessages % 100), WaitForChildShutdown());
292 } 292 }
293 293
294 } // namespace 294 } // namespace
295 } // namespace system 295 } // namespace system
296 } // namespace mojo 296 } // namespace mojo
297 297
298 #endif // defined(OS_POSIX) 298 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « mojo/common/test/multiprocess_test_base_unittest.cc ('k') | mojo/system/platform_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698