[Lldb-commits] [lldb] r135008 - in /lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array: ./ Makefile TestDataFormatterSmartArray.py main.cpp

Enrico Granata granata.enrico at gmail.com
Tue Jul 12 15:57:47 PDT 2011


Author: enrico
Date: Tue Jul 12 17:57:47 2011
New Revision: 135008

URL: http://llvm.org/viewvc/llvm-project?rev=135008&view=rev
Log:
test cases

Added:
    lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/
    lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/Makefile
    lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py
    lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/main.cpp

Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/Makefile?rev=135008&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/Makefile (added)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/Makefile Tue Jul 12 17:57:47 2011
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py?rev=135008&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py (added)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py Tue Jul 12 17:57:47 2011
@@ -0,0 +1,291 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class DataFormatterTestCase(TestBase):
+
+    mydir = os.path.join("functionalities", "data-formatter", "data-formatter-smart-array")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_with_dsym_and_run_command(self):
+        """Test data formatter commands."""
+        self.buildDsym()
+        self.data_formatter_commands()
+
+    def test_with_dwarf_and_run_command(self):
+        """Test data formatter commands."""
+        self.buildDwarf()
+        self.data_formatter_commands()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number to break at.
+        self.line = line_number('main.cpp', '// Set break point at this line.')
+
+    def data_formatter_commands(self):
+        """Test that that file and class static variables display correctly."""
+        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+        self.expect("breakpoint set -f main.cpp -l %d" % self.line,
+                    BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
+                        self.line)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stopped',
+                       'stop reason = breakpoint'])
+        
+        # This is the function to remove the custom formats in order to have a
+        # clean slate for the next test case.
+        def cleanup():
+            self.runCmd('type format clear', check=False)
+            self.runCmd('type summary clear', check=False)
+
+        # Execute the cleanup function during test case tear down.
+        self.addTearDownHook(cleanup)
+
+# check that we are not looping here
+        self.runCmd("type summary add -f \"${var%V}\" SomeData")
+
+        self.expect("frame variable data",
+            substrs = ['error'])
+# ${var%s}
+        self.runCmd("type summary add -f \"ptr = ${var%s}\" \"char *\"")
+
+        self.expect("frame variable strptr",
+            substrs = ['ptr = \"',
+                       'Hello world!'])
+
+        self.expect("frame variable other.strptr",
+            substrs = ['ptr = \"',
+                        'Nested Hello world!'])
+        
+        self.runCmd("type summary add -f \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\"")
+        
+        self.expect("frame variable strarr",
+                    substrs = ['arr = \"',
+                               'Hello world!'])
+        
+        self.expect("frame variable other.strarr",
+                    substrs = ['arr = \"',
+                               'Nested Hello world!'])
+
+# ${var%c}
+        self.runCmd("type summary add -f \"ptr = ${var%c}\" \"char *\"")
+    
+        self.expect("frame variable strptr",
+                substrs = ['ptr = \"',
+                           'Hello world!'])
+    
+        self.expect("frame variable other.strptr",
+                substrs = ['ptr = \"',
+                           'Nested Hello world!'])
+
+        self.runCmd("type summary add -f \"arr = ${var%c}\" -x \"char \\[[0-9]+\\]\"")
+
+        self.expect("frame variable strarr",
+                    substrs = ['arr = \"',
+                               'Hello world!'])
+
+        self.expect("frame variable other.strarr",
+                    substrs = ['arr = \"',
+                               'Nested Hello world!'])
+        
+# ${var%char[]}
+        self.runCmd("type summary add -f \"arr = ${var%char[]}\" -x \"char \\[[0-9]+\\]\"")
+
+        self.expect("frame variable strarr",
+                    substrs = ['arr = \"',
+                               'Hello world!'])
+
+        self.expect("frame variable other.strarr",
+                    substrs = ['arr = ',
+                               'Nested Hello world!'])
+
+        self.runCmd("type summary add -f \"ptr = ${var%char[]}\" \"char *\"")
+
+        self.expect("frame variable strptr",
+            substrs = ['ptr = \"',
+            'Hello world!'])
+        
+        self.expect("frame variable other.strptr",
+            substrs = ['ptr = \"',
+            'Nested Hello world!'])
+
+# ${var%a}
+        self.runCmd("type summary add -f \"arr = ${var%a}\" -x \"char \\[[0-9]+\\]\"")
+
+        self.expect("frame variable strarr",
+                    substrs = ['arr = \"',
+                               'Hello world!'])
+
+        self.expect("frame variable other.strarr",
+                    substrs = ['arr = ',
+                               'Nested Hello world!'])
+
+        self.runCmd("type summary add -f \"ptr = ${var%a}\" \"char *\"")
+
+        self.expect("frame variable strptr",
+                    substrs = ['ptr = \"',
+                               'Hello world!'])
+
+        self.expect("frame variable other.strptr",
+                    substrs = ['ptr = \"',
+                               'Nested Hello world!'])
+
+        self.runCmd("type summary add -f \"ptr = ${var[]%char[]}\" \"char *\"")
+        
+# I do not know the size of the data, but you are asking for a full array slice..
+# use the ${var%char[]} to obtain a string as result
+        self.expect("frame variable strptr", matching=False,
+                    substrs = ['ptr = \"',
+                               'Hello world!'])
+        
+        self.expect("frame variable other.strptr", matching=False,
+                    substrs = ['ptr = \"',
+                               'Nested Hello world!'])
+
+# You asked an array-style printout...
+        self.runCmd("type summary add -f \"ptr = ${var[0-1]%char[]}\" \"char *\"")
+        
+        self.expect("frame variable strptr",
+                    substrs = ['ptr = ',
+                               '[{H},{e}]'])
+        
+        self.expect("frame variable other.strptr",
+                    substrs = ['ptr = ',
+                               '[{N},{e}]'])
+
+# using [] is required here
+        self.runCmd("type summary add -f \"arr = ${var%x}\" \"int [5]\"")
+        
+        self.expect("frame variable intarr",
+                    substrs = ['intarr = {',
+                               '[0] = 1'])
+        
+        self.expect("frame variable other.intarr",
+                    substrs = ['intarr = {',
+                               '[0] = 9'])
+
+        self.runCmd("type summary add -f \"arr = ${var[]%x}\" \"int [5]\"")
+        
+        self.expect("frame variable intarr",
+                    substrs = ['intarr = arr =',
+                               '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
+        
+        self.expect("frame variable other.intarr",
+                    substrs = ['intarr = arr =',
+                               '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
+
+# printing each array item as an array
+        self.runCmd("type summary add -f \"arr = ${var[]%uint32_t[]}\" \"int [5]\"")
+        
+        self.expect("frame variable intarr",
+                    substrs = ['intarr = arr =',
+                               '{0x00000001},{0x00000001},{0x00000002},{0x00000003},{0x00000005}'])
+        
+        self.expect("frame variable other.intarr",
+                    substrs = ['intarr = arr = ',
+                               '{0x00000009},{0x00000008},{0x00000007},{0x00000006},{0x00000005}'])
+
+# printing full array as an array
+        self.runCmd("type summary add -f \"arr = ${var%uint32_t[]}\" \"int [5]\"")
+        
+        self.expect("frame variable intarr",
+                    substrs = ['intarr = arr =',
+                               '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005'])
+        
+        self.expect("frame variable other.intarr",
+                    substrs = ['intarr = arr =',
+                               '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005'])
+
+# printing each array item as an array
+        self.runCmd("type summary add -f \"arr = ${var[]%float32[]}\" \"float [7]\"")
+        
+        self.expect("frame variable flarr",
+                    substrs = ['flarr = arr =',
+                               '{78.5},{77.4},{78},{76.1},{76.7},{76.8},{77}'])
+        
+        self.expect("frame variable other.flarr",
+                    substrs = ['flarr = arr = ',
+                               '{25.5},{25.7},{25.9},{26.4},{27.1},{27.3},{26.9}'])
+        
+# printing full array as an array
+        self.runCmd("type summary add -f \"arr = ${var%float32[]}\" \"float [7]\"")
+        
+        self.expect("frame variable flarr",
+                    substrs = ['flarr = arr =',
+                               '78.5,77.4,78,76.1,76.7,76.8,77'])
+        
+        self.expect("frame variable other.flarr",
+                    substrs = ['flarr = arr =',
+                               '25.5,25.7,25.9,26.4,27.1,27.3,26.9'])
+
+# using array smart summary strings for pointers should make no sense
+        self.runCmd("type summary add -f \"arr = ${var%float32[]}\" \"float *\"")
+        self.runCmd("type summary add -f \"arr = ${var%int32_t[]}\" \"int *\"")
+
+        self.expect("frame variable flptr", matching=False,
+                    substrs = ['78.5,77.4,78,76.1,76.7,76.8,77'])
+        
+        self.expect("frame variable intptr", matching=False,
+                    substrs = ['1,1,2,3,5'])
+
+# use y and Y
+        self.runCmd("type summary add -f \"arr = ${var%y}\" \"float [7]\"")
+        self.runCmd("type summary add -f \"arr = ${var%y}\" \"int [5]\"")
+
+        self.expect("frame variable flarr",
+                    substrs = ['flarr = arr =',
+                               '00 00 9d 42,cd cc 9a 42,00 00 9c 42,33 33 98 42,66 66 99 42,9a 99 99 42,00 00 9a 42'])
+        
+        self.expect("frame variable other.flarr",
+                    substrs = ['flarr = arr =',
+                               '00 00 cc 41,9a 99 cd 41,33 33 cf 41,33 33 d3 41,cd cc d8 41,66 66 da 41,33 33 d7 41'])
+
+        self.expect("frame variable intarr",
+                    substrs = ['intarr = arr =',
+                               '01 00 00 00,01 00 00 00,02 00 00 00,03 00 00 00,05 00 00 00'])
+        
+        self.expect("frame variable other.intarr",
+                    substrs = ['intarr = arr = ',
+                               '09 00 00 00,08 00 00 00,07 00 00 00,06 00 00 00,05 00 00 00'])
+                    
+        self.runCmd("type summary add -f \"arr = ${var%Y}\" \"float [7]\"")
+        self.runCmd("type summary add -f \"arr = ${var%Y}\" \"int [5]\"")
+            
+        self.expect("frame variable flarr",
+                    substrs = ['flarr = arr =',
+                               '...B,cd cc 9a 42',
+                               'ff.B,9a 99 99 42'])
+        
+        self.expect("frame variable other.flarr",
+                    substrs = ['flarr = arr =',
+                               '...A,33 33 cf 41',
+                               '33.A,cd cc d8 41'])
+        
+        self.expect("frame variable intarr",
+                    substrs = ['intarr = arr =',
+                               '....,01 00 00 00',
+                               '....,05 00 00 00'])
+        
+        self.expect("frame variable other.intarr",
+                    substrs = ['intarr = arr = ',
+                               '09 00 00 00',
+                               '....,07 00 00 00'])
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/main.cpp?rev=135008&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/main.cpp (added)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-smart-array/main.cpp Tue Jul 12 17:57:47 2011
@@ -0,0 +1,65 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+struct SomeData
+{
+    int x;
+};
+
+struct SomeOtherData
+{
+    char strarr[32];
+    char *strptr;
+    int intarr[5];
+    float flarr[7];
+    
+    SomeOtherData()
+    {
+        strcpy(strarr,"Nested Hello world!");
+        strptr = new char[128];
+        strcpy(strptr,"Nested Hello world!");
+        intarr[0] = 9;
+        intarr[1] = 8;
+        intarr[2] = 7;
+        intarr[3] = 6;
+        intarr[4] = 5;
+        
+        flarr[0] = 25.5;
+        flarr[1] = 25.7;
+        flarr[2] = 25.9;
+        flarr[3] = 26.4;
+        flarr[4] = 27.1;
+        flarr[5] = 27.3;
+        flarr[6] = 26.9;
+    }
+};
+
+int main (int argc, const char * argv[])
+{
+    char strarr[32] = "Hello world!";
+    char *strptr = NULL;
+    strptr = "Hello world!";
+    int intarr[5] = {1,1,2,3,5};
+    float flarr[7] = {78.5,77.4,78.0,76.1,76.7,76.8,77.0};
+    
+    SomeData data;
+    
+    SomeOtherData other;
+    
+    float* flptr = flarr;
+    int* intptr = intarr;
+    
+    return 0; // Set break point at this line.
+    
+}





More information about the lldb-commits mailing list