[Lldb-commits] [PATCH] D46005: [test] Add a utility for dumping all tests in the dotest suite

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 24 05:49:09 PDT 2018


labath created this revision.
labath added reviewers: JDevlieghere, aprantl, amccarth.

The utility iterates through the tests in the suite, much like dotest
does, and prints all tests it found. So that it can set up the
environment properly, it needs to be called with a single argument - the
path to the lldb executable.

Right now it's not wired up to anything, but the idea is to call this
from the lldbtest lit format, to enable running tests with a finer
granularity.

The main reason I do this as a separate utility (and not inside the test format)
is that importing our tests requires a lot of fiddling with the import path and
has a bunch of side effects (e.g., loading liblldb into the address space), and
I did not want to expose the main lit process to this.


https://reviews.llvm.org/D46005

Files:
  lit/Suite/lldbtestdumper.py


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()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46005.143720.patch
Type: text/x-patch
Size: 2261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180424/8284b043/attachment.bin>


More information about the lldb-commits mailing list