2010-09-13 20:54:30 +00:00
|
|
|
"""
|
|
|
|
If the build* function is passed the compiler argument, for example, 'llvm-gcc',
|
|
|
|
it is passed as a make variable to the make command. Otherwise, we check the
|
|
|
|
LLDB_CC environment variable; if it is defined, it is passed as a make variable
|
|
|
|
to the make command.
|
|
|
|
|
|
|
|
If neither the compiler keyword argument nor the LLDB_CC environment variable is
|
|
|
|
specified, no CC make variable is passed to the make command. The Makefile gets
|
|
|
|
to define the default CC being used.
|
2010-09-21 00:09:27 +00:00
|
|
|
|
|
|
|
Same idea holds for LLDB_ARCH environment variable, which maps to the ARCH make
|
|
|
|
variable.
|
2010-09-13 20:54:30 +00:00
|
|
|
"""
|
|
|
|
|
2016-05-14 00:42:30 +00:00
|
|
|
# System imports
|
|
|
|
import os
|
2013-06-24 15:40:27 +00:00
|
|
|
import platform
|
2016-05-14 00:42:30 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# Our imports
|
2015-11-03 02:06:18 +00:00
|
|
|
import lldbsuite.test.lldbtest as lldbtest
|
2016-02-02 09:49:37 +00:00
|
|
|
import lldbsuite.test.lldbutil as lldbutil
|
2020-06-02 16:08:11 -07:00
|
|
|
from lldbsuite.test import configuration
|
2016-05-14 00:42:30 +00:00
|
|
|
from lldbsuite.test_event import build_exception
|
2010-08-31 17:42:54 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-01-27 02:58:54 +00:00
|
|
|
def getArchitecture():
|
2011-05-27 23:42:45 +00:00
|
|
|
"""Returns the architecture in effect the test suite is running with."""
|
2020-06-02 16:08:11 -07:00
|
|
|
return configuration.arch if configuration.arch else ""
|
2011-01-27 02:58:54 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-11-17 00:52:41 +00:00
|
|
|
def getCompiler():
|
2011-05-27 23:42:45 +00:00
|
|
|
"""Returns the compiler in effect the test suite is running with."""
|
2020-06-02 16:08:11 -07:00
|
|
|
compiler = configuration.compiler if configuration.compiler else "clang"
|
2016-02-02 09:49:37 +00:00
|
|
|
compiler = lldbutil.which(compiler)
|
2016-02-01 23:21:27 +00:00
|
|
|
return os.path.realpath(compiler)
|
2010-11-17 00:52:41 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-01-25 00:31:48 +00:00
|
|
|
def getArchFlag():
|
|
|
|
"""Returns the flag required to specify the arch"""
|
|
|
|
compiler = getCompiler()
|
|
|
|
if compiler is None:
|
|
|
|
return ""
|
|
|
|
elif "gcc" in compiler:
|
|
|
|
archflag = "-m"
|
|
|
|
elif "clang" in compiler:
|
2014-07-22 16:19:29 +00:00
|
|
|
archflag = "-arch"
|
2013-01-25 00:31:48 +00:00
|
|
|
else:
|
|
|
|
archflag = None
|
|
|
|
|
2014-07-22 16:19:29 +00:00
|
|
|
return ("ARCHFLAG=" + archflag) if archflag else ""
|
2013-01-25 00:31:48 +00:00
|
|
|
|
2018-02-06 18:22:51 +00:00
|
|
|
def getMake(test_subdir, test_name):
|
2018-01-30 18:29:16 +00:00
|
|
|
"""Returns the invocation for GNU make.
|
2018-02-06 18:22:51 +00:00
|
|
|
The first argument is a tuple of the relative path to the testcase
|
|
|
|
and its filename stem."""
|
2015-12-07 21:24:25 +00:00
|
|
|
if platform.system() == "FreeBSD" or platform.system() == "NetBSD":
|
2018-01-30 18:29:16 +00:00
|
|
|
make = "gmake"
|
2013-06-24 15:40:27 +00:00
|
|
|
else:
|
2018-01-30 18:29:16 +00:00
|
|
|
make = "make"
|
|
|
|
|
|
|
|
# Construct the base make invocation.
|
|
|
|
lldb_test = os.environ["LLDB_TEST"]
|
2020-02-07 15:13:38 -08:00
|
|
|
lldb_test_src = os.environ["LLDB_TEST_SRC"]
|
2020-06-02 16:49:03 -07:00
|
|
|
if not (lldb_test and lldb_test_src and configuration.test_build_dir and test_subdir and
|
2020-02-07 15:13:38 -08:00
|
|
|
test_name and (not os.path.isabs(test_subdir))):
|
2018-01-30 18:29:16 +00:00
|
|
|
raise Exception("Could not derive test directories")
|
2020-06-02 16:49:03 -07:00
|
|
|
build_dir = os.path.join(configuration.test_build_dir, test_subdir, test_name)
|
2020-02-07 15:13:38 -08:00
|
|
|
src_dir = os.path.join(lldb_test_src, test_subdir)
|
2018-01-30 18:29:16 +00:00
|
|
|
# This is a bit of a hack to make inline testcases work.
|
2018-02-06 18:22:51 +00:00
|
|
|
makefile = os.path.join(src_dir, "Makefile")
|
2018-01-30 18:29:16 +00:00
|
|
|
if not os.path.isfile(makefile):
|
|
|
|
makefile = os.path.join(build_dir, "Makefile")
|
|
|
|
return [make,
|
2018-02-06 18:22:51 +00:00
|
|
|
"VPATH="+src_dir,
|
2018-01-30 18:29:16 +00:00
|
|
|
"-C", build_dir,
|
2018-02-06 18:22:51 +00:00
|
|
|
"-I", src_dir,
|
[dotest] Avoid the need for LEVEL= makefile boilerplate
Summary:
Instead of each test case knowing its depth relative to the test root,
we can just have dotest add the folder containing Makefile.rules to the
include path.
This was motivated by r370616, though I have been wanting to do this
ever since we moved to building tests out-of-tree.
The only manually modified files in this patch are lldbinline.py and
plugins/builder_base.py. The rest of the patch has been produced by this
shell command:
find . \( -name Makefile -o -name '*.mk' \) -exec sed --in-place -e '/LEVEL *:\?=/d' -e '1,2{/^$/d}' -e 's,\$(LEVEL)/,,' {} +
Reviewers: teemperor, aprantl, espindola, jfb
Subscribers: emaste, javed.absar, arichardson, christof, arphaman, lldb-commits
Differential Revision: https://reviews.llvm.org/D67083
llvm-svn: 370845
2019-09-04 07:46:25 +00:00
|
|
|
"-I", os.path.join(lldb_test, "make"),
|
2018-01-30 18:29:16 +00:00
|
|
|
"-f", makefile]
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-06-24 15:40:27 +00:00
|
|
|
|
2010-09-22 23:00:20 +00:00
|
|
|
def getArchSpec(architecture):
|
|
|
|
"""
|
|
|
|
Helper function to return the key-value string to specify the architecture
|
|
|
|
used for the make system.
|
|
|
|
"""
|
|
|
|
arch = architecture if architecture else None
|
2020-06-02 16:08:11 -07:00
|
|
|
if not arch and configuration.arch:
|
|
|
|
arch = configuration.arch
|
2010-09-22 23:00:20 +00:00
|
|
|
|
2014-07-22 16:19:29 +00:00
|
|
|
return ("ARCH=" + arch) if arch else ""
|
2010-09-22 23:00:20 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-13 20:54:30 +00:00
|
|
|
def getCCSpec(compiler):
|
|
|
|
"""
|
2010-09-21 00:09:27 +00:00
|
|
|
Helper function to return the key-value string to specify the compiler
|
2010-09-13 20:54:30 +00:00
|
|
|
used for the make system.
|
|
|
|
"""
|
|
|
|
cc = compiler if compiler else None
|
2020-06-02 16:08:11 -07:00
|
|
|
if not cc and configuration.compiler:
|
|
|
|
cc = configuration.compiler
|
2014-07-22 16:19:29 +00:00
|
|
|
if cc:
|
|
|
|
return "CC=\"%s\"" % cc
|
|
|
|
else:
|
|
|
|
return ""
|
2010-09-13 20:54:30 +00:00
|
|
|
|
2019-10-10 17:27:06 +00:00
|
|
|
def getDsymutilSpec():
|
|
|
|
"""
|
|
|
|
Helper function to return the key-value string to specify the dsymutil
|
|
|
|
used for the make system.
|
|
|
|
"""
|
2020-06-02 16:49:03 -07:00
|
|
|
if configuration.dsymutil:
|
|
|
|
return "DSYMUTIL={}".format(configuration.dsymutil)
|
|
|
|
return ""
|
2019-10-10 17:27:06 +00:00
|
|
|
|
|
|
|
def getSDKRootSpec():
|
|
|
|
"""
|
|
|
|
Helper function to return the key-value string to specify the SDK root
|
|
|
|
used for the make system.
|
|
|
|
"""
|
2020-06-02 16:49:03 -07:00
|
|
|
if configuration.sdkroot:
|
|
|
|
return "SDKROOT={}".format(configuration.sdkroot)
|
|
|
|
return ""
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-10-10 17:27:09 +00:00
|
|
|
def getModuleCacheSpec():
|
|
|
|
"""
|
|
|
|
Helper function to return the key-value string to specify the clang
|
|
|
|
module cache used for the make system.
|
|
|
|
"""
|
2020-06-02 16:08:11 -07:00
|
|
|
if configuration.clang_module_cache_dir:
|
2019-10-10 17:27:09 +00:00
|
|
|
return "CLANG_MODULE_CACHE_DIR={}".format(
|
2020-06-02 16:08:11 -07:00
|
|
|
configuration.clang_module_cache_dir)
|
2020-06-02 16:49:03 -07:00
|
|
|
return ""
|
2019-10-10 17:27:09 +00:00
|
|
|
|
2010-09-22 23:00:20 +00:00
|
|
|
def getCmdLine(d):
|
2010-09-21 00:09:27 +00:00
|
|
|
"""
|
2010-09-22 23:00:20 +00:00
|
|
|
Helper function to return a properly formatted command line argument(s)
|
|
|
|
string used for the make system.
|
2010-09-21 00:09:27 +00:00
|
|
|
"""
|
2010-09-22 23:00:20 +00:00
|
|
|
|
|
|
|
# If d is None or an empty mapping, just return an empty string.
|
|
|
|
if not d:
|
|
|
|
return ""
|
2015-03-13 21:51:11 +00:00
|
|
|
pattern = '%s="%s"' if "win32" in sys.platform else "%s='%s'"
|
2015-04-16 09:18:12 +00:00
|
|
|
|
|
|
|
def setOrAppendVariable(k, v):
|
2019-08-20 23:56:32 +00:00
|
|
|
append_vars = ["CFLAGS", "CFLAGS_EXTRAS", "LD_EXTRAS"]
|
2015-10-26 16:50:51 +00:00
|
|
|
if k in append_vars and k in os.environ:
|
2015-04-16 09:18:12 +00:00
|
|
|
v = os.environ[k] + " " + v
|
|
|
|
return pattern % (k, v)
|
2015-10-23 17:53:51 +00:00
|
|
|
cmdline = " ".join([setOrAppendVariable(k, v) for k, v in list(d.items())])
|
2010-09-21 00:09:27 +00:00
|
|
|
|
2014-07-22 16:19:29 +00:00
|
|
|
return cmdline
|
2010-09-21 00:09:27 +00:00
|
|
|
|
2010-09-13 20:54:30 +00:00
|
|
|
|
2016-05-14 00:42:30 +00:00
|
|
|
def runBuildCommands(commands, sender):
|
|
|
|
try:
|
|
|
|
lldbtest.system(commands, sender=sender)
|
|
|
|
except subprocess.CalledProcessError as called_process_error:
|
|
|
|
# Convert to a build-specific error.
|
|
|
|
# We don't do that in lldbtest.system() since that
|
|
|
|
# is more general purpose.
|
|
|
|
raise build_exception.BuildError(called_process_error)
|
|
|
|
|
|
|
|
|
2012-02-01 01:49:50 +00:00
|
|
|
def buildDefault(
|
|
|
|
sender=None,
|
|
|
|
architecture=None,
|
|
|
|
compiler=None,
|
|
|
|
dictionary=None,
|
2018-02-06 18:22:51 +00:00
|
|
|
testdir=None,
|
|
|
|
testname=None):
|
2010-09-13 20:54:30 +00:00
|
|
|
"""Build the binaries the default way."""
|
2014-07-22 16:19:29 +00:00
|
|
|
commands = []
|
2019-10-10 17:27:06 +00:00
|
|
|
commands.append(getMake(testdir, testname) +
|
|
|
|
["all",
|
|
|
|
getArchSpec(architecture),
|
|
|
|
getCCSpec(compiler),
|
|
|
|
getDsymutilSpec(),
|
|
|
|
getSDKRootSpec(),
|
2019-10-10 17:27:09 +00:00
|
|
|
getModuleCacheSpec(),
|
2019-10-10 17:27:06 +00:00
|
|
|
getCmdLine(dictionary)])
|
2014-07-22 16:19:29 +00:00
|
|
|
|
2016-05-14 00:42:30 +00:00
|
|
|
runBuildCommands(commands, sender=sender)
|
2010-09-03 23:49:16 +00:00
|
|
|
|
|
|
|
# True signifies that we can handle building default.
|
|
|
|
return True
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-02-01 01:49:50 +00:00
|
|
|
def buildDwarf(
|
|
|
|
sender=None,
|
|
|
|
architecture=None,
|
|
|
|
compiler=None,
|
|
|
|
dictionary=None,
|
2018-02-06 18:22:51 +00:00
|
|
|
testdir=None,
|
|
|
|
testname=None):
|
2010-09-13 20:54:30 +00:00
|
|
|
"""Build the binaries with dwarf debug info."""
|
2014-07-22 16:19:29 +00:00
|
|
|
commands = []
|
2018-02-06 18:22:51 +00:00
|
|
|
commands.append(getMake(testdir, testname) +
|
2019-10-10 17:27:06 +00:00
|
|
|
["MAKE_DSYM=NO",
|
|
|
|
getArchSpec(architecture),
|
|
|
|
getCCSpec(compiler),
|
|
|
|
getDsymutilSpec(),
|
|
|
|
getSDKRootSpec(),
|
2019-10-10 17:27:09 +00:00
|
|
|
getModuleCacheSpec(),
|
2019-10-10 17:27:06 +00:00
|
|
|
getCmdLine(dictionary)])
|
2010-08-31 17:42:54 +00:00
|
|
|
|
2016-05-14 00:42:30 +00:00
|
|
|
runBuildCommands(commands, sender=sender)
|
2011-02-11 00:06:48 +00:00
|
|
|
# True signifies that we can handle building dwarf.
|
2010-08-31 17:42:54 +00:00
|
|
|
return True
|
2010-09-16 01:53:04 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-07 10:02:17 +00:00
|
|
|
def buildDwo(
|
|
|
|
sender=None,
|
|
|
|
architecture=None,
|
|
|
|
compiler=None,
|
|
|
|
dictionary=None,
|
2018-02-06 18:22:51 +00:00
|
|
|
testdir=None,
|
|
|
|
testname=None):
|
2015-10-07 10:02:17 +00:00
|
|
|
"""Build the binaries with dwarf debug info."""
|
|
|
|
commands = []
|
2018-02-06 18:22:51 +00:00
|
|
|
commands.append(getMake(testdir, testname) +
|
2019-10-10 17:27:06 +00:00
|
|
|
["MAKE_DSYM=NO",
|
|
|
|
"MAKE_DWO=YES",
|
2018-01-30 18:29:16 +00:00
|
|
|
getArchSpec(architecture),
|
|
|
|
getCCSpec(compiler),
|
2019-10-10 17:27:06 +00:00
|
|
|
getDsymutilSpec(),
|
|
|
|
getSDKRootSpec(),
|
2019-10-10 17:27:09 +00:00
|
|
|
getModuleCacheSpec(),
|
2018-01-30 18:29:16 +00:00
|
|
|
getCmdLine(dictionary)])
|
2015-10-07 10:02:17 +00:00
|
|
|
|
2016-05-14 00:42:30 +00:00
|
|
|
runBuildCommands(commands, sender=sender)
|
2015-10-07 10:02:17 +00:00
|
|
|
# True signifies that we can handle building dwo.
|
|
|
|
return True
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-05-26 13:57:03 +00:00
|
|
|
def buildGModules(
|
|
|
|
sender=None,
|
|
|
|
architecture=None,
|
|
|
|
compiler=None,
|
|
|
|
dictionary=None,
|
2018-02-06 18:22:51 +00:00
|
|
|
testdir=None,
|
|
|
|
testname=None):
|
2016-05-26 13:57:03 +00:00
|
|
|
"""Build the binaries with dwarf debug info."""
|
|
|
|
commands = []
|
2018-02-06 18:22:51 +00:00
|
|
|
commands.append(getMake(testdir, testname) +
|
2018-01-30 18:29:16 +00:00
|
|
|
["MAKE_DSYM=NO",
|
2016-05-26 13:57:03 +00:00
|
|
|
"MAKE_GMODULES=YES",
|
|
|
|
getArchSpec(architecture),
|
|
|
|
getCCSpec(compiler),
|
2019-10-10 17:27:06 +00:00
|
|
|
getDsymutilSpec(),
|
|
|
|
getSDKRootSpec(),
|
2019-10-10 17:27:09 +00:00
|
|
|
getModuleCacheSpec(),
|
2016-05-26 13:57:03 +00:00
|
|
|
getCmdLine(dictionary)])
|
|
|
|
|
|
|
|
lldbtest.system(commands, sender=sender)
|
|
|
|
# True signifies that we can handle building with gmodules.
|
|
|
|
return True
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
Some re-achitecturing of the plugins interface. The caller is now required to
pass in a 'sender' arg to the buildDefault(), buildDsym(), buildDwarf(), and
cleanup() functions. The sender arg will be the test instance itself (i.e.,
an instance of TestBase). This is so that the relevant command execution can be
recorded in the TestBase.session object if sender is available.
The lldbtest.system() command has been modified to pop the 'sender' arg out of
the keyword arguments dictionary and use it as the test instance to facilitate
seesion recordings. An example is in test/types/AbstractBase.py:
def generic_type_tester(self, atoms, quotedDisplay=False):
"""Test that variables with basic types are displayed correctly."""
# First, capture the golden output emitted by the oracle, i.e., the
# series of printf statements.
go = system("./a.out", sender=self)
There are cases when sender is None. This is the case when the @classmethod is
involved in the use of these APIs. When this happens, there is no recording
into a session object, but printing on the sys.stderr is still honored if the
trace flag is ON.
An example is in test/settings/TestSettings.py:
@classmethod
def classCleanup(cls):
system(["/bin/sh", "-c", "rm -f output.txt"])
system(["/bin/sh", "-c", "rm -f stdout.txt"])
llvm-svn: 116648
2010-10-15 23:55:05 +00:00
|
|
|
def cleanup(sender=None, dictionary=None):
|
2010-09-22 23:00:20 +00:00
|
|
|
"""Perform a platform-specific cleanup after the test."""
|
2010-09-16 01:53:04 +00:00
|
|
|
return True
|