blob: 577c1c4ddd35c6ea17b8414bd2b2a0c96b995b90 [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"
rockotc637caf9b2016-02-10 09:57:0812#include "mojo/edk/embedder/embedder.h"
13#include "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 {
rockotc637caf9b2016-02-10 09:57:0821 MojoInitialier() { mojo::edk::Init(); }
morrita373af03b2014-09-09 19:35:2422};
23
24base::LazyInstance<MojoInitialier> g_mojo_initializer
25 = LAZY_INSTANCE_INITIALIZER;
26
27class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase {
28public:
29 typedef IPC::test::IPCChannelPerfTestBase Super;
30
31 MojoChannelPerfTest();
32
morritac4db5472015-03-13 20:44:3933 void TearDown() override {
morritac4db5472015-03-13 20:44:3934 IPC::test::IPCChannelPerfTestBase::TearDown();
35 }
36
dchengfe61fca2014-10-22 02:29:5237 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
morrita373af03b2014-09-09 19:35:2438 const IPC::ChannelHandle& handle,
morritac4db5472015-03-13 20:44:3939 base::SequencedTaskRunner* runner) override {
erikchen30dc2812015-09-24 03:26:3840 return IPC::ChannelMojo::CreateServerFactory(runner, handle);
morrita54f6f80c2014-09-23 21:16:0041 }
42
dchengfe61fca2014-10-22 02:29:5243 bool DidStartClient() override {
morrita54f6f80c2014-09-23 21:16:0044 bool ok = IPCTestBase::DidStartClient();
45 DCHECK(ok);
morrita54f6f80c2014-09-23 21:16:0046 return ok;
morrita373af03b2014-09-09 19:35:2447 }
morrita373af03b2014-09-09 19:35:2448};
49
morritac4db5472015-03-13 20:44:3950MojoChannelPerfTest::MojoChannelPerfTest() {
morrita373af03b2014-09-09 19:35:2451 g_mojo_initializer.Get();
52}
53
54
55TEST_F(MojoChannelPerfTest, ChannelPingPong) {
56 RunTestChannelPingPong(GetDefaultTestParams());
morritac4db5472015-03-13 20:44:3957
58 base::RunLoop run_loop;
59 run_loop.RunUntilIdle();
morrita373af03b2014-09-09 19:35:2460}
61
62TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
63 RunTestChannelProxyPingPong(GetDefaultTestParams());
morritac4db5472015-03-13 20:44:3964
65 base::RunLoop run_loop;
66 run_loop.RunUntilIdle();
morrita373af03b2014-09-09 19:35:2467}
68
jam76bcf0c2015-10-02 21:01:2869// Test to see how many channels we can create.
70TEST_F(MojoChannelPerfTest, DISABLED_MaxChannelCount) {
71#if defined(OS_POSIX)
72 LOG(INFO) << "base::GetMaxFds " << base::GetMaxFds();
73 base::SetFdLimit(20000);
74#endif
75
rockotc637caf9b2016-02-10 09:57:0876 std::vector<mojo::edk::PlatformChannelPair*> channels;
jam76bcf0c2015-10-02 21:01:2877 for (size_t i = 0; i < 10000; ++i) {
78 LOG(INFO) << "channels size: " << channels.size();
rockotc637caf9b2016-02-10 09:57:0879 channels.push_back(new mojo::edk::PlatformChannelPair());
jam76bcf0c2015-10-02 21:01:2880 }
81}
82
morrita373af03b2014-09-09 19:35:2483class MojoTestClient : public IPC::test::PingPongTestClient {
84 public:
85 typedef IPC::test::PingPongTestClient SuperType;
86
87 MojoTestClient();
88
dchengfe61fca2014-10-22 02:29:5289 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
morrita373af03b2014-09-09 19:35:2490};
91
92MojoTestClient::MojoTestClient() {
93 g_mojo_initializer.Get();
94}
95
96scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
97 IPC::Listener* listener) {
morrita00194e782015-04-09 19:43:2798 return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create(
leon.hand20a6c4c2015-06-19 02:25:4899 task_runner(), IPCTestBase::GetChannelName("PerformanceClient"),
erikchen30dc2812015-09-24 03:26:38100 IPC::Channel::MODE_CLIENT, listener));
morrita373af03b2014-09-09 19:35:24101}
102
103MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
104 MojoTestClient client;
morritac4db5472015-03-13 20:44:39105 int rv = client.RunMain();
106
107 base::RunLoop run_loop;
108 run_loop.RunUntilIdle();
109
110 return rv;
morrita373af03b2014-09-09 19:35:24111}
112
113} // namespace