Reviewers: Søren Gjesse, Description: Fix issue 96, "test-debug/ThreadedDebugging is flaky"
The previous test assumed the V8 thread would begin executing before the Debugger thread issued its break statement. Since it's actually impossible to guarantee this situation (it'd require putting a barrier inside the JS), fudge it by putting the debugger thread to sleep for 1 second before issuing the break. Also beefed up the test by ensuring "x" is actually incremented. In the JS portion, move "x" to be a global variable. In the driver, issue an additional debug command to look for a value of "x" != 1. Ran the test for about 8 hours on Windows without a hang or a failure BUG=96 Please review this at http://codereview.chromium.org/42686 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M test/cctest/test-debug.cc Index: test/cctest/test-debug.cc =================================================================== --- test/cctest/test-debug.cc (revision 1622) +++ test/cctest/test-debug.cc (working copy) @@ -3311,6 +3311,15 @@ void Run(); }; +// Is this a valid response to display the value of x? +bool IsThreadedValidXMessage(char* message) { + // seq 103 is our command to evaluate x + const char* seq_str = "\"request_seq\":103,"; + // x should be > 1 + const char* value_str = "\"value\":1,"; + return strstr(message, seq_str) != NULL && + !strstr(message, value_str); +} static void ThreadedMessageHandler(const uint16_t* message, int length, void *data) { @@ -3321,6 +3330,9 @@ } printf("%s\n", print_buffer); fflush(stdout); + if (IsThreadedValidXMessage(print_buffer)) { + threaded_debugging_barriers.barrier_3.Wait(); + } } @@ -3332,8 +3344,8 @@ " return \"Return from bar(\" + new_value + \")\";\n" "}\n" "\n" + "var x = 1;\n" "function foo() {\n" - " var x = 1;\n" " while ( flag == true ) {\n" " x = x + 1;\n" " }\n" @@ -3360,13 +3372,20 @@ "\"arguments\":{\"expression\":\"bar(false)\"}}"; const char* command_2 = "{\"seq\":103," "\"type\":\"request\"," + "\"command\":\"evaluate\"," + "\"arguments\":{\"expression\":\"x\"}}"; + const char* command_3 = "{\"seq\":104," + "\"type\":\"request\"," "\"command\":\"continue\"}"; threaded_debugging_barriers.barrier_1.Wait(); + // Give V8Thread time to actually run the infinite loop a few iterations + OS::Sleep(1000); v8::Debug::DebugBreak(); threaded_debugging_barriers.barrier_2.Wait(); v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); + v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer)); } DebuggerThread debugger_thread; @@ -3381,6 +3400,9 @@ v8_thread.Join(); debugger_thread.Join(); + + // Wait until x's value is printed out before terminating + threaded_debugging_barriers.barrier_3.Wait(); } /* Test RecursiveBreakpoints */ --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
