[Lldb-commits] [PATCH] D20567: Avoid using stdio in TestVirtual

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu May 26 01:44:29 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL270831: Avoid using stdio in TestVirtual (authored by labath).

Changed prior to commit:
  http://reviews.llvm.org/D20567?vs=58418&id=58579#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20567

Files:
  lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py
  lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp

Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp
@@ -84,17 +84,20 @@
     C *c_as_C = new C();
     A *c_as_A = c_as_C;
 
-    printf ("a_as_A->a() = '%s'\n", a_as_A->a());
-    printf ("a_as_A->b() = '%s'\n", a_as_A->b());
-    printf ("a_as_A->c() = '%s'\n", a_as_A->c());
-    printf ("b_as_A->a() = '%s'\n", b_as_A->a());
-    printf ("b_as_A->b() = '%s'\n", b_as_A->b());
-    printf ("b_as_A->c() = '%s'\n", b_as_A->c());
-    printf ("b_as_B->aa() = '%s'\n", b_as_B->aa());
-    printf ("c_as_A->a() = '%s'\n", c_as_A->a());
-    printf ("c_as_A->b() = '%s'\n", c_as_A->b());
-    printf ("c_as_A->c() = '%s'\n", c_as_A->c());
-    printf ("c_as_C->aa() = '%s'\n", c_as_C->aa());
+    char golden[4096];
+    char *p = golden;
+    char *end = p + sizeof golden;
+    p += snprintf(p, end-p, "a_as_A->a() = '%s'\n", a_as_A->a());
+    p += snprintf(p, end-p, "a_as_A->b() = '%s'\n", a_as_A->b());
+    p += snprintf(p, end-p, "a_as_A->c() = '%s'\n", a_as_A->c());
+    p += snprintf(p, end-p, "b_as_A->a() = '%s'\n", b_as_A->a());
+    p += snprintf(p, end-p, "b_as_A->b() = '%s'\n", b_as_A->b());
+    p += snprintf(p, end-p, "b_as_A->c() = '%s'\n", b_as_A->c());
+    p += snprintf(p, end-p, "b_as_B->aa() = '%s'\n", b_as_B->aa());
+    p += snprintf(p, end-p, "c_as_A->a() = '%s'\n", c_as_A->a());
+    p += snprintf(p, end-p, "c_as_A->b() = '%s'\n", c_as_A->b());
+    p += snprintf(p, end-p, "c_as_A->c() = '%s'\n", c_as_A->c());
+    p += snprintf(p, end-p, "c_as_C->aa() = '%s'\n", c_as_C->aa());
     puts("");// Set first breakpoint here.
     // then evaluate:
     // expression a_as_A->a()
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py
@@ -22,9 +22,6 @@
     # printf() stmts (see main.cpp).
     pattern = re.compile("^([^=]*) = '([^=]*)'$")
 
-    # Assert message.
-    PRINTF_OUTPUT_GROKKED = "The printf output from compiled code is parsed correctly"
-
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)
@@ -58,11 +55,13 @@
         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
         self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
 
-        # First, capture the golden output from the program itself from the
-        # series of printf statements.
-        stdout = process.GetSTDOUT(1024)
-        
-        self.assertIsNotNone(stdout, "Encountered an error reading the process's output")
+        # First, capture the golden output from the program itself.
+        golden = thread.GetFrameAtIndex(0).FindVariable("golden")
+        self.assertTrue(golden.IsValid(), "Encountered an error reading the process's golden variable")
+        error = lldb.SBError()
+        golden_str = process.ReadCStringFromMemory(golden.AddressOf().GetValueAsUnsigned(), 4096, error);
+        self.assertTrue(error.Success())
+        self.assertTrue("c_as_C" in golden_str)
 
         # This golden list contains a list of "my_expr = 'value' pairs extracted
         # from the golden output.
@@ -72,7 +71,7 @@
         #
         #     my_expr = 'value'
         #
-        for line in stdout.split(os.linesep):
+        for line in golden_str.split(os.linesep):
             match = self.pattern.search(line)
             if match:
                 my_expr, val = match.group(1), match.group(2)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20567.58579.patch
Type: text/x-patch
Size: 3825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160526/0893f3cb/attachment-0001.bin>


More information about the lldb-commits mailing list