blob: dca405ee1dbac7f41da9eb462b585d5ac5ccaf82 [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"
6#include "ipc/ipc_perftest_support.h"
7#include "ipc/mojo/ipc_channel_mojo.h"
morrita7c48ab82014-09-24 06:16:00 +09008#include "ipc/mojo/ipc_channel_mojo_host.h"
jamesr8dddfa22014-10-03 13:26:48 +09009#include "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
32 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
33 const IPC::ChannelHandle& handle,
mostynbd41cdbb2014-10-07 16:17:16 +090034 base::TaskRunner* runner) override {
morrita7c48ab82014-09-24 06:16:00 +090035 host_.reset(new IPC::ChannelMojoHost(task_runner()));
morrita98b6e4a2014-09-26 12:20:48 +090036 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
37 handle);
morrita7c48ab82014-09-24 06:16:00 +090038 }
39
mostynbd41cdbb2014-10-07 16:17:16 +090040 virtual bool DidStartClient() override {
morrita7c48ab82014-09-24 06:16:00 +090041 bool ok = IPCTestBase::DidStartClient();
42 DCHECK(ok);
43 host_->OnClientLaunched(client_process());
44 return ok;
morritaab779702014-09-10 04:35:24 +090045 }
46
47 void set_io_thread_task_runner(base::TaskRunner* runner) {
48 io_thread_task_runner_ = runner;
49 }
50
51 private:
52 base::TaskRunner* io_thread_task_runner_;
morrita7c48ab82014-09-24 06:16:00 +090053 scoped_ptr<IPC::ChannelMojoHost> host_;
morritaab779702014-09-10 04:35:24 +090054};
55
56MojoChannelPerfTest::MojoChannelPerfTest()
57 : io_thread_task_runner_() {
58 g_mojo_initializer.Get();
59}
60
61
62TEST_F(MojoChannelPerfTest, ChannelPingPong) {
63 RunTestChannelPingPong(GetDefaultTestParams());
64}
65
66TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
67 RunTestChannelProxyPingPong(GetDefaultTestParams());
68}
69
70class MojoTestClient : public IPC::test::PingPongTestClient {
71 public:
72 typedef IPC::test::PingPongTestClient SuperType;
73
74 MojoTestClient();
75
76 virtual scoped_ptr<IPC::Channel> CreateChannel(
mostynbd41cdbb2014-10-07 16:17:16 +090077 IPC::Listener* listener) override;
morritaab779702014-09-10 04:35:24 +090078};
79
80MojoTestClient::MojoTestClient() {
81 g_mojo_initializer.Get();
82}
83
84scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
85 IPC::Listener* listener) {
morrita7c48ab82014-09-24 06:16:00 +090086 return scoped_ptr<IPC::Channel>(
87 IPC::ChannelMojo::Create(NULL,
88 IPCTestBase::GetChannelName("PerformanceClient"),
89 IPC::Channel::MODE_CLIENT,
90 listener));
morritaab779702014-09-10 04:35:24 +090091}
92
93MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
94 MojoTestClient client;
95 return client.RunMain();
96}
97
98} // namespace