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

Side by Side Diff: test/cctest/test-debug.cc

Issue 557773002: Do not force interrupt in test-debug/ProcessDebugMessagesThreaded. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 6513 matching lines...) Expand 10 before | Expand all | Expand 10 after
6524 } 6524 }
6525 6525
6526 6526
6527 class SendCommandThread : public v8::base::Thread { 6527 class SendCommandThread : public v8::base::Thread {
6528 public: 6528 public:
6529 explicit SendCommandThread(v8::Isolate* isolate) 6529 explicit SendCommandThread(v8::Isolate* isolate)
6530 : Thread(Options("SendCommandThread")), 6530 : Thread(Options("SendCommandThread")),
6531 semaphore_(0), 6531 semaphore_(0),
6532 isolate_(isolate) {} 6532 isolate_(isolate) {}
6533 6533
6534 static void ProcessDebugMessages(v8::Isolate* isolate, void* data) { 6534 class ClientDataImpl : public v8::Debug::ClientData {
6535 v8::Debug::ProcessDebugMessages(); 6535 public:
6536 reinterpret_cast<v8::base::Semaphore*>(data)->Signal(); 6536 explicit ClientDataImpl(v8::base::Semaphore* semaphore)
6537 : semaphore_(semaphore) {}
6538 v8::base::Semaphore* semaphore() { return semaphore_; }
6539
6540 private:
6541 v8::base::Semaphore* semaphore_;
6542 };
6543
6544 static void CountingAndSignallingMessageHandler(
6545 const v8::Debug::Message& message) {
6546 if (message.IsResponse()) {
6547 counting_message_handler_counter++;
6548 ClientDataImpl* data =
6549 reinterpret_cast<ClientDataImpl*>(message.GetClientData());
6550 v8::base::Semaphore* semaphore = data->semaphore();
6551 semaphore->Signal();
6552 }
6537 } 6553 }
6538 6554
6539 virtual void Run() { 6555 virtual void Run() {
6540 semaphore_.Wait(); 6556 semaphore_.Wait();
6541 const int kBufferSize = 1000; 6557 const int kBufferSize = 1000;
6542 uint16_t buffer[kBufferSize]; 6558 uint16_t buffer[kBufferSize];
6543 const char* scripts_command = 6559 const char* scripts_command =
6544 "{\"seq\":0," 6560 "{\"seq\":0,"
6545 "\"type\":\"request\"," 6561 "\"type\":\"request\","
6546 "\"command\":\"scripts\"}"; 6562 "\"command\":\"scripts\"}";
6547 int length = AsciiToUtf16(scripts_command, buffer); 6563 int length = AsciiToUtf16(scripts_command, buffer);
6548 // Send scripts command. 6564 // Send scripts command.
6549 6565
6550 for (int i = 0; i < 100; i++) { 6566 for (int i = 0; i < 100; i++) {
6551 CHECK_EQ(i, counting_message_handler_counter); 6567 CHECK_EQ(i, counting_message_handler_counter);
6552 // Queue debug message. 6568 // Queue debug message.
6553 v8::Debug::SendCommand(isolate_, buffer, length); 6569 v8::Debug::SendCommand(isolate_, buffer, length,
6554 // Synchronize with the main thread to force message processing. 6570 new ClientDataImpl(&semaphore_));
6555 isolate_->RequestInterrupt(ProcessDebugMessages, &semaphore_); 6571 // Wait for the message handler to pick up the response.
6556 semaphore_.Wait(); 6572 semaphore_.Wait();
6557 } 6573 }
6558 6574
6559 v8::V8::TerminateExecution(isolate_); 6575 v8::V8::TerminateExecution(isolate_);
6560 } 6576 }
6561 6577
6562 void StartSending() { 6578 void StartSending() { semaphore_.Signal(); }
6563 semaphore_.Signal();
6564 }
6565 6579
6566 private: 6580 private:
6567 v8::base::Semaphore semaphore_; 6581 v8::base::Semaphore semaphore_;
6568 v8::Isolate* isolate_; 6582 v8::Isolate* isolate_;
6569 }; 6583 };
6570 6584
6571 6585
6572 static SendCommandThread* send_command_thread_ = NULL; 6586 static SendCommandThread* send_command_thread_ = NULL;
6573 6587
6574 static void StartSendingCommands( 6588 static void StartSendingCommands(
6575 const v8::FunctionCallbackInfo<v8::Value>& info) { 6589 const v8::FunctionCallbackInfo<v8::Value>& info) {
6576 send_command_thread_->StartSending(); 6590 send_command_thread_->StartSending();
6577 } 6591 }
6578 6592
6579 6593
6580 TEST(ProcessDebugMessagesThreaded) { 6594 TEST(ProcessDebugMessagesThreaded) {
6581 DebugLocalContext env; 6595 DebugLocalContext env;
6582 v8::Isolate* isolate = env->GetIsolate(); 6596 v8::Isolate* isolate = env->GetIsolate();
6583 v8::HandleScope scope(isolate); 6597 v8::HandleScope scope(isolate);
6584 6598
6585 counting_message_handler_counter = 0; 6599 counting_message_handler_counter = 0;
6586 6600
6587 v8::Debug::SetMessageHandler(CountingMessageHandler); 6601 v8::Debug::SetMessageHandler(
6602 SendCommandThread::CountingAndSignallingMessageHandler);
6588 send_command_thread_ = new SendCommandThread(isolate); 6603 send_command_thread_ = new SendCommandThread(isolate);
6589 send_command_thread_->Start(); 6604 send_command_thread_->Start();
6590 6605
6591 v8::Handle<v8::FunctionTemplate> start = 6606 v8::Handle<v8::FunctionTemplate> start =
6592 v8::FunctionTemplate::New(isolate, StartSendingCommands); 6607 v8::FunctionTemplate::New(isolate, StartSendingCommands);
6593 env->Global()->Set(v8_str("start"), start->GetFunction()); 6608 env->Global()->Set(v8_str("start"), start->GetFunction());
6594 6609
6595 CompileRun("start(); while (true) { }"); 6610 CompileRun("start(); while (true) { }");
6596 6611
6597 CHECK_EQ(100, counting_message_handler_counter); 6612 CHECK_EQ(100, counting_message_handler_counter);
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
7400 v8::Isolate* isolate = env->GetIsolate(); 7415 v8::Isolate* isolate = env->GetIsolate();
7401 v8::HandleScope scope(isolate); 7416 v8::HandleScope scope(isolate);
7402 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); 7417 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate);
7403 TerminationThread terminator(isolate); 7418 TerminationThread terminator(isolate);
7404 terminator.Start(); 7419 terminator.Start();
7405 v8::TryCatch try_catch; 7420 v8::TryCatch try_catch;
7406 v8::Debug::DebugBreak(isolate); 7421 v8::Debug::DebugBreak(isolate);
7407 CompileRun("while (true);"); 7422 CompileRun("while (true);");
7408 CHECK(try_catch.HasTerminated()); 7423 CHECK(try_catch.HasTerminated());
7409 } 7424 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698