| 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" | |
| 14 #include "base/files/file_util.h" | |
| 15 #include "base/files/scoped_temp_dir.h" | |
| 16 #include "base/location.h" | 13 #include "base/location.h" |
| 17 #include "base/logging.h" | 14 #include "base/logging.h" |
| 18 #include "build/build_config.h" // TODO(vtl): Remove this. | 15 #include "build/build_config.h" // TODO(vtl): Remove this. |
| 19 #include "mojo/edk/embedder/platform_shared_buffer.h" | 16 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 20 #include "mojo/edk/embedder/scoped_platform_handle.h" | 17 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 21 #include "mojo/edk/system/channel.h" | 18 #include "mojo/edk/system/channel.h" |
| 22 #include "mojo/edk/system/dispatcher.h" | 19 #include "mojo/edk/system/dispatcher.h" |
| 23 #include "mojo/edk/system/message_pipe.h" | 20 #include "mojo/edk/system/message_pipe.h" |
| 24 #include "mojo/edk/system/message_pipe_test_utils.h" | 21 #include "mojo/edk/system/message_pipe_test_utils.h" |
| 25 #include "mojo/edk/system/platform_handle_dispatcher.h" | 22 #include "mojo/edk/system/platform_handle_dispatcher.h" |
| 26 #include "mojo/edk/system/raw_channel.h" | 23 #include "mojo/edk/system/raw_channel.h" |
| 27 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 24 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
| 28 #include "mojo/edk/system/test_utils.h" | 25 #include "mojo/edk/system/test_utils.h" |
| 26 #include "mojo/edk/test/scoped_test_dir.h" |
| 29 #include "mojo/edk/test/test_utils.h" | 27 #include "mojo/edk/test/test_utils.h" |
| 30 #include "mojo/edk/util/scoped_file.h" | 28 #include "mojo/edk/util/scoped_file.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 30 |
| 33 namespace mojo { | 31 namespace mojo { |
| 34 namespace system { | 32 namespace system { |
| 35 namespace { | 33 namespace { |
| 36 | 34 |
| 37 class MultiprocessMessagePipeTest | 35 class MultiprocessMessagePipeTest |
| 38 : public test::MultiprocessMessagePipeTestBase {}; | 36 : public test::MultiprocessMessagePipeTestBase {}; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 } | 439 } |
| 442 | 440 |
| 443 return 0; | 441 return 0; |
| 444 } | 442 } |
| 445 | 443 |
| 446 class MultiprocessMessagePipeTestWithPipeCount | 444 class MultiprocessMessagePipeTestWithPipeCount |
| 447 : public test::MultiprocessMessagePipeTestBase, | 445 : public test::MultiprocessMessagePipeTestBase, |
| 448 public testing::WithParamInterface<size_t> {}; | 446 public testing::WithParamInterface<size_t> {}; |
| 449 | 447 |
| 450 TEST_P(MultiprocessMessagePipeTestWithPipeCount, PlatformHandlePassing) { | 448 TEST_P(MultiprocessMessagePipeTestWithPipeCount, PlatformHandlePassing) { |
| 451 base::ScopedTempDir temp_dir; | 449 mojo::test::ScopedTestDir test_dir; |
| 452 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 453 | 450 |
| 454 helper()->StartChild("CheckPlatformHandleFile"); | 451 helper()->StartChild("CheckPlatformHandleFile"); |
| 455 | 452 |
| 456 scoped_refptr<ChannelEndpoint> ep; | 453 scoped_refptr<ChannelEndpoint> ep; |
| 457 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); | 454 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
| 458 Init(ep); | 455 Init(ep); |
| 459 | 456 |
| 460 std::vector<scoped_refptr<PlatformHandleDispatcher>> dispatchers; | 457 std::vector<scoped_refptr<PlatformHandleDispatcher>> dispatchers; |
| 461 std::vector<DispatcherTransport> transports; | 458 std::vector<DispatcherTransport> transports; |
| 462 | 459 |
| 463 size_t pipe_count = GetParam(); | 460 size_t pipe_count = GetParam(); |
| 464 for (size_t i = 0; i < pipe_count; ++i) { | 461 for (size_t i = 0; i < pipe_count; ++i) { |
| 465 base::FilePath unused; | 462 util::ScopedFILE fp(test_dir.CreateFile()); |
| 466 util::ScopedFILE fp( | |
| 467 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | |
| 468 const std::string world("world"); | 463 const std::string world("world"); |
| 469 CHECK_EQ(fwrite(&world[0], 1, world.size(), fp.get()), world.size()); | 464 CHECK_EQ(fwrite(&world[0], 1, world.size(), fp.get()), world.size()); |
| 470 fflush(fp.get()); | 465 fflush(fp.get()); |
| 471 rewind(fp.get()); | 466 rewind(fp.get()); |
| 472 | 467 |
| 473 scoped_refptr<PlatformHandleDispatcher> dispatcher = | 468 scoped_refptr<PlatformHandleDispatcher> dispatcher = |
| 474 PlatformHandleDispatcher::Create(embedder::ScopedPlatformHandle( | 469 PlatformHandleDispatcher::Create(embedder::ScopedPlatformHandle( |
| 475 mojo::test::PlatformHandleFromFILE(fp.Pass()))); | 470 mojo::test::PlatformHandleFromFILE(fp.Pass()))); |
| 476 dispatchers.push_back(dispatcher); | 471 dispatchers.push_back(dispatcher); |
| 477 DispatcherTransport transport( | 472 DispatcherTransport transport( |
| (...skipping 32 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. | 505 // Android multi-process tests are not executing the new process. This is flaky. |
| 511 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 506 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 512 INSTANTIATE_TEST_CASE_P(PipeCount, | 507 INSTANTIATE_TEST_CASE_P(PipeCount, |
| 513 MultiprocessMessagePipeTestWithPipeCount, | 508 MultiprocessMessagePipeTestWithPipeCount, |
| 514 testing::Values(1u, 128u, 140u)); | 509 testing::Values(1u, 128u, 140u)); |
| 515 #endif | 510 #endif |
| 516 | 511 |
| 517 } // namespace | 512 } // namespace |
| 518 } // namespace system | 513 } // namespace system |
| 519 } // namespace mojo | 514 } // namespace mojo |
| OLD | NEW |