forked from crosswalk-project/chromium-crosswalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipc_mojo_perftest.cc
119 lines (93 loc) · 3.28 KB
/
ipc_mojo_perftest.cc
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
118
119
// 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 <memory>
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "ipc/ipc_channel_mojo.h"
#include "ipc/ipc_perftest_support.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();
}
std::unique_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_;
std::unique_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();
std::unique_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();
}
std::unique_ptr<Channel> MojoPerfTestClient::CreateChannel(Listener* listener) {
return 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