Skip to content

Commit

Permalink
Refactored lldb executable name discovery
Browse files Browse the repository at this point in the history
The lldb executable was referenced through the code by 7 different
(effectively) global variables.

global lldbExecutablePath
global lldbExecutable
os.environ['LLDB_EXEC']
os.environ['LLDB_TEST']
dotest.lldbExec
dotest.lldbHere
lldbtest.lldbExec

This change uses one global variable lldbtest_config.lldbExec to
replace them all.

Differential Revision: http://reviews.llvm.org/D9817

llvm-svn: 237600
  • Loading branch information
vharron committed May 18, 2015
1 parent 0f173ac commit 790d95c
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 118 deletions.
10 changes: 5 additions & 5 deletions lldb/test/benchmarks/disassembly/TestDisassembly.py
Expand Up @@ -15,7 +15,7 @@ class DisassembleDriverMainLoop(BenchBase):

def setUp(self):
"""
Note that lldbExec can be specified with the LLDB_EXEC env variable (see
Note that lldbtest_config.lldbExec can be specified with the LLDB_EXEC env variable (see
dotest.py), and gdbExec can be specified with the GDB_EXEC env variable.
This provides a flexibility in specifying different versions of gdb for
comparison purposes.
Expand All @@ -28,7 +28,7 @@ def setUp(self):
else:
self.gdbExec = "gdb"

self.exe = self.lldbHere
self.exe = lldbtest_config.lldbExec
self.function = 'Driver::MainLoop()'
self.lldb_avg = None
self.gdb_avg = None
Expand All @@ -41,7 +41,7 @@ def setUp(self):
def test_run_lldb_then_gdb(self):
"""Test disassembly on a large function with lldb vs. gdb."""
print
print "lldb path: %s" % self.lldbExec
print "lldb path: %s" % lldbtest_config.lldbExec
print "gdb path: %s" % self.gdbExec

print
Expand All @@ -56,7 +56,7 @@ def test_run_lldb_then_gdb(self):
def test_run_gdb_then_lldb(self):
"""Test disassembly on a large function with lldb vs. gdb."""
print
print "lldb path: %s" % self.lldbExec
print "lldb path: %s" % lldbtest_config.lldbExec
print "gdb path: %s" % self.gdbExec

print
Expand All @@ -73,7 +73,7 @@ def run_lldb_disassembly(self, exe, function, count):
prompt = self.child_prompt

# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s %s' % (self.lldbExec, self.lldbOption, exe))
self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
child = self.child

# Turn on logging for what the child sends back.
Expand Down
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
if lldb.bmExecutable:
self.exe = lldb.bmExecutable
else:
self.exe = self.lldbHere
self.exe = lldbtest_config.lldbExec
self.count = lldb.bmIterationCount
if self.count <= 0:
self.count = 10
Expand Down
Expand Up @@ -13,7 +13,7 @@ def setUp(self):
BenchBase.setUp(self)
self.gdb_41_exe = '/Xcode41/usr/bin/gdb'
self.gdb_42_exe = '/Developer/usr/bin/gdb'
self.exe = self.lldbHere
self.exe = lldbtest_config.lldbExec
self.function = 'Driver::MainLoop()'
self.gdb_41_avg = None
self.gdb_42_avg = None
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/benchmarks/expression/TestExpressionCmd.py
Expand Up @@ -40,7 +40,7 @@ def run_lldb_repeated_exprs(self, exe_name, count):
self.stopwatch.reset()
for i in range(count):
# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
child = self.child

# Turn on logging for what the child sends back.
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/benchmarks/expression/TestRepeatedExprs.py
Expand Up @@ -42,7 +42,7 @@ def run_lldb_repeated_exprs(self, exe_name, count):
prompt = self.child_prompt

# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s %s' % (self.lldbExec, self.lldbOption, exe))
self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
child = self.child

# Turn on logging for what the child sends back.
Expand Down
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
if lldb.bmExecutable:
self.exe = lldb.bmExecutable
else:
self.exe = self.lldbHere
self.exe = lldbtest_config.lldbExec
if lldb.bmBreakpointSpec:
self.break_spec = lldb.bmBreakpointSpec
else:
Expand Down Expand Up @@ -42,7 +42,7 @@ def run_frame_variable_bench(self, exe, break_spec, count):
self.stopwatch.reset()
for i in range(count):
# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
child = self.child

# Turn on logging for what the child sends back.
Expand Down
4 changes: 2 additions & 2 deletions lldb/test/benchmarks/startup/TestStartupDelays.py
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
if lldb.bmExecutable:
self.exe = lldb.bmExecutable
else:
self.exe = self.lldbHere
self.exe = lldbtest_config.lldbExec
if lldb.bmBreakpointSpec:
self.break_spec = lldb.bmBreakpointSpec
else:
Expand Down Expand Up @@ -50,7 +50,7 @@ def run_startup_delays_bench(self, exe, break_spec, count):
self.stopwatch2.reset()
for i in range(count):
# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s' % (self.lldbHere, self.lldbOption))
self.child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
child = self.child

# Turn on logging for what the child sends back.
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/benchmarks/stepping/TestRunHooksThenSteppings.py
Expand Up @@ -29,7 +29,7 @@ def run_lldb_runhooks_then_steppings(self, count):
self.child_prompt = '(lldb) '
prompt = self.child_prompt

self.child = pexpect.spawn('%s %s' % (self.lldbHere, self.lldbOption))
self.child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
self.child.expect_exact(prompt)
# So that the child gets torn down after the test.
child = self.child
Expand Down
4 changes: 2 additions & 2 deletions lldb/test/benchmarks/stepping/TestSteppingSpeed.py
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
if lldb.bmExecutable:
self.exe = lldb.bmExecutable
else:
self.exe = self.lldbHere
self.exe = lldbtest_config.lldbExec
if lldb.bmBreakpointSpec:
self.break_spec = lldb.bmBreakpointSpec
else:
Expand Down Expand Up @@ -42,7 +42,7 @@ def run_lldb_steppings(self, exe, break_spec, count):
prompt = self.child_prompt

# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
child = self.child

# Turn on logging for what the child sends back.
Expand Down
Expand Up @@ -11,7 +11,7 @@ class CompileRunToBreakpointBench(BenchBase):

def setUp(self):
BenchBase.setUp(self)
self.exe = self.lldbHere
self.exe = lldbtest_config.lldbExec
self.function = 'Driver::MainLoop()'

self.count = lldb.bmIterationCount
Expand All @@ -38,7 +38,7 @@ def run_one_round():
prompt = self.child_prompt

# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s %s' % (self.lldbExec, self.lldbOption, exe))
self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
child = self.child

# Turn on logging for what the child sends back.
Expand Down
101 changes: 42 additions & 59 deletions lldb/test/dotest.py
Expand Up @@ -148,9 +148,6 @@ def writeln(self, arg=None):
# The path to LLDB.framework is optional.
lldbFrameworkPath = None

# The path to lldb is optional
lldbExecutablePath = None

# The config file is optional.
configFile = None

Expand Down Expand Up @@ -482,7 +479,6 @@ def parseOptionsAndInitTestdirs():
global useCategories
global skipCategories
global lldbFrameworkPath
global lldbExecutablePath
global configFile
global archs
global compilers
Expand Down Expand Up @@ -755,7 +751,7 @@ def parseOptionsAndInitTestdirs():
lldbFrameworkPath = args.framework

if args.executable:
lldbExecutablePath = args.executable
lldbtest_config.lldbExec = args.executable

if args.libcxx:
os.environ["LIBCXX_PATH"] = args.libcxx
Expand Down Expand Up @@ -946,7 +942,6 @@ def setupSysPath():
global svn_info
global svn_silent
global lldbFrameworkPath
global lldbExecutablePath

# Get the directory containing the current script.
if "DOTEST_PROFILE" in os.environ and "DOTEST_SCRIPT_DIR" in os.environ:
Expand Down Expand Up @@ -1005,23 +1000,18 @@ def setupSysPath():
# Some of the tests can invoke the 'lldb' command directly.
# We'll try to locate the appropriate executable right here.

lldbExec = None
lldbMiExec = None
lldbHere = None
if lldbExecutablePath:
if is_exe(lldbExecutablePath):
lldbExec = lldbExecutablePath
lldbHere = lldbExec
else:
print lldbExecutablePath + " is not an executable, lldb tests will fail."
else:

# The lldb executable can be set from the command line
# if it's not set, we try to find it now
# first, we try the environment
if not lldbtest_config.lldbExec:
# First, you can define an environment variable LLDB_EXEC specifying the
# full pathname of the lldb executable.
if "LLDB_EXEC" in os.environ and is_exe(os.environ["LLDB_EXEC"]):
lldbExec = os.environ["LLDB_EXEC"]
else:
lldbExec = None

if "LLDB_EXEC" in os.environ:
lldbtest_config.lldbExec = os.environ["LLDB_EXEC"]

if not lldbtest_config.lldbExec:
executable = ['lldb']
dbgExec = os.path.join(base, *(xcode3_build_dir + dbg + executable))
dbgExec2 = os.path.join(base, *(xcode4_build_dir + dbg + executable))
Expand All @@ -1034,54 +1024,50 @@ def setupSysPath():

# The 'lldb' executable built here in the source tree.
if is_exe(dbgExec):
lldbHere = dbgExec
lldbtest_config.lldbExec = dbgExec
elif is_exe(dbgExec2):
lldbHere = dbgExec2
lldbtest_config.lldbExec = dbgExec2
elif is_exe(dbcExec):
lldbHere = dbcExec
lldbtest_config.lldbExec = dbcExec
elif is_exe(dbcExec2):
lldbHere = dbcExec2
lldbtest_config.lldbExec = dbcExec2
elif is_exe(relExec):
lldbHere = relExec
lldbtest_config.lldbExec = relExec
elif is_exe(relExec2):
lldbHere = relExec2
lldbtest_config.lldbExec = relExec2
elif is_exe(baiExec):
lldbHere = baiExec
lldbtest_config.lldbExec = baiExec
elif is_exe(baiExec2):
lldbHere = baiExec2
elif lldbExec:
lldbHere = lldbExec

# One last chance to locate the 'lldb' executable.
if not lldbExec:
lldbExec = which('lldb')
if lldbHere and not lldbExec:
lldbExec = lldbHere
if lldbExec and not lldbHere:
lldbHere = lldbExec

if lldbHere:
os.environ["LLDB_HERE"] = lldbHere
lldbLibDir = os.path.split(lldbHere)[0] # confusingly, this is the "bin" directory
os.environ["LLDB_LIB_DIR"] = lldbLibDir
lldbImpLibDir = os.path.join(lldbLibDir, '..', 'lib') if sys.platform.startswith('win32') else lldbLibDir
os.environ["LLDB_IMPLIB_DIR"] = lldbImpLibDir
if not noHeaders:
print "LLDB library dir:", os.environ["LLDB_LIB_DIR"]
print "LLDB import library dir:", os.environ["LLDB_IMPLIB_DIR"]
os.system('%s -v' % lldbHere)
lldbtest_config.lldbExec = baiExec2
elif lldbtest_config.lldbExec:
lldbtest_config.lldbExec = lldbtest_config.lldbExec

if not lldbtest_config.lldbExec:
# Last, check the path
lldbtest_config.lldbExec = which('lldb')

if lldbtest_config.lldbExec and not is_exe(lldbtest_config.lldbExec):
print "'{}' is not a path to a valid executable"
del lldbtest_config.lldbExec

if not lldbExec:
if not lldbtest_config.lldbExec:
print "The 'lldb' executable cannot be located. Some of the tests may not be run as a result."
else:
os.environ["LLDB_EXEC"] = lldbExec
#print "The 'lldb' from PATH env variable", lldbExec
sys.exit(-1)

lldbLibDir = os.path.dirname(lldbtest_config.lldbExec) # confusingly, this is the "bin" directory
os.environ["LLDB_LIB_DIR"] = lldbLibDir
lldbImpLibDir = os.path.join(lldbLibDir, '..', 'lib') if sys.platform.startswith('win32') else lldbLibDir
os.environ["LLDB_IMPLIB_DIR"] = lldbImpLibDir
if not noHeaders:
print "LLDB library dir:", os.environ["LLDB_LIB_DIR"]
print "LLDB import library dir:", os.environ["LLDB_IMPLIB_DIR"]
os.system('%s -v' % lldbtest_config.lldbExec)

# Assume lldb-mi is in same place as lldb
# If not found, disable the lldb-mi tests
global dont_do_lldbmi_test
if lldbExec and is_exe(lldbExec + "-mi"):
lldbMiExec = lldbExec + "-mi"
if lldbtest_config.lldbExec and is_exe(lldbtest_config.lldbExec + "-mi"):
lldbMiExec = lldbtest_config.lldbExec + "-mi"
if not lldbMiExec:
dont_do_lldbmi_test = True
if just_do_lldbmi_test:
Expand Down Expand Up @@ -1119,11 +1105,8 @@ def setupSysPath():

# If our lldb supports the -P option, use it to find the python path:
init_in_python_dir = os.path.join('lldb', '__init__.py')
lldb_dash_p_result = None

lldbExecutable = lldbHere if lldbHere else lldbExec
if lldbExecutable:
lldb_dash_p_result = subprocess.check_output([lldbExecutable, "-P"], stderr=subprocess.STDOUT)
lldb_dash_p_result = subprocess.check_output([lldbtest_config.lldbExec, "-P"], stderr=subprocess.STDOUT)

if lldb_dash_p_result and not lldb_dash_p_result.startswith(("<", "lldb: invalid option:")) \
and not lldb_dash_p_result.startswith("Traceback"):
Expand Down
4 changes: 2 additions & 2 deletions lldb/test/driver/batch_mode/TestBatchMode.py
Expand Up @@ -55,7 +55,7 @@ def batch_mode (self):

# First time through, pass CRASH so the process will crash and stop in batch mode.
run_commands = ' -b -o "break set -n main" -o "run" -o "continue" -k "frame var touch_me_not"'
self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (self.lldbHere, self.lldbOption, run_commands, exe))
self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
child = self.child
# Turn on logging for what the child sends back.
if self.TraceOn():
Expand All @@ -78,7 +78,7 @@ def batch_mode (self):

# Now do it again, and see make sure if we don't crash, we quit:
run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (self.lldbHere, self.lldbOption, run_commands, exe))
self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
child = self.child
# Turn on logging for what the child sends back.
if self.TraceOn():
Expand Down
Expand Up @@ -20,7 +20,7 @@ def test_command_regex(self):
regex_prompt = "Enter one of more sed substitution commands in the form: 's/<regex>/<subst>/'.\r\nTerminate the substitution list with an empty line.\r\n"
regex_prompt1 = "\r\n"

child = pexpect.spawn('%s %s' % (self.lldbHere, self.lldbOption))
child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
# Turn on logging for what the child sends back.
if self.TraceOn():
child.logfile_read = sys.stdout
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/functionalities/completion/TestCompletion.py
Expand Up @@ -236,7 +236,7 @@ def complete_from_to(self, str_input, patterns, turn_off_re_match=False):
prompt = "(lldb) "

# So that the child gets torn down after the test.
self.child = pexpect.spawn(self.lldbHere,
self.child = pexpect.spawn(lldbtest_config.lldbExec,
[self.lldbOption] + ['--no-use-colors'])
child = self.child
# Turn on logging for input/output to/from the child.
Expand Down
Expand Up @@ -41,7 +41,7 @@ def convenience_variables(self):
python_prompt = ">>> "

# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
child = self.child
# Turn on logging for what the child sends back.
if self.TraceOn():
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/functionalities/format/TestFormats.py
Expand Up @@ -18,7 +18,7 @@ def test_formats(self):
self.buildDwarf ()
import pexpect
prompt = "(lldb) "
child = pexpect.spawn('%s %s -x -o "b main" -o r a.out' % (self.lldbHere, self.lldbOption))
child = pexpect.spawn('%s %s -x -o "b main" -o r a.out' % (lldbtest_config.lldbExec, self.lldbOption))
# Turn on logging for what the child sends back.
if self.TraceOn():
child.logfile_read = sys.stdout
Expand Down
Expand Up @@ -34,7 +34,7 @@ def test_lldb_invocation_with_single_quote_in_filename(self):
prompt = "(lldb) "

# So that the child gets torn down after the test.
self.child = pexpect.spawn('%s %s "%s"' % (self.lldbHere, self.lldbOption, self.myexe))
self.child = pexpect.spawn('%s %s "%s"' % (lldbtest_config.lldbExec, self.lldbOption, self.myexe))
child = self.child
child.setecho(True)
# Turn on logging for input/output to/from the child.
Expand Down

0 comments on commit 790d95c

Please sign in to comment.