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

Side by Side Diff: ipc/ipc_fuzzing_tests.cc

Issue 2451953003: Change most IPC tests to use ChannelMojo. (Closed)
Patch Set: Created 4 years, 1 month 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_proxy_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 <stdint.h> 5 #include <stdint.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 7
8 #include <limits> 8 #include <limits>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (FUZZER_ROUTING_ID != last_msg_->routing_id()) 251 if (FUZZER_ROUTING_ID != last_msg_->routing_id())
252 return false; 252 return false;
253 return (type_id == last_msg_->type()); 253 return (type_id == last_msg_->type());
254 } 254 }
255 255
256 IPC::Message* last_msg_; 256 IPC::Message* last_msg_;
257 }; 257 };
258 258
259 // Runs the fuzzing server child mode. Returns when the preset number of 259 // Runs the fuzzing server child mode. Returns when the preset number of
260 // messages have been received. 260 // messages have been received.
261 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(FuzzServerClient) { 261 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(FuzzServerClient) {
262 base::MessageLoopForIO main_message_loop;
263 FuzzerServerListener listener; 262 FuzzerServerListener listener;
264 std::unique_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( 263 Connect(&listener);
265 IPCTestBase::GetChannelName("FuzzServerClient"), &listener, 264 listener.Init(channel());
266 main_message_loop.task_runner()));
267 CHECK(channel->Connect());
268 listener.Init(channel.get());
269 base::RunLoop().Run(); 265 base::RunLoop().Run();
270 return 0; 266 Close();
271 } 267 }
272 268
273 class IPCFuzzingTest : public IPCTestBase { 269 using IPCFuzzingTest = IPCChannelMojoTestBase;
274 };
275 270
276 // This test makes sure that the FuzzerClientListener and FuzzerServerListener 271 // This test makes sure that the FuzzerClientListener and FuzzerServerListener
277 // are working properly by generating two well formed IPC calls. 272 // are working properly by generating two well formed IPC calls.
278 TEST_F(IPCFuzzingTest, SanityTest) { 273 TEST_F(IPCFuzzingTest, SanityTest) {
279 Init("FuzzServerClient"); 274 Init("FuzzServerClient");
280 275
281 FuzzerClientListener listener; 276 FuzzerClientListener listener;
282 CreateChannel(&listener); 277 CreateChannel(&listener);
283 listener.Init(channel()); 278 listener.Init(channel());
284 ASSERT_TRUE(ConnectChannel()); 279 ASSERT_TRUE(ConnectChannel());
285 ASSERT_TRUE(StartClient());
286 280
287 IPC::Message* msg = NULL; 281 IPC::Message* msg = NULL;
288 int value = 43; 282 int value = 43;
289 msg = new MsgClassIS(value, base::ASCIIToUTF16("expect 43")); 283 msg = new MsgClassIS(value, base::ASCIIToUTF16("expect 43"));
290 sender()->Send(msg); 284 sender()->Send(msg);
291 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID)); 285 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID));
292 286
293 msg = new MsgClassSI(base::ASCIIToUTF16("expect 44"), ++value); 287 msg = new MsgClassSI(base::ASCIIToUTF16("expect 44"), ++value);
294 sender()->Send(msg); 288 sender()->Send(msg);
295 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID)); 289 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID));
296 290
297 EXPECT_TRUE(WaitForClientShutdown()); 291 EXPECT_TRUE(WaitForClientShutdown());
298 DestroyChannel(); 292 DestroyChannel();
299 } 293 }
300 294
301 // This test uses a payload that is smaller than expected. This generates an 295 // This test uses a payload that is smaller than expected. This generates an
302 // error while unpacking the IPC buffer which in debug trigger an assertion and 296 // error while unpacking the IPC buffer. Right after we generate another valid
303 // in release is ignored (!). Right after we generate another valid IPC to make 297 // IPC to make sure framing is working properly.
304 // sure framing is working properly.
305 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
306 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) { 298 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) {
307 Init("FuzzServerClient"); 299 Init("FuzzServerClient");
308 300
309 FuzzerClientListener listener; 301 FuzzerClientListener listener;
310 CreateChannel(&listener); 302 CreateChannel(&listener);
311 listener.Init(channel()); 303 listener.Init(channel());
312 ASSERT_TRUE(ConnectChannel()); 304 ASSERT_TRUE(ConnectChannel());
313 ASSERT_TRUE(StartClient());
314 305
315 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, 306 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID,
316 IPC::Message::PRIORITY_NORMAL); 307 IPC::Message::PRIORITY_NORMAL);
317 msg->WriteInt(666); 308 msg->WriteInt(666);
318 sender()->Send(msg); 309 sender()->Send(msg);
319 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); 310 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID));
320 311
321 msg = new MsgClassSI(base::ASCIIToUTF16("expect one"), 1); 312 msg = new MsgClassSI(base::ASCIIToUTF16("expect one"), 1);
322 sender()->Send(msg); 313 sender()->Send(msg);
323 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); 314 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID));
324 315
325 EXPECT_TRUE(WaitForClientShutdown()); 316 EXPECT_TRUE(WaitForClientShutdown());
326 DestroyChannel(); 317 DestroyChannel();
327 } 318 }
328 #endif
329 319
330 // This test uses a payload that has too many arguments, but so the payload size 320 // This test uses a payload that has too many arguments, but so the payload size
331 // is big enough so the unpacking routine does not generate an error as in the 321 // is big enough so the unpacking routine does not generate an error as in the
332 // case of MsgBadPayloadShort test. This test does not pinpoint a flaw (per se) 322 // case of MsgBadPayloadShort test. This test does not pinpoint a flaw (per se)
333 // as by design we don't carry type information on the IPC message. 323 // as by design we don't carry type information on the IPC message.
334 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) { 324 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) {
335 Init("FuzzServerClient"); 325 Init("FuzzServerClient");
336 326
337 FuzzerClientListener listener; 327 FuzzerClientListener listener;
338 CreateChannel(&listener); 328 CreateChannel(&listener);
339 listener.Init(channel()); 329 listener.Init(channel());
340 ASSERT_TRUE(ConnectChannel()); 330 ASSERT_TRUE(ConnectChannel());
341 ASSERT_TRUE(StartClient());
342 331
343 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID, 332 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID,
344 IPC::Message::PRIORITY_NORMAL); 333 IPC::Message::PRIORITY_NORMAL);
345 msg->WriteString16(base::ASCIIToUTF16("d")); 334 msg->WriteString16(base::ASCIIToUTF16("d"));
346 msg->WriteInt(0); 335 msg->WriteInt(0);
347 msg->WriteInt(0x65); // Extra argument. 336 msg->WriteInt(0x65); // Extra argument.
348 337
349 sender()->Send(msg); 338 sender()->Send(msg);
350 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID)); 339 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID));
351 340
352 // Now send a well formed message to make sure the receiver wasn't 341 // Now send a well formed message to make sure the receiver wasn't
353 // thrown out of sync by the extra argument. 342 // thrown out of sync by the extra argument.
354 msg = new MsgClassIS(3, base::ASCIIToUTF16("expect three")); 343 msg = new MsgClassIS(3, base::ASCIIToUTF16("expect three"));
355 sender()->Send(msg); 344 sender()->Send(msg);
356 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); 345 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID));
357 346
358 EXPECT_TRUE(WaitForClientShutdown()); 347 EXPECT_TRUE(WaitForClientShutdown());
359 DestroyChannel(); 348 DestroyChannel();
360 } 349 }
361 350
362 } // namespace 351 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_channel_proxy_unittest.cc ('k') | ipc/ipc_send_fds_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698