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

Side by Side Diff: mojo/edk/system/remote_message_pipe_unittest.cc

Issue 799113004: Update mojo sdk to rev 59145288bae55b0fce4276b017df6a1117bcf00f (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add mojo's ply to checklicenses whitelist Created 6 years 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
« no previous file with comments | « mojo/edk/system/message_pipe_test_utils.cc ('k') | mojo/edk/system/waiter.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_file.h" 14 #include "base/files/scoped_file.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/test/test_io_thread.h" 20 #include "base/test/test_io_thread.h"
21 #include "base/threading/platform_thread.h" // For |Sleep()|. 21 #include "base/threading/platform_thread.h" // For |Sleep()|.
22 #include "build/build_config.h" // TODO(vtl): Remove this. 22 #include "build/build_config.h" // TODO(vtl): Remove this.
23 #include "mojo/edk/embedder/platform_channel_pair.h" 23 #include "mojo/edk/embedder/platform_channel_pair.h"
24 #include "mojo/edk/embedder/platform_shared_buffer.h" 24 #include "mojo/edk/embedder/platform_shared_buffer.h"
25 #include "mojo/edk/embedder/scoped_platform_handle.h" 25 #include "mojo/edk/embedder/scoped_platform_handle.h"
26 #include "mojo/edk/embedder/simple_platform_support.h" 26 #include "mojo/edk/embedder/simple_platform_support.h"
27 #include "mojo/edk/system/channel.h" 27 #include "mojo/edk/system/channel.h"
28 #include "mojo/edk/system/channel_endpoint.h" 28 #include "mojo/edk/system/channel_endpoint.h"
29 #include "mojo/edk/system/channel_endpoint_id.h" 29 #include "mojo/edk/system/channel_endpoint_id.h"
30 #include "mojo/edk/system/incoming_endpoint.h"
30 #include "mojo/edk/system/message_pipe.h" 31 #include "mojo/edk/system/message_pipe.h"
31 #include "mojo/edk/system/message_pipe_dispatcher.h" 32 #include "mojo/edk/system/message_pipe_dispatcher.h"
32 #include "mojo/edk/system/platform_handle_dispatcher.h" 33 #include "mojo/edk/system/platform_handle_dispatcher.h"
33 #include "mojo/edk/system/raw_channel.h" 34 #include "mojo/edk/system/raw_channel.h"
34 #include "mojo/edk/system/shared_buffer_dispatcher.h" 35 #include "mojo/edk/system/shared_buffer_dispatcher.h"
35 #include "mojo/edk/system/test_utils.h" 36 #include "mojo/edk/system/test_utils.h"
36 #include "mojo/edk/system/waiter.h" 37 #include "mojo/edk/system/waiter.h"
37 #include "mojo/edk/test/test_utils.h" 38 #include "mojo/edk/test/test_utils.h"
38 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
39 40
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 133
133 void BootstrapChannelEndpointsOnIOThread(scoped_refptr<ChannelEndpoint> ep0, 134 void BootstrapChannelEndpointsOnIOThread(scoped_refptr<ChannelEndpoint> ep0,
134 scoped_refptr<ChannelEndpoint> ep1) { 135 scoped_refptr<ChannelEndpoint> ep1) {
135 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); 136 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
136 137
137 if (!channels_[0]) 138 if (!channels_[0])
138 CreateAndInitChannel(0); 139 CreateAndInitChannel(0);
139 if (!channels_[1]) 140 if (!channels_[1])
140 CreateAndInitChannel(1); 141 CreateAndInitChannel(1);
141 142
142 channels_[0]->AttachAndRunEndpoint(ep0, true); 143 channels_[0]->SetBootstrapEndpoint(ep0);
143 channels_[1]->AttachAndRunEndpoint(ep1, true); 144 channels_[1]->SetBootstrapEndpoint(ep1);
144 } 145 }
145 146
146 void BootstrapChannelEndpointOnIOThread(unsigned channel_index, 147 void BootstrapChannelEndpointOnIOThread(unsigned channel_index,
147 scoped_refptr<ChannelEndpoint> ep) { 148 scoped_refptr<ChannelEndpoint> ep) {
148 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); 149 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
149 CHECK(channel_index == 0 || channel_index == 1); 150 CHECK(channel_index == 0 || channel_index == 1);
150 151
151 CreateAndInitChannel(channel_index); 152 CreateAndInitChannel(channel_index);
152 channels_[channel_index]->AttachAndRunEndpoint(ep, true); 153 channels_[channel_index]->SetBootstrapEndpoint(ep);
153 } 154 }
154 155
155 void RestoreInitialStateOnIOThread() { 156 void RestoreInitialStateOnIOThread() {
156 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); 157 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
157 158
158 TearDownOnIOThread(); 159 TearDownOnIOThread();
159 SetUpOnIOThread(); 160 SetUpOnIOThread();
160 } 161 }
161 162
162 embedder::SimplePlatformSupport platform_support_; 163 embedder::SimplePlatformSupport platform_support_;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // Now put another message pipe on the channel. 327 // Now put another message pipe on the channel.
327 328
328 // Do this by creating a message pipe (for the |channels(0)| side) and 329 // Do this by creating a message pipe (for the |channels(0)| side) and
329 // attaching and running it, yielding the remote ID. A message is then sent 330 // attaching and running it, yielding the remote ID. A message is then sent
330 // via |ep0| (i.e., sent using |mp0|, port 0) with this remote ID. Upon 331 // via |ep0| (i.e., sent using |mp0|, port 0) with this remote ID. Upon
331 // receiving this message, |PassIncomingMessagePipe()| is used to obtain the 332 // receiving this message, |PassIncomingMessagePipe()| is used to obtain the
332 // message pipe on the other side. 333 // message pipe on the other side.
333 scoped_refptr<ChannelEndpoint> ep2; 334 scoped_refptr<ChannelEndpoint> ep2;
334 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalProxy(&ep2)); 335 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalProxy(&ep2));
335 ASSERT_TRUE(channels(0)); 336 ASSERT_TRUE(channels(0));
336 ChannelEndpointId remote_id = channels(0)->AttachAndRunEndpoint(ep2, false); 337 size_t endpoint_info_size = channels(0)->GetSerializedEndpointSize();
337 EXPECT_TRUE(remote_id.is_remote()); 338 scoped_ptr<char[]> endpoint_info(new char[endpoint_info_size]);
339 channels(0)->SerializeEndpoint(ep2, endpoint_info.get());
338 340
339 waiter.Init(); 341 waiter.Init();
340 ASSERT_EQ( 342 ASSERT_EQ(
341 MOJO_RESULT_OK, 343 MOJO_RESULT_OK,
342 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 344 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
343 345
344 EXPECT_EQ(MOJO_RESULT_OK, 346 EXPECT_EQ(MOJO_RESULT_OK,
345 mp0->WriteMessage(0, UserPointer<const void>(&remote_id), 347 mp0->WriteMessage(0, UserPointer<const void>(endpoint_info.get()),
346 sizeof(remote_id), nullptr, 348 static_cast<uint32_t>(endpoint_info_size),
347 MOJO_WRITE_MESSAGE_FLAG_NONE)); 349 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
348 350
349 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 351 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
350 EXPECT_EQ(123u, context); 352 EXPECT_EQ(123u, context);
351 hss = HandleSignalsState(); 353 hss = HandleSignalsState();
352 mp1->RemoveAwakable(1, &waiter, &hss); 354 mp1->RemoveAwakable(1, &waiter, &hss);
353 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 355 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
354 hss.satisfied_signals); 356 hss.satisfied_signals);
355 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 357 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
356 358
357 ChannelEndpointId received_id; 359 EXPECT_EQ(endpoint_info_size, channels(1)->GetSerializedEndpointSize());
358 buffer_size = static_cast<uint32_t>(sizeof(received_id)); 360 scoped_ptr<char[]> received_endpoint_info(new char[endpoint_info_size]);
361 buffer_size = static_cast<uint32_t>(endpoint_info_size);
359 EXPECT_EQ(MOJO_RESULT_OK, 362 EXPECT_EQ(MOJO_RESULT_OK,
360 mp1->ReadMessage(1, UserPointer<void>(&received_id), 363 mp1->ReadMessage(1, UserPointer<void>(received_endpoint_info.get()),
361 MakeUserPointer(&buffer_size), nullptr, nullptr, 364 MakeUserPointer(&buffer_size), nullptr, nullptr,
362 MOJO_READ_MESSAGE_FLAG_NONE)); 365 MOJO_READ_MESSAGE_FLAG_NONE));
363 EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size)); 366 EXPECT_EQ(endpoint_info_size, static_cast<size_t>(buffer_size));
364 EXPECT_EQ(remote_id, received_id); 367 EXPECT_EQ(0, memcmp(received_endpoint_info.get(), endpoint_info.get(),
368 endpoint_info_size));
365 369
366 // Warning: The local side of mp3 is port 0, not port 1. 370 // Warning: The local side of mp3 is port 0, not port 1.
367 scoped_refptr<MessagePipe> mp3 = 371 scoped_refptr<IncomingEndpoint> incoming_endpoint =
368 channels(1)->PassIncomingMessagePipe(received_id); 372 channels(1)->DeserializeEndpoint(received_endpoint_info.get());
373 ASSERT_TRUE(incoming_endpoint);
374 scoped_refptr<MessagePipe> mp3 = incoming_endpoint->ConvertToMessagePipe();
369 ASSERT_TRUE(mp3); 375 ASSERT_TRUE(mp3);
370 376
371 // Write: MP 2, port 0 -> MP 3, port 1. 377 // Write: MP 2, port 0 -> MP 3, port 1.
372 378
373 waiter.Init(); 379 waiter.Init();
374 ASSERT_EQ( 380 ASSERT_EQ(
375 MOJO_RESULT_OK, 381 MOJO_RESULT_OK,
376 mp3->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); 382 mp3->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
377 383
378 EXPECT_EQ( 384 EXPECT_EQ(
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 mp0->Close(0); 1360 mp0->Close(0);
1355 mp1->Close(1); 1361 mp1->Close(1);
1356 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 1362 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
1357 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. 1363 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed.
1358 local_mp->Close(1); 1364 local_mp->Close(1);
1359 } 1365 }
1360 1366
1361 } // namespace 1367 } // namespace
1362 } // namespace system 1368 } // namespace system
1363 } // namespace mojo 1369 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_test_utils.cc ('k') | mojo/edk/system/waiter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698