OLD | NEW |
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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/files/scoped_file.h" | |
16 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
17 #include "base/location.h" | 16 #include "base/location.h" |
18 #include "base/logging.h" | 17 #include "base/logging.h" |
19 #include "build/build_config.h" // TODO(vtl): Remove this. | 18 #include "build/build_config.h" // TODO(vtl): Remove this. |
20 #include "mojo/edk/embedder/platform_shared_buffer.h" | 19 #include "mojo/edk/embedder/platform_shared_buffer.h" |
21 #include "mojo/edk/embedder/scoped_platform_handle.h" | 20 #include "mojo/edk/embedder/scoped_platform_handle.h" |
22 #include "mojo/edk/system/channel.h" | 21 #include "mojo/edk/system/channel.h" |
23 #include "mojo/edk/system/dispatcher.h" | 22 #include "mojo/edk/system/dispatcher.h" |
24 #include "mojo/edk/system/message_pipe.h" | 23 #include "mojo/edk/system/message_pipe.h" |
25 #include "mojo/edk/system/message_pipe_test_utils.h" | 24 #include "mojo/edk/system/message_pipe_test_utils.h" |
26 #include "mojo/edk/system/platform_handle_dispatcher.h" | 25 #include "mojo/edk/system/platform_handle_dispatcher.h" |
27 #include "mojo/edk/system/raw_channel.h" | 26 #include "mojo/edk/system/raw_channel.h" |
28 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 27 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
29 #include "mojo/edk/system/test_utils.h" | 28 #include "mojo/edk/system/test_utils.h" |
30 #include "mojo/edk/test/test_utils.h" | 29 #include "mojo/edk/test/test_utils.h" |
| 30 #include "mojo/edk/util/scoped_file.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 namespace mojo { | 33 namespace mojo { |
34 namespace system { | 34 namespace system { |
35 namespace { | 35 namespace { |
36 | 36 |
37 class MultiprocessMessagePipeTest | 37 class MultiprocessMessagePipeTest |
38 : public test::MultiprocessMessagePipeTestBase {}; | 38 : public test::MultiprocessMessagePipeTestBase {}; |
39 | 39 |
40 // For each message received, sends a reply message with the same contents | 40 // For each message received, sends a reply message with the same contents |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 | 424 |
425 for (int i = 0; i < num_handles; ++i) { | 425 for (int i = 0; i < num_handles; ++i) { |
426 CHECK_EQ(dispatchers[i]->GetType(), Dispatcher::Type::PLATFORM_HANDLE); | 426 CHECK_EQ(dispatchers[i]->GetType(), Dispatcher::Type::PLATFORM_HANDLE); |
427 | 427 |
428 scoped_refptr<PlatformHandleDispatcher> dispatcher( | 428 scoped_refptr<PlatformHandleDispatcher> dispatcher( |
429 static_cast<PlatformHandleDispatcher*>(dispatchers[i].get())); | 429 static_cast<PlatformHandleDispatcher*>(dispatchers[i].get())); |
430 embedder::ScopedPlatformHandle h = dispatcher->PassPlatformHandle().Pass(); | 430 embedder::ScopedPlatformHandle h = dispatcher->PassPlatformHandle().Pass(); |
431 CHECK(h.is_valid()); | 431 CHECK(h.is_valid()); |
432 dispatcher->Close(); | 432 dispatcher->Close(); |
433 | 433 |
434 base::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h.Pass(), "r")); | 434 util::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h.Pass(), "r")); |
435 CHECK(fp); | 435 CHECK(fp); |
436 std::string fread_buffer(100, '\0'); | 436 std::string fread_buffer(100, '\0'); |
437 size_t bytes_read = | 437 size_t bytes_read = |
438 fread(&fread_buffer[0], 1, fread_buffer.size(), fp.get()); | 438 fread(&fread_buffer[0], 1, fread_buffer.size(), fp.get()); |
439 fread_buffer.resize(bytes_read); | 439 fread_buffer.resize(bytes_read); |
440 CHECK_EQ(fread_buffer, "world"); | 440 CHECK_EQ(fread_buffer, "world"); |
441 } | 441 } |
442 | 442 |
443 return 0; | 443 return 0; |
444 } | 444 } |
(...skipping 11 matching lines...) Expand all Loading... |
456 scoped_refptr<ChannelEndpoint> ep; | 456 scoped_refptr<ChannelEndpoint> ep; |
457 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); | 457 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
458 Init(ep); | 458 Init(ep); |
459 | 459 |
460 std::vector<scoped_refptr<PlatformHandleDispatcher>> dispatchers; | 460 std::vector<scoped_refptr<PlatformHandleDispatcher>> dispatchers; |
461 std::vector<DispatcherTransport> transports; | 461 std::vector<DispatcherTransport> transports; |
462 | 462 |
463 size_t pipe_count = GetParam(); | 463 size_t pipe_count = GetParam(); |
464 for (size_t i = 0; i < pipe_count; ++i) { | 464 for (size_t i = 0; i < pipe_count; ++i) { |
465 base::FilePath unused; | 465 base::FilePath unused; |
466 base::ScopedFILE fp( | 466 util::ScopedFILE fp( |
467 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | 467 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); |
468 const std::string world("world"); | 468 const std::string world("world"); |
469 CHECK_EQ(fwrite(&world[0], 1, world.size(), fp.get()), world.size()); | 469 CHECK_EQ(fwrite(&world[0], 1, world.size(), fp.get()), world.size()); |
470 fflush(fp.get()); | 470 fflush(fp.get()); |
471 rewind(fp.get()); | 471 rewind(fp.get()); |
472 | 472 |
473 scoped_refptr<PlatformHandleDispatcher> dispatcher = | 473 scoped_refptr<PlatformHandleDispatcher> dispatcher = |
474 PlatformHandleDispatcher::Create(embedder::ScopedPlatformHandle( | 474 PlatformHandleDispatcher::Create(embedder::ScopedPlatformHandle( |
475 mojo::test::PlatformHandleFromFILE(fp.Pass()))); | 475 mojo::test::PlatformHandleFromFILE(fp.Pass()))); |
476 dispatchers.push_back(dispatcher); | 476 dispatchers.push_back(dispatcher); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 // Android multi-process tests are not executing the new process. This is flaky. | 510 // Android multi-process tests are not executing the new process. This is flaky. |
511 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 511 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
512 INSTANTIATE_TEST_CASE_P(PipeCount, | 512 INSTANTIATE_TEST_CASE_P(PipeCount, |
513 MultiprocessMessagePipeTestWithPipeCount, | 513 MultiprocessMessagePipeTestWithPipeCount, |
514 testing::Values(1u, 128u, 140u)); | 514 testing::Values(1u, 128u, 140u)); |
515 #endif | 515 #endif |
516 | 516 |
517 } // namespace | 517 } // namespace |
518 } // namespace system | 518 } // namespace system |
519 } // namespace mojo | 519 } // namespace mojo |
OLD | NEW |