Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1511)

Side by Side Diff: ipc/ipc_test_base.h

Issue 488003003: Add ChannelProxy benchmark to ipc_perftests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolved conflicts Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IPC_IPC_TEST_BASE_H_ 5 #ifndef IPC_IPC_TEST_BASE_H_
6 #define IPC_IPC_TEST_BASE_H_ 6 #define IPC_IPC_TEST_BASE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/process/process.h" 12 #include "base/process/process.h"
13 #include "base/test/multiprocess_test.h" 13 #include "base/test/multiprocess_test.h"
14 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_channel_proxy.h" 15 #include "ipc/ipc_channel_proxy.h"
16 #include "ipc/ipc_multiprocess_test.h" 16 #include "ipc/ipc_multiprocess_test.h"
17 17
18 namespace base { 18 namespace base {
19 class MessageLoopForIO; 19 class MessageLoop;
20 } 20 }
21 21
22 // A test fixture for multiprocess IPC tests. Such tests include a "client" side 22 // A test fixture for multiprocess IPC tests. Such tests include a "client" side
23 // (running in a separate process). The same client may be shared between 23 // (running in a separate process). The same client may be shared between
24 // several different tests. 24 // several different tests.
25 class IPCTestBase : public base::MultiProcessTest { 25 class IPCTestBase : public base::MultiProcessTest {
26 public: 26 public:
27 // The channel name is based on the client's name. This is a public static 27 // The channel name is based on the client's name. This is a public static
28 // helper to be used by the client-side code; server-side test code should 28 // helper to be used by the client-side code; server-side test code should
29 // usually not use this (directly). 29 // usually not use this (directly).
30 static std::string GetChannelName(const std::string& test_client_name); 30 static std::string GetChannelName(const std::string& test_client_name);
31 31
32 protected: 32 protected:
33 IPCTestBase(); 33 IPCTestBase();
34 virtual ~IPCTestBase(); 34 virtual ~IPCTestBase();
35 35
36 virtual void SetUp() OVERRIDE; 36 virtual void SetUp() OVERRIDE;
37 virtual void TearDown() OVERRIDE; 37 virtual void TearDown() OVERRIDE;
38 virtual scoped_ptr<base::MessageLoop> CreateMessageLoop();
38 39
39 // Initializes the test to use the given client. 40 // Initializes the test to use the given client.
40 void Init(const std::string& test_client_name); 41 void Init(const std::string& test_client_name);
41 42
42 // Creates a channel with the given listener and connects to the channel 43 // Creates a channel with the given listener and connects to the channel
43 // (returning true if successful), respectively. Use these to use a channel 44 // (returning true if successful), respectively. Use these to use a channel
44 // directly. Since the listener must outlive the channel, you must destroy the 45 // directly. Since the listener must outlive the channel, you must destroy the
45 // channel before the listener gets destroyed. 46 // channel before the listener gets destroyed.
46 void CreateChannel(IPC::Listener* listener); 47 void CreateChannel(IPC::Listener* listener);
47 bool ConnectChannel(); 48 bool ConnectChannel();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // channel or a proxy). 80 // channel or a proxy).
80 IPC::Sender* sender() { 81 IPC::Sender* sender() {
81 return channel_.get() ? static_cast<IPC::Sender*>(channel_.get()) : 82 return channel_.get() ? static_cast<IPC::Sender*>(channel_.get()) :
82 static_cast<IPC::Sender*>(channel_proxy_.get()); 83 static_cast<IPC::Sender*>(channel_proxy_.get());
83 } 84 }
84 85
85 IPC::Channel* channel() { return channel_.get(); } 86 IPC::Channel* channel() { return channel_.get(); }
86 IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); } 87 IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); }
87 88
88 const base::ProcessHandle& client_process() const { return client_process_; } 89 const base::ProcessHandle& client_process() const { return client_process_; }
89 scoped_refptr<base::TaskRunner> io_thread_task_runner(); 90 scoped_refptr<base::TaskRunner> task_runner();
90 91
91 private: 92 private:
92 std::string test_client_name_; 93 std::string test_client_name_;
93 scoped_ptr<base::MessageLoopForIO> message_loop_; 94 scoped_ptr<base::MessageLoop> message_loop_;
94 95
95 scoped_ptr<IPC::Channel> channel_; 96 scoped_ptr<IPC::Channel> channel_;
96 scoped_ptr<IPC::ChannelProxy> channel_proxy_; 97 scoped_ptr<IPC::ChannelProxy> channel_proxy_;
97 98
98 base::ProcessHandle client_process_; 99 base::ProcessHandle client_process_;
99 100
100 DISALLOW_COPY_AND_ASSIGN(IPCTestBase); 101 DISALLOW_COPY_AND_ASSIGN(IPCTestBase);
101 }; 102 };
102 103
103 // Use this to declare the client side for tests using IPCTestBase. 104 // Use this to declare the client side for tests using IPCTestBase.
104 #define MULTIPROCESS_IPC_TEST_CLIENT_MAIN(test_client_name) \ 105 #define MULTIPROCESS_IPC_TEST_CLIENT_MAIN(test_client_name) \
105 MULTIPROCESS_IPC_TEST_MAIN(test_client_name ## TestClientMain) 106 MULTIPROCESS_IPC_TEST_MAIN(test_client_name ## TestClientMain)
106 107
107 #endif // IPC_IPC_TEST_BASE_H_ 108 #endif // IPC_IPC_TEST_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698