Chromium Code Reviews| Index: build/android/pylib/utils/test_environment.py |
| diff --git a/build/android/pylib/utils/test_environment.py b/build/android/pylib/utils/test_environment.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5a45665e85160252085a268200293d3530894948 |
| --- /dev/null |
| +++ b/build/android/pylib/utils/test_environment.py |
| @@ -0,0 +1,41 @@ |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import logging |
| +import os |
| +import psutil |
| + |
| +from pylib import android_commands |
| +from pylib import ports |
| + |
| +def _KillWebServers(): |
| + for retry in range(5): |
| + for server in ['lighttpd', 'web-page-replay']: |
| + pids = [p.pid for p in psutil.process_iter() if server in p.name] |
| + for pid in pids: |
| + try: |
| + logging.warning('Killing %s %s', server, pid) |
| + os.kill(pid, signal.SIGQUIT) |
| + except Exception as e: |
| + logging.warning('Failed killing %s %s %s', server, pid, e) |
| + |
| + |
| +def CleanupPendingProcesses(restart_adb_as_root): |
|
tonyg
2013/11/15 05:45:10
Please add a docstring
Primiano Tucci (use gerrit)
2013/11/19 18:13:03
Done.
|
| + _KillWebServers() |
| + did_restart_host_adb = False |
| + for device in android_commands.GetAttachedDevices(): |
| + adb = android_commands.AndroidCommands(device) |
| + # Make sure we restart the host adb server only once. |
| + if not did_restart_host_adb: |
| + adb.RestartAdbServer() |
| + did_restart_host_adb = True |
| + adb.RestartAdbdOnDevice() |
| + if restart_adb_as_root: |
| + adb.EnableAdbRoot() |
| + adb.WaitForDevicePm() |
| + |
| + # Reset the test port allocation. It's important to do it before starting |
| + # to dispatch any step. |
| + if not ports.ResetTestServerPortAllocation(): |
| + raise Exception('Failed to reset test server port.') |