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 "ipc/mojo/ipc_channel_mojo_host.h"
9 #include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h"
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
17 struct MojoInitialier
{
19 mojo::embedder::test::InitWithSimplePlatformSupport();
23 base::LazyInstance
<MojoInitialier
> g_mojo_initializer
24 = LAZY_INSTANCE_INITIALIZER
;
26 class MojoChannelPerfTest
: public IPC::test::IPCChannelPerfTestBase
{
28 typedef IPC::test::IPCChannelPerfTestBase Super
;
30 MojoChannelPerfTest();
32 scoped_ptr
<IPC::ChannelFactory
> CreateChannelFactory(
33 const IPC::ChannelHandle
& handle
,
34 base::TaskRunner
* runner
) override
{
35 host_
.reset(new IPC::ChannelMojoHost(task_runner()));
36 return IPC::ChannelMojo::CreateServerFactory(host_
->channel_delegate(),
40 bool DidStartClient() override
{
41 bool ok
= IPCTestBase::DidStartClient();
43 host_
->OnClientLaunched(client_process().Handle());
47 void set_io_thread_task_runner(base::TaskRunner
* runner
) {
48 io_thread_task_runner_
= runner
;
52 base::TaskRunner
* io_thread_task_runner_
;
53 scoped_ptr
<IPC::ChannelMojoHost
> host_
;
56 MojoChannelPerfTest::MojoChannelPerfTest()
57 : io_thread_task_runner_() {
58 g_mojo_initializer
.Get();
62 TEST_F(MojoChannelPerfTest
, ChannelPingPong
) {
63 RunTestChannelPingPong(GetDefaultTestParams());
66 TEST_F(MojoChannelPerfTest
, ChannelProxyPingPong
) {
67 RunTestChannelProxyPingPong(GetDefaultTestParams());
70 class MojoTestClient
: public IPC::test::PingPongTestClient
{
72 typedef IPC::test::PingPongTestClient SuperType
;
76 scoped_ptr
<IPC::Channel
> CreateChannel(IPC::Listener
* listener
) override
;
79 MojoTestClient::MojoTestClient() {
80 g_mojo_initializer
.Get();
83 scoped_ptr
<IPC::Channel
> MojoTestClient::CreateChannel(
84 IPC::Listener
* listener
) {
85 return scoped_ptr
<IPC::Channel
>(
86 IPC::ChannelMojo::Create(NULL
,
87 IPCTestBase::GetChannelName("PerformanceClient"),
88 IPC::Channel::MODE_CLIENT
,
92 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient
) {
93 MojoTestClient client
;
94 return client
.RunMain();