Index: lit/Suite/lldbtestdumper.py =================================================================== --- /dev/null +++ lit/Suite/lldbtestdumper.py @@ -0,0 +1,78 @@ +""" +A utility that prints all tests in the dotest suite. It expects to be called +with a single argument - path to the lldb executable. +""" + +from __future__ import print_function +import subprocess +import os +import os.path +import sys + +lldb_test_root = None + + +def get_tests(test_or_suite): + import unittest2 + + if not isinstance(test_or_suite, unittest2.suite.TestSuite): + yield test_or_suite + return + + for nested in test_or_suite: + for test in get_tests(nested): + yield test + + +def set_up_environment(): + global lldb_test_root + + this_file_dir = os.path.abspath(os.path.dirname(__file__)) + lldb_root = os.path.abspath(os.path.join(this_file_dir, '..', '..')) + lldb_test_root = os.path.join( + lldb_root, + 'packages', + 'Python', + 'lldbsuite', + 'test') + use_lldb_suite_dir = os.path.join(lldb_root, "scripts") + + lldb_executable = os.path.abspath(sys.argv[1]) + site_packages = subprocess.check_output([lldb_executable, '-P']).strip() + + sys.path[0:0] = [use_lldb_suite_dir, site_packages] + import use_lldb_suite + + import lldb + lldb.DBG = lldb.SBDebugger.Create() + + os.environ["LLDB_TEST"] = lldb_test_root + + +def main(): + set_up_environment() + + import unittest2 + + sys.path[0:0] = [""] # Placeholder for dirpath below + for dirpath, _, filenames in os.walk(lldb_test_root): + sys.path[0] = dirpath + dirpath = os.path.relpath(dirpath, lldb_test_root) + for name in filenames: + base, ext = os.path.splitext(name) + if ext != ".py": + continue + if not name.startswith("Test"): + continue + + suite = unittest2.defaultTestLoader.loadTestsFromName(base) + for test in get_tests(suite): + print( + dirpath.replace(os.sep, ' '), + name, + test.__class__.__name__, + test._testMethodName) + + +if __name__ == '__main__': + main()