[Lldb-commits] [lldb] r114600 - in /lldb/trunk/test: lldbtest.py plugins/darwin.py types/TestBasicTypes.py

Johnny Chen johnny.chen at apple.com
Wed Sep 22 16:00:20 PDT 2010


Author: johnny
Date: Wed Sep 22 18:00:20 2010
New Revision: 114600

URL: http://llvm.org/viewvc/llvm-project?rev=114600&view=rev
Log:
Checked in an initial template for the types directory.  Right now, it doesn't
actually test-and-compare anything yet.  The lldbtest.TestBase has an added
method setTearDownCleanup(dictionary=None) to facilitate running the cleanup
right after each data type test is run.  The test case can pass a dictionary
object when registering the test case cleanup.

There is currently only int_type test in the repository.

Added:
    lldb/trunk/test/types/TestBasicTypes.py
Modified:
    lldb/trunk/test/lldbtest.py
    lldb/trunk/test/plugins/darwin.py

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=114600&r1=114599&r2=114600&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Wed Sep 22 18:00:20 2010
@@ -132,6 +132,8 @@
 
 BREAKPOINT_HIT_ONCE = "Breakpoint resolved with hit cout = 1"
 
+STEP_OUT_SUCCEEDED = "Thread step-out succeeded"
+
 STOPPED_DUE_TO_BREAKPOINT = "Process state is stopped due to breakpoint"
 
 STOPPED_DUE_TO_STEP_IN = "Process state is stopped due to step in"
@@ -354,6 +356,14 @@
         # And the result object.
         self.res = lldb.SBCommandReturnObject()
 
+        # These are for customized teardown cleanup.
+        self.dict = None
+        self.doTearDownCleanup = False
+
+    def setTearDownCleanup(self, dictionary=None):
+        self.dict = dictionary
+        self.doTearDownCleanup = True
+
     def tearDown(self):
         #import traceback
         #traceback.print_stack()
@@ -367,6 +377,12 @@
 
         del self.dbg
 
+        # Perform registered teardown cleanup.
+        if self.doTearDownCleanup:
+            module = __import__(sys.platform)
+            if not module.cleanup(dictionary=self.dict):
+                raise Exception("Don't know how to do cleanup")
+
     def runCmd(self, cmd, msg=None, check=True, trace=False, setCookie=True):
         """
         Ask the command interpreter to handle the command and then check its
@@ -549,22 +565,22 @@
             # End of while loop.
 
 
-    def buildDefault(self, compiler=None):
+    def buildDefault(self, architecture=None, compiler=None, dictionary=None):
         """Platform specific way to build the default binaries."""
         module = __import__(sys.platform)
-        if not module.buildDefault(compiler):
+        if not module.buildDefault(architecture, compiler, dictionary):
             raise Exception("Don't know how to build default binary")
 
-    def buildDsym(self, compiler=None):
+    def buildDsym(self, architecture=None, compiler=None, dictionary=None):
         """Platform specific way to build binaries with dsym info."""
         module = __import__(sys.platform)
-        if not module.buildDsym(compiler):
+        if not module.buildDsym(architecture, compiler, dictionary):
             raise Exception("Don't know how to build binary with dsym")
 
-    def buildDwarf(self, compiler=None):
+    def buildDwarf(self, architecture=None, compiler=None, dictionary=None):
         """Platform specific way to build binaries with dwarf maps."""
         module = __import__(sys.platform)
-        if not module.buildDwarf(compiler):
+        if not module.buildDwarf(architecture, compiler, dictionary):
             raise Exception("Don't know how to build binary with dwarf")
 
     def DebugSBValue(self, frame, val):

Modified: lldb/trunk/test/plugins/darwin.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/plugins/darwin.py?rev=114600&r1=114599&r2=114600&view=diff
==============================================================================
--- lldb/trunk/test/plugins/darwin.py (original)
+++ lldb/trunk/test/plugins/darwin.py Wed Sep 22 18:00:20 2010
@@ -17,6 +17,18 @@
 
 #print "Hello, darwin plugin!"
 
+def getArchSpec(architecture):
+    """
+    Helper function to return the key-value string to specify the architecture
+    used for the make system.
+    """
+    arch = architecture if architecture else None
+    if not arch and "LLDB_ARCH" in os.environ:
+        arch = os.environ["LLDB_ARCH"]
+
+    # Note the leading space character.
+    return (" ARCH=" + arch) if arch else ""
+
 def getCCSpec(compiler):
     """
     Helper function to return the key-value string to specify the compiler
