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 "base/run_loop.h"
7 #include "ipc/ipc_perftest_support.h"
8 #include "ipc/mojo/ipc_channel_mojo.h"
9 #include "ipc/mojo/ipc_channel_mojo_host.h"
10 #include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h"
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
18 struct MojoInitialier
{
20 mojo::embedder::test::InitWithSimplePlatformSupport();
24 base::LazyInstance
<MojoInitialier
> g_mojo_initializer
25 = LAZY_INSTANCE_INITIALIZER
;
27 class MojoChannelPerfTest
: public IPC::test::IPCChannelPerfTestBase
{
29 typedef IPC::test::IPCChannelPerfTestBase Super
;
31 MojoChannelPerfTest();
33 void TearDown() override
{
35 IPC::test::IPCChannelPerfTestBase::TearDown();
38 scoped_ptr
<IPC::ChannelFactory
> CreateChannelFactory(
39 const IPC::ChannelHandle
& handle
,
40 base::SequencedTaskRunner
* runner
) override
{
41 ipc_support_
.reset(new IPC::ScopedIPCSupport(runner
));
42 host_
.reset(new IPC::ChannelMojoHost(runner
));
43 return IPC::ChannelMojo::CreateServerFactory(host_
->channel_delegate(),
47 bool DidStartClient() override
{
48 bool ok
= IPCTestBase::DidStartClient();
50 host_
->OnClientLaunched(client_process().Handle());
55 scoped_ptr
<IPC::ScopedIPCSupport
> ipc_support_
;
56 scoped_ptr
<IPC::ChannelMojoHost
> host_
;
59 MojoChannelPerfTest::MojoChannelPerfTest() {
60 g_mojo_initializer
.Get();
64 TEST_F(MojoChannelPerfTest
, ChannelPingPong
) {
65 RunTestChannelPingPong(GetDefaultTestParams());
67 base::RunLoop run_loop
;
68 run_loop
.RunUntilIdle();
71 TEST_F(MojoChannelPerfTest
, ChannelProxyPingPong
) {
72 RunTestChannelProxyPingPong(GetDefaultTestParams());
74 base::RunLoop run_loop
;
75 run_loop
.RunUntilIdle();
78 class MojoTestClient
: public IPC::test::PingPongTestClient
{
80 typedef IPC::test::PingPongTestClient SuperType
;
84 scoped_ptr
<IPC::Channel
> CreateChannel(IPC::Listener
* listener
) override
;
87 scoped_ptr
<IPC::ScopedIPCSupport
> ipc_support_
;
90 MojoTestClient::MojoTestClient() {
91 g_mojo_initializer
.Get();
94 scoped_ptr
<IPC::Channel
> MojoTestClient::CreateChannel(
95 IPC::Listener
* listener
) {
96 ipc_support_
.reset(new IPC::ScopedIPCSupport(task_runner()));
97 return scoped_ptr
<IPC::Channel
>(
98 IPC::ChannelMojo::Create(NULL
,
99 IPCTestBase::GetChannelName("PerformanceClient"),
100 IPC::Channel::MODE_CLIENT
,
104 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient
) {
105 MojoTestClient client
;
106 int rv
= client
.RunMain();
108 base::RunLoop run_loop
;
109 run_loop
.RunUntilIdle();