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

Side by Side Diff: handler/win/registration_pipe_state_test.cc

Issue 1126783004: Introduce RegistrationServer. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: One extra comment. Created 5 years, 7 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
« no previous file with comments | « handler/win/registration_pipe_state.cc ('k') | handler/win/registration_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "handler/win/registration_pipe_state.h"
16
17 #include <windows.h>
18
19 #include "base/basictypes.h"
20 #include "base/logging.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "client/crashpad_info.h"
23 #include "client/registration_protocol_win.h"
24 #include "gtest/gtest.h"
25 #include "handler/win/registration_test_base.h"
26 #include "util/win/scoped_handle.h"
27
28 namespace crashpad {
29 namespace test {
30 namespace {
31
32 class RegistrationRegistrationPipeStateTest : public RegistrationTestBase {
33 public:
34 RegistrationRegistrationPipeStateTest() : pipe_state_() {}
35
36 void SetUp() override {
37 ScopedFileHANDLE pipe(
38 CreateNamedPipe(pipe_name().c_str(),
39 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED |
40 FILE_FLAG_FIRST_PIPE_INSTANCE,
41 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
42 1,
43 512, // nOutBufferSize
44 512, // nInBufferSize
45 20, // nDefaultTimeOut
46 nullptr)); // lpSecurityAttributes
47 ASSERT_TRUE(pipe.is_valid());
48 pipe_state_.reset(new RegistrationPipeState(pipe.Pass(), &delegate()));
49 }
50
51 ~RegistrationRegistrationPipeStateTest() override {}
52
53 RegistrationPipeState& pipe_state() {
54 DCHECK(pipe_state_.get());
55 return *pipe_state_;
56 }
57
58 private:
59 scoped_ptr<RegistrationPipeState> pipe_state_;
60 DISALLOW_COPY_AND_ASSIGN(RegistrationRegistrationPipeStateTest);
61 };
62
63 TEST_F(RegistrationRegistrationPipeStateTest, CancelIoWhenConnectIsComplete) {
64 // -> Connecting
65 ASSERT_TRUE(pipe_state().Initialize());
66
67 ScopedFileHANDLE client(Connect());
68
69 ASSERT_TRUE(client.is_valid());
70
71 // Connect completion.
72 ASSERT_EQ(WAIT_OBJECT_0,
73 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
74
75 // Connecting -> Stopping
76 pipe_state().Stop();
77
78 // Stop completion.
79 ASSERT_EQ(WAIT_OBJECT_0,
80 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
81 }
82
83 TEST_F(RegistrationRegistrationPipeStateTest, CancelIoWhenReadIsComplete) {
84 // -> Connecting
85 ASSERT_TRUE(pipe_state().Initialize());
86
87 ScopedFileHANDLE client(Connect());
88
89 ASSERT_TRUE(client.is_valid());
90
91 // Connect completion.
92 ASSERT_EQ(WAIT_OBJECT_0,
93 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
94
95 // Connecting -> Reading
96 ASSERT_TRUE(pipe_state().OnCompletion());
97
98 RegistrationRequest request = {0};
99 CrashpadInfo crashpad_info;
100 request.client_process_id = GetCurrentProcessId();
101 request.crashpad_info_address =
102 reinterpret_cast<WinVMAddress>(&crashpad_info);
103
104 ASSERT_TRUE(WriteRequest(client.get(), &request, sizeof(request)));
105
106 // Read completion.
107 ASSERT_EQ(WAIT_OBJECT_0,
108 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
109
110 // Reading -> Stopping
111 pipe_state().Stop();
112
113 // Stop completion.
114 ASSERT_EQ(WAIT_OBJECT_0,
115 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
116 }
117
118 TEST_F(RegistrationRegistrationPipeStateTest, CancelIoWhenWriteIsComplete) {
119 // -> Connecting
120 ASSERT_TRUE(pipe_state().Initialize());
121
122 ScopedFileHANDLE client(Connect());
123
124 ASSERT_TRUE(client.is_valid());
125
126 // Connect completion.
127 ASSERT_EQ(WAIT_OBJECT_0,
128 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
129
130 // Connecting -> Reading
131 ASSERT_TRUE(pipe_state().OnCompletion());
132
133 RegistrationRequest request = {0};
134 CrashpadInfo crashpad_info;
135 request.client_process_id = GetCurrentProcessId();
136 request.crashpad_info_address =
137 reinterpret_cast<WinVMAddress>(&crashpad_info);
138
139 ASSERT_TRUE(WriteRequest(client.get(), &request, sizeof(request)));
140
141 // Read completion.
142 ASSERT_EQ(WAIT_OBJECT_0,
143 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
144
145 // Reading -> Writing -> Waiting for Close
146 ASSERT_TRUE(pipe_state().OnCompletion());
147
148 RegistrationResponse response = {0};
149 ASSERT_TRUE(ReadResponse(client.get(), &response));
150
151 // Waiting for Close -> Stopping
152 pipe_state().Stop();
153
154 // Stop completion.
155 ASSERT_EQ(WAIT_OBJECT_0,
156 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
157 }
158
159 TEST_F(RegistrationRegistrationPipeStateTest, CancelIoWhenCloseIsComplete) {
160 // -> Connecting
161 ASSERT_TRUE(pipe_state().Initialize());
162
163 ScopedFileHANDLE client(Connect());
164
165 ASSERT_TRUE(client.is_valid());
166
167 // Connect completion.
168 ASSERT_EQ(WAIT_OBJECT_0,
169 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
170
171 // Connecting -> Reading
172 ASSERT_TRUE(pipe_state().OnCompletion());
173
174 RegistrationRequest request = {0};
175 CrashpadInfo crashpad_info;
176 request.client_process_id = GetCurrentProcessId();
177 request.crashpad_info_address =
178 reinterpret_cast<WinVMAddress>(&crashpad_info);
179
180 ASSERT_TRUE(WriteRequest(client.get(), &request, sizeof(request)));
181
182 // Read completion.
183 ASSERT_EQ(WAIT_OBJECT_0,
184 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
185
186 // Reading -> Writing -> Waiting for Close
187 ASSERT_TRUE(pipe_state().OnCompletion());
188
189 RegistrationResponse response = {0};
190 ASSERT_TRUE(ReadResponse(client.get(), &response));
191
192 client.reset();
193
194 // Wait for close completion.
195 ASSERT_EQ(WAIT_OBJECT_0,
196 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
197
198 // Waiting for Close -> Stopping
199 pipe_state().Stop();
200
201 // Stop completion.
202 ASSERT_EQ(WAIT_OBJECT_0,
203 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
204 }
205
206 TEST_F(RegistrationRegistrationPipeStateTest, FullCycle) {
207 // -> Connecting
208 ASSERT_TRUE(pipe_state().Initialize());
209
210 ScopedFileHANDLE client(Connect());
211
212 ASSERT_TRUE(client.is_valid());
213
214 // Connect completion.
215 ASSERT_EQ(WAIT_OBJECT_0,
216 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
217
218 // Connecting -> Reading
219 ASSERT_TRUE(pipe_state().OnCompletion());
220
221 RegistrationRequest request = {0};
222 CrashpadInfo crashpad_info;
223 request.client_process_id = GetCurrentProcessId();
224 request.crashpad_info_address =
225 reinterpret_cast<WinVMAddress>(&crashpad_info);
226
227 ASSERT_TRUE(WriteRequest(client.get(), &request, sizeof(request)));
228
229 // Read completion.
230 ASSERT_EQ(WAIT_OBJECT_0,
231 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
232
233 // Reading -> Writing -> Waiting for Close
234 ASSERT_TRUE(pipe_state().OnCompletion());
235
236 RegistrationResponse response = {0};
237 ASSERT_TRUE(ReadResponse(client.get(), &response));
238
239 client.reset();
240
241 // Wait for close completion.
242 ASSERT_EQ(WAIT_OBJECT_0,
243 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
244
245 // Waiting for Close -> Reset -> Connecting
246 ASSERT_TRUE(pipe_state().OnCompletion());
247
248 client = Connect();
249 ASSERT_TRUE(client.is_valid());
250
251 pipe_state().Stop();
252
253 ASSERT_EQ(WAIT_OBJECT_0,
254 WaitForSingleObject(pipe_state().completion_event(), INFINITE));
255 }
256
257 } // namespace
258 } // namespace test
259 } // namespace crashpad
OLDNEW
« no previous file with comments | « handler/win/registration_pipe_state.cc ('k') | handler/win/registration_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698