Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: build/android/pylib/utils/xvfb.py

Issue 11734008: [Android] Move Xvfb and TimeProfile from run_tests.py into individual files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/utils/time_profile.py ('k') | build/android/run_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (c) 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.
4
5 import os
6 import signal
7 import subprocess
8 import sys
9 import time
10
11
12 def _IsLinux():
13 """Return True if on Linux; else False."""
14 return sys.platform.startswith('linux')
15
16
17 class Xvfb(object):
18 """Class to start and stop Xvfb if relevant. Nop if not Linux."""
19
20 def __init__(self):
21 self._pid = 0
22
23 def Start(self):
24 """Start Xvfb and set an appropriate DISPLAY environment. Linux only.
25
26 Copied from tools/code_coverage/coverage_posix.py
27 """
28 if not _IsLinux():
29 return
30 proc = subprocess.Popen(['Xvfb', ':9', '-screen', '0', '1024x768x24',
31 '-ac'],
32 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
33 self._pid = proc.pid
34 if not self._pid:
35 raise Exception('Could not start Xvfb')
36 os.environ['DISPLAY'] = ':9'
37
38 # Now confirm, giving a chance for it to start if needed.
39 for _ in range(10):
40 proc = subprocess.Popen('xdpyinfo >/dev/null', shell=True)
41 _, retcode = os.waitpid(proc.pid, 0)
42 if retcode == 0:
43 break
44 time.sleep(0.25)
45 if retcode != 0:
46 raise Exception('Could not confirm Xvfb happiness')
47
48 def Stop(self):
49 """Stop Xvfb if needed. Linux only."""
50 if self._pid:
51 try:
52 os.kill(self._pid, signal.SIGKILL)
53 except:
54 pass
55 del os.environ['DISPLAY']
56 self._pid = 0
OLDNEW
« no previous file with comments | « build/android/pylib/utils/time_profile.py ('k') | build/android/run_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698