blob: 8bdac8c9a7ed6e2a1b175df7f9b0f14b811d4557 [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"
6#include "ipc/ipc_perftest_support.h"
7#include "ipc/mojo/ipc_channel_mojo.h"
morrita54f6f80c2014-09-23 21:16:008#include "ipc/mojo/ipc_channel_mojo_host.h"
jamesra03ae492014-10-03 04:26:489#include "mojo/edk/embedder/test_embedder.h"
morrita373af03b2014-09-09 19:35:2410
11namespace {
12
13// This is needed because we rely on //base/test:test_support_perf and
14// it provides main() which doesn't have Mojo initialization. We need
15// some way to call InitWithSimplePlatformSupport() only once before
16// using Mojo.
17struct MojoInitialier {
18 MojoInitialier() {
19 mojo::embedder::test::InitWithSimplePlatformSupport();
20 }
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
dchengfe61fca2014-10-22 02:29:5232 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
morrita373af03b2014-09-09 19:35:2433 const IPC::ChannelHandle& handle,
mostynb50a41f32014-10-07 07:17:1634 base::TaskRunner* runner) override {
morrita54f6f80c2014-09-23 21:16:0035 host_.reset(new IPC::ChannelMojoHost(task_runner()));
morritae9453ea2014-09-26 03:20:4836 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
37 handle);
morrita54f6f80c2014-09-23 21:16:0038 }
39
dchengfe61fca2014-10-22 02:29:5240 bool DidStartClient() override {
morrita54f6f80c2014-09-23 21:16:0041 bool ok = IPCTestBase::DidStartClient();
42 DCHECK(ok);
rvargas07b589c2015-01-12 22:23:2343 host_->OnClientLaunched(client_process().Handle());
morrita54f6f80c2014-09-23 21:16:0044 return ok;
morrita373af03b2014-09-09 19:35:2445 }
46
47 void set_io_thread_task_runner(base::TaskRunner* runner) {
48 io_thread_task_runner_ = runner;
49 }
50
51 private:
52 base::TaskRunner* io_thread_task_runner_;
morrita54f6f80c2014-09-23 21:16:0053 scoped_ptr<IPC::ChannelMojoHost> host_;
morrita373af03b2014-09-09 19:35:2454};
55
56MojoChannelPerfTest::MojoChannelPerfTest()
57 : io_thread_task_runner_() {
58 g_mojo_initializer.Get();
59}
60
61
62TEST_F(MojoChannelPerfTest, ChannelPingPong) {
63 RunTestChannelPingPong(GetDefaultTestParams());
64}
65
66TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
67 RunTestChannelProxyPingPong(GetDefaultTestParams());
68}
69
70class MojoTestClient : public IPC::test::PingPongTestClient {
71 public:
72 typedef IPC::test::PingPongTestClient SuperType;
73
74 MojoTestClient();
75
dchengfe61fca2014-10-22 02:29:5276 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
morrita373af03b2014-09-09 19:35:2477};
78
79MojoTestClient::MojoTestClient() {
80 g_mojo_initializer.Get();
81}
82
83scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
84 IPC::Listener* listener) {
morrita54f6f80c2014-09-23 21:16:0085 return scoped_ptr<IPC::Channel>(
86 IPC::ChannelMojo::Create(NULL,
87 IPCTestBase::GetChannelName("PerformanceClient"),
88 IPC::Channel::MODE_CLIENT,
89 listener));
morrita373af03b2014-09-09 19:35:2490}
91
92MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
93 MojoTestClient client;
94 return client.RunMain();
95}
96
97} // namespace