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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 #endif | 12 #endif |
13 | 13 |
14 #include <stdio.h> | 14 #include <stdio.h> |
15 #include <string> | 15 #include <string> |
16 #include <utility> | 16 #include <utility> |
17 | 17 |
18 #include "ipc/ipc_tests.h" | 18 #include "ipc/ipc_tests.h" |
19 | 19 |
20 #include "base/base_switches.h" | 20 #include "base/base_switches.h" |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/debug/debug_on_start_win.h" | 22 #include "base/debug/debug_on_start_win.h" |
23 #include "base/perftimer.h" | 23 #include "base/perftimer.h" |
| 24 #include "base/pickle.h" |
24 #include "base/test/perf_test_suite.h" | 25 #include "base/test/perf_test_suite.h" |
25 #include "base/test/test_suite.h" | 26 #include "base/test/test_suite.h" |
26 #include "base/threading/thread.h" | 27 #include "base/threading/thread.h" |
27 #include "ipc/ipc_descriptors.h" | 28 #include "ipc/ipc_descriptors.h" |
28 #include "ipc/ipc_channel.h" | 29 #include "ipc/ipc_channel.h" |
29 #include "ipc/ipc_channel_proxy.h" | 30 #include "ipc/ipc_channel_proxy.h" |
30 #include "ipc/ipc_message_utils.h" | 31 #include "ipc/ipc_message_utils.h" |
31 #include "ipc/ipc_multiprocess_test.h" | 32 #include "ipc/ipc_multiprocess_test.h" |
32 #include "ipc/ipc_sender.h" | 33 #include "ipc/ipc_sender.h" |
33 #include "ipc/ipc_switches.h" | 34 #include "ipc/ipc_switches.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 junk[sizeof(junk)-1] = 0; | 179 junk[sizeof(junk)-1] = 0; |
179 message->WriteString(std::string(junk)); | 180 message->WriteString(std::string(junk)); |
180 | 181 |
181 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text); | 182 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text); |
182 sender->Send(message); | 183 sender->Send(message); |
183 } | 184 } |
184 | 185 |
185 class MyChannelListener : public IPC::Listener { | 186 class MyChannelListener : public IPC::Listener { |
186 public: | 187 public: |
187 virtual bool OnMessageReceived(const IPC::Message& message) { | 188 virtual bool OnMessageReceived(const IPC::Message& message) { |
188 IPC::MessageIterator iter(message); | 189 PickleIterator iter(message); |
189 | 190 |
190 iter.NextInt(); | 191 int ignored; |
191 const std::string data = iter.NextString(); | 192 EXPECT_TRUE(iter.ReadInt(&ignored)); |
192 const std::string big_string = iter.NextString(); | 193 std::string data; |
| 194 EXPECT_TRUE(iter.ReadString(&data)); |
| 195 std::string big_string; |
| 196 EXPECT_TRUE(iter.ReadString(&big_string)); |
193 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); | 197 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); |
194 | 198 |
195 | 199 |
196 if (--messages_left_ == 0) { | 200 if (--messages_left_ == 0) { |
197 MessageLoop::current()->Quit(); | 201 MessageLoop::current()->Quit(); |
198 } else { | 202 } else { |
199 Send(sender_, "Foo"); | 203 Send(sender_, "Foo"); |
200 } | 204 } |
201 return true; | 205 return true; |
202 } | 206 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 thread.Stop(); | 336 thread.Stop(); |
333 } | 337 } |
334 | 338 |
335 class ChannelListenerWithOnConnectedSend : public IPC::Listener { | 339 class ChannelListenerWithOnConnectedSend : public IPC::Listener { |
336 public: | 340 public: |
337 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE { | 341 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE { |
338 SendNextMessage(); | 342 SendNextMessage(); |
339 } | 343 } |
340 | 344 |
341 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 345 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
342 IPC::MessageIterator iter(message); | 346 PickleIterator iter(message); |
343 | 347 |
344 iter.NextInt(); | 348 int ignored; |
345 const std::string data = iter.NextString(); | 349 EXPECT_TRUE(iter.ReadInt(&ignored)); |
346 const std::string big_string = iter.NextString(); | 350 std::string data; |
| 351 EXPECT_TRUE(iter.ReadString(&data)); |
| 352 std::string big_string; |
| 353 EXPECT_TRUE(iter.ReadString(&big_string)); |
347 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); | 354 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); |
348 SendNextMessage(); | 355 SendNextMessage(); |
349 return true; | 356 return true; |
350 } | 357 } |
351 | 358 |
352 virtual void OnChannelError() OVERRIDE { | 359 virtual void OnChannelError() OVERRIDE { |
353 // There is a race when closing the channel so the last message may be lost. | 360 // There is a race when closing the channel so the last message may be lost. |
354 EXPECT_LE(messages_left_, 1); | 361 EXPECT_LE(messages_left_, 1); |
355 MessageLoop::current()->Quit(); | 362 MessageLoop::current()->Quit(); |
356 } | 363 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 std::cout << "Reflector up" << std::endl; | 459 std::cout << "Reflector up" << std::endl; |
453 } | 460 } |
454 | 461 |
455 ~ChannelReflectorListener() { | 462 ~ChannelReflectorListener() { |
456 std::cout << "Client Messages: " << count_messages_ << std::endl; | 463 std::cout << "Client Messages: " << count_messages_ << std::endl; |
457 std::cout << "Client Latency: " << latency_messages_ << std::endl; | 464 std::cout << "Client Latency: " << latency_messages_ << std::endl; |
458 } | 465 } |
459 | 466 |
460 virtual bool OnMessageReceived(const IPC::Message& message) { | 467 virtual bool OnMessageReceived(const IPC::Message& message) { |
461 count_messages_++; | 468 count_messages_++; |
462 IPC::MessageIterator iter(message); | 469 PickleIterator iter(message); |
463 int time = iter.NextInt(); | 470 int time; |
464 int msgid = iter.NextInt(); | 471 EXPECT_TRUE(iter.ReadInt(&time)); |
| 472 int msgid; |
| 473 EXPECT_TRUE(iter.ReadInt(&msgid)); |
465 std::string payload = iter.NextString(); | 474 std::string payload = iter.NextString(); |
466 latency_messages_ += GetTickCount() - time; | 475 latency_messages_ += GetTickCount() - time; |
467 | 476 |
468 // cout << "reflector msg received: " << msgid << endl; | 477 // cout << "reflector msg received: " << msgid << endl; |
469 if (payload == "quit") | 478 if (payload == "quit") |
470 MessageLoop::current()->Quit(); | 479 MessageLoop::current()->Quit(); |
471 | 480 |
472 IPC::Message* msg = new IPC::Message(0, | 481 IPC::Message* msg = new IPC::Message(0, |
473 2, | 482 2, |
474 IPC::Message::PRIORITY_NORMAL); | 483 IPC::Message::PRIORITY_NORMAL); |
(...skipping 23 matching lines...) Expand all Loading... |
498 std::cout << "perflistener up" << std::endl; | 507 std::cout << "perflistener up" << std::endl; |
499 } | 508 } |
500 | 509 |
501 ~ChannelPerfListener() { | 510 ~ChannelPerfListener() { |
502 std::cout << "Server Messages: " << count_messages_ << std::endl; | 511 std::cout << "Server Messages: " << count_messages_ << std::endl; |
503 std::cout << "Server Latency: " << latency_messages_ << std::endl; | 512 std::cout << "Server Latency: " << latency_messages_ << std::endl; |
504 } | 513 } |
505 | 514 |
506 virtual bool OnMessageReceived(const IPC::Message& message) { | 515 virtual bool OnMessageReceived(const IPC::Message& message) { |
507 count_messages_++; | 516 count_messages_++; |
508 // decode the string so this gets counted in the total time | 517 // Decode the string so this gets counted in the total time. |
509 IPC::MessageIterator iter(message); | 518 PickleIterator iter(message); |
510 int time = iter.NextInt(); | 519 int time; |
511 int msgid = iter.NextInt(); | 520 EXPECT_TRUE(iter.ReadInt(&time)); |
| 521 int msgid; |
| 522 EXPECT_TRUE(iter.ReadInt(&msgid)); |
512 std::string cur = iter.NextString(); | 523 std::string cur = iter.NextString(); |
513 latency_messages_ += GetTickCount() - time; | 524 latency_messages_ += GetTickCount() - time; |
514 | 525 |
515 // cout << "perflistener got message" << endl; | |
516 | |
517 count_down_--; | 526 count_down_--; |
518 if (count_down_ == 0) { | 527 if (count_down_ == 0) { |
519 IPC::Message* msg = new IPC::Message(0, | 528 IPC::Message* msg = new IPC::Message(0, |
520 2, | 529 2, |
521 IPC::Message::PRIORITY_NORMAL); | 530 IPC::Message::PRIORITY_NORMAL); |
522 msg->WriteInt(GetTickCount()); | 531 msg->WriteInt(GetTickCount()); |
523 msg->WriteInt(count_down_); | 532 msg->WriteInt(count_down_); |
524 msg->WriteString("quit"); | 533 msg->WriteString("quit"); |
525 channel_->Send(msg); | 534 channel_->Send(msg); |
526 SetTimer(NULL, 1, 250, (TIMERPROC) PostQuitMessage); | 535 SetTimer(NULL, 1, 250, (TIMERPROC) PostQuitMessage); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 #endif // PERFORMANCE_TEST | 600 #endif // PERFORMANCE_TEST |
592 | 601 |
593 int main(int argc, char** argv) { | 602 int main(int argc, char** argv) { |
594 #ifdef PERFORMANCE_TEST | 603 #ifdef PERFORMANCE_TEST |
595 int retval = base::PerfTestSuite(argc, argv).Run(); | 604 int retval = base::PerfTestSuite(argc, argv).Run(); |
596 #else | 605 #else |
597 int retval = base::TestSuite(argc, argv).Run(); | 606 int retval = base::TestSuite(argc, argv).Run(); |
598 #endif | 607 #endif |
599 return retval; | 608 return retval; |
600 } | 609 } |
OLD | NEW |