morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "base/lazy_instance.h" |
morrita | 9d483fc | 2015-03-14 05:44:39 +0900 | [diff] [blame] | 6 | #include "base/run_loop.h" |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 7 | #include "ipc/ipc_perftest_support.h" |
| 8 | #include "ipc/mojo/ipc_channel_mojo.h" |
blundell | 4bb8035 | 2015-01-24 01:27:14 +0900 | [diff] [blame] | 9 | #include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h" |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 10 | |
| 11 | namespace { |
| 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. |
| 17 | struct MojoInitialier { |
| 18 | MojoInitialier() { |
| 19 | mojo::embedder::test::InitWithSimplePlatformSupport(); |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | base::LazyInstance<MojoInitialier> g_mojo_initializer |
| 24 | = LAZY_INSTANCE_INITIALIZER; |
| 25 | |
| 26 | class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase { |
| 27 | public: |
| 28 | typedef IPC::test::IPCChannelPerfTestBase Super; |
| 29 | |
| 30 | MojoChannelPerfTest(); |
| 31 | |
morrita | 9d483fc | 2015-03-14 05:44:39 +0900 | [diff] [blame] | 32 | void TearDown() override { |
morrita | 9d483fc | 2015-03-14 05:44:39 +0900 | [diff] [blame] | 33 | IPC::test::IPCChannelPerfTestBase::TearDown(); |
| 34 | } |
| 35 | |
dcheng | ef7721a | 2014-10-22 11:29:52 +0900 | [diff] [blame] | 36 | scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 37 | const IPC::ChannelHandle& handle, |
morrita | 9d483fc | 2015-03-14 05:44:39 +0900 | [diff] [blame] | 38 | base::SequencedTaskRunner* runner) override { |
erikchen | c596f54 | 2015-09-24 12:26:38 +0900 | [diff] [blame^] | 39 | return IPC::ChannelMojo::CreateServerFactory(runner, handle); |
morrita | 7c48ab8 | 2014-09-24 06:16:00 +0900 | [diff] [blame] | 40 | } |
| 41 | |
dcheng | ef7721a | 2014-10-22 11:29:52 +0900 | [diff] [blame] | 42 | bool DidStartClient() override { |
morrita | 7c48ab8 | 2014-09-24 06:16:00 +0900 | [diff] [blame] | 43 | bool ok = IPCTestBase::DidStartClient(); |
| 44 | DCHECK(ok); |
morrita | 7c48ab8 | 2014-09-24 06:16:00 +0900 | [diff] [blame] | 45 | return ok; |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 46 | } |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 47 | }; |
| 48 | |
morrita | 9d483fc | 2015-03-14 05:44:39 +0900 | [diff] [blame] | 49 | MojoChannelPerfTest::MojoChannelPerfTest() { |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 50 | g_mojo_initializer.Get(); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | TEST_F(MojoChannelPerfTest, ChannelPingPong) { |
| 55 | RunTestChannelPingPong(GetDefaultTestParams()); |
morrita | 9d483fc | 2015-03-14 05:44:39 +0900 | [diff] [blame] | 56 | |
| 57 | base::RunLoop run_loop; |
| 58 | run_loop.RunUntilIdle(); |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) { |
| 62 | RunTestChannelProxyPingPong(GetDefaultTestParams()); |
morrita | 9d483fc | 2015-03-14 05:44:39 +0900 | [diff] [blame] | 63 | |
| 64 | base::RunLoop run_loop; |
| 65 | run_loop.RunUntilIdle(); |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | class MojoTestClient : public IPC::test::PingPongTestClient { |
| 69 | public: |
| 70 | typedef IPC::test::PingPongTestClient SuperType; |
| 71 | |
| 72 | MojoTestClient(); |
| 73 | |
dcheng | ef7721a | 2014-10-22 11:29:52 +0900 | [diff] [blame] | 74 | scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override; |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | MojoTestClient::MojoTestClient() { |
| 78 | g_mojo_initializer.Get(); |
| 79 | } |
| 80 | |
| 81 | scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel( |
| 82 | IPC::Listener* listener) { |
morrita | d7325c2 | 2015-04-10 04:43:27 +0900 | [diff] [blame] | 83 | return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create( |
leon.han | 5dd52cd | 2015-06-19 11:25:48 +0900 | [diff] [blame] | 84 | task_runner(), IPCTestBase::GetChannelName("PerformanceClient"), |
erikchen | c596f54 | 2015-09-24 12:26:38 +0900 | [diff] [blame^] | 85 | IPC::Channel::MODE_CLIENT, listener)); |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) { |
| 89 | MojoTestClient client; |
morrita | 9d483fc | 2015-03-14 05:44:39 +0900 | [diff] [blame] | 90 | int rv = client.RunMain(); |
| 91 | |
| 92 | base::RunLoop run_loop; |
| 93 | run_loop.RunUntilIdle(); |
| 94 | |
| 95 | return rv; |
morrita | ab77970 | 2014-09-10 04:35:24 +0900 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | } // namespace |