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.
11 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
),
12 os
.pardir
, os
.pardir
, os
.pardir
, 'tools', 'telemetry'))
14 from telemetry
import benchmark_runner
18 """Launches DBus to work around a bug in GLib.
20 Works around a bug in GLib where it performs operations which aren't
21 async-signal-safe (in particular, memory allocations) between fork and exec
22 when it spawns subprocesses. This causes threads inside Chrome's browser and
23 utility processes to get stuck, and this harness to hang waiting for those
24 processes, which will never terminate. This doesn't happen on users'
25 machines, because they have an active desktop session and the
26 DBUS_SESSION_BUS_ADDRESS environment variable set, but it does happen on the
27 bots. See crbug.com/309093 for more details.
30 True if it actually spawned DBus.
33 if (platform
.uname()[0].lower() != 'linux' or
34 'DBUS_SESSION_BUS_ADDRESS' in os
.environ
):
37 # Only start DBus on systems that are actually running X. Using DISPLAY
38 # variable is not reliable, because is it set by the /etc/init.d/buildbot
39 # script for all slaves.
40 # TODO(sergiyb): When all GPU slaves are migrated to swarming, we can remove
41 # assignment of the DISPLAY from /etc/init.d/buildbot because this hack was
42 # used to run GPU tests on buildbot. After it is removed, we can use DISPLAY
43 # variable here to check if we are running X.
44 if subprocess
.call(['pidof', 'X'], stdout
=subprocess
.PIPE
) == 0:
46 print 'DBUS_SESSION_BUS_ADDRESS env var not found, starting dbus-launch'
47 dbus_output
= subprocess
.check_output(['dbus-launch']).split('\n')
48 for line
in dbus_output
:
49 m
= re
.match(r
'([^=]+)\=(.+)', line
)
51 os
.environ
[m
.group(1)] = m
.group(2)
52 print ' setting %s to %s' % (m
.group(1), m
.group(2))
54 except (subprocess
.CalledProcessError
, OSError) as e
:
55 print 'Exception while running dbus_launch: %s' % e
60 """Manually kills the previously-launched DBus daemon.
62 It appears that passing --exit-with-session to dbus-launch in
63 _LaunchDBus(), above, doesn't cause the launched dbus-daemon to shut
64 down properly. Manually kill the sub-process using the PID it gave
67 This function is called when the flag --spawn-dbus is given, and if
68 _LaunchDBus(), above, actually spawned the dbus-daemon.
71 if 'DBUS_SESSION_BUS_PID' in os
.environ
:
72 dbus_pid
= os
.environ
['DBUS_SESSION_BUS_PID']
74 os
.kill(int(dbus_pid
), signal
.SIGTERM
)
75 print ' killed dbus-daemon with PID %s' % dbus_pid
77 print ' error killing dbus-daemon with PID %s: %s' % (dbus_pid
, e
)
78 # Try to clean up any stray DBUS_SESSION_BUS_ADDRESS environment
79 # variable too. Some of the bots seem to re-invoke runtest.py in a
80 # way that this variable sticks around from run to run.
81 if 'DBUS_SESSION_BUS_ADDRESS' in os
.environ
:
82 del os
.environ
['DBUS_SESSION_BUS_ADDRESS']
83 print ' cleared DBUS_SESSION_BUS_ADDRESS environment variable'
86 if __name__
== '__main__':
87 top_level_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
88 config
= benchmark_runner
.ProjectConfig(
89 top_level_dir
=top_level_dir
,
90 benchmark_dirs
=[os
.path
.join(top_level_dir
, 'gpu_tests')])
92 did_launch_dbus
= _LaunchDBus()
94 retcode
= benchmark_runner
.main(config
)