ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / build / android / pylib / utils / test_environment.py
blob4d88a45e6523fefbc2f4abf212553ea1339e5f18
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.
5 import logging
6 import psutil
7 import signal
9 from pylib.device import device_errors
10 from pylib.device import device_utils
13 def _KillWebServers():
14 for s in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT, signal.SIGKILL]:
15 signalled = []
16 for server in ['lighttpd', 'webpagereplay']:
17 for p in psutil.process_iter():
18 try:
19 if not server in ' '.join(p.cmdline):
20 continue
21 logging.info('Killing %s %s %s', s, server, p.pid)
22 p.send_signal(s)
23 signalled.append(p)
24 except Exception as e:
25 logging.warning('Failed killing %s %s %s', server, p.pid, e)
26 for p in signalled:
27 try:
28 p.wait(1)
29 except Exception as e:
30 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."""
35 _KillWebServers()
36 device_utils.RestartServer()
37 p = device_utils.DeviceUtils.parallel()
38 p.old_interface.RestartAdbdOnDevice()
39 try:
40 p.EnableRoot()
41 except device_errors.CommandFailedError as e:
42 # TODO(jbudorick) Handle this exception appropriately after interface
43 # conversions are finished.
44 logging.error(str(e))
45 p.WaitUntilFullyBooted()