[Lldb-commits] [lldb] r180955 - Fix check_public_api_headers test on mac os x, and refactor some logic into lldbtest.py

Daniel Malea daniel.malea at intel.com
Thu May 2 14:44:31 PDT 2013


Author: dmalea
Date: Thu May  2 16:44:31 2013
New Revision: 180955

URL: http://llvm.org/viewvc/llvm-project?rev=180955&view=rev
Log:
Fix check_public_api_headers test on mac os x, and refactor some logic into lldbtest.py
- moved build logic from Makefile and TestPublicAPIHeaders.py into lldbtest to allow reuse
- added decorator @skipIfi386


Modified:
    lldb/trunk/test/api/check_public_api_headers/Makefile
    lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/test/api/check_public_api_headers/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/api/check_public_api_headers/Makefile?rev=180955&r1=180954&r2=180955&view=diff
==============================================================================
--- lldb/trunk/test/api/check_public_api_headers/Makefile (original)
+++ lldb/trunk/test/api/check_public_api_headers/Makefile Thu May  2 16:44:31 2013
@@ -2,20 +2,4 @@ LEVEL = ../../make
 
 CXX_SOURCES := main.cpp
 
-MY_OS = $(shell uname -s)
-ifeq "$(MY_OS)" "Darwin"
-    LD_EXTRAS ?= -framework LLDB
-else
-    LD_EXTRAS ?= $(LLDB_LIB_DIR)/liblldb.so
-endif
-
-# If no c++ std was specified on CXXFLAGS, use c++11
-ifeq (,$(findstring -std=c++,$(CXXFLAGS)))
-  CFLAGS_EXTRAS := -std=c++11
-endif
-
-# Example dictionary to pass to the Python build method:
-# 
-# FRAMEWORK_INCLUDES=-F/Volumes/data/lldb/svn/trunk/build/Debug
-
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py?rev=180955&r1=180954&r2=180955&view=diff
==============================================================================
--- lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py (original)
+++ lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py Thu May  2 16:44:31 2013
@@ -17,6 +17,7 @@ class SBDirCheckerCase(TestBase):
         self.lib_dir = os.environ["LLDB_LIB_DIR"]
         self.template = 'main.cpp.template'
         self.source = 'main.cpp'
+        self.exe_name = 'a.out'
 
     def test_sb_api_directory(self):
         """Test the SB API directory and make sure there's no unwanted stuff."""
@@ -24,15 +25,9 @@ class SBDirCheckerCase(TestBase):
         if self.getArchitecture() == "i386":
             self.skipTest("LLDB is 64-bit and cannot be linked to 32-bit test program.")
 
-        # Call the program generator to produce main.cpp.
+        # Generate main.cpp, build it, and execute.
         self.generate_main_cpp()
-
-        if sys.platform.startswith("darwin"):
-            d = {'FRAMEWORK_INCLUDES' : "-F%s" % self.lib_dir}
-        if sys.platform.startswith("linux") or os.environ.get('LLDB_BUILD_TYPE') == 'Makefile':
-            d = {'FRAMEWORK_INCLUDES' : "-I%s" % os.path.join(os.environ["LLDB_SRC"], "include")}
-        self.buildDefault(dictionary=d)
-        self.exe_name = 'a.out'
+        self.buildDriver(self.source, self.exe_name)
         self.sanity_check_executable(self.exe_name)
 
     def generate_main_cpp(self):
@@ -69,10 +64,7 @@ class SBDirCheckerCase(TestBase):
 
         self.line_to_break = line_number(self.source, '// Set breakpoint here.')
 
-        existing_library_path = os.environ[self.dylibPath] if self.dylibPath in os.environ else None
-
-        env_val = self.lib_dir if not existing_library_path else "%s:%s" % (existing_library_path, self.lib_dir)
-        env_cmd = "settings set target.env-vars %s=%s" %(self.dylibPath, env_val)
+        env_cmd = "settings set target.env-vars %s=%s" %(self.dylibPath, self.getLLDBLibraryEnvVal())
         if self.TraceOn():
             print "Set environment to: ", env_cmd
         self.runCmd(env_cmd)

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=180955&r1=180954&r2=180955&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Thu May  2 16:44:31 2013
@@ -594,6 +594,21 @@ def skipIfIcc(func):
             func(*args, **kwargs)
     return wrapper
 
