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 arch = architecture if architecture else None
97 if not arch and configuration.arch:
98 arch = configuration.arch
100 return ("ARCH=" + arch) if arch else ""
102 def getCCSpec(self, compiler):
104 Helper function to return the key-value string to specify the compiler
105 used for the make system.
107 cc = compiler if compiler else None
108 if not cc and configuration.compiler:
109 cc = configuration.compiler
111 return "CC=\"%s\"" % cc
115 def getSDKRootSpec(self):
117 Helper function to return the key-value string to specify the SDK root
118 used for the make system.
120 if configuration.sdkroot:
121 return "SDKROOT={}".format(configuration.sdkroot)
124 def getModuleCacheSpec(self):
126 Helper function to return the key-value string to specify the clang
127 module cache used for the make system.
129 if configuration.clang_module_cache_dir:
130 return "CLANG_MODULE_CACHE_DIR={}".format(
131 configuration.clang_module_cache_dir)
134 def buildDefault(self,
141 """Build the binaries the default way."""
144 self.getMake(testdir, testname) + [
146 self.getArchCFlags(architecture),
147 self.getArchSpec(architecture),
148 self.getCCSpec(compiler),
149 self.getExtraMakeArgs(),
150 self.getSDKRootSpec(),
151 self.getModuleCacheSpec(),
152 self.getCmdLine(dictionary)
155 self.runBuildCommands(commands, sender=sender)
157 # True signifies that we can handle building default.
167 """Build the binaries with dwarf debug info."""
170 self.getMake(testdir, testname) + [
172 self.getArchCFlags(architecture),
173 self.getArchSpec(architecture),
174 self.getCCSpec(compiler),
175 self.getExtraMakeArgs(),
176 self.getSDKRootSpec(),
177 self.getModuleCacheSpec(),
178 self.getCmdLine(dictionary)
181 self.runBuildCommands(commands, sender=sender)
182 # True signifies that we can handle building dwarf.
192 """Build the binaries with dwarf debug info."""
195 self.getMake(testdir, testname) + [
196 "MAKE_DSYM=NO", "MAKE_DWO=YES",
197 self.getArchCFlags(architecture),
198 self.getArchSpec(architecture),
199 self.getCCSpec(compiler),
200 self.getExtraMakeArgs(),
201 self.getSDKRootSpec(),
202 self.getModuleCacheSpec(),
203 self.getCmdLine(dictionary)
206 self.runBuildCommands(commands, sender=sender)
207 # True signifies that we can handle building dwo.
210 def buildGModules(self,
217 """Build the binaries with dwarf debug info."""
220 self.getMake(testdir, testname) + [
221 "MAKE_DSYM=NO", "MAKE_GMODULES=YES",
222 self.getArchCFlags(architecture),
223 self.getArchSpec(architecture),
224 self.getCCSpec(compiler),
225 self.getExtraMakeArgs(),
226 self.getSDKRootSpec(),
227 self.getModuleCacheSpec(),
228 self.getCmdLine(dictionary)
231 self.runBuildCommands(commands, sender=sender)
232 # True signifies that we can handle building with gmodules.
242 # False signifies that we cannot handle building with dSYM.
245 def cleanup(self, sender=None, dictionary=None):
246 """Perform a platform-specific cleanup after the test."""