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

Side by Side Diff: ipc/ipc_fuzzing_tests.cc

Issue 10692155: Switch to TimeDelta interfaces for process waiting functions in net and ipc. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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 | « ipc/ipc_channel_posix_unittest.cc ('k') | ipc/ipc_send_fds_test.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 <stdio.h> 5 #include <stdio.h>
6 #include <string> 6 #include <string>
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 IPC::Message* msg = NULL; 275 IPC::Message* msg = NULL;
276 int value = 43; 276 int value = 43;
277 msg = new MsgClassIS(value, L"expect 43"); 277 msg = new MsgClassIS(value, L"expect 43");
278 chan.Send(msg); 278 chan.Send(msg);
279 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID)); 279 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID));
280 280
281 msg = new MsgClassSI(L"expect 44", ++value); 281 msg = new MsgClassSI(L"expect 44", ++value);
282 chan.Send(msg); 282 chan.Send(msg);
283 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID)); 283 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID));
284 284
285 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); 285 EXPECT_TRUE(base::WaitForSingleProcess(
286 server_process, base::TimeDelta::FromSeconds(5)));
286 base::CloseProcessHandle(server_process); 287 base::CloseProcessHandle(server_process);
287 } 288 }
288 289
289 // This test uses a payload that is smaller than expected. 290 // This test uses a payload that is smaller than expected.
290 // This generates an error while unpacking the IPC buffer which in 291 // This generates an error while unpacking the IPC buffer which in
291 // In debug this triggers an assertion and in release it is ignored(!!). Right 292 // In debug this triggers an assertion and in release it is ignored(!!). Right
292 // after we generate another valid IPC to make sure framing is working 293 // after we generate another valid IPC to make sure framing is working
293 // properly. 294 // properly.
294 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 295 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
295 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) { 296 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) {
296 FuzzerClientListener listener; 297 FuzzerClientListener listener;
297 IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_SERVER, 298 IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_SERVER,
298 &listener); 299 &listener);
299 base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER, &chan); 300 base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER, &chan);
300 ASSERT_TRUE(server_process); 301 ASSERT_TRUE(server_process);
301 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); 302 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
302 ASSERT_TRUE(chan.Connect()); 303 ASSERT_TRUE(chan.Connect());
303 listener.Init(&chan); 304 listener.Init(&chan);
304 305
305 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, 306 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID,
306 IPC::Message::PRIORITY_NORMAL); 307 IPC::Message::PRIORITY_NORMAL);
307 msg->WriteInt(666); 308 msg->WriteInt(666);
308 chan.Send(msg); 309 chan.Send(msg);
309 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); 310 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID));
310 311
311 msg = new MsgClassSI(L"expect one", 1); 312 msg = new MsgClassSI(L"expect one", 1);
312 chan.Send(msg); 313 chan.Send(msg);
313 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); 314 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID));
314 315
315 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); 316 EXPECT_TRUE(base::WaitForSingleProcess(
317 server_process, base::TimeDelta::FromSeconds(5)));
316 base::CloseProcessHandle(server_process); 318 base::CloseProcessHandle(server_process);
317 } 319 }
318 #endif 320 #endif
319 321
320 // This test uses a payload that has too many arguments, but so the payload 322 // This test uses a payload that has too many arguments, but so the payload
321 // size is big enough so the unpacking routine does not generate an error as 323 // size is big enough so the unpacking routine does not generate an error as
322 // in the case of MsgBadPayloadShort test. 324 // in the case of MsgBadPayloadShort test.
323 // This test does not pinpoint a flaw (per se) as by design we don't carry 325 // This test does not pinpoint a flaw (per se) as by design we don't carry
324 // type information on the IPC message. 326 // type information on the IPC message.
325 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) { 327 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) {
(...skipping 14 matching lines...) Expand all
340 342
341 chan.Send(msg); 343 chan.Send(msg);
342 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID)); 344 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID));
343 345
344 // Now send a well formed message to make sure the receiver wasn't 346 // Now send a well formed message to make sure the receiver wasn't
345 // thrown out of sync by the extra argument. 347 // thrown out of sync by the extra argument.
346 msg = new MsgClassIS(3, L"expect three"); 348 msg = new MsgClassIS(3, L"expect three");
347 chan.Send(msg); 349 chan.Send(msg);
348 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); 350 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID));
349 351
350 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); 352 EXPECT_TRUE(base::WaitForSingleProcess(
353 server_process, base::TimeDelta::FromSeconds(5)));
351 base::CloseProcessHandle(server_process); 354 base::CloseProcessHandle(server_process);
352 } 355 }
353 356
354 // This class is for testing the IPC_BEGIN_MESSAGE_MAP_EX macros. 357 // This class is for testing the IPC_BEGIN_MESSAGE_MAP_EX macros.
355 class ServerMacroExTest { 358 class ServerMacroExTest {
356 public: 359 public:
357 ServerMacroExTest() : unhandled_msgs_(0) { 360 ServerMacroExTest() : unhandled_msgs_(0) {
358 } 361 }
359 362
360 virtual ~ServerMacroExTest() { 363 virtual ~ServerMacroExTest() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, 411 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID,
409 IPC::Message::PRIORITY_NORMAL); 412 IPC::Message::PRIORITY_NORMAL);
410 msg->WriteInt(0x64); 413 msg->WriteInt(0x64);
411 msg->WriteInt(0x32); 414 msg->WriteInt(0x32);
412 EXPECT_FALSE(server.OnMessageReceived(*msg)); 415 EXPECT_FALSE(server.OnMessageReceived(*msg));
413 delete msg; 416 delete msg;
414 417
415 EXPECT_EQ(0, server.unhandled_msgs()); 418 EXPECT_EQ(0, server.unhandled_msgs());
416 #endif 419 #endif
417 } 420 }
OLDNEW
« no previous file with comments | « ipc/ipc_channel_posix_unittest.cc ('k') | ipc/ipc_send_fds_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698