| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stddef.h> | |
| 6 #include <memory> | |
| 7 | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "base/threading/thread_task_runner_handle.h" | |
| 11 #include "build/build_config.h" | |
| 12 #include "ipc/ipc_perftest_support.h" | |
| 13 #include "ipc/mojo/ipc_channel_mojo.h" | |
| 14 #include "mojo/edk/embedder/embedder.h" | |
| 15 #include "mojo/edk/embedder/platform_channel_pair.h" | |
| 16 #include "mojo/edk/test/multiprocess_test_helper.h" | |
| 17 #include "mojo/edk/test/scoped_ipc_support.h" | |
| 18 | |
| 19 namespace IPC { | |
| 20 namespace { | |
| 21 | |
| 22 class MojoChannelPerfTest : public test::IPCChannelPerfTestBase { | |
| 23 public: | |
| 24 void TearDown() override { | |
| 25 ipc_support_.reset(); | |
| 26 test::IPCChannelPerfTestBase::TearDown(); | |
| 27 } | |
| 28 | |
| 29 std::unique_ptr<ChannelFactory> CreateChannelFactory( | |
| 30 const ChannelHandle& handle, | |
| 31 base::SequencedTaskRunner* runner) override { | |
| 32 ipc_support_.reset(new mojo::edk::test::ScopedIPCSupport(io_task_runner())); | |
| 33 return ChannelMojo::CreateServerFactory( | |
| 34 helper_.StartChild("MojoPerfTestClient")); | |
| 35 } | |
| 36 | |
| 37 bool StartClient() override { | |
| 38 return true; | |
| 39 } | |
| 40 | |
| 41 bool WaitForClientShutdown() override { | |
| 42 return helper_.WaitForChildTestShutdown(); | |
| 43 } | |
| 44 | |
| 45 mojo::edk::test::MultiprocessTestHelper helper_; | |
| 46 std::unique_ptr<mojo::edk::test::ScopedIPCSupport> ipc_support_; | |
| 47 }; | |
| 48 | |
| 49 TEST_F(MojoChannelPerfTest, ChannelPingPong) { | |
| 50 RunTestChannelPingPong(GetDefaultTestParams()); | |
| 51 | |
| 52 base::RunLoop run_loop; | |
| 53 run_loop.RunUntilIdle(); | |
| 54 } | |
| 55 | |
| 56 TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) { | |
| 57 RunTestChannelProxyPingPong(GetDefaultTestParams()); | |
| 58 | |
| 59 base::RunLoop run_loop; | |
| 60 run_loop.RunUntilIdle(); | |
| 61 } | |
| 62 | |
| 63 // Test to see how many channels we can create. | |
| 64 TEST_F(MojoChannelPerfTest, DISABLED_MaxChannelCount) { | |
| 65 #if defined(OS_POSIX) | |
| 66 LOG(INFO) << "base::GetMaxFds " << base::GetMaxFds(); | |
| 67 base::SetFdLimit(20000); | |
| 68 #endif | |
| 69 | |
| 70 std::vector<mojo::edk::PlatformChannelPair*> channels; | |
| 71 for (size_t i = 0; i < 10000; ++i) { | |
| 72 LOG(INFO) << "channels size: " << channels.size(); | |
| 73 channels.push_back(new mojo::edk::PlatformChannelPair()); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 class MojoPerfTestClient : public test::PingPongTestClient { | |
| 78 public: | |
| 79 typedef test::PingPongTestClient SuperType; | |
| 80 | |
| 81 MojoPerfTestClient(); | |
| 82 | |
| 83 std::unique_ptr<Channel> CreateChannel(Listener* listener) override; | |
| 84 | |
| 85 int Run(MojoHandle handle); | |
| 86 | |
| 87 private: | |
| 88 mojo::edk::test::ScopedIPCSupport ipc_support_; | |
| 89 mojo::ScopedMessagePipeHandle handle_; | |
| 90 }; | |
| 91 | |
| 92 MojoPerfTestClient::MojoPerfTestClient() | |
| 93 : ipc_support_(base::ThreadTaskRunnerHandle::Get()) { | |
| 94 mojo::edk::test::MultiprocessTestHelper::ChildSetup(); | |
| 95 } | |
| 96 | |
| 97 std::unique_ptr<Channel> MojoPerfTestClient::CreateChannel(Listener* listener) { | |
| 98 return ChannelMojo::Create(std::move(handle_), Channel::MODE_CLIENT, | |
| 99 listener); | |
| 100 } | |
| 101 | |
| 102 int MojoPerfTestClient::Run(MojoHandle handle) { | |
| 103 handle_ = mojo::MakeScopedHandle(mojo::MessagePipeHandle(handle)); | |
| 104 return RunMain(); | |
| 105 } | |
| 106 | |
| 107 MULTIPROCESS_TEST_MAIN(MojoPerfTestClientTestChildMain) { | |
| 108 MojoPerfTestClient client; | |
| 109 int rv = mojo::edk::test::MultiprocessTestHelper::RunClientMain( | |
| 110 base::Bind(&MojoPerfTestClient::Run, base::Unretained(&client))); | |
| 111 | |
| 112 base::RunLoop run_loop; | |
| 113 run_loop.RunUntilIdle(); | |
| 114 | |
| 115 return rv; | |
| 116 } | |
| 117 | |
| 118 } // namespace | |
| 119 } // namespace IPC | |
| OLD | NEW |