From b052f6c5951d37e4e481efab5b5cd6b2cfeddd67 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Thu, 23 Sep 2010 23:35:28 +0000 Subject: [PATCH] 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 --- lldb/test/lldbtest.py | 2 +- lldb/test/types/TestBasicTypes.py | 81 +++++++++++++++++++++++++++++-- lldb/test/types/basic_type.cpp | 10 ++-- lldb/test/types/int.cpp | 2 +- lldb/test/types/long.cpp | 9 ++++ 5 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 lldb/test/types/long.cpp diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py index ea9e3228ba21..87111737b447 100644 --- a/lldb/test/lldbtest.py +++ b/lldb/test/lldbtest.py @@ -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" diff --git a/lldb/test/types/TestBasicTypes.py b/lldb/test/types/TestBasicTypes.py index c4aa918d9785..6eb029a3f16d 100644 --- a/lldb/test/types/TestBasicTypes.py +++ b/lldb/test/types/TestBasicTypes.py @@ -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__': diff --git a/lldb/test/types/basic_type.cpp b/lldb/test/types/basic_type.cpp index ca9c217a9fc1..a2e9df305eff 100644 --- a/lldb/test/types/basic_type.cpp +++ b/lldb/test/types/basic_type.cpp @@ -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); diff --git a/lldb/test/types/int.cpp b/lldb/test/types/int.cpp index ec461700de5c..922398b1c6e3 100644 --- a/lldb/test/types/int.cpp +++ b/lldb/test/types/int.cpp @@ -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" diff --git a/lldb/test/types/long.cpp b/lldb/test/types/long.cpp new file mode 100644 index 000000000000..be91a0c92286 --- /dev/null +++ b/lldb/test/types/long.cpp @@ -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"