OLD | NEW |
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 IPCTestBase::GetChannelName("FuzzServerClient"), &listener)); | 264 IPCTestBase::GetChannelName("FuzzServerClient"), &listener)); |
265 CHECK(channel->Connect()); | 265 CHECK(channel->Connect()); |
266 listener.Init(channel.get()); | 266 listener.Init(channel.get()); |
267 base::MessageLoop::current()->Run(); | 267 base::MessageLoop::current()->Run(); |
268 return 0; | 268 return 0; |
269 } | 269 } |
270 | 270 |
271 class IPCFuzzingTest : public IPCTestBase { | 271 class IPCFuzzingTest : public IPCTestBase { |
272 }; | 272 }; |
273 | 273 |
| 274 #if defined(OS_ANDROID) |
| 275 #define MAYBE_SanityTest DISABLED_SanityTest |
| 276 #else |
| 277 #define MAYBE_SanityTest SanityTest |
| 278 #endif |
274 // This test makes sure that the FuzzerClientListener and FuzzerServerListener | 279 // This test makes sure that the FuzzerClientListener and FuzzerServerListener |
275 // are working properly by generating two well formed IPC calls. | 280 // are working properly by generating two well formed IPC calls. |
276 TEST_F(IPCFuzzingTest, SanityTest) { | 281 TEST_F(IPCFuzzingTest, MAYBE_SanityTest) { |
277 Init("FuzzServerClient"); | 282 Init("FuzzServerClient"); |
278 | 283 |
279 FuzzerClientListener listener; | 284 FuzzerClientListener listener; |
280 CreateChannel(&listener); | 285 CreateChannel(&listener); |
281 listener.Init(channel()); | 286 listener.Init(channel()); |
282 ASSERT_TRUE(ConnectChannel()); | 287 ASSERT_TRUE(ConnectChannel()); |
283 ASSERT_TRUE(StartClient()); | 288 ASSERT_TRUE(StartClient()); |
284 | 289 |
285 IPC::Message* msg = NULL; | 290 IPC::Message* msg = NULL; |
286 int value = 43; | 291 int value = 43; |
287 msg = new MsgClassIS(value, base::ASCIIToUTF16("expect 43")); | 292 msg = new MsgClassIS(value, base::ASCIIToUTF16("expect 43")); |
288 sender()->Send(msg); | 293 sender()->Send(msg); |
289 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID)); | 294 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID)); |
290 | 295 |
291 msg = new MsgClassSI(base::ASCIIToUTF16("expect 44"), ++value); | 296 msg = new MsgClassSI(base::ASCIIToUTF16("expect 44"), ++value); |
292 sender()->Send(msg); | 297 sender()->Send(msg); |
293 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID)); | 298 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID)); |
294 | 299 |
295 EXPECT_TRUE(WaitForClientShutdown()); | 300 EXPECT_TRUE(WaitForClientShutdown()); |
296 DestroyChannel(); | 301 DestroyChannel(); |
297 } | 302 } |
298 | 303 |
| 304 #if defined(OS_ANDROID) |
| 305 #define MAYBE_MsgBadPayloadShort DISABLED_MsgBadPayloadShort |
| 306 #else |
| 307 #define MAYBE_MsgBadPayloadShort MsgBadPayloadShort |
| 308 #endif |
299 // This test uses a payload that is smaller than expected. This generates an | 309 // This test uses a payload that is smaller than expected. This generates an |
300 // error while unpacking the IPC buffer which in debug trigger an assertion and | 310 // error while unpacking the IPC buffer which in debug trigger an assertion and |
301 // in release is ignored (!). Right after we generate another valid IPC to make | 311 // in release is ignored (!). Right after we generate another valid IPC to make |
302 // sure framing is working properly. | 312 // sure framing is working properly. |
303 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 313 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
304 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) { | 314 TEST_F(IPCFuzzingTest, MAYBE_MsgBadPayloadShort) { |
305 Init("FuzzServerClient"); | 315 Init("FuzzServerClient"); |
306 | 316 |
307 FuzzerClientListener listener; | 317 FuzzerClientListener listener; |
308 CreateChannel(&listener); | 318 CreateChannel(&listener); |
309 listener.Init(channel()); | 319 listener.Init(channel()); |
310 ASSERT_TRUE(ConnectChannel()); | 320 ASSERT_TRUE(ConnectChannel()); |
311 ASSERT_TRUE(StartClient()); | 321 ASSERT_TRUE(StartClient()); |
312 | 322 |
313 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, | 323 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, |
314 IPC::Message::PRIORITY_NORMAL); | 324 IPC::Message::PRIORITY_NORMAL); |
315 msg->WriteInt(666); | 325 msg->WriteInt(666); |
316 sender()->Send(msg); | 326 sender()->Send(msg); |
317 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); | 327 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); |
318 | 328 |
319 msg = new MsgClassSI(base::ASCIIToUTF16("expect one"), 1); | 329 msg = new MsgClassSI(base::ASCIIToUTF16("expect one"), 1); |
320 sender()->Send(msg); | 330 sender()->Send(msg); |
321 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); | 331 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); |
322 | 332 |
323 EXPECT_TRUE(WaitForClientShutdown()); | 333 EXPECT_TRUE(WaitForClientShutdown()); |
324 DestroyChannel(); | 334 DestroyChannel(); |
325 } | 335 } |
326 #endif | 336 #endif |
327 | 337 |
| 338 #if defined(OS_ANDROID) |
| 339 #define MAYBE_MsgBadPayloadArgs DISABLED_MsgBadPayloadArgs |
| 340 #else |
| 341 #define MAYBE_MsgBadPayloadArgs MsgBadPayloadArgs |
| 342 #endif |
328 // This test uses a payload that has too many arguments, but so the payload size | 343 // This test uses a payload that has too many arguments, but so the payload size |
329 // is big enough so the unpacking routine does not generate an error as in the | 344 // is big enough so the unpacking routine does not generate an error as in the |
330 // case of MsgBadPayloadShort test. This test does not pinpoint a flaw (per se) | 345 // case of MsgBadPayloadShort test. This test does not pinpoint a flaw (per se) |
331 // as by design we don't carry type information on the IPC message. | 346 // as by design we don't carry type information on the IPC message. |
332 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) { | 347 TEST_F(IPCFuzzingTest, MAYBE_MsgBadPayloadArgs) { |
333 Init("FuzzServerClient"); | 348 Init("FuzzServerClient"); |
334 | 349 |
335 FuzzerClientListener listener; | 350 FuzzerClientListener listener; |
336 CreateChannel(&listener); | 351 CreateChannel(&listener); |
337 listener.Init(channel()); | 352 listener.Init(channel()); |
338 ASSERT_TRUE(ConnectChannel()); | 353 ASSERT_TRUE(ConnectChannel()); |
339 ASSERT_TRUE(StartClient()); | 354 ASSERT_TRUE(StartClient()); |
340 | 355 |
341 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID, | 356 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID, |
342 IPC::Message::PRIORITY_NORMAL); | 357 IPC::Message::PRIORITY_NORMAL); |
343 msg->WriteString16(base::ASCIIToUTF16("d")); | 358 msg->WriteString16(base::ASCIIToUTF16("d")); |
344 msg->WriteInt(0); | 359 msg->WriteInt(0); |
345 msg->WriteInt(0x65); // Extra argument. | 360 msg->WriteInt(0x65); // Extra argument. |
346 | 361 |
347 sender()->Send(msg); | 362 sender()->Send(msg); |
348 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID)); | 363 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID)); |
349 | 364 |
350 // Now send a well formed message to make sure the receiver wasn't | 365 // Now send a well formed message to make sure the receiver wasn't |
351 // thrown out of sync by the extra argument. | 366 // thrown out of sync by the extra argument. |
352 msg = new MsgClassIS(3, base::ASCIIToUTF16("expect three")); | 367 msg = new MsgClassIS(3, base::ASCIIToUTF16("expect three")); |
353 sender()->Send(msg); | 368 sender()->Send(msg); |
354 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); | 369 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); |
355 | 370 |
356 EXPECT_TRUE(WaitForClientShutdown()); | 371 EXPECT_TRUE(WaitForClientShutdown()); |
357 DestroyChannel(); | 372 DestroyChannel(); |
358 } | 373 } |
359 | 374 |
360 } // namespace | 375 } // namespace |
OLD | NEW |