[Lldb-commits] [lldb] r114708 - in /lldb/trunk/test: lldbtest.py types/TestBasicTypes.py types/basic_type.cpp types/int.cpp types/long.cpp
Johnny Chen
johnny.chen at apple.com
Thu Sep 23 16:35:28 PDT 2010
Author: johnny
Date: Thu Sep 23 18:35:28 2010
New Revision: 114708
URL: http://llvm.org/viewvc/llvm-project?rev=114708&view=rev
Log:
Added a generic_type_tester() to the TestBasicTypes class to be used for
testing various combinations of displaying variales of basic types.
The generic_type_tester() works by first capturing the golden output produced
by the printf stmts of ./a.out, creating a list of (var, value) pairs, and then
running the a.out to a stop point, and comparing the 'frame variable var' output
against the list of (var, value) pairs.
Modified int_type() and added long_type() to use generic_type_tester().
Also modified TestBase.expect() such that substring matching also return ok if
the substring starts at the 0-th position.
Added:
lldb/trunk/test/types/long.cpp
Modified:
lldb/trunk/test/lldbtest.py
lldb/trunk/test/types/TestBasicTypes.py
lldb/trunk/test/types/basic_type.cpp
lldb/trunk/test/types/int.cpp
Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=114708&r1=114707&r2=114708&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Thu Sep 23 18:35:28 2010
@@ -483,7 +483,7 @@
keepgoing = matched if matching else not matched
if substrs and keepgoing:
for str in substrs:
- matched = output.find(str) > 0
+ matched = output.find(str) != -1
if trace:
print >> sys.stderr, "%s sub string: %s" % (heading, str)
print >> sys.stderr, "Matched" if matched else "Not matched"
Modified: lldb/trunk/test/types/TestBasicTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/types/TestBasicTypes.py?rev=114708&r1=114707&r2=114708&view=diff
==============================================================================
--- lldb/trunk/test/types/TestBasicTypes.py (original)
+++ lldb/trunk/test/types/TestBasicTypes.py Thu Sep 23 18:35:28 2010
@@ -3,14 +3,22 @@
"""
import os, time
+import re
import unittest2
import lldb
from lldbtest import *
+def Msg(var, val):
+ return "'frame variable %s' matches the compiler's output: %s" % (var, val)
+
class BasicTypesTestCase(TestBase):
mydir = "types"
+ # This is the pattern by design to match the " var = 'value'" output from
+ # printf() stmts (see basic_type.cpp).
+ pattern = re.compile(" (\*?a[^=]*) = '([^=]*)'$")
+
def test_int_type_with_dsym(self):
"""Test that int-type variables are displayed correctly."""
d = {'CXX_SOURCES': 'int.cpp'}
@@ -25,17 +33,82 @@
self.setTearDownCleanup(dictionary=d)
self.int_type()
+ def test_long_type_with_dsym(self):
+ """Test that long-type variables are displayed correctly."""
+ d = {'CXX_SOURCES': 'long.cpp'}
+ self.buildDsym(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ self.long_type()
+
+ def test_long_type_with_dwarf(self):
+ """Test that long-type variables are displayed correctly."""
+ d = {'CXX_SOURCES': 'long.cpp'}
+ self.buildDwarf(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ self.long_type()
+
def int_type(self):
"""Test that int-type variables are displayed correctly."""
- self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+ self.generic_type_tester("int")
- self.runCmd("breakpoint set --name Puts")
+ def long_type(self):
+ """Test that long-type variables are displayed correctly."""
+ self.generic_type_tester("long")
+
+ def generic_type_tester(self, type):
+ """Test that variables with basic types are displayed correctly."""
+
+ # First, capture the golden output emitted by the oracle, i.e., the
+ # series of printf statements.
+ go = system("./a.out")
+ # This golden list contains a list of (variable, value) pairs extracted
+ # from the golden output.
+ gl = []
+
+ # Scan the golden output line by line, looking for the pattern:
+ #
+ # variable = 'value'
+ #
+ # Filter out the following lines, for the time being:
+ #
+ # 'a_ref = ...'
+ # 'a_class_ref.m_a = ...'
+ # 'a_class_ref.m_b = ...'
+ # 'a_struct_ref.a = ...'
+ # 'a_struct_ref.b = ...'
+ # 'a_union_zero_ref.a = ...'
+ # 'a_union_nonzero_ref.u.a = ...'
+ #
+ # rdar://problem/8471016 frame variable a_ref should display the referenced value as well
+ # rdar://problem/8470987 frame variable a_class_ref.m_a does not work
+ notnow = set(['a_ref',
+ 'a_class_ref.m_a', 'a_class_ref.m_b',
+ 'a_struct_ref.a', 'a_struct_ref.b',
+ 'a_union_zero_ref.a', 'a_union_nonzero_ref.u.a'])
+ for line in go.split(os.linesep):
+ match = self.pattern.search(line)
+ if match:
+ var, val = match.group(1), match.group(2)
+ if var in notnow:
+ continue
+ gl.append((var, val))
+ #print "golden list:", gl
+ # Bring the program to the point where we can issue a series of
+ # 'frame variable' command.
+ self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+ self.runCmd("breakpoint set --name Puts")
self.runCmd("run", RUN_SUCCEEDED)
-
self.runCmd("thread step-out", STEP_OUT_SUCCEEDED)
- self.runCmd("frame variable a")
+ # Now iterate through the golden list, comparing against the output from
+ # 'frame variable var'.
+ for var, val in gl:
+ self.runCmd("frame variable %s" % var)
+ output = self.res.GetOutput()
+ self.expect(output, Msg(var, val), exe=False,
+ patterns = ["\(%s.*\)" % type],
+ substrs = [" %s = %s" % (var, val)])
if __name__ == '__main__':
Modified: lldb/trunk/test/types/basic_type.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/types/basic_type.cpp?rev=114708&r1=114707&r2=114708&view=diff
==============================================================================
--- lldb/trunk/test/types/basic_type.cpp (original)
+++ lldb/trunk/test/types/basic_type.cpp Thu Sep 23 18:35:28 2010
@@ -125,8 +125,8 @@
#ifdef T_PRINTF_FORMAT
printf ("%s: a = '" T_PRINTF_FORMAT "'\n", T_CSTR, a);
- printf ("%s*: a = %p => '" T_PRINTF_FORMAT "'\n", T_CSTR, a_ptr, *a_ptr);
- printf ("%s&: a = %p => '" T_PRINTF_FORMAT "'\n", T_CSTR, &a_ref, a_ref);
+ printf ("%s*: %p => *a_ptr = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_ptr, *a_ptr);
+ printf ("%s&: @%p => a_ref = '" T_PRINTF_FORMAT "'\n", T_CSTR, &a_ref, a_ref);
printf ("%s[2]: a_array_bounded[0] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_bounded[0]);
printf ("%s[2]: a_array_bounded[1] = '" T_PRINTF_FORMAT "'\n", T_CSTR, a_array_bounded[1]);
@@ -152,9 +152,9 @@
printf ("(a_union_zero_t*) a_union_zero_ptr = %p, a_union_zero_ptr->a = '" T_PRINTF_FORMAT "'\n", a_union_zero_ptr, a_union_zero_ptr->a);
printf ("(a_union_zero_t&) a_union_zero_ref = %p, a_union_zero_ref.a = '" T_PRINTF_FORMAT "'\n", &a_union_zero_ref, a_union_zero_ref.a);
- printf ("(a_union_nonzero_t) a_union_nonzero.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero.u.a);
- printf ("(a_union_nonzero_t*) a_union_nonzero_ptr = %p, a_union_nonzero_ptr->a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero_ptr, a_union_nonzero_ptr->u.a);
- printf ("(a_union_nonzero_t&) a_union_nonzero_ref = %p, a_union_nonzero_ref.a = '" T_PRINTF_FORMAT "'\n", &a_union_nonzero_ref, a_union_nonzero_ref.u.a);
+ printf ("(a_union_nonzero_t) a_union_nonzero.u.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero.u.a);
+ printf ("(a_union_nonzero_t*) a_union_nonzero_ptr = %p, a_union_nonzero_ptr->u.a = '" T_PRINTF_FORMAT "'\n", a_union_nonzero_ptr, a_union_nonzero_ptr->u.a);
+ printf ("(a_union_nonzero_t&) a_union_nonzero_ref = %p, a_union_nonzero_ref.u.a = '" T_PRINTF_FORMAT "'\n", &a_union_nonzero_ref, a_union_nonzero_ref.u.a);
printf ("(a_struct_t[2]) a_struct_array_bounded[0].a = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[0].a);
printf ("(a_struct_t[2]) a_struct_array_bounded[0].b = '" T_PRINTF_FORMAT "'\n", a_struct_array_bounded[0].b);
Modified: lldb/trunk/test/types/int.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/types/int.cpp?rev=114708&r1=114707&r2=114708&view=diff
==============================================================================
--- lldb/trunk/test/types/int.cpp (original)
+++ lldb/trunk/test/types/int.cpp Thu Sep 23 18:35:28 2010
@@ -3,7 +3,7 @@
#define T_VALUE_1 11001110
#define T_VALUE_2 22002220
#define T_VALUE_3 33003330
-#define T_VALUE_4 44044440
+#define T_VALUE_4 44004440
#define T_PRINTF_FORMAT "%i"
#include "basic_type.cpp"
Added: lldb/trunk/test/types/long.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/types/long.cpp?rev=114708&view=auto
==============================================================================
--- lldb/trunk/test/types/long.cpp (added)
+++ lldb/trunk/test/types/long.cpp Thu Sep 23 18:35:28 2010
@@ -0,0 +1,9 @@
+#define T long
+#define T_CSTR "long"
+#define T_VALUE_1 110011101111
+#define T_VALUE_2 220022202222
+#define T_VALUE_3 330033303333
+#define T_VALUE_4 440044404444
+#define T_PRINTF_FORMAT "%ld"
+
+#include "basic_type.cpp"
More information about the lldb-commits
mailing list