blob: e3b91fd1ae45084dd08906c4208ebbd4f9d85981 [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"
blundell4bb80352015-01-24 01:27:14 +09009#include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h"
morritaab779702014-09-10 04:35:24 +090010
11namespace {
12
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
16// using Mojo.
17struct MojoInitialier {
18 MojoInitialier() {
19 mojo::embedder::test::InitWithSimplePlatformSupport();
20 }
21};
22
23base::LazyInstance<MojoInitialier> g_mojo_initializer
24 = LAZY_INSTANCE_INITIALIZER;
25
26class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase {
27public:
28 typedef IPC::test::IPCChannelPerfTestBase Super;
29
30 MojoChannelPerfTest();
31
morrita9d483fc2015-03-14 05:44:39 +090032 void TearDown() override {
morrita9d483fc2015-03-14 05:44:39 +090033 IPC::test::IPCChannelPerfTestBase::TearDown();
34 }
35
dchengef7721a2014-10-22 11:29:52 +090036 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
morritaab779702014-09-10 04:35:24 +090037 const IPC::ChannelHandle& handle,
morrita9d483fc2015-03-14 05:44:39 +090038 base::SequencedTaskRunner* runner) override {
erikchenc596f542015-09-24 12:26:38 +090039 return IPC::ChannelMojo::CreateServerFactory(runner, handle);
morrita7c48ab82014-09-24 06:16:00 +090040 }
41
dchengef7721a2014-10-22 11:29:52 +090042 bool DidStartClient() override {
morrita7c48ab82014-09-24 06:16:00 +090043 bool ok = IPCTestBase::DidStartClient();
44 DCHECK(ok);
morrita7c48ab82014-09-24 06:16:00 +090045 return ok;
morritaab779702014-09-10 04:35:24 +090046 }
morritaab779702014-09-10 04:35:24 +090047};
48
morrita9d483fc2015-03-14 05:44:39 +090049MojoChannelPerfTest::MojoChannelPerfTest() {
morritaab779702014-09-10 04:35:24 +090050 g_mojo_initializer.Get();
51}
52
53
54TEST_F(MojoChannelPerfTest, ChannelPingPong) {
55 RunTestChannelPingPong(GetDefaultTestParams());
morrita9d483fc2015-03-14 05:44:39 +090056
57 base::RunLoop run_loop;
58 run_loop.RunUntilIdle();
morritaab779702014-09-10 04:35:24 +090059}
60
61TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
62 RunTestChannelProxyPingPong(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
68class MojoTestClient : public IPC::test::PingPongTestClient {
69 public:
70 typedef IPC::test::PingPongTestClient SuperType;
71
72 MojoTestClient();
73
dchengef7721a2014-10-22 11:29:52 +090074 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
morritaab779702014-09-10 04:35:24 +090075};
76
77MojoTestClient::MojoTestClient() {
78 g_mojo_initializer.Get();
79}
80
81scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
82 IPC::Listener* listener) {
morritad7325c22015-04-10 04:43:27 +090083 return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create(
leon.han5dd52cd2015-06-19 11:25:48 +090084 task_runner(), IPCTestBase::GetChannelName("PerformanceClient"),
erikchenc596f542015-09-24 12:26:38 +090085 IPC::Channel::MODE_CLIENT, listener));
morritaab779702014-09-10 04:35:24 +090086}
87
88MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
89 MojoTestClient client;
morrita9d483fc2015-03-14 05:44:39 +090090 int rv = client.RunMain();
91
92 base::RunLoop run_loop;
93 run_loop.RunUntilIdle();
94
95 return rv;
morritaab779702014-09-10 04:35:24 +090096}
97
98} // namespace