1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
9 from pylib import android_commands
10 from pylib.device import device_utils
12 def _KillWebServers():
13 for s in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT, signal.SIGKILL]:
15 for server in ['lighttpd', 'webpagereplay']:
16 for p in psutil.process_iter():
18 if not server in ' '.join(p.cmdline):
20 logging.info('Killing %s %s %s', s, server, p.pid)
23 except Exception as e:
24 logging.warning('Failed killing %s %s %s', server, p.pid, e)
28 except Exception as e:
29 logging.warning('Failed waiting for %s to die. %s', p.pid, e)
33 def CleanupLeftoverProcesses():
34 """Clean up the test environment, restarting fresh adb and HTTP daemons."""
36 did_restart_host_adb = False
37 for device_serial in android_commands.GetAttachedDevices():
38 device = device_utils.DeviceUtils(device_serial)
39 # Make sure we restart the host adb server only once.
40 if not did_restart_host_adb:
41 device.old_interface.RestartAdbServer()
42 did_restart_host_adb = True
43 device.old_interface.RestartAdbdOnDevice()
44 device.old_interface.EnableAdbRoot()
45 device.old_interface.WaitForDevicePm()