+def skipIfi386(func):
+    """Decorate the item to skip tests that should be skipped if building 32-bit."""
+    if isinstance(func, type) and issubclass(func, unittest2.TestCase):
+        raise Exception("@skipIfi386 can only be used to decorate a test method")
+    @wraps(func)
+    def wrapper(*args, **kwargs):
+        from unittest2 import case
+        self = args[0]
+        if "i386" == self.getArchitecture():
+            self.skipTest("skipping because i386 is not a supported architecture")
+        else:
+            func(*args, **kwargs)
+    return wrapper
+
+
 class Base(unittest2.TestCase):
     """
     Abstract base for performing lldb (see TestBase) or other generic tests (see
@@ -1097,6 +1112,39 @@ class Base(unittest2.TestCase):
     # Build methods supported through a plugin interface
     # ==================================================
 
+    def buildDriver(self, sources, exe_name):
+        """ Platform-specific way to build a program that links with LLDB (via the liblldb.so
+            or LLDB.framework).
+        """
+        if "gcc" in self.getCompiler() and "4.6" in self.getCompilerVersion():
+          stdflag = "std=c++0x"
+        else:
+          stdflag = "-std=c++11"
+
+        if sys.platform.startswith("darwin"):
+            dsym = os.path.join(self.lib_dir, 'LLDB.framework', 'LLDB')
+            d = {'CXX_SOURCES' : sources,
+                 'EXE' : exe_name,
+                 'CFLAGS_EXTRAS' : "%s -stdlib=libc++" % stdflag,
+                 'FRAMEWORK_INCLUDES' : "-F%s" % self.lib_dir,
+                 'LD_EXTRAS' : dsym,
+                }
+        elif sys.platform.startswith("linux") or os.environ.get('LLDB_BUILD_TYPE') == 'Makefile':
+            d = {'CXX_SOURCES' : sources, 
+                 'EXE' : exe_name,
+                 'CFLAGS_EXTRAS' : "%s -I%s" % (stdflag, os.path.join(os.environ["LLDB_SRC"], "include")),
+                 'LD_EXTRAS' : "-L%s -llldb" % self.lib_dir}
+        if self.TraceOn():
+            print "Building LLDB Driver (%s) from sources %s" % (exe_name, sources)
+
+        self.buildDefault(dictionary=d)
+
+    def buildProgram(self, sources, exe_name):
+        """ Platform specific way to build an executable from C/C++ sources. """
+        d = {'CXX_SOURCES' : sources,
+             'EXE' : exe_name}
+        self.buildDefault(dictionary=d)
+
     def buildDefault(self, architecture=None, compiler=None, dictionary=None, clean=True):
         """Platform specific way to build the default binaries."""
         if lldb.skip_build_and_cleanup:
@@ -1129,6 +1177,19 @@ class Base(unittest2.TestCase):
         if not module.cleanup(self, dictionary):
             raise Exception("Don't know how to do cleanup with dictionary: "+dictionary)
 
+    def getLLDBLibraryEnvVal(self):
+        """ Returns the path that the OS-specific library search environment variable
+            (self.dylibPath) should be set to in order for a program to find the LLDB
+            library. If an environment variable named self.dylibPath is already set,
+            the new path is appended to it and returned.
+        """
+        existing_library_path = os.environ[self.dylibPath] if self.dylibPath in os.environ else None
+        if existing_library_path:
+            return "%s:%s" % (existing_library_path, self.lib_dir)
+        elif sys.platform.startswith("darwin"):
+            return os.path.join(self.lib_dir, 'LLDB.framework')
+        else:
+            return self.lib_dir
 
 class TestBase(Base):
     """





More information about the lldb-commits mailing list