| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import atexit | 5 import atexit |
| 6 import hashlib | 6 import hashlib |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import os.path | 9 import os.path |
| 10 import random | 10 import random |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 def _run(): | 120 def _run(): |
| 121 def _wait_for_fifo(): | 121 def _wait_for_fifo(): |
| 122 for _ in xrange(max_attempts): | 122 for _ in xrange(max_attempts): |
| 123 output = subprocess.check_output(fifo_command).strip() | 123 output = subprocess.check_output(fifo_command).strip() |
| 124 if output == fifo_path: | 124 if output == fifo_path: |
| 125 return | 125 return |
| 126 time.sleep(1) | 126 time.sleep(1) |
| 127 if on_fifo_closed: | 127 if on_fifo_closed: |
| 128 on_fifo_closed() | 128 on_fifo_closed() |
| 129 raise Exception('Unable to find fifo.') | 129 raise Exception('Timed out waiting for shell the create the fifo file.') |
| 130 _wait_for_fifo() | 130 _wait_for_fifo() |
| 131 stdout_cat = subprocess.Popen( | 131 stdout_cat = subprocess.Popen( |
| 132 self._adb_command(['shell', 'run-as', _MOJO_SHELL_PACKAGE_NAME, | 132 self._adb_command(['shell', 'run-as', _MOJO_SHELL_PACKAGE_NAME, |
| 133 'cat', fifo_path]), stdout=pipe) | 133 'cat', fifo_path]), stdout=pipe) |
| 134 atexit.register(_exit_if_needed, stdout_cat) | 134 atexit.register(_exit_if_needed, stdout_cat) |
| 135 stdout_cat.wait() | 135 stdout_cat.wait() |
| 136 if on_fifo_closed: | 136 if on_fifo_closed: |
| 137 on_fifo_closed() | 137 on_fifo_closed() |
| 138 | 138 |
| 139 thread = threading.Thread(target=_run, name='StdoutRedirector') | 139 thread = threading.Thread(target=_run, name='StdoutRedirector') |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 Results.output = rf.read() | 440 Results.output = rf.read() |
| 441 | 441 |
| 442 run_thread = threading.Thread(target=do_run) | 442 run_thread = threading.Thread(target=do_run) |
| 443 run_thread.start() | 443 run_thread.start() |
| 444 run_thread.join(timeout) | 444 run_thread.join(timeout) |
| 445 | 445 |
| 446 if run_thread.is_alive(): | 446 if run_thread.is_alive(): |
| 447 self.stop_shell() | 447 self.stop_shell() |
| 448 return None, Results.output, True | 448 return None, Results.output, True |
| 449 return None, Results.output, False | 449 return None, Results.output, False |
| OLD | NEW |