summaryrefslogtreecommitdiffstats
path: root/ipc/mojo/ipc_mojo_perftest.cc
blob: b1c6c86b6c7112ac0f0ee59381f4eb48f4d90920 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>

#include "base/run_loop.h"
#include "base/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "ipc/ipc_perftest_support.h"
#include "ipc/mojo/ipc_channel_mojo.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/test/multiprocess_test_helper.h"
#include "mojo/edk/test/scoped_ipc_support.h"

namespace IPC {
namespace {

class MojoChannelPerfTest : public test::IPCChannelPerfTestBase {
 public:
  void TearDown() override {
    ipc_support_.reset();
    test::IPCChannelPerfTestBase::TearDown();
  }

  scoped_ptr<ChannelFactory> CreateChannelFactory(
      const ChannelHandle& handle,
      base::SequencedTaskRunner* runner) override {
    ipc_support_.reset(new mojo::edk::test::ScopedIPCSupport(io_task_runner()));
    return ChannelMojo::CreateServerFactory(
        helper_.StartChild("MojoPerfTestClient"));
  }

  bool StartClient() override {
    return true;
  }

  bool WaitForClientShutdown() override {
    return helper_.WaitForChildTestShutdown();
  }

  mojo::edk::test::MultiprocessTestHelper helper_;
  scoped_ptr<mojo::edk::test::ScopedIPCSupport> ipc_support_;
};

TEST_F(MojoChannelPerfTest, ChannelPingPong) {
  RunTestChannelPingPong(GetDefaultTestParams());

  base::RunLoop run_loop;
  run_loop.RunUntilIdle();
}

TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
  RunTestChannelProxyPingPong(GetDefaultTestParams());

  base::RunLoop run_loop;
  run_loop.RunUntilIdle();
}

// Test to see how many channels we can create.
TEST_F(MojoChannelPerfTest, DISABLED_MaxChannelCount) {
#if defined(OS_POSIX)
  LOG(INFO) << "base::GetMaxFds " << base::GetMaxFds();
  base::SetFdLimit(20000);
#endif

  std::vector<mojo::edk::PlatformChannelPair*> channels;
  for (size_t i = 0; i < 10000; ++i) {
    LOG(INFO) << "channels size: " << channels.size();
    channels.push_back(new mojo::edk::PlatformChannelPair());
  }
}

class MojoPerfTestClient : public test::PingPongTestClient {
 public:
  typedef test::PingPongTestClient SuperType;

  MojoPerfTestClient();

  scoped_ptr<Channel> CreateChannel(Listener* listener) override;

  int Run(MojoHandle handle);

 private:
  mojo::edk::test::ScopedIPCSupport ipc_support_;
  mojo::ScopedMessagePipeHandle handle_;
};

MojoPerfTestClient::MojoPerfTestClient()
    : ipc_support_(base::ThreadTaskRunnerHandle::Get()) {
  mojo::edk::test::MultiprocessTestHelper::ChildSetup();
}

scoped_ptr<Channel> MojoPerfTestClient::CreateChannel(Listener* listener) {
  return scoped_ptr<Channel>(
      ChannelMojo::Create(std::move(handle_), Channel::MODE_CLIENT, listener));
}

int MojoPerfTestClient::Run(MojoHandle handle) {
  handle_ = mojo::MakeScopedHandle(mojo::MessagePipeHandle(handle));
  return RunMain();
}

MULTIPROCESS_TEST_MAIN(MojoPerfTestClientTestChildMain) {
  MojoPerfTestClient client;
  int rv = mojo::edk::test::MultiprocessTestHelper::RunClientMain(
      base::Bind(&MojoPerfTestClient::Run, base::Unretained(&client)));

  base::RunLoop run_loop;
  run_loop.RunUntilIdle();

  return rv;
}

}  // namespace
}  // namespace IPC