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

Johnny Chen johnny.chen at apple.com
Mon Oct 11 15:25:46 PDT 2010


Author: johnny
Date: Mon Oct 11 17:25:46 2010
New Revision: 116255

URL: http://llvm.org/viewvc/llvm-project?rev=116255&view=rev
Log:
Added the capability for the test driver to relocate the tests and the intermediate
files to a different top level directory than those specified on the command line.

When relocated, the test clanups normally performed afterwards after each test method
and after each test class will not be exercised at all.  This allows for an easier
postmortem analysis of test failures.

Example:

./dotest.py -v -t -r /tmp/lldbtest types

will create a /tmp/lldbtest directory which houses the types directory and its supported
files.

Files modified:

o dotest.py, lldbtest.py:

  Add logic to process '-r dir' option to support relocating the tests to a different
  top level directory instead of exected in place.

o darwin.py, test/types/Makefile:

  The 'make clean' should only clean the minimum .o and .d files.

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

Modified: lldb/trunk/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=116255&r1=116254&r2=116255&view=diff
==============================================================================
--- lldb/trunk/test/dotest.py (original)
+++ lldb/trunk/test/dotest.py Mon Oct 11 17:25:46 2010
@@ -63,12 +63,18 @@
 # Ignore the build search path relative to this script to locate the lldb.py module.
 ignore = False
 
-# By default, we skip long running test case.  Use "-l" option to override.
+# By default, we skip long running test case.  Use '-l' option to override.
 skipLongRunningTest = True
 
 # The regular expression pattern to match against eligible filenames as our test cases.
 regexp = None
 
+# By default, tests are executed in place and cleanups are performed afterwards.
+# Use '-r dir' option to relocate the tests and their intermediate files to a
+# different directory and to forgo any cleanups.  The directory specified must
+# not exist yet.
+rdir = None
+
 # Default verbosity is 0.
 verbose = 0
 
@@ -98,6 +104,9 @@
        tree relative to this script; use PYTHONPATH to locate the module
 -l   : don't skip long running test
 -p   : specify a regexp filename pattern for inclusion in the test suite
+-r   : specify a dir to relocate the tests and their intermediate files to;
+       the directory must not exist before running this test driver;
+       no cleanup of intermediate test files is performed in this case
 -t   : trace lldb command execution and result
 -v   : do verbose mode of unittest framework
 -w   : insert some wait time (currently 0.5 sec) between consecutive test cases
@@ -136,6 +145,7 @@
     global ignore
     global skipLongRunningTest
     global regexp
+    global rdir
     global verbose
     global testdirs
 
@@ -187,6 +197,16 @@
                 usage()
             regexp = sys.argv[index]
             index += 1
+        elif sys.argv[index].startswith('-r'):
+            # Increment by 1 to fetch the relocated directory argument.
+            index += 1
+            if index >= len(sys.argv) or sys.argv[index].startswith('-'):
+                usage()
+            rdir = os.path.abspath(sys.argv[index])
+            if os.path.exists(rdir):
+                print "Relocated directory:", rdir, "must not exist!"
+                usage()
+            index += 1
         elif sys.argv[index].startswith('-t'):
             os.environ["LLDB_COMMAND_TRACE"] = "YES"
             index += 1
@@ -204,6 +224,39 @@
     if len(sys.argv) > index:
         testdirs = map(os.path.abspath, sys.argv[index:])
 
+    # If '-r dir' is specified, the tests should be run under the relocated
+    # directory.  Let's copy the testdirs over.
+    if rdir:
+        from shutil import copytree, ignore_patterns
+
+        tmpdirs = []
+        for srcdir in testdirs:
+            dstdir = os.path.join(rdir, os.path.basename(srcdir))
+            # Don't copy the *.pyc and .svn stuffs.
+            copytree(srcdir, dstdir, ignore=ignore_patterns('*.pyc', '.svn'))
+            tmpdirs.append(dstdir)
+
+        # This will be our modified testdirs.
+        testdirs = tmpdirs
+
+        # With '-r dir' specified, there's no cleanup of intermediate test files.
+        os.environ["LLDB_DO_CLEANUP"] = 'NO'
+
+        # If testdirs is ['test'], the make directory has already been copied
+        # recursively and is contained within the rdir/test dir.  For anything
+        # else, we would need to copy over the make directory and its contents,
+        # so that, os.listdir(rdir) looks like, for example:
+        #
+        #     array_types conditional_break make
+        #
+        # where the make directory contains the Makefile.rules file.
+        if len(testdirs) != 1 or os.path.basename(testdirs[0]) != 'test':
+            # Don't copy the .svn stuffs.
+            copytree('make', os.path.join(rdir, 'make'),
+                     ignore=ignore_patterns('.svn'))
+
+    #print "testdirs:", testdirs
+
     # Source the configFile if specified.
     # The side effect, if any, will be felt from this point on.  An example
     # config file may be these simple two lines:
@@ -227,13 +280,26 @@
 def setupSysPath():
     """Add LLDB.framework/Resources/Python to the search paths for modules."""
 
+    global rdir
+    global testdirs
+
     # Get the directory containing the current script.
     scriptPath = sys.path[0]
     if not scriptPath.endswith('test'):
         print "This script expects to reside in lldb's test directory."
         sys.exit(-1)
 
