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

Side by Side Diff: testing/xvfb.py

Issue 9621014: Separate xvfb.py logic into its own script (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Save 5 lines, a variable is not needed Created 8 years, 9 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 | « testing/test_env.py ('k') | tools/isolate/isolate.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 #!/usr/bin/env python
2 # Copyright (c) 2012 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 """Runs the test with xvfb on linux. Runs the test normally on other platforms.
7
8 For simplicity in gyp targets, this script just runs the test normal on
9 non-linux platforms.
10 """
11
12 import os
13 import platform
14 import signal
15 import subprocess
16 import sys
17
18 import test_env
19
20
21 def kill(pid):
22 """Kills a process and traps exception if the process doesn't exist anymore.
23 """
24 # If the process doesn't exist, it raises an exception that we can ignore.
25 try:
26 os.kill(pid, signal.SIGKILL)
27 except OSError:
28 pass
29
30
31 def get_xvfb_path(server_dir):
32 """Figures out which X server to use."""
33 xvfb_path = os.path.join(server_dir, 'Xvfb.' + platform.architecture()[0])
34 if not os.path.exists(xvfb_path):
35 xvfb_path = os.path.join(server_dir, 'Xvfb')
36 if not os.path.exists(xvfb_path):
37 print >> sys.stderr, (
38 'No Xvfb found in designated server path: %s' % server_dir)
39 raise Exception('No virtual server')
40 return xvfb_path
41
42
43 def start_xvfb(xvfb_path, display):
44 """Starts a virtual X server that we run the tests in.
45
46 This makes it so we can run the tests even if we didn't start the tests from
47 an X session.
48
49 Args:
50 xvfb_path: Path to Xvfb.
51 """
52 proc = subprocess.Popen(
53 [xvfb_path, display, '-screen', '0', '1024x768x24', '-ac'],
54 stdout=subprocess.PIPE,
55 stderr=subprocess.STDOUT)
56 return proc.pid
57
58
59 def wait_for_xvfb(xdisplaycheck, env):
60 """Waits for xvfb to be fully initialized by using xdisplaycheck."""
61 try:
62 subprocess.check_call(
63 [xdisplaycheck],
64 stdout=subprocess.PIPE,
65 stderr=subprocess.STDOUT,
66 env=env)
67 except subprocess.CalledProcessError:
68 print >> sys.stderr, 'Xvfb failed to load properly.'
69 return False
70 return True
71
72
73 def run_executable(cmd, build_dir, env):
74 """Runs an executable within a xvfb buffer on linux or normally on other
75 platforms.
76
77 Requires that both xvfb and icewm are installed on linux.
78 """
79 pid = None
80 xvfb = 'Xvfb'
81 try:
82 if sys.platform == 'linux2':
83 # Defaults to X display 9.
84 display = ':9'
85 pid = start_xvfb(xvfb, display)
86 env['DISPLAY'] = display
87 if not wait_for_xvfb(os.path.join(build_dir, 'xdisplaycheck'), env):
88 return 3
89 # Some ChromeOS tests need a window manager. Technically, it could be
90 # another script but that would be overkill.
91 subprocess.Popen(
92 'icewm', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
93 return test_env.run_executable(cmd, env)
94 finally:
95 if pid:
96 kill(pid)
97
98
99 def main():
100 if len(sys.argv) < 3:
101 print >> sys.stderr, (
102 'Usage: xvfb.py [path to build_dir] [command args...]')
103 return 2
104 return run_executable(sys.argv[2:], sys.argv[1], os.environ.copy())
105
106
107 if __name__ == "__main__":
108 sys.exit(main())
OLDNEW
« no previous file with comments | « testing/test_env.py ('k') | tools/isolate/isolate.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698