6 import lldbsuite.test.lldbtest as lldbtest
7 import lldbsuite.test.lldbutil as lldbutil
8 from lldbsuite.test import configuration
9 from lldbsuite.test_event import build_exception
13 def getArchitecture(self):
14 """Returns the architecture in effect the test suite is running with."""
15 return configuration.arch if configuration.arch else ""
17 def getCompiler(self):
18 """Returns the compiler in effect the test suite is running with."""
19 compiler = configuration.compiler if configuration.compiler else "clang"
20 compiler = lldbutil.which(compiler)
21 return os.path.abspath(compiler)
23 def getExtraMakeArgs(self):
25 Helper function to return extra argumentsfor the make system. This
26 method is meant to be overridden by platform specific builders.
30 def getArchCFlags(self, architecture):
31 """Returns the ARCH_CFLAGS for the make system."""
34 def getMake(self, test_subdir, test_name):
35 """Returns the invocation for GNU make.
36 The first argument is a tuple of the relative path to the testcase
37 and its filename stem."""
38 if platform.system() == "FreeBSD" or platform.system() == "NetBSD":
43 # Construct the base make invocation.
44 lldb_test = os.environ["LLDB_TEST"]
45 if not (lldb_test and configuration.test_build_dir and test_subdir
46 and test_name and (not os.path.isabs(test_subdir))):
47 raise Exception("Could not derive test directories")
48 build_dir = os.path.join(configuration.test_build_dir, test_subdir,
50 src_dir = os.path.join(configuration.test_src_root, test_subdir)
51 # This is a bit of a hack to make inline testcases work.
52 makefile = os.path.join(src_dir, "Makefile")
53 if not os.path.isfile(makefile):
54 makefile = os.path.join(build_dir, "Makefile")
56 make, "VPATH=" + src_dir, "-C", build_dir, "-I", src_dir, "-I",
57 os.path.join(lldb_test, "make"), "-f", makefile
60 def getCmdLine(self, d):
62 Helper function to return a properly formatted command line argument(s)
63 string used for the make system.
66 # If d is None or an empty mapping, just return an empty string.
69 pattern = '%s="%s"' if "win32" in sys.platform else "%s='%s'"
71 def setOrAppendVariable(k, v):
72 append_vars = ["CFLAGS", "CFLAGS_EXTRAS", "LD_EXTRAS"]
73 if k in append_vars and k in os.environ:
74 v = os.environ[k] + " " + v
75 return pattern % (k, v)
78 [setOrAppendVariable(k, v) for k, v in list(d.items())])
82 def runBuildCommands(self, commands, sender):
84 lldbtest.system(commands, sender=sender)
85 except subprocess.CalledProcessError as called_process_error:
86 # Convert to a build-specific error.
87 # We don't do that in lldbtest.system() since that
88 # is more general purpose.
89 raise build_exception.BuildError(called_process_error)
91 def getArchSpec(self, architecture):
93 Helper function to return the key-value string to specify the architecture
94 used for the make system.
96 return ("ARCH=" + architecture) if architecture else ""
98 def getCCSpec(self, compiler):
100 Helper function to return the key-value string to specify the compiler
101 used for the make system.
103 cc = compiler if compiler else None
104 if not cc and configuration.compiler:
105 cc = configuration.compiler
107 return "CC=\"%s\"" % cc
111 def getSDKRootSpec(self):
113 Helper function to return the key-value string to specify the SDK root
114 used for the make system.
116 if configuration.sdkroot:
117 return "SDKROOT={}".format(configuration.sdkroot)
120 def getModuleCacheSpec(self):
122 Helper function to return the key-value string to specify the clang
123 module cache used for the make system.
125 if configuration.clang_module_cache_dir:
126 return "CLANG_MODULE_CACHE_DIR={}".format(
127 configuration.clang_module_cache_dir)
130 def buildDefault(self,
137 """Build the binaries the default way."""
140 self.getMake(testdir, testname) + [
142 self.getArchCFlags(architecture),
143 self.getArchSpec(architecture),
144 self.getCCSpec(compiler),
145 self.getExtraMakeArgs(),
146 self.getSDKRootSpec(),
147 self.getModuleCacheSpec(),
148 self.getCmdLine(dictionary)
151 self.runBuildCommands(commands, sender=sender)
153 # True signifies that we can handle building default.
163 """Build the binaries with dwarf debug info."""
166 self.getMake(testdir, testname) + [
168 self.getArchCFlags(architecture),
169 self.getArchSpec(architecture),
170 self.getCCSpec(compiler),
171 self.getExtraMakeArgs(),
172 self.getSDKRootSpec(),
173 self.getModuleCacheSpec(),
174 self.getCmdLine(dictionary)
177 self.runBuildCommands(commands, sender=sender)
178 # True signifies that we can handle building dwarf.
188 """Build the binaries with dwarf debug info."""
191 self.getMake(testdir, testname) + [
192 "MAKE_DSYM=NO", "MAKE_DWO=YES",
193 self.getArchCFlags(architecture),
194 self.getArchSpec(architecture),
195 self.getCCSpec(compiler),
196 self.getExtraMakeArgs(),
197 self.getSDKRootSpec(),
198 self.getModuleCacheSpec(),
199 self.getCmdLine(dictionary)
202 self.runBuildCommands(commands, sender=sender)
203 # True signifies that we can handle building dwo.
206 def buildGModules(self,
213 """Build the binaries with dwarf debug info."""
216 self.getMake(testdir, testname) + [
217 "MAKE_DSYM=NO", "MAKE_GMODULES=YES",
218 self.getArchCFlags(architecture),
219 self.getArchSpec(architecture),
220 self.getCCSpec(compiler),
221 self.getExtraMakeArgs(),
222 self.getSDKRootSpec(),
223 self.getModuleCacheSpec(),
224 self.getCmdLine(dictionary)
227 self.runBuildCommands(commands, sender=sender)
228 # True signifies that we can handle building with gmodules.
238 # False signifies that we cannot handle building with dSYM.
241 def cleanup(self, sender=None, dictionary=None):
242 """Perform a platform-specific cleanup after the test."""