[Lldb-commits] [lldb] r210594 - Added gdb-remote test to verify M memory write.

Todd Fiala todd.fiala at gmail.com
Tue Jun 10 15:15:57 PDT 2014


Author: tfiala
Date: Tue Jun 10 17:15:56 2014
New Revision: 210594

URL: http://llvm.org/viewvc/llvm-project?rev=210594&view=rev
Log:
Added gdb-remote test to verify M memory write.

Modified:
    lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py
    lldb/trunk/test/tools/lldb-gdbserver/main.cpp

Modified: lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py?rev=210594&r1=210593&r2=210594&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py (original)
+++ lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py Tue Jun 10 17:15:56 2014
@@ -49,7 +49,7 @@ class LldbGdbServerTestCase(TestBase):
         self.set_inferior_startup_launch()
 
         # Uncomment this code to force only a single test to run (by name).
-        # if not re.search(r"qSupported", self._testMethodName):
+        # if not re.search(r"written_M", self._testMethodName):
         #     self.skipTest("focusing on one test")
 
     def reset_test_sequence(self):
@@ -1958,6 +1958,68 @@ class LldbGdbServerTestCase(TestBase):
         self.set_inferior_startup_launch()
         self.qSupported_returns_known_stub_features()
 
+    def written_M_content_reads_back_correctly(self):
+        TEST_MESSAGE = "Testing: 1, 2, 3, got this?"
+        
+        # Start up the stub and start/prep the inferior.
+        procs = self.prep_debug_monitor_and_inferior(inferior_args=["set-message:foo", "get-data-address-hex:g_message", "sleep:1", "print-message:"])
+        self.test_sequence.add_log_lines(
+            [
+             # Start running after initial stop.
+             "read packet: $c#00",
+             # Match output line that prints the memory address of the message buffer within the inferior. 
+             # Note we require launch-only testing so we can get inferior otuput.
+             { "type":"output_match", "regex":r"^data address: 0x([0-9a-fA-F]+)\r\n$", "capture":{ 1:"message_address"} },
+             # Now stop the inferior.
+             "read packet: {}".format(chr(03)),
+             # And wait for the stop notification.
+             {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }],
+            True)
+        context = self.expect_gdbremote_sequence()
+        self.assertIsNotNone(context)
+
+        # Grab the message address.
+        self.assertIsNotNone(context.get("message_address"))
+        message_address = int(context.get("message_address"), 16)
+
+        # Hex-encode the test message, adding null termination.
+        hex_encoded_message = TEST_MESSAGE.encode("hex")
+        hex_encoded_message += "00"
+
+        # Write the message to the inferior.
+        self.reset_test_sequence()
+        self.test_sequence.add_log_lines(
+            ["read packet: $M{0:x},{1:x}:{2}#00".format(message_address, len(hex_encoded_message), hex_encoded_message),
+             "send packet: $OK#00",
+             "read packet: $c#00",
+             { "type":"output_match", "regex":r"^message: (.+)\r\n$", "capture":{ 1:"printed_message"} },
+             "send packet: $W00#00",
+            ], True)
+        context = self.expect_gdbremote_sequence()
+        self.assertIsNotNone(context)
+
+        # Ensure what we read from inferior memory is what we wrote.
+        printed_message = context.get("printed_message")
+        self.assertIsNotNone(printed_message)
+        self.assertEquals(printed_message, TEST_MESSAGE)
+
+    @debugserver_test
+    @dsym_test
+    def test_written_M_content_reads_back_correctly_debugserver_dsym(self):
+        self.init_debugserver_test()
+        self.buildDsym()
+        self.set_inferior_startup_launch()
+        self.written_M_content_reads_back_correctly()
+
+    @llgs_test
+    @dwarf_test
+    @unittest2.expectedFailure()
+    def test_written_M_content_reads_back_correctly_llgs_dwarf(self):
+        self.init_llgs_test()
+        self.buildDwarf()
+        self.set_inferior_startup_launch()
+        self.written_M_content_reads_back_correctly()
+
 
 if __name__ == '__main__':
     unittest2.main()

Modified: lldb/trunk/test/tools/lldb-gdbserver/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/main.cpp?rev=210594&r1=210593&r2=210594&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-gdbserver/main.cpp (original)
+++ lldb/trunk/test/tools/lldb-gdbserver/main.cpp Tue Jun 10 17:15:56 2014
@@ -24,6 +24,7 @@ static const char *const RETVAL_PREFIX
 static const char *const SLEEP_PREFIX                = "sleep:";
 static const char *const STDERR_PREFIX               = "stderr:";
 static const char *const SET_MESSAGE_PREFIX          = "set-message:";
+static const char *const PRINT_MESSAGE_COMMAND       = "print-message:";
 static const char *const GET_DATA_ADDRESS_PREFIX     = "get-data-address-hex:";
 static const char *const GET_STACK_ADDRESS_COMMAND   = "get-stack-address-hex:";
 static const char *const GET_HEAP_ADDRESS_COMMAND    = "get-heap-address-hex:";
@@ -264,6 +265,12 @@ int main (int argc, char **argv)
 			g_message[sizeof (g_message) - 1] = '\0';
 
 		}
+		else if (std::strstr (argv[i], PRINT_MESSAGE_COMMAND))
+		{
+			pthread_mutex_lock (&g_print_mutex);
+            printf ("message: %s\n", g_message);
+			pthread_mutex_unlock (&g_print_mutex);
+		}
         else if (std::strstr (argv[i], GET_DATA_ADDRESS_PREFIX))
         {
             volatile void *data_p = nullptr;





More information about the lldb-commits mailing list