blob: 9f063ab8dee9ae46cbad819c7affc6d0bc0266bb [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"
morrita7c48ab82014-09-24 06:16:00 +09009#include "ipc/mojo/ipc_channel_mojo_host.h"
blundell4bb80352015-01-24 01:27:14 +090010#include "third_party/mojo/src/mojo/edk/embedder/test_embedder.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
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
morrita9d483fc2015-03-14 05:44:39 +090033 void TearDown() override {
34 ipc_support_.reset();
35 IPC::test::IPCChannelPerfTestBase::TearDown();
36 }
37
dchengef7721a2014-10-22 11:29:52 +090038 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
morritaab779702014-09-10 04:35:24 +090039 const IPC::ChannelHandle& handle,
morrita9d483fc2015-03-14 05:44:39 +090040 base::SequencedTaskRunner* runner) override {
41 ipc_support_.reset(new IPC::ScopedIPCSupport(runner));
42 host_.reset(new IPC::ChannelMojoHost(runner));
morrita98b6e4a2014-09-26 12:20:48 +090043 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
44 handle);
morrita7c48ab82014-09-24 06:16:00 +090045 }
46
dchengef7721a2014-10-22 11:29:52 +090047 bool DidStartClient() override {
morrita7c48ab82014-09-24 06:16:00 +090048 bool ok = IPCTestBase::DidStartClient();
49 DCHECK(ok);
rvargasf355d882015-01-13 07:23:23 +090050 host_->OnClientLaunched(client_process().Handle());
morrita7c48ab82014-09-24 06:16:00 +090051 return ok;
morritaab779702014-09-10 04:35:24 +090052 }
53
morritaab779702014-09-10 04:35:24 +090054 private:
morrita9d483fc2015-03-14 05:44:39 +090055 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_;
morrita7c48ab82014-09-24 06:16:00 +090056 scoped_ptr<IPC::ChannelMojoHost> host_;
morritaab779702014-09-10 04:35:24 +090057};
58
morrita9d483fc2015-03-14 05:44:39 +090059MojoChannelPerfTest::MojoChannelPerfTest() {
morritaab779702014-09-10 04:35:24 +090060 g_mojo_initializer.Get();
61}
62
63
64TEST_F(MojoChannelPerfTest, ChannelPingPong) {
65 RunTestChannelPingPong(GetDefaultTestParams());
morrita9d483fc2015-03-14 05:44:39 +090066
67 base::RunLoop run_loop;
68 run_loop.RunUntilIdle();
morritaab779702014-09-10 04:35:24 +090069}
70
71TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
72 RunTestChannelProxyPingPong(GetDefaultTestParams());
morrita9d483fc2015-03-14 05:44:39 +090073
74 base::RunLoop run_loop;
75 run_loop.RunUntilIdle();
morritaab779702014-09-10 04:35:24 +090076}
77
78class MojoTestClient : public IPC::test::PingPongTestClient {
79 public:
80 typedef IPC::test::PingPongTestClient SuperType;
81
82 MojoTestClient();
83
dchengef7721a2014-10-22 11:29:52 +090084 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
morrita9d483fc2015-03-14 05:44:39 +090085
86 private:
87 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_;
morritaab779702014-09-10 04:35:24 +090088};
89
90MojoTestClient::MojoTestClient() {
91 g_mojo_initializer.Get();
92}
93
94scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
95 IPC::Listener* listener) {
morrita9d483fc2015-03-14 05:44:39 +090096 ipc_support_.reset(new IPC::ScopedIPCSupport(task_runner()));
morrita7c48ab82014-09-24 06:16:00 +090097 return scoped_ptr<IPC::Channel>(
98 IPC::ChannelMojo::Create(NULL,
99 IPCTestBase::GetChannelName("PerformanceClient"),
100 IPC::Channel::MODE_CLIENT,
101 listener));
morritaab779702014-09-10 04:35:24 +0900102}
103
104MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
105 MojoTestClient client;
morrita9d483fc2015-03-14 05:44:39 +0900106 int rv = client.RunMain();
107
108 base::RunLoop run_loop;
109 run_loop.RunUntilIdle();
110
111 return rv;
morritaab779702014-09-10 04:35:24 +0900112}
113
114} // namespace