Skip to content

Commit

Permalink
[dotest] Make --test-subdir work with --no-multiprocess
Browse files Browse the repository at this point in the history
The single-process test runner is invoked in a number of different
scenarios, including when multiple test dirs are specified or (afaict)
when lit is used to drive the test suite.

Unfortunately the --test-subdir option did not work with the single
process test runner, breaking an important use case (using lit to run
swift-lldb Linux tests):

  Failure URL: https://ci.swift.org/job/swift-PR-Linux/6841

We won't be able to run lldb tests within swift PR testing without
filtering down the set of tests.

This change makes --test-subdir work with the single-process runner.

git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@339929 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vedantk committed Aug 16, 2018
1 parent 7b6b97f commit 243c816
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
37 changes: 36 additions & 1 deletion packages/Python/lldbsuite/test/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@
# The base directory in which the tests are being built.
test_build_dir = None

# The only directory to scan for tests. If multiple test directories are
# specified, and an exclusive test subdirectory is specified, the latter option
# takes precedence.
exclusive_test_subdir = None

# Parallel execution settings
is_inferior_test_runner = False
multiprocess_test_subdir = None
num_threads = None
no_multiprocess_test_runner = False
test_runner_name = None
Expand Down Expand Up @@ -144,3 +148,34 @@ def shouldSkipBecauseOfCategories(test_categories):
return True

return False


def get_absolute_path_to_exclusive_test_subdir():
"""
If an exclusive test subdirectory is specified, return its absolute path.
Otherwise return None.
"""
test_directory = os.path.dirname(os.path.realpath(__file__))

if not exclusive_test_subdir:
return

if len(exclusive_test_subdir) > 0:
test_subdir = os.path.join(test_directory, exclusive_test_subdir)
if os.path.isdir(test_subdir):
return test_subdir

print('specified test subdirectory {} is not a valid directory\n'
.format(test_subdir))


def get_absolute_path_to_root_test_dir():
"""
If an exclusive test subdirectory is specified, return its absolute path.
Otherwise, return the absolute path of the root test directory.
"""
test_subdir = get_absolute_path_to_exclusive_test_subdir()
if test_subdir:
return test_subdir

return os.path.dirname(os.path.realpath(__file__))
13 changes: 2 additions & 11 deletions packages/Python/lldbsuite/test/dosep.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ def rerun_tests(test_subdir, tests_for_rerun, dotest_argv, session_dir,
print("\nTest rerun complete\n")


def main(num_threads, test_subdir, test_runner_name, results_formatter):
def main(num_threads, test_runner_name, results_formatter):
"""Run dotest.py in inferior mode in parallel.
@param num_threads the parsed value of the num-threads command line
Expand Down Expand Up @@ -1600,16 +1600,7 @@ def main(num_threads, test_subdir, test_runner_name, results_formatter):

session_dir = os.path.join(os.getcwd(), dotest_options.s)

# The root directory was specified on the command line
test_directory = os.path.dirname(os.path.realpath(__file__))
if test_subdir and len(test_subdir) > 0:
test_subdir = os.path.join(test_directory, test_subdir)
if not os.path.isdir(test_subdir):
print(
'specified test subdirectory {} is not a valid directory\n'
.format(test_subdir))
else:
test_subdir = test_directory
test_subdir = configuration.get_absolute_path_to_root_test_dir()

# clean core files in test tree from previous runs (Linux)
cores = find('core.*', test_subdir)
Expand Down
17 changes: 11 additions & 6 deletions packages/Python/lldbsuite/test/dotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def parseOptionsAndInitTestdirs():
configuration.num_threads = args.num_threads

if args.test_subdir:
configuration.multiprocess_test_subdir = args.test_subdir
configuration.exclusive_test_subdir = args.test_subdir

if args.test_runner_name:
configuration.test_runner_name = args.test_runner_name
Expand Down Expand Up @@ -895,6 +895,7 @@ def visit_file(dir, name):
unittest2.defaultTestLoader.loadTestsFromName(base))


# TODO: This should be replaced with a call to find_test_files_in_dir_tree.
def visit(prefix, dir, names):
"""Visitor function for os.path.walk(path, visit, arg)."""

Expand Down Expand Up @@ -1172,7 +1173,6 @@ def run_suite():
from . import dosep
dosep.main(
configuration.num_threads,
configuration.multiprocess_test_subdir,
configuration.test_runner_name,
configuration.results_formatter_object)
raise Exception("should never get here")
Expand Down Expand Up @@ -1267,10 +1267,15 @@ def run_suite():
# Don't do lldb-server (llgs) tests on anything except Linux.
configuration.dont_do_llgs_test = not ("linux" in target_platform)

#
# Walk through the testdirs while collecting tests.
#
for testdir in configuration.testdirs:
# Collect tests from the specified testing directories. If a test
# subdirectory filter is explicitly specified, limit the search to that
# subdirectory.
exclusive_test_subdir = configuration.get_absolute_path_to_exclusive_test_subdir()
if exclusive_test_subdir:
dirs_to_search = [exclusive_test_subdir]
else:
dirs_to_search = configuration.testdirs
for testdir in dirs_to_search:
for (dirpath, dirnames, filenames) in os.walk(testdir):
visit('Test', dirpath, filenames)

Expand Down

0 comments on commit 243c816

Please sign in to comment.