blob: d4337037a9dcacda733d77637d7141275cfb0f07 [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"
8#include "mojo/embedder/test_embedder.h"
9
10namespace {
11
12// This is needed because we rely on //base/test:test_support_perf and
13// it provides main() which doesn't have Mojo initialization. We need
14// some way to call InitWithSimplePlatformSupport() only once before
15// using Mojo.
16struct MojoInitialier {
17 MojoInitialier() {
18 mojo::embedder::test::InitWithSimplePlatformSupport();
19 }
20};
21
22base::LazyInstance<MojoInitialier> g_mojo_initializer
23 = LAZY_INSTANCE_INITIALIZER;
24
25class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase {
26public:
27 typedef IPC::test::IPCChannelPerfTestBase Super;
28
29 MojoChannelPerfTest();
30
31 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
32 const IPC::ChannelHandle& handle,
33 base::TaskRunner* runner) OVERRIDE {
34 return IPC::ChannelMojo::CreateFactory(
35 handle, IPC::Channel::MODE_SERVER, runner);
36 }
37
38 void set_io_thread_task_runner(base::TaskRunner* runner) {
39 io_thread_task_runner_ = runner;
40 }
41
42 private:
43 base::TaskRunner* io_thread_task_runner_;
44};
45
46MojoChannelPerfTest::MojoChannelPerfTest()
47 : io_thread_task_runner_() {
48 g_mojo_initializer.Get();
49}
50
51
52TEST_F(MojoChannelPerfTest, ChannelPingPong) {
53 RunTestChannelPingPong(GetDefaultTestParams());
54}
55
56TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
57 RunTestChannelProxyPingPong(GetDefaultTestParams());
58}
59
60class MojoTestClient : public IPC::test::PingPongTestClient {
61 public:
62 typedef IPC::test::PingPongTestClient SuperType;
63
64 MojoTestClient();
65
66 virtual scoped_ptr<IPC::Channel> CreateChannel(
67 IPC::Listener* listener) OVERRIDE;
68};
69
70MojoTestClient::MojoTestClient() {
71 g_mojo_initializer.Get();
72}
73
74scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
75 IPC::Listener* listener) {
76 return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create(
77 IPCTestBase::GetChannelName("PerformanceClient"),
78 IPC::Channel::MODE_CLIENT, listener,
79 task_runner()));
80}
81
82MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
83 MojoTestClient client;
84 return client.RunMain();
85}
86
87} // namespace