blob: dc96dd19a1448f11347acc769e6f372270a16f99 [file] [log] [blame]
morritaab779702014-09-10 04:35:24 +09001// 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"
morrita9d483fc2015-03-14 05:44:39 +09006#include "base/run_loop.h"
morritaab779702014-09-10 04:35:24 +09007#include "ipc/ipc_perftest_support.h"
8#include "ipc/mojo/ipc_channel_mojo.h"
morrita7c48ab82014-09-24 06:16:00 +09009#include "ipc/mojo/ipc_channel_mojo_host.h"
blundell4bb80352015-01-24 01:27:14 +090010#include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h"
morritaab779702014-09-10 04:35:24 +090011
12namespace {
13
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
17// using Mojo.
18struct MojoInitialier {
19 MojoInitialier() {
20 mojo::embedder::test::InitWithSimplePlatformSupport();
21 }
22};
23
24base::LazyInstance<MojoInitialier> g_mojo_initializer
25 = LAZY_INSTANCE_INITIALIZER;
26
27class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase {
28public:
29 typedef IPC::test::IPCChannelPerfTestBase Super;
30
31 MojoChannelPerfTest();
32
morrita9d483fc2015-03-14 05:44:39 +090033 void TearDown() override {
morrita9d483fc2015-03-14 05:44:39 +090034 IPC::test::IPCChannelPerfTestBase::TearDown();
35 }
36
dchengef7721a2014-10-22 11:29:52 +090037 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
morritaab779702014-09-10 04:35:24 +090038 const IPC::ChannelHandle& handle,
morrita9d483fc2015-03-14 05:44:39 +090039 base::SequencedTaskRunner* runner) override {
morrita9d483fc2015-03-14 05:44:39 +090040 host_.reset(new IPC::ChannelMojoHost(runner));
morrita98b6e4a2014-09-26 12:20:48 +090041 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
morritad7325c22015-04-10 04:43:27 +090042 runner, handle);
morrita7c48ab82014-09-24 06:16:00 +090043 }
44
dchengef7721a2014-10-22 11:29:52 +090045 bool DidStartClient() override {
morrita7c48ab82014-09-24 06:16:00 +090046 bool ok = IPCTestBase::DidStartClient();
47 DCHECK(ok);
rvargasf355d882015-01-13 07:23:23 +090048 host_->OnClientLaunched(client_process().Handle());
morrita7c48ab82014-09-24 06:16:00 +090049 return ok;
morritaab779702014-09-10 04:35:24 +090050 }
51
morritaab779702014-09-10 04:35:24 +090052 private:
morrita7c48ab82014-09-24 06:16:00 +090053 scoped_ptr<IPC::ChannelMojoHost> host_;
morritaab779702014-09-10 04:35:24 +090054};
55
morrita9d483fc2015-03-14 05:44:39 +090056MojoChannelPerfTest::MojoChannelPerfTest() {
morritaab779702014-09-10 04:35:24 +090057 g_mojo_initializer.Get();
58}
59
60
61TEST_F(MojoChannelPerfTest, ChannelPingPong) {
62 RunTestChannelPingPong(GetDefaultTestParams());
morrita9d483fc2015-03-14 05:44:39 +090063
64 base::RunLoop run_loop;
65 run_loop.RunUntilIdle();
morritaab779702014-09-10 04:35:24 +090066}
67
68TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
69 RunTestChannelProxyPingPong(GetDefaultTestParams());
morrita9d483fc2015-03-14 05:44:39 +090070
71 base::RunLoop run_loop;
72 run_loop.RunUntilIdle();
morritaab779702014-09-10 04:35:24 +090073}
74
75class MojoTestClient : public IPC::test::PingPongTestClient {
76 public:
77 typedef IPC::test::PingPongTestClient SuperType;
78
79 MojoTestClient();
80
dchengef7721a2014-10-22 11:29:52 +090081 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
morritaab779702014-09-10 04:35:24 +090082};
83
84MojoTestClient::MojoTestClient() {
85 g_mojo_initializer.Get();
86}
87
88scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
89 IPC::Listener* listener) {
morritad7325c22015-04-10 04:43:27 +090090 return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create(
91 NULL, task_runner(), IPCTestBase::GetChannelName("PerformanceClient"),
92 IPC::Channel::MODE_CLIENT, listener));
morritaab779702014-09-10 04:35:24 +090093}
94
95MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
96 MojoTestClient client;
morrita9d483fc2015-03-14 05:44:39 +090097 int rv = client.RunMain();
98
99 base::RunLoop run_loop;
100 run_loop.RunUntilIdle();
101
102 return rv;
morritaab779702014-09-10 04:35:24 +0900103}
104
105} // namespace