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

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

Issue 484893004: Mojo: Make Core own a PlatformSupport, and plumb it through to Channel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 4 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/system/core.cc ('k') | mojo/system/remote_message_pipe_unittest.cc » ('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 #include <stdint.h> 5 #include <stdint.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 24 matching lines...) Expand all
35 #include "mojo/system/test_utils.h" 35 #include "mojo/system/test_utils.h"
36 #include "mojo/system/waiter.h" 36 #include "mojo/system/waiter.h"
37 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
38 38
39 namespace mojo { 39 namespace mojo {
40 namespace system { 40 namespace system {
41 namespace { 41 namespace {
42 42
43 class ChannelThread { 43 class ChannelThread {
44 public: 44 public:
45 ChannelThread() : test_io_thread_(test::TestIOThread::kManualStart) {} 45 explicit ChannelThread(embedder::PlatformSupport* platform_support)
46 : platform_support_(platform_support),
47 test_io_thread_(test::TestIOThread::kManualStart) {}
46 ~ChannelThread() { Stop(); } 48 ~ChannelThread() { Stop(); }
47 49
48 void Start(embedder::ScopedPlatformHandle platform_handle, 50 void Start(embedder::ScopedPlatformHandle platform_handle,
49 scoped_refptr<MessagePipe> message_pipe) { 51 scoped_refptr<MessagePipe> message_pipe) {
50 test_io_thread_.Start(); 52 test_io_thread_.Start();
51 test_io_thread_.PostTaskAndWait( 53 test_io_thread_.PostTaskAndWait(
52 FROM_HERE, 54 FROM_HERE,
53 base::Bind(&ChannelThread::InitChannelOnIOThread, 55 base::Bind(&ChannelThread::InitChannelOnIOThread,
54 base::Unretained(this), 56 base::Unretained(this),
55 base::Passed(&platform_handle), 57 base::Passed(&platform_handle),
(...skipping 16 matching lines...) Expand all
72 test_io_thread_.Stop(); 74 test_io_thread_.Stop();
73 } 75 }
74 76
75 private: 77 private:
76 void InitChannelOnIOThread(embedder::ScopedPlatformHandle platform_handle, 78 void InitChannelOnIOThread(embedder::ScopedPlatformHandle platform_handle,
77 scoped_refptr<MessagePipe> message_pipe) { 79 scoped_refptr<MessagePipe> message_pipe) {
78 CHECK_EQ(base::MessageLoop::current(), test_io_thread_.message_loop()); 80 CHECK_EQ(base::MessageLoop::current(), test_io_thread_.message_loop());
79 CHECK(platform_handle.is_valid()); 81 CHECK(platform_handle.is_valid());
80 82
81 // Create and initialize |Channel|. 83 // Create and initialize |Channel|.
82 channel_ = new Channel(); 84 channel_ = new Channel(platform_support_);
83 CHECK(channel_->Init(RawChannel::Create(platform_handle.Pass()))); 85 CHECK(channel_->Init(RawChannel::Create(platform_handle.Pass())));
84 86
85 // Attach the message pipe endpoint. 87 // Attach the message pipe endpoint.
86 // Note: On the "server" (parent process) side, we need not attach the 88 // Note: On the "server" (parent process) side, we need not attach the
87 // message pipe endpoint immediately. However, on the "client" (child 89 // message pipe endpoint immediately. However, on the "client" (child
88 // process) side, this *must* be done here -- otherwise, the |Channel| may 90 // process) side, this *must* be done here -- otherwise, the |Channel| may
89 // receive/process messages (which it can do as soon as it's hooked up to 91 // receive/process messages (which it can do as soon as it's hooked up to
90 // the IO thread message loop, and that message loop runs) before the 92 // the IO thread message loop, and that message loop runs) before the
91 // message pipe endpoint is attached. 93 // message pipe endpoint is attached.
92 CHECK_EQ(channel_->AttachMessagePipeEndpoint(message_pipe, 1), 94 CHECK_EQ(channel_->AttachMessagePipeEndpoint(message_pipe, 1),
93 Channel::kBootstrapEndpointId); 95 Channel::kBootstrapEndpointId);
94 CHECK(channel_->RunMessagePipeEndpoint(Channel::kBootstrapEndpointId, 96 CHECK(channel_->RunMessagePipeEndpoint(Channel::kBootstrapEndpointId,
95 Channel::kBootstrapEndpointId)); 97 Channel::kBootstrapEndpointId));
96 } 98 }
97 99
98 void ShutdownChannelOnIOThread() { 100 void ShutdownChannelOnIOThread() {
99 CHECK(channel_); 101 CHECK(channel_);
100 channel_->Shutdown(); 102 channel_->Shutdown();
101 channel_ = NULL; 103 channel_ = NULL;
102 } 104 }
103 105
106 embedder::PlatformSupport* const platform_support_;
104 test::TestIOThread test_io_thread_; 107 test::TestIOThread test_io_thread_;
105 scoped_refptr<Channel> channel_; 108 scoped_refptr<Channel> channel_;
106 109
107 DISALLOW_COPY_AND_ASSIGN(ChannelThread); 110 DISALLOW_COPY_AND_ASSIGN(ChannelThread);
108 }; 111 };
109 112
110 class MultiprocessMessagePipeTest : public testing::Test { 113 class MultiprocessMessagePipeTest : public testing::Test {
111 public: 114 public:
112 MultiprocessMessagePipeTest() {} 115 MultiprocessMessagePipeTest() : channel_thread_(&platform_support_) {}
113 virtual ~MultiprocessMessagePipeTest() {} 116 virtual ~MultiprocessMessagePipeTest() {}
114 117
115 protected: 118 protected:
116 void Init(scoped_refptr<MessagePipe> mp) { 119 void Init(scoped_refptr<MessagePipe> mp) {
117 channel_thread_.Start(helper_.server_platform_handle.Pass(), mp); 120 channel_thread_.Start(helper_.server_platform_handle.Pass(), mp);
118 } 121 }
119 122
123 embedder::PlatformSupport* platform_support() { return &platform_support_; }
120 mojo::test::MultiprocessTestHelper* helper() { return &helper_; } 124 mojo::test::MultiprocessTestHelper* helper() { return &helper_; }
121 125
122 private: 126 private:
127 embedder::SimplePlatformSupport platform_support_;
123 ChannelThread channel_thread_; 128 ChannelThread channel_thread_;
124 mojo::test::MultiprocessTestHelper helper_; 129 mojo::test::MultiprocessTestHelper helper_;
125 130
126 DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTest); 131 DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTest);
127 }; 132 };
128 133
129 MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp, 134 MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp,
130 MojoHandleSignals signals, 135 MojoHandleSignals signals,
131 HandleSignalsState* signals_state) { 136 HandleSignalsState* signals_state) {
132 Waiter waiter; 137 Waiter waiter;
133 waiter.Init(); 138 waiter.Init();
134 139
135 MojoResult add_result = mp->AddWaiter(0, &waiter, signals, 0, signals_state); 140 MojoResult add_result = mp->AddWaiter(0, &waiter, signals, 0, signals_state);
136 if (add_result != MOJO_RESULT_OK) { 141 if (add_result != MOJO_RESULT_OK) {
137 return (add_result == MOJO_RESULT_ALREADY_EXISTS) ? MOJO_RESULT_OK 142 return (add_result == MOJO_RESULT_ALREADY_EXISTS) ? MOJO_RESULT_OK
138 : add_result; 143 : add_result;
139 } 144 }
140 145
141 MojoResult wait_result = waiter.Wait(MOJO_DEADLINE_INDEFINITE, NULL); 146 MojoResult wait_result = waiter.Wait(MOJO_DEADLINE_INDEFINITE, NULL);
142 mp->RemoveWaiter(0, &waiter, signals_state); 147 mp->RemoveWaiter(0, &waiter, signals_state);
143 return wait_result; 148 return wait_result;
144 } 149 }
145 150
146 // For each message received, sends a reply message with the same contents 151 // For each message received, sends a reply message with the same contents
147 // repeated twice, until the other end is closed or it receives "quitquitquit" 152 // repeated twice, until the other end is closed or it receives "quitquitquit"
148 // (which it doesn't reply to). It'll return the number of messages received, 153 // (which it doesn't reply to). It'll return the number of messages received,
149 // not including any "quitquitquit" message, modulo 100. 154 // not including any "quitquitquit" message, modulo 100.
150 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { 155 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
151 ChannelThread channel_thread; 156 embedder::SimplePlatformSupport platform_support;
157 ChannelThread channel_thread(&platform_support);
152 embedder::ScopedPlatformHandle client_platform_handle = 158 embedder::ScopedPlatformHandle client_platform_handle =
153 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); 159 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
154 CHECK(client_platform_handle.is_valid()); 160 CHECK(client_platform_handle.is_valid());
155 scoped_refptr<MessagePipe> mp(new MessagePipe( 161 scoped_refptr<MessagePipe> mp(new MessagePipe(
156 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), 162 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()),
157 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); 163 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint())));
158 channel_thread.Start(client_platform_handle.Pass(), mp); 164 channel_thread.Start(client_platform_handle.Pass(), mp);
159 165
160 const std::string quitquitquit("quitquitquit"); 166 const std::string quitquitquit("quitquitquit");
161 int rv = 0; 167 int rv = 0;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 EXPECT_EQ(0u, hss.satisfied_signals); 316 EXPECT_EQ(0u, hss.satisfied_signals);
311 EXPECT_EQ(0u, hss.satisfiable_signals); 317 EXPECT_EQ(0u, hss.satisfiable_signals);
312 318
313 mp->Close(0); 319 mp->Close(0);
314 320
315 EXPECT_EQ(static_cast<int>(kNumMessages % 100), 321 EXPECT_EQ(static_cast<int>(kNumMessages % 100),
316 helper()->WaitForChildShutdown()); 322 helper()->WaitForChildShutdown());
317 } 323 }
318 324
319 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { 325 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
320 ChannelThread channel_thread; 326 embedder::SimplePlatformSupport platform_support;
327 ChannelThread channel_thread(&platform_support);
321 embedder::ScopedPlatformHandle client_platform_handle = 328 embedder::ScopedPlatformHandle client_platform_handle =
322 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); 329 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
323 CHECK(client_platform_handle.is_valid()); 330 CHECK(client_platform_handle.is_valid());
324 scoped_refptr<MessagePipe> mp(new MessagePipe( 331 scoped_refptr<MessagePipe> mp(new MessagePipe(
325 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), 332 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()),
326 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); 333 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint())));
327 channel_thread.Start(client_platform_handle.Pass(), mp); 334 channel_thread.Start(client_platform_handle.Pass(), mp);
328 335
329 // Wait for the first message from our parent. 336 // Wait for the first message from our parent.
330 HandleSignalsState hss; 337 HandleSignalsState hss;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 #endif 428 #endif
422 TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) { 429 TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
423 helper()->StartChild("CheckSharedBuffer"); 430 helper()->StartChild("CheckSharedBuffer");
424 431
425 scoped_refptr<MessagePipe> mp(new MessagePipe( 432 scoped_refptr<MessagePipe> mp(new MessagePipe(
426 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), 433 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()),
427 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); 434 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint())));
428 Init(mp); 435 Init(mp);
429 436
430 // Make a shared buffer. 437 // Make a shared buffer.
431 embedder::SimplePlatformSupport platform_support;
432 scoped_refptr<SharedBufferDispatcher> dispatcher; 438 scoped_refptr<SharedBufferDispatcher> dispatcher;
433 EXPECT_EQ(MOJO_RESULT_OK, 439 EXPECT_EQ(MOJO_RESULT_OK,
434 SharedBufferDispatcher::Create( 440 SharedBufferDispatcher::Create(
435 &platform_support, 441 platform_support(),
436 SharedBufferDispatcher::kDefaultCreateOptions, 442 SharedBufferDispatcher::kDefaultCreateOptions,
437 100, 443 100,
438 &dispatcher)); 444 &dispatcher));
439 ASSERT_TRUE(dispatcher); 445 ASSERT_TRUE(dispatcher);
440 446
441 // Make a mapping. 447 // Make a mapping.
442 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping; 448 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping;
443 EXPECT_EQ(MOJO_RESULT_OK, 449 EXPECT_EQ(MOJO_RESULT_OK,
444 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 450 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
445 ASSERT_TRUE(mapping); 451 ASSERT_TRUE(mapping);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); 514 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
509 EXPECT_EQ(0u, hss.satisfied_signals); 515 EXPECT_EQ(0u, hss.satisfied_signals);
510 EXPECT_EQ(0u, hss.satisfiable_signals); 516 EXPECT_EQ(0u, hss.satisfiable_signals);
511 517
512 mp->Close(0); 518 mp->Close(0);
513 519
514 EXPECT_EQ(0, helper()->WaitForChildShutdown()); 520 EXPECT_EQ(0, helper()->WaitForChildShutdown());
515 } 521 }
516 522
517 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { 523 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
518 ChannelThread channel_thread; 524 embedder::SimplePlatformSupport platform_support;
525 ChannelThread channel_thread(&platform_support);
519 embedder::ScopedPlatformHandle client_platform_handle = 526 embedder::ScopedPlatformHandle client_platform_handle =
520 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); 527 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
521 CHECK(client_platform_handle.is_valid()); 528 CHECK(client_platform_handle.is_valid());
522 scoped_refptr<MessagePipe> mp(new MessagePipe( 529 scoped_refptr<MessagePipe> mp(new MessagePipe(
523 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), 530 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()),
524 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); 531 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint())));
525 channel_thread.Start(client_platform_handle.Pass(), mp); 532 channel_thread.Start(client_platform_handle.Pass(), mp);
526 533
527 HandleSignalsState hss; 534 HandleSignalsState hss;
528 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), 535 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 EXPECT_EQ(0u, hss.satisfiable_signals); 630 EXPECT_EQ(0u, hss.satisfiable_signals);
624 631
625 mp->Close(0); 632 mp->Close(0);
626 633
627 EXPECT_EQ(0, helper()->WaitForChildShutdown()); 634 EXPECT_EQ(0, helper()->WaitForChildShutdown());
628 } 635 }
629 636
630 } // namespace 637 } // namespace
631 } // namespace system 638 } // namespace system
632 } // namespace mojo 639 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/core.cc ('k') | mojo/system/remote_message_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698