| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import os | |
| 7 import re | |
| 8 import subprocess | |
| 9 import sys | |
| 10 | |
| 11 from gpu_tests import path_util | |
| 12 | |
| 13 path_util.SetupTelemetryPaths() | |
| 14 | |
| 15 from telemetry import benchmark_runner | |
| 16 | |
| 17 import gpu_project_config | |
| 18 | |
| 19 | |
| 20 def _LaunchDBus(): | |
| 21 """Launches DBus to work around a bug in GLib. | |
| 22 | |
| 23 Works around a bug in GLib where it performs operations which aren't | |
| 24 async-signal-safe (in particular, memory allocations) between fork and exec | |
| 25 when it spawns subprocesses. This causes threads inside Chrome's browser and | |
| 26 utility processes to get stuck, and this harness to hang waiting for those | |
| 27 processes, which will never terminate. This doesn't happen on users' | |
| 28 machines, because they have an active desktop session and the | |
| 29 DBUS_SESSION_BUS_ADDRESS environment variable set, but it does happen on the | |
| 30 bots. See crbug.com/309093 for more details. | |
| 31 | |
| 32 Returns: | |
| 33 True if it actually spawned DBus. | |
| 34 """ | |
| 35 import platform | |
| 36 if (platform.uname()[0].lower() != 'linux' or | |
| 37 'DBUS_SESSION_BUS_ADDRESS' in os.environ): | |
| 38 return False | |
| 39 | |
| 40 # Only start DBus on systems that are actually running X. Using DISPLAY | |
| 41 # variable is not reliable, because is it set by the /etc/init.d/buildbot | |
| 42 # script for all slaves. | |
| 43 # TODO(sergiyb): When all GPU slaves are migrated to swarming, we can remove | |
| 44 # assignment of the DISPLAY from /etc/init.d/buildbot because this hack was | |
| 45 # used to run GPU tests on buildbot. After it is removed, we can use DISPLAY | |
| 46 # variable here to check if we are running X. | |
| 47 if subprocess.call(['pidof', 'X'], stdout=subprocess.PIPE) == 0: | |
| 48 try: | |
| 49 print 'DBUS_SESSION_BUS_ADDRESS env var not found, starting dbus-launch' | |
| 50 dbus_output = subprocess.check_output(['dbus-launch']).split('\n') | |
| 51 for line in dbus_output: | |
| 52 m = re.match(r'([^=]+)\=(.+)', line) | |
| 53 if m: | |
| 54 os.environ[m.group(1)] = m.group(2) | |
| 55 print ' setting %s to %s' % (m.group(1), m.group(2)) | |
| 56 return True | |
| 57 except (subprocess.CalledProcessError, OSError) as e: | |
| 58 print 'Exception while running dbus_launch: %s' % e | |
| 59 return False | |
| 60 | |
| 61 | |
| 62 def _ShutdownDBus(): | |
| 63 """Manually kills the previously-launched DBus daemon. | |
| 64 | |
| 65 It appears that passing --exit-with-session to dbus-launch in | |
| 66 _LaunchDBus(), above, doesn't cause the launched dbus-daemon to shut | |
| 67 down properly. Manually kill the sub-process using the PID it gave | |
| 68 us at launch time. | |
| 69 | |
| 70 This function is called when the flag --spawn-dbus is given, and if | |
| 71 _LaunchDBus(), above, actually spawned the dbus-daemon. | |
| 72 """ | |
| 73 import signal | |
| 74 if 'DBUS_SESSION_BUS_PID' in os.environ: | |
| 75 dbus_pid = os.environ['DBUS_SESSION_BUS_PID'] | |
| 76 try: | |
| 77 os.kill(int(dbus_pid), signal.SIGTERM) | |
| 78 print ' killed dbus-daemon with PID %s' % dbus_pid | |
| 79 except OSError as e: | |
| 80 print ' error killing dbus-daemon with PID %s: %s' % (dbus_pid, e) | |
| 81 # Try to clean up any stray DBUS_SESSION_BUS_ADDRESS environment | |
| 82 # variable too. Some of the bots seem to re-invoke runtest.py in a | |
| 83 # way that this variable sticks around from run to run. | |
| 84 if 'DBUS_SESSION_BUS_ADDRESS' in os.environ: | |
| 85 del os.environ['DBUS_SESSION_BUS_ADDRESS'] | |
| 86 print ' cleared DBUS_SESSION_BUS_ADDRESS environment variable' | |
| 87 | |
| 88 | |
| 89 if __name__ == '__main__': | |
| 90 did_launch_dbus = _LaunchDBus() | |
| 91 try: | |
| 92 retcode = benchmark_runner.main(gpu_project_config.CONFIG) | |
| 93 finally: | |
| 94 if did_launch_dbus: | |
| 95 _ShutdownDBus() | |
| 96 | |
| 97 sys.exit(retcode) | |
| OLD | NEW |