summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodd Fiala <todd.fiala@gmail.com>2015-10-02 20:51:11 +0000
committerTodd Fiala <todd.fiala@gmail.com>2015-10-02 20:51:11 +0000
commitae5dee8031c1ee2b9a6660cbf5efeff45cac7cf4 (patch)
tree48f239b3e1bc94d8c5f9aa24316b7a72224e9837
parentb85db178a08611df3c50ed6ad780cd1ee639c22f (diff)
downloadbcm5719-llvm-ae5dee8031c1ee2b9a6660cbf5efeff45cac7cf4.tar.gz
bcm5719-llvm-ae5dee8031c1ee2b9a6660cbf5efeff45cac7cf4.zip
Fix race on subprocess.Popen return values.
This fixes: https://llvm.org/bugs/show_bug.cgi?id=25019 llvm-svn: 249182
-rw-r--r--lldb/test/test_runner/lib/process_control.py45
-rw-r--r--lldb/test/test_runner/test/process_control_tests.py5
2 files changed, 49 insertions, 1 deletions
diff --git a/lldb/test/test_runner/lib/process_control.py b/lldb/test/test_runner/lib/process_control.py
index 9a788665d27..ba30840147e 100644
--- a/lldb/test/test_runner/lib/process_control.py
+++ b/lldb/test/test_runner/lib/process_control.py
@@ -611,3 +611,48 @@ class ProcessDriver(object):
self.io_thread.output,
not completed_normally,
self.returncode)
+
+
+def patched_init(self, *args, **kwargs):
+ self.original_init(*args, **kwargs)
+ # Initialize our condition variable that protects wait()/poll().
+ self.wait_condition = threading.Condition()
+
+
+def patched_wait(self):
+ self.wait_condition.acquire()
+ try:
+ result = self.original_wait()
+ # The process finished. Signal the condition.
+ self.wait_condition.notify_all()
+ return result
+ finally:
+ self.wait_condition.release()
+
+
+def patched_poll(self):
+ self.wait_condition.acquire()
+ try:
+ result = self.original_poll()
+ if self.returncode is not None:
+ # We did complete, and we have the return value.
+ # Signal the event to indicate we're done.
+ self.wait_condition.notify_all()
+ return result
+ finally:
+ self.wait_condition.release()
+
+
+def patch_up_subprocess_popen():
+ subprocess.Popen.original_init = subprocess.Popen.__init__
+ subprocess.Popen.__init__ = patched_init
+
+ subprocess.Popen.original_wait = subprocess.Popen.wait
+ subprocess.Popen.wait = patched_wait
+
+ subprocess.Popen.original_poll = subprocess.Popen.poll
+ subprocess.Popen.poll = patched_poll
+
+# Replace key subprocess.Popen() threading-unprotected methods with
+# threading-protected versions.
+patch_up_subprocess_popen()
diff --git a/lldb/test/test_runner/test/process_control_tests.py b/lldb/test/test_runner/test/process_control_tests.py
index 6eddd386b03..354506d6581 100644
--- a/lldb/test/test_runner/test/process_control_tests.py
+++ b/lldb/test/test_runner/test/process_control_tests.py
@@ -202,6 +202,9 @@ class ProcessControlTimeoutTests(ProcessControlTests):
"""inferior exit detected when inferior children are live with shared
stdout/stderr handles.
"""
+ # Requires review D13362 or equivalent to be implemented.
+ self.skipTest("http://reviews.llvm.org/D13362")
+
driver = TestInferiorDriver()
# Create the inferior (I1), and instruct it to create a child (C1)
@@ -220,7 +223,7 @@ class ProcessControlTimeoutTests(ProcessControlTests):
"process failed to complete")
# Ensure we didn't receive a timeout.
- self.assertTrue(
+ self.assertFalse(
driver.was_timeout, "inferior should have completed normally")
self.assertEqual(
OpenPOWER on IntegriCloud