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

Side by Side Diff: sandbox/win/src/ipc_unittest.cc

Issue 1507413003: clang/win: Let some chromium_code targets build with -Wextra. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: content_browsertests Created 5 years 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 | « sandbox/win/src/interception_unittest.cc ('k') | sandbox/win/src/job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include "sandbox/win/src/crosscall_client.h" 7 #include "sandbox/win/src/crosscall_client.h"
8 #include "sandbox/win/src/crosscall_server.h" 8 #include "sandbox/win/src/crosscall_server.h"
9 #include "sandbox/win/src/sharedmem_ipc_client.h" 9 #include "sandbox/win/src/sharedmem_ipc_client.h"
10 #include "sandbox/win/src/sharedmem_ipc_server.h" 10 #include "sandbox/win/src/sharedmem_ipc_server.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 } 62 }
63 63
64 TEST(IPCTest, ChannelMaker) { 64 TEST(IPCTest, ChannelMaker) {
65 // Test that our testing rig is computing offsets properly. We should have 65 // Test that our testing rig is computing offsets properly. We should have
66 // 5 channnels and the offset to the first channel is 108 bytes in 32 bits 66 // 5 channnels and the offset to the first channel is 108 bytes in 32 bits
67 // and 216 in 64 bits. 67 // and 216 in 64 bits.
68 size_t channel_start = 0; 68 size_t channel_start = 0;
69 IPCControl* client_control = MakeChannels(12 * 64, 4096, &channel_start); 69 IPCControl* client_control = MakeChannels(12 * 64, 4096, &channel_start);
70 ASSERT_TRUE(NULL != client_control); 70 ASSERT_TRUE(NULL != client_control);
71 EXPECT_EQ(5, client_control->channels_count); 71 EXPECT_EQ(5u, client_control->channels_count);
72 #if defined(_WIN64) 72 #if defined(_WIN64)
73 EXPECT_EQ(216, channel_start); 73 EXPECT_EQ(216u, channel_start);
74 #else 74 #else
75 EXPECT_EQ(108, channel_start); 75 EXPECT_EQ(108u, channel_start);
76 #endif 76 #endif
77 delete[] reinterpret_cast<char*>(client_control); 77 delete[] reinterpret_cast<char*>(client_control);
78 } 78 }
79 79
80 TEST(IPCTest, ClientLockUnlock) { 80 TEST(IPCTest, ClientLockUnlock) {
81 // Make 7 channels of kIPCChannelSize (1kb) each. Test that we lock and 81 // Make 7 channels of kIPCChannelSize (1kb) each. Test that we lock and
82 // unlock channels properly. 82 // unlock channels properly.
83 size_t base_start = 0; 83 size_t base_start = 0;
84 IPCControl* client_control = 84 IPCControl* client_control =
85 MakeChannels(kIPCChannelSize, 4096 * 2, &base_start); 85 MakeChannels(kIPCChannelSize, 4096 * 2, &base_start);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 SharedMemIPCClient client(mem); 159 SharedMemIPCClient client(mem);
160 160
161 CrossCallReturn answer; 161 CrossCallReturn answer;
162 uint32_t tag1 = 666; 162 uint32_t tag1 = 666;
163 const wchar_t *text = L"98765 - 43210"; 163 const wchar_t *text = L"98765 - 43210";
164 base::string16 copied_text; 164 base::string16 copied_text;
165 CrossCallParamsEx* actual_params; 165 CrossCallParamsEx* actual_params;
166 166
167 CrossCall(client, tag1, text, &answer); 167 CrossCall(client, tag1, text, &answer);
168 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer()); 168 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer());
169 EXPECT_EQ(1, actual_params->GetParamsCount()); 169 EXPECT_EQ(1u, actual_params->GetParamsCount());
170 EXPECT_EQ(tag1, actual_params->GetTag()); 170 EXPECT_EQ(tag1, actual_params->GetTag());
171 EXPECT_TRUE(actual_params->GetParameterStr(0, &copied_text)); 171 EXPECT_TRUE(actual_params->GetParameterStr(0, &copied_text));
172 EXPECT_STREQ(text, copied_text.c_str()); 172 EXPECT_STREQ(text, copied_text.c_str());
173 173
174 // Check with an empty string. 174 // Check with an empty string.
175 uint32_t tag2 = 777; 175 uint32_t tag2 = 777;
176 const wchar_t* null_text = NULL; 176 const wchar_t* null_text = NULL;
177 CrossCall(client, tag2, null_text, &answer); 177 CrossCall(client, tag2, null_text, &answer);
178 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer()); 178 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer());
179 EXPECT_EQ(1, actual_params->GetParamsCount()); 179 EXPECT_EQ(1u, actual_params->GetParamsCount());
180 EXPECT_EQ(tag2, actual_params->GetTag()); 180 EXPECT_EQ(tag2, actual_params->GetTag());
181 uint32_t param_size = 1; 181 uint32_t param_size = 1;
182 ArgType type = INVALID_TYPE; 182 ArgType type = INVALID_TYPE;
183 void* param_addr = actual_params->GetRawParameter(0, &param_size, &type); 183 void* param_addr = actual_params->GetRawParameter(0, &param_size, &type);
184 EXPECT_TRUE(NULL != param_addr); 184 EXPECT_TRUE(NULL != param_addr);
185 EXPECT_EQ(0, param_size); 185 EXPECT_EQ(0u, param_size);
186 EXPECT_EQ(WCHAR_TYPE, type); 186 EXPECT_EQ(WCHAR_TYPE, type);
187 EXPECT_TRUE(actual_params->GetParameterStr(0, &copied_text)); 187 EXPECT_TRUE(actual_params->GetParameterStr(0, &copied_text));
188 188
189 uint32_t tag3 = 888; 189 uint32_t tag3 = 888;
190 param_size = 1; 190 param_size = 1;
191 copied_text.clear(); 191 copied_text.clear();
192 192
193 // Check with an empty string and a non-empty string. 193 // Check with an empty string and a non-empty string.
194 CrossCall(client, tag3, null_text, text, &answer); 194 CrossCall(client, tag3, null_text, text, &answer);
195 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer()); 195 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer());
196 EXPECT_EQ(2, actual_params->GetParamsCount()); 196 EXPECT_EQ(2u, actual_params->GetParamsCount());
197 EXPECT_EQ(tag3, actual_params->GetTag()); 197 EXPECT_EQ(tag3, actual_params->GetTag());
198 type = INVALID_TYPE; 198 type = INVALID_TYPE;
199 param_addr = actual_params->GetRawParameter(0, &param_size, &type); 199 param_addr = actual_params->GetRawParameter(0, &param_size, &type);
200 EXPECT_TRUE(NULL != param_addr); 200 EXPECT_TRUE(NULL != param_addr);
201 EXPECT_EQ(0, param_size); 201 EXPECT_EQ(0u, param_size);
202 EXPECT_EQ(WCHAR_TYPE, type); 202 EXPECT_EQ(WCHAR_TYPE, type);
203 EXPECT_TRUE(actual_params->GetParameterStr(0, &copied_text)); 203 EXPECT_TRUE(actual_params->GetParameterStr(0, &copied_text));
204 EXPECT_TRUE(actual_params->GetParameterStr(1, &copied_text)); 204 EXPECT_TRUE(actual_params->GetParameterStr(1, &copied_text));
205 EXPECT_STREQ(text, copied_text.c_str()); 205 EXPECT_STREQ(text, copied_text.c_str());
206 206
207 param_size = 1; 207 param_size = 1;
208 base::string16 copied_text_p0, copied_text_p2; 208 base::string16 copied_text_p0, copied_text_p2;
209 209
210 const wchar_t *text2 = L"AeFG"; 210 const wchar_t *text2 = L"AeFG";
211 CrossCall(client, tag1, text2, null_text, text, &answer); 211 CrossCall(client, tag1, text2, null_text, text, &answer);
212 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer()); 212 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer());
213 EXPECT_EQ(3, actual_params->GetParamsCount()); 213 EXPECT_EQ(3u, actual_params->GetParamsCount());
214 EXPECT_EQ(tag1, actual_params->GetTag()); 214 EXPECT_EQ(tag1, actual_params->GetTag());
215 EXPECT_TRUE(actual_params->GetParameterStr(0, &copied_text_p0)); 215 EXPECT_TRUE(actual_params->GetParameterStr(0, &copied_text_p0));
216 EXPECT_STREQ(text2, copied_text_p0.c_str()); 216 EXPECT_STREQ(text2, copied_text_p0.c_str());
217 EXPECT_TRUE(actual_params->GetParameterStr(2, &copied_text_p2)); 217 EXPECT_TRUE(actual_params->GetParameterStr(2, &copied_text_p2));
218 EXPECT_STREQ(text, copied_text_p2.c_str()); 218 EXPECT_STREQ(text, copied_text_p2.c_str());
219 type = INVALID_TYPE; 219 type = INVALID_TYPE;
220 param_addr = actual_params->GetRawParameter(1, &param_size, &type); 220 param_addr = actual_params->GetRawParameter(1, &param_size, &type);
221 EXPECT_TRUE(NULL != param_addr); 221 EXPECT_TRUE(NULL != param_addr);
222 EXPECT_EQ(0, param_size); 222 EXPECT_EQ(0u, param_size);
223 EXPECT_EQ(WCHAR_TYPE, type); 223 EXPECT_EQ(WCHAR_TYPE, type);
224 224
225 CloseChannelEvents(client_control); 225 CloseChannelEvents(client_control);
226 delete[] reinterpret_cast<char*>(client_control); 226 delete[] reinterpret_cast<char*>(client_control);
227 } 227 }
228 228
229 TEST(IPCTest, CrossCallIntPacking) { 229 TEST(IPCTest, CrossCallIntPacking) {
230 // Check handling for regular 32 bit integers used in Windows. 230 // Check handling for regular 32 bit integers used in Windows.
231 size_t base_start = 0; 231 size_t base_start = 0;
232 IPCControl* client_control = 232 IPCControl* client_control =
233 MakeChannels(kIPCChannelSize, 4096 * 4, &base_start); 233 MakeChannels(kIPCChannelSize, 4096 * 4, &base_start);
234 client_control->server_alive = HANDLE(1); 234 client_control->server_alive = HANDLE(1);
235 FixChannels(client_control, base_start, kIPCChannelSize, FIX_PONG_READY); 235 FixChannels(client_control, base_start, kIPCChannelSize, FIX_PONG_READY);
236 236
237 uint32_t tag1 = 999; 237 uint32_t tag1 = 999;
238 uint32_t tag2 = 111; 238 uint32_t tag2 = 111;
239 const wchar_t *text = L"godzilla"; 239 const wchar_t *text = L"godzilla";
240 CrossCallParamsEx* actual_params; 240 CrossCallParamsEx* actual_params;
241 241
242 char* mem = reinterpret_cast<char*>(client_control); 242 char* mem = reinterpret_cast<char*>(client_control);
243 SharedMemIPCClient client(mem); 243 SharedMemIPCClient client(mem);
244 244
245 CrossCallReturn answer; 245 CrossCallReturn answer;
246 DWORD dw = 0xE6578; 246 DWORD dw = 0xE6578;
247 CrossCall(client, tag2, dw, &answer); 247 CrossCall(client, tag2, dw, &answer);
248 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer()); 248 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer());
249 EXPECT_EQ(1, actual_params->GetParamsCount()); 249 EXPECT_EQ(1u, actual_params->GetParamsCount());
250 EXPECT_EQ(tag2, actual_params->GetTag()); 250 EXPECT_EQ(tag2, actual_params->GetTag());
251 ArgType type = INVALID_TYPE; 251 ArgType type = INVALID_TYPE;
252 uint32_t param_size = 1; 252 uint32_t param_size = 1;
253 void* param_addr = actual_params->GetRawParameter(0, &param_size, &type); 253 void* param_addr = actual_params->GetRawParameter(0, &param_size, &type);
254 ASSERT_EQ(sizeof(dw), param_size); 254 ASSERT_EQ(sizeof(dw), param_size);
255 EXPECT_EQ(UINT32_TYPE, type); 255 EXPECT_EQ(UINT32_TYPE, type);
256 ASSERT_TRUE(NULL != param_addr); 256 ASSERT_TRUE(NULL != param_addr);
257 EXPECT_EQ(0, memcmp(&dw, param_addr, param_size)); 257 EXPECT_EQ(0, memcmp(&dw, param_addr, param_size));
258 258
259 // Check handling for windows HANDLES. 259 // Check handling for windows HANDLES.
260 HANDLE h = HANDLE(0x70000500); 260 HANDLE h = HANDLE(0x70000500);
261 CrossCall(client, tag1, text, h, &answer); 261 CrossCall(client, tag1, text, h, &answer);
262 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer()); 262 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer());
263 EXPECT_EQ(2, actual_params->GetParamsCount()); 263 EXPECT_EQ(2u, actual_params->GetParamsCount());
264 EXPECT_EQ(tag1, actual_params->GetTag()); 264 EXPECT_EQ(tag1, actual_params->GetTag());
265 type = INVALID_TYPE; 265 type = INVALID_TYPE;
266 param_addr = actual_params->GetRawParameter(1, &param_size, &type); 266 param_addr = actual_params->GetRawParameter(1, &param_size, &type);
267 ASSERT_EQ(sizeof(h), param_size); 267 ASSERT_EQ(sizeof(h), param_size);
268 EXPECT_EQ(VOIDPTR_TYPE, type); 268 EXPECT_EQ(VOIDPTR_TYPE, type);
269 ASSERT_TRUE(NULL != param_addr); 269 ASSERT_TRUE(NULL != param_addr);
270 EXPECT_EQ(0, memcmp(&h, param_addr, param_size)); 270 EXPECT_EQ(0, memcmp(&h, param_addr, param_size));
271 271
272 // Check combination of 32 and 64 bits. 272 // Check combination of 32 and 64 bits.
273 CrossCall(client, tag2, h, dw, h, &answer); 273 CrossCall(client, tag2, h, dw, h, &answer);
274 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer()); 274 actual_params = reinterpret_cast<CrossCallParamsEx*>(client.GetBuffer());
275 EXPECT_EQ(3, actual_params->GetParamsCount()); 275 EXPECT_EQ(3u, actual_params->GetParamsCount());
276 EXPECT_EQ(tag2, actual_params->GetTag()); 276 EXPECT_EQ(tag2, actual_params->GetTag());
277 type = INVALID_TYPE; 277 type = INVALID_TYPE;
278 param_addr = actual_params->GetRawParameter(0, &param_size, &type); 278 param_addr = actual_params->GetRawParameter(0, &param_size, &type);
279 ASSERT_EQ(sizeof(h), param_size); 279 ASSERT_EQ(sizeof(h), param_size);
280 EXPECT_EQ(VOIDPTR_TYPE, type); 280 EXPECT_EQ(VOIDPTR_TYPE, type);
281 ASSERT_TRUE(NULL != param_addr); 281 ASSERT_TRUE(NULL != param_addr);
282 EXPECT_EQ(0, memcmp(&h, param_addr, param_size)); 282 EXPECT_EQ(0, memcmp(&h, param_addr, param_size));
283 type = INVALID_TYPE; 283 type = INVALID_TYPE;
284 param_addr = actual_params->GetRawParameter(1, &param_size, &type); 284 param_addr = actual_params->GetRawParameter(1, &param_size, &type);
285 ASSERT_EQ(sizeof(dw), param_size); 285 ASSERT_EQ(sizeof(dw), param_size);
(...skipping 20 matching lines...) Expand all
306 params_1.CopyParamIn(0, &value, sizeof(value), false, UINT32_TYPE); 306 params_1.CopyParamIn(0, &value, sizeof(value), false, UINT32_TYPE);
307 void* buffer = const_cast<void*>(params_1.GetBuffer()); 307 void* buffer = const_cast<void*>(params_1.GetBuffer());
308 308
309 uint32_t out_size = 0; 309 uint32_t out_size = 0;
310 CrossCallParamsEx* ccp = 0; 310 CrossCallParamsEx* ccp = 0;
311 ccp = CrossCallParamsEx::CreateFromBuffer(buffer, params_1.GetSize(), 311 ccp = CrossCallParamsEx::CreateFromBuffer(buffer, params_1.GetSize(),
312 &out_size); 312 &out_size);
313 ASSERT_TRUE(NULL != ccp); 313 ASSERT_TRUE(NULL != ccp);
314 EXPECT_TRUE(ccp->GetBuffer() != buffer); 314 EXPECT_TRUE(ccp->GetBuffer() != buffer);
315 EXPECT_EQ(kTag, ccp->GetTag()); 315 EXPECT_EQ(kTag, ccp->GetTag());
316 EXPECT_EQ(1, ccp->GetParamsCount()); 316 EXPECT_EQ(1u, ccp->GetParamsCount());
317 delete[] (reinterpret_cast<char*>(ccp)); 317 delete[] (reinterpret_cast<char*>(ccp));
318 318
319 // Test that we handle integer overflow on the number of params 319 // Test that we handle integer overflow on the number of params
320 // correctly. We use a test-only ctor for ActualCallParams that 320 // correctly. We use a test-only ctor for ActualCallParams that
321 // allows to create malformed cross-call buffers. 321 // allows to create malformed cross-call buffers.
322 const int32_t kPtrDiffSz = sizeof(ptrdiff_t); 322 const int32_t kPtrDiffSz = sizeof(ptrdiff_t);
323 for (int32_t ix = -1; ix != 3; ++ix) { 323 for (int32_t ix = -1; ix != 3; ++ix) {
324 uint32_t fake_num_params = (UINT32_MAX / kPtrDiffSz) + ix; 324 uint32_t fake_num_params = (UINT32_MAX / kPtrDiffSz) + ix;
325 ActualCallParams<1, kBufferSize> params_2(kTag, fake_num_params); 325 ActualCallParams<1, kBufferSize> params_2(kTag, fake_num_params);
326 params_2.CopyParamIn(0, &value, sizeof(value), false, UINT32_TYPE); 326 params_2.CopyParamIn(0, &value, sizeof(value), false, UINT32_TYPE);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 EXPECT_EQ(kBusyChannel, client_control->channels[0].state); 427 EXPECT_EQ(kBusyChannel, client_control->channels[0].state);
428 EXPECT_EQ(kFreeChannel, client_control->channels[1].state); 428 EXPECT_EQ(kFreeChannel, client_control->channels[1].state);
429 EXPECT_EQ(kFreeChannel, client_control->channels[2].state); 429 EXPECT_EQ(kFreeChannel, client_control->channels[2].state);
430 430
431 void* buff1 = client.GetBuffer(); 431 void* buff1 = client.GetBuffer();
432 EXPECT_TRUE(mem + client_control->channels[1].channel_base == buff1); 432 EXPECT_TRUE(mem + client_control->channels[1].channel_base == buff1);
433 EXPECT_EQ(kBusyChannel, client_control->channels[0].state); 433 EXPECT_EQ(kBusyChannel, client_control->channels[0].state);
434 EXPECT_EQ(kBusyChannel, client_control->channels[1].state); 434 EXPECT_EQ(kBusyChannel, client_control->channels[1].state);
435 EXPECT_EQ(kFreeChannel, client_control->channels[2].state); 435 EXPECT_EQ(kFreeChannel, client_control->channels[2].state);
436 436
437 EXPECT_EQ(0, client_control->channels[1].ipc_tag); 437 EXPECT_EQ(0u, client_control->channels[1].ipc_tag);
438 438
439 uint32_t tag = 7654; 439 uint32_t tag = 7654;
440 CrossCallReturn answer; 440 CrossCallReturn answer;
441 CrossCallParamsMock* params1 = new(buff1) CrossCallParamsMock(tag, 1); 441 CrossCallParamsMock* params1 = new(buff1) CrossCallParamsMock(tag, 1);
442 FakeOkAnswerInChannel(buff1); 442 FakeOkAnswerInChannel(buff1);
443 443
444 ResultCode result = client.DoCall(params1, &answer); 444 ResultCode result = client.DoCall(params1, &answer);
445 if (SBOX_ERROR_CHANNEL_ERROR != result) 445 if (SBOX_ERROR_CHANNEL_ERROR != result)
446 client.FreeBuffer(buff1); 446 client.FreeBuffer(buff1);
447 447
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 &call_return)); 622 &call_return));
623 EXPECT_EQ(SBOX_ALL_OK, call_return.call_outcome); 623 EXPECT_EQ(SBOX_ALL_OK, call_return.call_outcome);
624 EXPECT_TRUE(bar == call_return.extended[0].handle); 624 EXPECT_TRUE(bar == call_return.extended[0].handle);
625 EXPECT_EQ(foo, call_return.extended[1].unsigned_int); 625 EXPECT_EQ(foo, call_return.extended[1].unsigned_int);
626 626
627 CloseChannelEvents(client_control); 627 CloseChannelEvents(client_control);
628 delete[] reinterpret_cast<char*>(client_control); 628 delete[] reinterpret_cast<char*>(client_control);
629 } 629 }
630 630
631 } // namespace sandbox 631 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/interception_unittest.cc ('k') | sandbox/win/src/job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698