@@ -29,50 +41,57 @@
     # Note the leading space character.
     return (" CC=" + cc) if cc else ""
 
-def getArchSpec(architecture):
+def getCmdLine(d):
     """
-    Helper function to return the key-value string to specify the architecture
-    used for the make system.
+    Helper function to return a properly formatted command line argument(s)
+    string used for the make system.
     """
-    arch = architecture if architecture else None
-    if not arch and "LLDB_ARCH" in os.environ:
-        arch = os.environ["LLDB_ARCH"]
+
+    # If d is None or an empty mapping, just return an empty string.
+    if not d:
+        return ""
+
+    cmdline = " ".join(["%s='%s'" % (k, v) for k, v in d.items()])
 
     # Note the leading space character.
-    return (" ARCH=" + arch) if arch else ""
+    return " " + cmdline
 
 
-def buildDefault(architecture=None, compiler=None):
+def buildDefault(architecture=None, compiler=None, dictionary=None):
     """Build the binaries the default way."""
     lldbtest.system(["/bin/sh", "-c",
                      "make clean; make"
-                     + getArchSpec(architecture) + getCCSpec(compiler)])
+                     + getArchSpec(architecture) + getCCSpec(compiler)
+                     + getCmdLine(dictionary)])
 
     # True signifies that we can handle building default.
     return True
 
-def buildDsym(architecture=None, compiler=None):
+def buildDsym(architecture=None, compiler=None, dictionary=None):
     """Build the binaries with dsym debug info."""
     lldbtest.system(["/bin/sh", "-c",
                      "make clean; make MAKE_DSYM=YES"
-                     + getArchSpec(architecture) + getCCSpec(compiler)])
+                     + getArchSpec(architecture) + getCCSpec(compiler)
+                     + getCmdLine(dictionary)])
 
     # True signifies that we can handle building dsym.
     return True
 
-def buildDwarf(architecture=None, compiler=None):
+def buildDwarf(architecture=None, compiler=None, dictionary=None):
     """Build the binaries with dwarf debug info."""
     lldbtest.system(["/bin/sh", "-c",
                      "make clean; make MAKE_DSYM=NO"
-                     + getArchSpec(architecture) + getCCSpec(compiler)])
+                     + getArchSpec(architecture) + getCCSpec(compiler)
+                     + getCmdLine(dictionary)])
 
     # True signifies that we can handle building dsym.
     return True
 
-def cleanup():
-    """Do class-wide cleanup after the test."""
+def cleanup(dictionary=None):
+    """Perform a platform-specific cleanup after the test."""
     if os.path.isfile("Makefile"):
-        lldbtest.system(["/bin/sh", "-c", "make clean"])
+        lldbtest.system(["/bin/sh", "-c", "make clean" + getCmdLine(dictionary)]
+                        )
 
     # True signifies that we can handle building dsym.
     return True

Added: lldb/trunk/test/types/TestBasicTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/types/TestBasicTypes.py?rev=114600&view=auto
==============================================================================
--- lldb/trunk/test/types/TestBasicTypes.py (added)
+++ lldb/trunk/test/types/TestBasicTypes.py Wed Sep 22 18:00:20 2010
@@ -0,0 +1,45 @@
+"""
+Test that variables of basic types are displayed correctly.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class BasicTypesTestCase(TestBase):
+
+    mydir = "types"
+
+    def test_int_type_with_dsym(self):
+        """Test that int-type variables are displayed correctly."""
+        d = {'CXX_SOURCES': 'int.cpp'}
+        self.buildDsym(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.int_type()
+
+    def test_int_type_with_dwarf(self):
+        """Test that int-type variables are displayed correctly."""
+        d = {'CXX_SOURCES': 'int.cpp'}
+        self.buildDwarf(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.int_type()
+
+    def int_type(self):
+        """Test that int-type variables are displayed correctly."""
+        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")
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()





More information about the lldb-commits mailing list