[Lldb-commits] [lldb] r112606 - in /lldb/trunk/test: dotest.py lldbtest.py plugins/ plugins/darwin.py

Johnny Chen johnny.chen at apple.com
Tue Aug 31 10:42:54 PDT 2010


Author: johnny
Date: Tue Aug 31 12:42:54 2010
New Revision: 112606

URL: http://llvm.org/viewvc/llvm-project?rev=112606&view=rev
Log:
Changed the buildDsym()/buildDwarf() TestBase methods to use a plugin framework
to delegate the building of binaries to a sys.platform-sepcific plugin.

Modified the dotest.py test driver to add the "plugins" directory to the
PYTHONPATH as well.

darwin.py is the Mac OS X plugin module.

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

Modified: lldb/trunk/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=112606&r1=112605&r2=112606&view=diff
==============================================================================
--- lldb/trunk/test/dotest.py (original)
+++ lldb/trunk/test/dotest.py Tue Aug 31 12:42:54 2010
@@ -81,6 +81,7 @@
         sys.exit(-1)
 
     os.environ["LLDB_TEST"] = scriptPath
+    pluginPath = os.path.join(scriptPath, 'plugins')
 
     base = os.path.abspath(os.path.join(scriptPath, os.pardir))
     dbgPath = os.path.join(base, 'build', 'Debug', 'LLDB.framework',
@@ -101,6 +102,7 @@
 
     sys.path.append(lldbPath)
     sys.path.append(scriptPath)
+    sys.path.append(pluginPath)
 
 
 def initTestdirs():

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=112606&r1=112605&r2=112606&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Tue Aug 31 12:42:54 2010
@@ -13,11 +13,11 @@
 LLDB_TEST and PYTHONPATH environment variables, for example:
 
 $ export LLDB_TEST=$PWD
-$ export PYTHONPATH=/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:$LLDB_TEST
+$ export PYTHONPATH=/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:$LLDB_TEST:$LLDB_TEST/plugins
 $ echo $LLDB_TEST
 /Volumes/data/lldb/svn/trunk/test
 $ echo $PYTHONPATH
-/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:/Volumes/data/lldb/svn/trunk/test
+/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:/Volumes/data/lldb/svn/trunk/test:/Volumes/data/lldb/svn/trunk/test/plugins
 $ python function_types/TestFunctionTypes.py
 .
 ----------------------------------------------------------------------
@@ -112,6 +112,12 @@
 import unittest2
 import lldb
 
+if "LLDB_COMMAND_TRACE" in os.environ and os.environ["LLDB_COMMAND_TRACE"]=="YES":
+    traceAlways = True
+else:
+    traceAlways = False
+
+
 #
 # Some commonly used assert messages.
 #
@@ -203,6 +209,51 @@
 def EnvArray():
     return map(lambda k,v: k+"="+v, os.environ.keys(), os.environ.values())
 
+# From 2.7's subprocess.check_output() convenience function.
+def system(*popenargs, **kwargs):
+    r"""Run command with arguments and return its output as a byte string.
+
+    If the exit code was non-zero it raises a CalledProcessError.  The
+    CalledProcessError object will have the return code in the returncode
+    attribute and output in the output attribute.
+
+    The arguments are the same as for the Popen constructor.  Example:
+
+    >>> check_output(["ls", "-l", "/dev/null"])
+    'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'
+
+    The stdout argument is not allowed as it is used internally.
+    To capture standard error in the result, use stderr=STDOUT.
+
+    >>> check_output(["/bin/sh", "-c",
+    ...               "ls -l non_existent_file ; exit 0"],
+    ...              stderr=STDOUT)
+    'ls: non_existent_file: No such file or directory\n'
+    """
+    if 'stdout' in kwargs:
+        raise ValueError('stdout argument not allowed, it will be overridden.')
+    process = Popen(stdout=PIPE, *popenargs, **kwargs)
+    output, unused_err = process.communicate()
+    retcode = process.poll()
+
+    if traceAlways:
+        if isinstance(popenargs, types.StringTypes):
+            args = [popenargs]
+        else:
+            args = list(popenargs)
+        print >> sys.stderr
+        print >> sys.stderr, "os command:", args
+        print >> sys.stderr, "output:", output
+        print >> sys.stderr, "error:", unused_err
+        print >> sys.stderr, "retcode:", retcode
+
+    if retcode:
+        cmd = kwargs.get("args")
+        if cmd is None:
+            cmd = popenargs[0]
+        raise CalledProcessError(retcode, cmd, output=output)
+    return output
+
 
 class TestBase(unittest2.TestCase):
     """This LLDB abstract base class is meant to be subclassed."""
@@ -221,9 +272,6 @@
     # Can be overridden by the LLDB_TIME_WAIT environment variable.
     timeWait = 1.0;
 
-    # os.environ["LLDB_COMMAND_TRACE"], if set to "YES", will turn on this flag.
-    traceAlways = False;
-
     def setUp(self):
         #import traceback
         #traceback.print_stack()
@@ -245,10 +293,6 @@
         if "LLDB_TIME_WAIT" in os.environ:
             self.timeWait = float(os.environ["LLDB_TIME_WAIT"])
 
-        if ("LLDB_COMMAND_TRACE" in os.environ and
-            os.environ["LLDB_COMMAND_TRACE"] == "YES"):
-            self.traceAlways = True
-
         # Create the debugger instance if necessary.
         try:
             self.dbg = lldb.DBG
@@ -288,7 +332,7 @@
         if not cmd or len(cmd) == 0:
             raise Exception("Bad 'cmd' parameter encountered")
 
-        trace = (True if self.traceAlways else trace)
+        trace = (True if traceAlways else trace)
 
         self.runStarted = (cmd.startswith("run") or
                            cmd.startswith("process launch"))
@@ -324,7 +368,7 @@
         'startstr' and matches the substrings contained in 'substrs'.
         """
 
-        trace = (True if self.traceAlways else trace)
+        trace = (True if traceAlways else trace)
 
         # First run the command.
         self.runCmd(cmd, trace = (True if trace else False))
@@ -354,79 +398,32 @@
     def invoke(self, obj, name, trace=False):
         """Use reflection to call a method dynamically with no argument."""
 
-        trace = (True if self.traceAlways else trace)
+        trace = (True if traceAlways else trace)
         
         method = getattr(obj, name)
         import inspect
         self.assertTrue(inspect.ismethod(method),
                         name + "is a method name of object: " + str(obj))
         result = method()
-        if self.traceAlways:
+        if trace:
             print str(method) + ":",  result
         return result
 
-    # From 2.7's subprocess.check_output() convenience function.
-    def system(self, *popenargs, **kwargs):
-        r"""Run command with arguments and return its output as a byte string.
-
-        If the exit code was non-zero it raises a CalledProcessError.  The
-        CalledProcessError object will have the return code in the returncode
-        attribute and output in the output attribute.
-
-        The arguments are the same as for the Popen constructor.  Example:
-
-        >>> check_output(["ls", "-l", "/dev/null"])
-        'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'
-
-        The stdout argument is not allowed as it is used internally.
-        To capture standard error in the result, use stderr=STDOUT.
-
-        >>> check_output(["/bin/sh", "-c",
-        ...               "ls -l non_existent_file ; exit 0"],
-        ...              stderr=STDOUT)
-        'ls: non_existent_file: No such file or directory\n'
-        """
-        if 'stdout' in kwargs:
-            raise ValueError('stdout argument not allowed, it will be overridden.')
-        process = Popen(stdout=PIPE, *popenargs, **kwargs)
-        output, unused_err = process.communicate()
-        retcode = process.poll()
-
-        if self.traceAlways:
-            if isinstance(popenargs, types.StringTypes):
-                args = [popenargs]
-            else:
-                args = list(popenargs)
-            print >> sys.stderr
-            print >> sys.stderr, "os command:", args
-            print >> sys.stderr, "output:", output
-            print >> sys.stderr, "error:", unused_err
-            print >> sys.stderr, "retcode:", retcode
-
-        if retcode:
-            cmd = kwargs.get("args")
-            if cmd is None:
-                cmd = popenargs[0]
-            raise CalledProcessError(retcode, cmd, output=output)
-        return output
-
     def buildDsym(self):
         """Platform specific way to build binaries with dsym info."""
-        if sys.platform.startswith("darwin"):
-            self.system(["/bin/sh", "-c", "make clean; make MAKE_DSYM=YES"])
-        else:
+        module = __import__(sys.platform)
+        if not module.buildDsym():
             raise Exception("Don't know how to build binary with dsym")
 
     def buildDwarf(self):
         """Platform specific way to build binaries with dwarf maps."""
-        if sys.platform.startswith("darwin"):
-            self.system(["/bin/sh", "-c", "make clean; make MAKE_DSYM=NO"])
-        else:
+        module = __import__(sys.platform)
+        if not module.buildDwarf():
             raise Exception("Don't know how to build binary with dwarf")
 
     def DebugSBValue(self, frame, val):
-        """Debug print a SBValue object, if self.traceAlways is True."""
-        if not self.traceAlways:
+        """Debug print a SBValue object, if traceAlways is True."""
+        if not traceAlways:
             return
 
         err = sys.stderr

Added: lldb/trunk/test/plugins/darwin.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/plugins/darwin.py?rev=112606&view=auto
==============================================================================
--- lldb/trunk/test/plugins/darwin.py (added)
+++ lldb/trunk/test/plugins/darwin.py Tue Aug 31 12:42:54 2010
@@ -0,0 +1,15 @@
+import lldbtest
+
+#print "Hello, darwin plugin!"
+
+def buildDsym():
+    lldbtest.system(["/bin/sh", "-c", "make clean; make MAKE_DSYM=YES"])
+
+    # True signifies that we can handle building dsym.
+    return True
+
+def buildDwarf():
+    lldbtest.system(["/bin/sh", "-c", "make clean; make MAKE_DSYM=NO"])
+
+    # True signifies that we can handle building dsym.
+    return True





More information about the lldb-commits mailing list