[Lldb-commits] [lldb] r270831 - Avoid using stdio in TestVirtual
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu May 26 01:38:04 PDT 2016
Author: labath
Date: Thu May 26 03:38:02 2016
New Revision: 270831
URL: http://llvm.org/viewvc/llvm-project?rev=270831&view=rev
Log:
Avoid using stdio in TestVirtual
Summary:
using stdio in tests does not work on windows, and it is not completely reliable on linux.
Avoid using stdio in this test, as it is not necessary for this purpose.
Reviewers: clayborg
Subscribers: lldb-commits, zturner
Differential Revision: http://reviews.llvm.org/D20567
Modified:
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp
Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py?rev=270831&r1=270830&r2=270831&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/TestVirtual.py Thu May 26 03:38:02 2016
@@ -22,9 +22,6 @@ class CppVirtualMadness(TestBase):
# 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 @@ class CppVirtualMadness(TestBase):
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 @@ class CppVirtualMadness(TestBase):
#
# 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)
Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp?rev=270831&r1=270830&r2=270831&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/virtual/main.cpp Thu May 26 03:38:02 2016
@@ -84,17 +84,20 @@ int main (int argc, char const *argv[],
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()
More information about the lldb-commits
mailing list