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

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

Issue 87026: DevTools: Support eventless host message dispatching. (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Rebase Created 11 years, 8 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 | « src/debug.cc ('k') | 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 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 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 3546 matching lines...) Expand 10 before | Expand all | Expand 10 after
3557 // Tests that MessageQueue doesn't destroy client data when expands and 3557 // Tests that MessageQueue doesn't destroy client data when expands and
3558 // does destroy when it dies. 3558 // does destroy when it dies.
3559 TEST(MessageQueueExpandAndDestroy) { 3559 TEST(MessageQueueExpandAndDestroy) {
3560 TestClientData::ResetCounters(); 3560 TestClientData::ResetCounters();
3561 { // Create a scope for the queue. 3561 { // Create a scope for the queue.
3562 MessageQueue queue(1); 3562 MessageQueue queue(1);
3563 queue.Put(Message::NewCommand(Vector<uint16_t>::empty(), 3563 queue.Put(Message::NewCommand(Vector<uint16_t>::empty(),
3564 new TestClientData())); 3564 new TestClientData()));
3565 queue.Put(Message::NewCommand(Vector<uint16_t>::empty(), 3565 queue.Put(Message::NewCommand(Vector<uint16_t>::empty(),
3566 new TestClientData())); 3566 new TestClientData()));
3567 queue.Put(Message::NewHostDispatch(new TestClientData())); 3567 queue.Put(Message::NewCommand(Vector<uint16_t>::empty(),
3568 new TestClientData()));
3568 ASSERT_EQ(0, TestClientData::destructor_call_counter); 3569 ASSERT_EQ(0, TestClientData::destructor_call_counter);
3569 queue.Get().Dispose(); 3570 queue.Get().Dispose();
3570 ASSERT_EQ(1, TestClientData::destructor_call_counter); 3571 ASSERT_EQ(1, TestClientData::destructor_call_counter);
3571 queue.Put(Message::NewHostDispatch(new TestClientData())); 3572 queue.Put(Message::NewCommand(Vector<uint16_t>::empty(),
3572 queue.Put(Message::NewHostDispatch(new TestClientData())); 3573 new TestClientData()));
3573 queue.Put(Message::NewHostDispatch(new TestClientData())); 3574 queue.Put(Message::NewCommand(Vector<uint16_t>::empty(),
3575 new TestClientData()));
3576 queue.Put(Message::NewCommand(Vector<uint16_t>::empty(),
3577 new TestClientData()));
3574 queue.Put(Message::NewOutput(v8::Handle<v8::String>(), 3578 queue.Put(Message::NewOutput(v8::Handle<v8::String>(),
3575 new TestClientData())); 3579 new TestClientData()));
3576 queue.Put(Message::NewEmptyMessage()); 3580 queue.Put(Message::NewEmptyMessage());
3577 ASSERT_EQ(1, TestClientData::destructor_call_counter); 3581 ASSERT_EQ(1, TestClientData::destructor_call_counter);
3578 queue.Get().Dispose(); 3582 queue.Get().Dispose();
3579 ASSERT_EQ(2, TestClientData::destructor_call_counter); 3583 ASSERT_EQ(2, TestClientData::destructor_call_counter);
3580 } 3584 }
3581 // All the client data should be destroyed when the queue is destroyed. 3585 // All the client data should be destroyed when the queue is destroyed.
3582 ASSERT_EQ(TestClientData::destructor_call_counter, 3586 ASSERT_EQ(TestClientData::destructor_call_counter,
3583 TestClientData::destructor_call_counter); 3587 TestClientData::destructor_call_counter);
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
4212 // handler. 4216 // handler.
4213 CompileRun("throw 1"); 4217 CompileRun("throw 1");
4214 4218
4215 // The message handler should be called. 4219 // The message handler should be called.
4216 CHECK_EQ(1, message_handler_hit_count); 4220 CHECK_EQ(1, message_handler_hit_count);
4217 4221
4218 CheckDebuggerUnloaded(true); 4222 CheckDebuggerUnloaded(true);
4219 } 4223 }
4220 4224
4221 4225
4222 int host_dispatch_hit_count = 0; 4226 /* Test DebuggerHostDispatch */
4223 static void HostDispatchHandlerHitCount(v8::Debug::ClientData* dispatch) { 4227 /* In this test, the debugger waits for a command on a breakpoint
4224 host_dispatch_hit_count++; 4228 * and is dispatching host commands while in the infinite loop.
4229 */
4230
4231 class HostDispatchV8Thread : public v8::internal::Thread {
4232 public:
4233 void Run();
4234 };
4235
4236 class HostDispatchDebuggerThread : public v8::internal::Thread {
4237 public:
4238 void Run();
4239 };
4240
4241 Barriers* host_dispatch_barriers;
4242
4243 static void HostDispatchMessageHandler(const uint16_t* message,
4244 int length,
4245 v8::Debug::ClientData* client_data) {
4246 static char print_buffer[1000];
4247 Utf16ToAscii(message, length, print_buffer);
4248 printf("%s\n", print_buffer);
4249 fflush(stdout);
4225 } 4250 }
4226 4251
4227 4252
4228 // Test that clearing the debug event listener actually clears all break points 4253 static void HostDispatchDispatchHandler() {
4229 // and related information. 4254 host_dispatch_barriers->semaphore_1->Signal();
4230 TEST(DebuggerHostDispatch) { 4255 }
4231 i::FLAG_debugger_auto_break = true; 4256
4257
4258 void HostDispatchV8Thread::Run() {
4259 const char* source_1 = "var y_global = 3;\n"
4260 "function cat( new_value ) {\n"
4261 " var x = new_value;\n"
4262 " y_global = 4;\n"
4263 " x = 3 * x + 1;\n"
4264 " y_global = 5;\n"
4265 " return x;\n"
4266 "}\n"
4267 "\n";
4268 const char* source_2 = "cat(17);\n";
4232 4269
4233 v8::HandleScope scope; 4270 v8::HandleScope scope;
4234 DebugLocalContext env; 4271 DebugLocalContext env;
4235 4272
4236 const int kBufferSize = 1000; 4273 // Setup message and host dispatch handlers.
4237 uint16_t buffer[kBufferSize]; 4274 v8::Debug::SetMessageHandler(HostDispatchMessageHandler);
4238 const char* command_continue = 4275 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */);
4239 "{\"seq\":0,"
4240 "\"type\":\"request\","
4241 "\"command\":\"continue\"}";
4242 4276
4243 // Create an empty function to call for processing debug commands 4277 CompileRun(source_1);
4244 v8::Local<v8::Function> empty = 4278 host_dispatch_barriers->barrier_1.Wait();
4245 CompileFunction(&env, "function empty(){}", "empty"); 4279 host_dispatch_barriers->barrier_2.Wait();
4246 4280 CompileRun(source_2);
4247 // Setup message and host dispatch handlers.
4248 v8::Debug::SetMessageHandler(DummyMessageHandler);
4249 v8::Debug::SetHostDispatchHandler(HostDispatchHandlerHitCount);
4250
4251 // Send a host dispatch by itself.
4252 v8::Debug::SendHostDispatch(NULL);
4253 empty->Call(env->Global(), 0, NULL); // Run JavaScript to activate debugger.
4254 CHECK_EQ(1, host_dispatch_hit_count);
4255
4256 // Fill a host dispatch and a continue command on the command queue.
4257 v8::Debug::SendHostDispatch(NULL);
4258 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
4259 empty->Call(env->Global(), 0, NULL); // Run JavaScript to activate debugger.
4260
4261 // Fill a continue command and a host dispatch on the command queue.
4262 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
4263 v8::Debug::SendHostDispatch(NULL);
4264 empty->Call(env->Global(), 0, NULL); // Run JavaScript to activate debugger.
4265 empty->Call(env->Global(), 0, NULL); // Run JavaScript to activate debugger.
4266
4267 // All the host dispatch callback should be called.
4268 CHECK_EQ(3, host_dispatch_hit_count);
4269 } 4281 }
4270 4282
4271 4283
4284 void HostDispatchDebuggerThread::Run() {
4285 const int kBufSize = 1000;
4286 uint16_t buffer[kBufSize];
4287
4288 const char* command_1 = "{\"seq\":101,"
4289 "\"type\":\"request\","
4290 "\"command\":\"setbreakpoint\","
4291 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}";
4292 const char* command_2 = "{\"seq\":102,"
4293 "\"type\":\"request\","
4294 "\"command\":\"continue\"}";
4295
4296 // v8 thread initializes, runs source_1
4297 host_dispatch_barriers->barrier_1.Wait();
4298 // 1: Set breakpoint in cat().
4299 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
4300
4301 host_dispatch_barriers->barrier_2.Wait();
4302 // v8 thread starts compiling source_2.
4303 // Break happens, to run queued commands and host dispatches.
4304 // Wait for host dispatch to be processed.
4305 host_dispatch_barriers->semaphore_1->Wait();
4306 // 2: Continue evaluation
4307 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
4308 }
4309
4310 HostDispatchDebuggerThread host_dispatch_debugger_thread;
4311 HostDispatchV8Thread host_dispatch_v8_thread;
4312
4313
4314 TEST(DebuggerHostDispatch) {
4315 i::FLAG_debugger_auto_break = true;
4316
4317 // Create a V8 environment
4318 Barriers stack_allocated_host_dispatch_barriers;
4319 stack_allocated_host_dispatch_barriers.Initialize();
4320 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers;
4321
4322 host_dispatch_v8_thread.Start();
4323 host_dispatch_debugger_thread.Start();
4324
4325 host_dispatch_v8_thread.Join();
4326 host_dispatch_debugger_thread.Join();
4327 }
4328
4329
4272 TEST(DebuggerAgent) { 4330 TEST(DebuggerAgent) {
4273 // Make sure this port is not used by other tests to allow tests to run in 4331 // Make sure this port is not used by other tests to allow tests to run in
4274 // parallel. 4332 // parallel.
4275 const int kPort = 5858; 4333 const int kPort = 5858;
4276 4334
4277 // Make a string with the port number. 4335 // Make a string with the port number.
4278 const int kPortBufferLen = 6; 4336 const int kPortBufferLen = 6;
4279 char port_str[kPortBufferLen]; 4337 char port_str[kPortBufferLen];
4280 OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort); 4338 OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort);
4281 4339
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); 4569 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
4512 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); 4570 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
4513 script2->Run(); 4571 script2->Run();
4514 script2->SetData(data_obj); 4572 script2->SetData(data_obj);
4515 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 4573 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
4516 f->Call(env->Global(), 0, NULL); 4574 f->Call(env->Global(), 0, NULL);
4517 CHECK_EQ(2, break_point_hit_count); 4575 CHECK_EQ(2, break_point_hit_count);
4518 CHECK_EQ("new name", last_script_name_hit); 4576 CHECK_EQ("new name", last_script_name_hit);
4519 CHECK_EQ("abc 123", last_script_data_hit); 4577 CHECK_EQ("abc 123", last_script_data_hit);
4520 } 4578 }
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698