-    os.environ["LLDB_TEST"] = scriptPath
+    if rdir:
+        # Set up the LLDB_TEST environment variable appropriately, so that the
+        # individual tests can be located relatively.
+        #
+        # See also lldbtest.TestBase.setUpClass(cls).
+        if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test':
+            os.environ["LLDB_TEST"] = os.path.join(rdir, 'test')
+        else:
+            os.environ["LLDB_TEST"] = rdir
+    else:
+        os.environ["LLDB_TEST"] = scriptPath
     pluginPath = os.path.join(scriptPath, 'plugins')
 
     # Append script dir and plugin dir to the sys.path.
@@ -316,7 +382,7 @@
 
             # We found a match for our test case.  Add it to the suite.
             if not sys.path.count(dir):
-                sys.path.append(dir)
+                sys.path.insert(0, dir)
             base = os.path.splitext(name)[0]
 
             # Thoroughly check the filterspec against the base module and admit

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=116255&r1=116254&r2=116255&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Mon Oct 11 17:25:46 2010
@@ -104,11 +104,21 @@
 import unittest2
 import lldb
 
+# See also dotest.parseOptionsAndInitTestdirs(), where the environment variables
+# LLDB_COMMAND_TRACE and LLDB_NO_CLEANUP are set from '-t' and '-r dir' options.
+
+# By default, traceAlways is False.
 if "LLDB_COMMAND_TRACE" in os.environ and os.environ["LLDB_COMMAND_TRACE"]=="YES":
     traceAlways = True
 else:
     traceAlways = False
 
+# By default, doCleanup is True.
+if "LLDB_DO_CLEANUP" in os.environ and os.environ["LLDB_DO_CLEANUP"]=="NO":
+    doCleanup = False
+else:
+    doCleanup = True
+
 
 #
 # Some commonly used assert messages.
@@ -284,20 +294,21 @@
         Do class-wide cleanup.
         """
 
-        # First, let's do the platform-specific cleanup.
-        module = __import__(sys.platform)
-        if not module.cleanup():
-            raise Exception("Don't know how to do cleanup")
+        if doCleanup:
+            # First, let's do the platform-specific cleanup.
+            module = __import__(sys.platform)
+            if not module.cleanup():
+                raise Exception("Don't know how to do cleanup")
 
-        # Subclass might have specific cleanup function defined.
-        if getattr(cls, "classCleanup", None):
-            if traceAlways:
-                print >> sys.stderr, "Call class-specific cleanup function for class:", cls
-            try:
-                cls.classCleanup()
-            except:
-                exc_type, exc_value, exc_tb = sys.exc_info()
-                traceback.print_exception(exc_type, exc_value, exc_tb)
+            # Subclass might have specific cleanup function defined.
+            if getattr(cls, "classCleanup", None):
+                if traceAlways:
+                    print >> sys.stderr, "Call class-specific cleanup function for class:", cls
+                try:
+                    cls.classCleanup()
+                except:
+                    exc_type, exc_value, exc_tb = sys.exc_info()
+                    traceback.print_exception(exc_type, exc_value, exc_tb)
 
         # Restore old working directory.
         if traceAlways:
@@ -366,7 +377,7 @@
         del self.dbg
 
         # Perform registered teardown cleanup.
-        if self.doTearDownCleanup:
+        if doCleanup and self.doTearDownCleanup:
             module = __import__(sys.platform)
             if not module.cleanup(dictionary=self.dict):
                 raise Exception("Don't know how to do cleanup")

Modified: lldb/trunk/test/plugins/darwin.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/plugins/darwin.py?rev=116255&r1=116254&r2=116255&view=diff
==============================================================================
--- lldb/trunk/test/plugins/darwin.py (original)
+++ lldb/trunk/test/plugins/darwin.py Mon Oct 11 17:25:46 2010
@@ -60,7 +60,7 @@
 def buildDefault(architecture=None, compiler=None, dictionary=None):
     """Build the binaries the default way."""
     lldbtest.system(["/bin/sh", "-c",
-                     "make clean; make"
+                     "make clean" + getCmdLine(dictionary) + "; make"
                      + getArchSpec(architecture) + getCCSpec(compiler)
                      + getCmdLine(dictionary)])
 
@@ -70,7 +70,8 @@
 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"
+                     "make clean" + getCmdLine(dictionary)
+                     + "; make MAKE_DSYM=YES"
                      + getArchSpec(architecture) + getCCSpec(compiler)
                      + getCmdLine(dictionary)])
 
@@ -80,7 +81,8 @@
 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"
+                     "make clean" + getCmdLine(dictionary)
+                     + "; make MAKE_DSYM=NO"
                      + getArchSpec(architecture) + getCCSpec(compiler)
                      + getCmdLine(dictionary)])
 

Modified: lldb/trunk/test/types/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/types/Makefile?rev=116255&r1=116254&r2=116255&view=diff
==============================================================================
--- lldb/trunk/test/types/Makefile (original)
+++ lldb/trunk/test/types/Makefile Mon Oct 11 17:25:46 2010
@@ -1,9 +1,5 @@
 LEVEL = ../make
 
-CXX_SOURCES := int.cpp
+#CXX_SOURCES := int.cpp
 
 include $(LEVEL)/Makefile.rules
-
-clean::
-	rm -rf *.o *.d
-





More information about the lldb-commits mailing list