OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 memset(junk, 'a', sizeof(junk)-1); | 175 memset(junk, 'a', sizeof(junk)-1); |
176 junk[sizeof(junk)-1] = 0; | 176 junk[sizeof(junk)-1] = 0; |
177 message->WriteString(std::string(junk)); | 177 message->WriteString(std::string(junk)); |
178 | 178 |
179 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text); | 179 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text); |
180 sender->Send(message); | 180 sender->Send(message); |
181 } | 181 } |
182 | 182 |
183 class MyChannelListener : public IPC::Channel::Listener { | 183 class MyChannelListener : public IPC::Channel::Listener { |
184 public: | 184 public: |
185 virtual void OnMessageReceived(const IPC::Message& message) { | 185 virtual bool OnMessageReceived(const IPC::Message& message) { |
186 IPC::MessageIterator iter(message); | 186 IPC::MessageIterator iter(message); |
187 | 187 |
188 iter.NextInt(); | 188 iter.NextInt(); |
189 const std::string data = iter.NextString(); | 189 const std::string data = iter.NextString(); |
190 const std::string big_string = iter.NextString(); | 190 const std::string big_string = iter.NextString(); |
191 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); | 191 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); |
192 | 192 |
193 | 193 |
194 if (--messages_left_ == 0) { | 194 if (--messages_left_ == 0) { |
195 MessageLoop::current()->Quit(); | 195 MessageLoop::current()->Quit(); |
196 } else { | 196 } else { |
197 Send(sender_, "Foo"); | 197 Send(sender_, "Foo"); |
198 } | 198 } |
| 199 return true; |
199 } | 200 } |
200 | 201 |
201 virtual void OnChannelError() { | 202 virtual void OnChannelError() { |
202 // There is a race when closing the channel so the last message may be lost. | 203 // There is a race when closing the channel so the last message may be lost. |
203 EXPECT_LE(messages_left_, 1); | 204 EXPECT_LE(messages_left_, 1); |
204 MessageLoop::current()->Quit(); | 205 MessageLoop::current()->Quit(); |
205 } | 206 } |
206 | 207 |
207 void Init(IPC::Message::Sender* s) { | 208 void Init(IPC::Message::Sender* s) { |
208 sender_ = s; | 209 sender_ = s; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 285 } |
285 thread.Stop(); | 286 thread.Stop(); |
286 } | 287 } |
287 | 288 |
288 class ChannelListenerWithOnConnectedSend : public IPC::Channel::Listener { | 289 class ChannelListenerWithOnConnectedSend : public IPC::Channel::Listener { |
289 public: | 290 public: |
290 virtual void OnChannelConnected(int32 peer_pid) { | 291 virtual void OnChannelConnected(int32 peer_pid) { |
291 SendNextMessage(); | 292 SendNextMessage(); |
292 } | 293 } |
293 | 294 |
294 virtual void OnMessageReceived(const IPC::Message& message) { | 295 virtual bool OnMessageReceived(const IPC::Message& message) { |
295 IPC::MessageIterator iter(message); | 296 IPC::MessageIterator iter(message); |
296 | 297 |
297 iter.NextInt(); | 298 iter.NextInt(); |
298 const std::string data = iter.NextString(); | 299 const std::string data = iter.NextString(); |
299 const std::string big_string = iter.NextString(); | 300 const std::string big_string = iter.NextString(); |
300 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); | 301 EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); |
301 SendNextMessage(); | 302 SendNextMessage(); |
| 303 return true; |
302 } | 304 } |
303 | 305 |
304 virtual void OnChannelError() { | 306 virtual void OnChannelError() { |
305 // There is a race when closing the channel so the last message may be lost. | 307 // There is a race when closing the channel so the last message may be lost. |
306 EXPECT_LE(messages_left_, 1); | 308 EXPECT_LE(messages_left_, 1); |
307 MessageLoop::current()->Quit(); | 309 MessageLoop::current()->Quit(); |
308 } | 310 } |
309 | 311 |
310 void Init(IPC::Message::Sender* s) { | 312 void Init(IPC::Message::Sender* s) { |
311 sender_ = s; | 313 sender_ = s; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 count_messages_(0), | 397 count_messages_(0), |
396 latency_messages_(0) { | 398 latency_messages_(0) { |
397 std::cout << "Reflector up" << std::endl; | 399 std::cout << "Reflector up" << std::endl; |
398 } | 400 } |
399 | 401 |
400 ~ChannelReflectorListener() { | 402 ~ChannelReflectorListener() { |
401 std::cout << "Client Messages: " << count_messages_ << std::endl; | 403 std::cout << "Client Messages: " << count_messages_ << std::endl; |
402 std::cout << "Client Latency: " << latency_messages_ << std::endl; | 404 std::cout << "Client Latency: " << latency_messages_ << std::endl; |
403 } | 405 } |
404 | 406 |
405 virtual void OnMessageReceived(const IPC::Message& message) { | 407 virtual bool OnMessageReceived(const IPC::Message& message) { |
406 count_messages_++; | 408 count_messages_++; |
407 IPC::MessageIterator iter(message); | 409 IPC::MessageIterator iter(message); |
408 int time = iter.NextInt(); | 410 int time = iter.NextInt(); |
409 int msgid = iter.NextInt(); | 411 int msgid = iter.NextInt(); |
410 std::string payload = iter.NextString(); | 412 std::string payload = iter.NextString(); |
411 latency_messages_ += GetTickCount() - time; | 413 latency_messages_ += GetTickCount() - time; |
412 | 414 |
413 // cout << "reflector msg received: " << msgid << endl; | 415 // cout << "reflector msg received: " << msgid << endl; |
414 if (payload == "quit") | 416 if (payload == "quit") |
415 MessageLoop::current()->Quit(); | 417 MessageLoop::current()->Quit(); |
416 | 418 |
417 IPC::Message* msg = new IPC::Message(0, | 419 IPC::Message* msg = new IPC::Message(0, |
418 2, | 420 2, |
419 IPC::Message::PRIORITY_NORMAL); | 421 IPC::Message::PRIORITY_NORMAL); |
420 msg->WriteInt(GetTickCount()); | 422 msg->WriteInt(GetTickCount()); |
421 msg->WriteInt(msgid); | 423 msg->WriteInt(msgid); |
422 msg->WriteString(payload); | 424 msg->WriteString(payload); |
423 channel_->Send(msg); | 425 channel_->Send(msg); |
| 426 return true; |
424 } | 427 } |
425 private: | 428 private: |
426 IPC::Channel *channel_; | 429 IPC::Channel *channel_; |
427 int count_messages_; | 430 int count_messages_; |
428 int latency_messages_; | 431 int latency_messages_; |
429 }; | 432 }; |
430 | 433 |
431 class ChannelPerfListener : public IPC::Channel::Listener { | 434 class ChannelPerfListener : public IPC::Channel::Listener { |
432 public: | 435 public: |
433 ChannelPerfListener(IPC::Channel* channel, int msg_count, int msg_size) : | 436 ChannelPerfListener(IPC::Channel* channel, int msg_count, int msg_size) : |
434 count_down_(msg_count), | 437 count_down_(msg_count), |
435 channel_(channel), | 438 channel_(channel), |
436 count_messages_(0), | 439 count_messages_(0), |
437 latency_messages_(0) { | 440 latency_messages_(0) { |
438 payload_.resize(msg_size); | 441 payload_.resize(msg_size); |
439 for (int i = 0; i < static_cast<int>(payload_.size()); i++) | 442 for (int i = 0; i < static_cast<int>(payload_.size()); i++) |
440 payload_[i] = 'a'; | 443 payload_[i] = 'a'; |
441 std::cout << "perflistener up" << std::endl; | 444 std::cout << "perflistener up" << std::endl; |
442 } | 445 } |
443 | 446 |
444 ~ChannelPerfListener() { | 447 ~ChannelPerfListener() { |
445 std::cout << "Server Messages: " << count_messages_ << std::endl; | 448 std::cout << "Server Messages: " << count_messages_ << std::endl; |
446 std::cout << "Server Latency: " << latency_messages_ << std::endl; | 449 std::cout << "Server Latency: " << latency_messages_ << std::endl; |
447 } | 450 } |
448 | 451 |
449 virtual void OnMessageReceived(const IPC::Message& message) { | 452 virtual bool OnMessageReceived(const IPC::Message& message) { |
450 count_messages_++; | 453 count_messages_++; |
451 // decode the string so this gets counted in the total time | 454 // decode the string so this gets counted in the total time |
452 IPC::MessageIterator iter(message); | 455 IPC::MessageIterator iter(message); |
453 int time = iter.NextInt(); | 456 int time = iter.NextInt(); |
454 int msgid = iter.NextInt(); | 457 int msgid = iter.NextInt(); |
455 std::string cur = iter.NextString(); | 458 std::string cur = iter.NextString(); |
456 latency_messages_ += GetTickCount() - time; | 459 latency_messages_ += GetTickCount() - time; |
457 | 460 |
458 // cout << "perflistener got message" << endl; | 461 // cout << "perflistener got message" << endl; |
459 | 462 |
460 count_down_--; | 463 count_down_--; |
461 if (count_down_ == 0) { | 464 if (count_down_ == 0) { |
462 IPC::Message* msg = new IPC::Message(0, | 465 IPC::Message* msg = new IPC::Message(0, |
463 2, | 466 2, |
464 IPC::Message::PRIORITY_NORMAL); | 467 IPC::Message::PRIORITY_NORMAL); |
465 msg->WriteInt(GetTickCount()); | 468 msg->WriteInt(GetTickCount()); |
466 msg->WriteInt(count_down_); | 469 msg->WriteInt(count_down_); |
467 msg->WriteString("quit"); | 470 msg->WriteString("quit"); |
468 channel_->Send(msg); | 471 channel_->Send(msg); |
469 SetTimer(NULL, 1, 250, (TIMERPROC) PostQuitMessage); | 472 SetTimer(NULL, 1, 250, (TIMERPROC) PostQuitMessage); |
470 return; | 473 return true; |
471 } | 474 } |
472 | 475 |
473 IPC::Message* msg = new IPC::Message(0, | 476 IPC::Message* msg = new IPC::Message(0, |
474 2, | 477 2, |
475 IPC::Message::PRIORITY_NORMAL); | 478 IPC::Message::PRIORITY_NORMAL); |
476 msg->WriteInt(GetTickCount()); | 479 msg->WriteInt(GetTickCount()); |
477 msg->WriteInt(count_down_); | 480 msg->WriteInt(count_down_); |
478 msg->WriteString(payload_); | 481 msg->WriteString(payload_); |
479 channel_->Send(msg); | 482 channel_->Send(msg); |
| 483 return true; |
480 } | 484 } |
481 | 485 |
482 private: | 486 private: |
483 int count_down_; | 487 int count_down_; |
484 std::string payload_; | 488 std::string payload_; |
485 IPC::Channel *channel_; | 489 IPC::Channel *channel_; |
486 int count_messages_; | 490 int count_messages_; |
487 int latency_messages_; | 491 int latency_messages_; |
488 }; | 492 }; |
489 | 493 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 #endif // PERFORMANCE_TEST | 537 #endif // PERFORMANCE_TEST |
534 | 538 |
535 int main(int argc, char** argv) { | 539 int main(int argc, char** argv) { |
536 #ifdef PERFORMANCE_TEST | 540 #ifdef PERFORMANCE_TEST |
537 int retval = base::PerfTestSuite(argc, argv).Run(); | 541 int retval = base::PerfTestSuite(argc, argv).Run(); |
538 #else | 542 #else |
539 int retval = base::TestSuite(argc, argv).Run(); | 543 int retval = base::TestSuite(argc, argv).Run(); |
540 #endif | 544 #endif |
541 return retval; | 545 return retval; |
542 } | 546 } |
OLD | NEW |