blob: d782c77ee59a51f8711fa803f3b8db2b9c829196 [file] [log] [blame]
morrita373af03b2014-09-09 19:35:241// 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
avi246998d82015-12-22 02:39:045#include <stddef.h>
6
morrita373af03b2014-09-09 19:35:247#include "base/lazy_instance.h"
morritac4db5472015-03-13 20:44:398#include "base/run_loop.h"
avi246998d82015-12-22 02:39:049#include "build/build_config.h"
morrita373af03b2014-09-09 19:35:2410#include "ipc/ipc_perftest_support.h"
11#include "ipc/mojo/ipc_channel_mojo.h"
jam76bcf0c2015-10-02 21:01:2812#include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
jam4ff34db2015-10-03 05:12:3513#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
morrita373af03b2014-09-09 19:35:2414
15namespace {
16
17// This is needed because we rely on //base/test:test_support_perf and
18// it provides main() which doesn't have Mojo initialization. We need
jam76bcf0c2015-10-02 21:01:2819// some way to call Init() only once before using Mojo.
morrita373af03b2014-09-09 19:35:2420struct MojoInitialier {
21 MojoInitialier() {
jam76bcf0c2015-10-02 21:01:2822 mojo::embedder::Init();
morrita373af03b2014-09-09 19:35:2423 }
24};
25
26base::LazyInstance<MojoInitialier> g_mojo_initializer
27 = LAZY_INSTANCE_INITIALIZER;
28
29class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase {
30public:
31 typedef IPC::test::IPCChannelPerfTestBase Super;
32
33 MojoChannelPerfTest();
34
morritac4db5472015-03-13 20:44:3935 void TearDown() override {
morritac4db5472015-03-13 20:44:3936 IPC::test::IPCChannelPerfTestBase::TearDown();
37 }
38
dchengfe61fca2014-10-22 02:29:5239 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
morrita373af03b2014-09-09 19:35:2440 const IPC::ChannelHandle& handle,
morritac4db5472015-03-13 20:44:3941 base::SequencedTaskRunner* runner) override {
erikchen30dc2812015-09-24 03:26:3842 return IPC::ChannelMojo::CreateServerFactory(runner, handle);
morrita54f6f80c2014-09-23 21:16:0043 }
44
dchengfe61fca2014-10-22 02:29:5245 bool DidStartClient() override {
morrita54f6f80c2014-09-23 21:16:0046 bool ok = IPCTestBase::DidStartClient();
47 DCHECK(ok);
morrita54f6f80c2014-09-23 21:16:0048 return ok;
morrita373af03b2014-09-09 19:35:2449 }
morrita373af03b2014-09-09 19:35:2450};
51
morritac4db5472015-03-13 20:44:3952MojoChannelPerfTest::MojoChannelPerfTest() {
morrita373af03b2014-09-09 19:35:2453 g_mojo_initializer.Get();
54}
55
56
57TEST_F(MojoChannelPerfTest, ChannelPingPong) {
58 RunTestChannelPingPong(GetDefaultTestParams());
morritac4db5472015-03-13 20:44:3959
60 base::RunLoop run_loop;
61 run_loop.RunUntilIdle();
morrita373af03b2014-09-09 19:35:2462}
63
64TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
65 RunTestChannelProxyPingPong(GetDefaultTestParams());
morritac4db5472015-03-13 20:44:3966
67 base::RunLoop run_loop;
68 run_loop.RunUntilIdle();
morrita373af03b2014-09-09 19:35:2469}
70
jam76bcf0c2015-10-02 21:01:2871// Test to see how many channels we can create.
72TEST_F(MojoChannelPerfTest, DISABLED_MaxChannelCount) {
73#if defined(OS_POSIX)
74 LOG(INFO) << "base::GetMaxFds " << base::GetMaxFds();
75 base::SetFdLimit(20000);
76#endif
77
78 std::vector<mojo::embedder::PlatformChannelPair*> channels;
79 for (size_t i = 0; i < 10000; ++i) {
80 LOG(INFO) << "channels size: " << channels.size();
81 channels.push_back(new mojo::embedder::PlatformChannelPair());
82 }
83}
84
morrita373af03b2014-09-09 19:35:2485class MojoTestClient : public IPC::test::PingPongTestClient {
86 public:
87 typedef IPC::test::PingPongTestClient SuperType;
88
89 MojoTestClient();
90
dchengfe61fca2014-10-22 02:29:5291 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
morrita373af03b2014-09-09 19:35:2492};
93
94MojoTestClient::MojoTestClient() {
95 g_mojo_initializer.Get();
96}
97
98scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
99 IPC::Listener* listener) {
morrita00194e782015-04-09 19:43:27100 return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create(
leon.hand20a6c4c2015-06-19 02:25:48101 task_runner(), IPCTestBase::GetChannelName("PerformanceClient"),
erikchen30dc2812015-09-24 03:26:38102 IPC::Channel::MODE_CLIENT, listener));
morrita373af03b2014-09-09 19:35:24103}
104
105MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
106 MojoTestClient client;
morritac4db5472015-03-13 20:44:39107 int rv = client.RunMain();
108
109 base::RunLoop run_loop;
110 run_loop.RunUntilIdle();
111
112 return rv;
morrita373af03b2014-09-09 19:35:24113}
114
115} // namespace