blob: 9f063ab8dee9ae46cbad819c7affc6d0bc0266bb [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
5#include "base/lazy_instance.h"
morritac4db5472015-03-13 20:44:396#include "base/run_loop.h"
morrita373af03b2014-09-09 19:35:247#include "ipc/ipc_perftest_support.h"
8#include "ipc/mojo/ipc_channel_mojo.h"
morrita54f6f80c2014-09-23 21:16:009#include "ipc/mojo/ipc_channel_mojo_host.h"
blundell471b74f2015-01-23 16:27:1410#include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h"
morrita373af03b2014-09-09 19:35:2411
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
16// some way to call InitWithSimplePlatformSupport() only once before
17// using Mojo.
18struct MojoInitialier {
19 MojoInitialier() {
20 mojo::embedder::test::InitWithSimplePlatformSupport();
21 }
22};
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 {
34 ipc_support_.reset();
35 IPC::test::IPCChannelPerfTestBase::TearDown();
36 }
37
dchengfe61fca2014-10-22 02:29:5238 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
morrita373af03b2014-09-09 19:35:2439 const IPC::ChannelHandle& handle,
morritac4db5472015-03-13 20:44:3940 base::SequencedTaskRunner* runner) override {
41 ipc_support_.reset(new IPC::ScopedIPCSupport(runner));
42 host_.reset(new IPC::ChannelMojoHost(runner));
morritae9453ea2014-09-26 03:20:4843 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
44 handle);
morrita54f6f80c2014-09-23 21:16:0045 }
46
dchengfe61fca2014-10-22 02:29:5247 bool DidStartClient() override {
morrita54f6f80c2014-09-23 21:16:0048 bool ok = IPCTestBase::DidStartClient();
49 DCHECK(ok);
rvargas07b589c2015-01-12 22:23:2350 host_->OnClientLaunched(client_process().Handle());
morrita54f6f80c2014-09-23 21:16:0051 return ok;
morrita373af03b2014-09-09 19:35:2452 }
53
morrita373af03b2014-09-09 19:35:2454 private:
morritac4db5472015-03-13 20:44:3955 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_;
morrita54f6f80c2014-09-23 21:16:0056 scoped_ptr<IPC::ChannelMojoHost> host_;
morrita373af03b2014-09-09 19:35:2457};
58
morritac4db5472015-03-13 20:44:3959MojoChannelPerfTest::MojoChannelPerfTest() {
morrita373af03b2014-09-09 19:35:2460 g_mojo_initializer.Get();
61}
62
63
64TEST_F(MojoChannelPerfTest, ChannelPingPong) {
65 RunTestChannelPingPong(GetDefaultTestParams());
morritac4db5472015-03-13 20:44:3966
67 base::RunLoop run_loop;
68 run_loop.RunUntilIdle();
morrita373af03b2014-09-09 19:35:2469}
70
71TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
72 RunTestChannelProxyPingPong(GetDefaultTestParams());
morritac4db5472015-03-13 20:44:3973
74 base::RunLoop run_loop;
75 run_loop.RunUntilIdle();
morrita373af03b2014-09-09 19:35:2476}
77
78class MojoTestClient : public IPC::test::PingPongTestClient {
79 public:
80 typedef IPC::test::PingPongTestClient SuperType;
81
82 MojoTestClient();
83
dchengfe61fca2014-10-22 02:29:5284 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
morritac4db5472015-03-13 20:44:3985
86 private:
87 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_;
morrita373af03b2014-09-09 19:35:2488};
89
90MojoTestClient::MojoTestClient() {
91 g_mojo_initializer.Get();
92}
93
94scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
95 IPC::Listener* listener) {
morritac4db5472015-03-13 20:44:3996 ipc_support_.reset(new IPC::ScopedIPCSupport(task_runner()));
morrita54f6f80c2014-09-23 21:16:0097 return scoped_ptr<IPC::Channel>(
98 IPC::ChannelMojo::Create(NULL,
99 IPCTestBase::GetChannelName("PerformanceClient"),
100 IPC::Channel::MODE_CLIENT,
101 listener));
morrita373af03b2014-09-09 19:35:24102}
103
104MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
105 MojoTestClient client;
morritac4db5472015-03-13 20:44:39106 int rv = client.RunMain();
107
108 base::RunLoop run_loop;
109 run_loop.RunUntilIdle();
110
111 return rv;
morrita373af03b2014-09-09 19:35:24112}
113
114} // namespace