blob: 6fdcbab49c90b5d369350a6f52096c9feead2a9f [file] [log] [blame]
morritaab779702014-09-10 04:35:24 +09001// 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 "base/lazy_instance.h"
morrita9d483fc2015-03-14 05:44:39 +09006#include "base/run_loop.h"
morritaab779702014-09-10 04:35:24 +09007#include "ipc/ipc_perftest_support.h"
8#include "ipc/mojo/ipc_channel_mojo.h"
jame76324e2015-10-03 06:01:28 +09009#include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
jam8ebc54c2015-10-03 14:12:35 +090010#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
morritaab779702014-09-10 04:35:24 +090011
12namespace {
13
14// This is needed because we rely on //base/test:test_support_perf and
15// it provides main() which doesn't have Mojo initialization. We need
jame76324e2015-10-03 06:01:28 +090016// some way to call Init() only once before using Mojo.
morritaab779702014-09-10 04:35:24 +090017struct MojoInitialier {
18 MojoInitialier() {
jame76324e2015-10-03 06:01:28 +090019 mojo::embedder::Init();
morritaab779702014-09-10 04:35:24 +090020 }
21};
22
23base::LazyInstance<MojoInitialier> g_mojo_initializer
24 = LAZY_INSTANCE_INITIALIZER;
25
26class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase {
27public:
28 typedef IPC::test::IPCChannelPerfTestBase Super;
29
30 MojoChannelPerfTest();
31
morrita9d483fc2015-03-14 05:44:39 +090032 void TearDown() override {
morrita9d483fc2015-03-14 05:44:39 +090033 IPC::test::IPCChannelPerfTestBase::TearDown();
34 }
35
dchengef7721a2014-10-22 11:29:52 +090036 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
morritaab779702014-09-10 04:35:24 +090037 const IPC::ChannelHandle& handle,
morrita9d483fc2015-03-14 05:44:39 +090038 base::SequencedTaskRunner* runner) override {
erikchenc596f542015-09-24 12:26:38 +090039 return IPC::ChannelMojo::CreateServerFactory(runner, handle);
morrita7c48ab82014-09-24 06:16:00 +090040 }
41
dchengef7721a2014-10-22 11:29:52 +090042 bool DidStartClient() override {
morrita7c48ab82014-09-24 06:16:00 +090043 bool ok = IPCTestBase::DidStartClient();
44 DCHECK(ok);
morrita7c48ab82014-09-24 06:16:00 +090045 return ok;
morritaab779702014-09-10 04:35:24 +090046 }
morritaab779702014-09-10 04:35:24 +090047};
48
morrita9d483fc2015-03-14 05:44:39 +090049MojoChannelPerfTest::MojoChannelPerfTest() {
morritaab779702014-09-10 04:35:24 +090050 g_mojo_initializer.Get();
51}
52
53
54TEST_F(MojoChannelPerfTest, ChannelPingPong) {
55 RunTestChannelPingPong(GetDefaultTestParams());
morrita9d483fc2015-03-14 05:44:39 +090056
57 base::RunLoop run_loop;
58 run_loop.RunUntilIdle();
morritaab779702014-09-10 04:35:24 +090059}
60
61TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
62 RunTestChannelProxyPingPong(GetDefaultTestParams());
morrita9d483fc2015-03-14 05:44:39 +090063
64 base::RunLoop run_loop;
65 run_loop.RunUntilIdle();
morritaab779702014-09-10 04:35:24 +090066}
67
jame76324e2015-10-03 06:01:28 +090068// Test to see how many channels we can create.
69TEST_F(MojoChannelPerfTest, DISABLED_MaxChannelCount) {
70#if defined(OS_POSIX)
71 LOG(INFO) << "base::GetMaxFds " << base::GetMaxFds();
72 base::SetFdLimit(20000);
73#endif
74
75 std::vector<mojo::embedder::PlatformChannelPair*> channels;
76 for (size_t i = 0; i < 10000; ++i) {
77 LOG(INFO) << "channels size: " << channels.size();
78 channels.push_back(new mojo::embedder::PlatformChannelPair());
79 }
80}
81
morritaab779702014-09-10 04:35:24 +090082class MojoTestClient : public IPC::test::PingPongTestClient {
83 public:
84 typedef IPC::test::PingPongTestClient SuperType;
85
86 MojoTestClient();
87
dchengef7721a2014-10-22 11:29:52 +090088 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
morritaab779702014-09-10 04:35:24 +090089};
90
91MojoTestClient::MojoTestClient() {
92 g_mojo_initializer.Get();
93}
94
95scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
96 IPC::Listener* listener) {
morritad7325c22015-04-10 04:43:27 +090097 return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create(
leon.han5dd52cd2015-06-19 11:25:48 +090098 task_runner(), IPCTestBase::GetChannelName("PerformanceClient"),
erikchenc596f542015-09-24 12:26:38 +090099 IPC::Channel::MODE_CLIENT, listener));
morritaab779702014-09-10 04:35:24 +0900100}
101
102MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
103 MojoTestClient client;
morrita9d483fc2015-03-14 05:44:39 +0900104 int rv = client.RunMain();
105
106 base::RunLoop run_loop;
107 run_loop.RunUntilIdle();
108
109 return rv;
morritaab779702014-09-10 04:35:24 +0900110}
111
112} // namespace