1 // 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.
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"
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
16 struct MojoInitialier
{
18 mojo::embedder::test::InitWithSimplePlatformSupport();
22 base::LazyInstance
<MojoInitialier
> g_mojo_initializer
23 = LAZY_INSTANCE_INITIALIZER
;
25 class MojoChannelPerfTest
: public IPC::test::IPCChannelPerfTestBase
{
27 typedef IPC::test::IPCChannelPerfTestBase Super
;
29 MojoChannelPerfTest();
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
);
38 void set_io_thread_task_runner(base::TaskRunner
* runner
) {
39 io_thread_task_runner_
= runner
;
43 base::TaskRunner
* io_thread_task_runner_
;
46 MojoChannelPerfTest::MojoChannelPerfTest()
47 : io_thread_task_runner_() {
48 g_mojo_initializer
.Get();
52 TEST_F(MojoChannelPerfTest
, ChannelPingPong
) {
53 RunTestChannelPingPong(GetDefaultTestParams());
56 TEST_F(MojoChannelPerfTest
, ChannelProxyPingPong
) {
57 RunTestChannelProxyPingPong(GetDefaultTestParams());
60 class MojoTestClient
: public IPC::test::PingPongTestClient
{
62 typedef IPC::test::PingPongTestClient SuperType
;
66 virtual scoped_ptr
<IPC::Channel
> CreateChannel(
67 IPC::Listener
* listener
) OVERRIDE
;
70 MojoTestClient::MojoTestClient() {
71 g_mojo_initializer
.Get();
74 scoped_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
,
82 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient
) {
83 MojoTestClient client
;
84 return client
.RunMain();