[Lldb-commits] [lldb] r251819 - Make dosep correctly invoke the top-level script when forking out

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 2 11:19:49 PST 2015


Author: zturner
Date: Mon Nov  2 13:19:49 2015
New Revision: 251819

URL: http://llvm.org/viewvc/llvm-project?rev=251819&view=rev
Log:
Make dosep correctly invoke the top-level script when forking out

packages/Python/lldbsuite is now a Python package, and it relies
on its __init__.py being called to do package-level initialization.
If you exec packages/Python/lldbsuite/dotest.py directly, you won't
get this package level initialization, and things will fail.  But
without this patch, this is exactly what dosep itself does.  To
launch the multi-processing fork, it was hardcoding a path to
dotest.py and exec'ing it from inside the package.

The fix here is to get the path of the top-level script, and
then exec'ing that instead.  A more robust solution would involve
refactoring the code so that dosep execs some internal script that
imports lldbsuite, but that's a bit more involved.

Differential Revision: http://reviews.llvm.org/D14157
Reviewed by: Todd Fiala

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/dosep.py
    lldb/trunk/packages/Python/lldbsuite/test/dotest.py

Modified: lldb/trunk/packages/Python/lldbsuite/test/dosep.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/dosep.py?rev=251819&r1=251818&r2=251819&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/dosep.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/dosep.py Mon Nov  2 13:19:49 2015
@@ -279,11 +279,12 @@ def call_with_timeout(command, timeout,
     return process_driver.results
 
 
-def process_dir(root, files, test_root, dotest_argv, inferior_pid_events):
+def process_dir(root, files, dotest_argv, inferior_pid_events):
     """Examine a directory for tests, and invoke any found within it."""
     results = []
     for name in files:
-        script_file = os.path.join(test_root, "dotest.py")
+        import __main__ as main
+        script_file = main.__file__
         command = ([sys.executable, script_file] +
                    dotest_argv +
                    ["--inferior", "-p", name, root])
@@ -966,7 +967,7 @@ def walk_and_invoke(test_directory, test
     test_work_items = []
     find_test_files_in_dir_tree(
         test_subdir, lambda testdir, test_files: test_work_items.append([
-            test_subdir, test_files, test_directory, dotest_argv, None]))
+            test_subdir, test_files, dotest_argv, None]))
 
     # Convert test work items into test results using whatever
     # was provided as the test run function.

Modified: lldb/trunk/packages/Python/lldbsuite/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/dotest.py?rev=251819&r1=251818&r2=251819&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/dotest.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/dotest.py Mon Nov  2 13:19:49 2015
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
 """
 A simple testing framework for lldb using python's unit testing framework.
 
@@ -2039,4 +2037,5 @@ def run_suite():
     exitTestSuite(failed)
 
 if __name__ == "__main__":
-    run_suite()
\ No newline at end of file
+    print(__file__ + " is for use as a module only.  It should not be run as a standalone script.")
+    sys.exit(-1)




More information about the lldb-commits mailing list