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.

llvm-svn: 114708
This commit is contained in:
Johnny Chen 2010-09-23 23:35:28 +00:00
parent c0aed7179a
commit b052f6c595
5 changed files with 93 additions and 11 deletions

View File

@ -483,7 +483,7 @@ class TestBase(unittest2.TestCase):
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"

View File

@ -3,14 +3,22 @@ Test that variables of basic types are displayed correctly.
"""
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 @@ class BasicTypesTestCase(TestBase):
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.generic_type_tester("int")
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__':

View File

@ -125,8 +125,8 @@ main (int argc, char const *argv[])
#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 @@ main (int argc, char const *argv[])
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);

View File

@ -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"

9
lldb/test/types/long.cpp Normal file
View File

@ -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"