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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « testing/test_env.py ('k') | tools/isolate/isolate.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/xvfb.py
diff --git a/testing/xvfb.py b/testing/xvfb.py
new file mode 100755
index 0000000000000000000000000000000000000000..ed82676e12d7c42c81b04fb2948f689b05827b07
--- /dev/null
+++ b/testing/xvfb.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Runs the test with xvfb on linux.
+
+For simplicity in gyp targets, this script has no effect on the other platforms.
+"""
+
+import os
+import platform
+import signal
+import subprocess
+import sys
+
+import test_env
+
+
+def kill(pid):
+ """Kills a process and traps exception if the process doesn't exist anymore.
+ """
+ # If the process doesn't exist, it raises an exception that we can ignore.
+ try:
+ os.kill(pid, signal.SIGKILL)
+ except OSError:
+ pass
+
+
+def get_xvfb_path(server_dir):
+ """Figures out which X server to use."""
+ xvfb_path = os.path.join(server_dir, 'Xvfb.' + platform.architecture()[0])
+ if not os.path.exists(xvfb_path):
+ xvfb_path = os.path.join(server_dir, 'Xvfb')
+ if not os.path.exists(xvfb_path):
+ print >> sys.stderr, (
+ 'No Xvfb found in designated server path: %s' % server_dir)
+ raise Exception('No virtual server')
+ return xvfb_path
+
+
+def start_xvfb(xvfb_path, display):
+ """Starts a virtual X server that we run the tests in.
+
+ This makes it so we can run the tests even if we didn't start the tests from
+ an X session.
+
+ Args:
+ xvfb_path: Path to Xvfb.
+ """
+ proc = subprocess.Popen(
+ [xvfb_path, display, '-screen', '0', '1024x768x24', '-ac'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ return proc.pid
+
+
+def wait_for_xvfb(xdisplaycheck, env):
+ """Waits for xvfb to be fully initialized by using xdisplaycheck."""
+ try:
+ subprocess.check_call(
+ [xdisplaycheck],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ env=env)
+ except subprocess.CalledProcessError:
+ print >> sys.stderr, 'Xvfb failed to load properly.'
+ return False
+ return True
+
+
+def run_executable(cmd, build_dir, env):
+ """Runs an executable within a xvfb buffer on linux.
+
+ Runs the test normally on other platforms. Requires that both xvfb and icewm
+ are installed on linux.
+ """
+ pid = None
+ xvfb = 'Xvfb'
+ try:
+ if sys.platform == 'linux2':
+ # Defaults to X display 9.
+ display = ':9'
+ pid = start_xvfb(xvfb, display)
+ env['DISPLAY'] = display
+ if not wait_for_xvfb(os.path.join(build_dir, 'xdisplaycheck'), env):
+ return 3
+ # Some ChromeOS tests need a window manager. Technically, it could be
+ # another script but that would be overkill.
+ subprocess.Popen(
+ 'icewm', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
+ return test_env.run_executable(cmd, env)
Roger Tawa OOO till Jul 10th 2012/03/07 19:51:27 should this be indented two more? the comment at
M-A Ruel 2012/03/07 20:21:05 I fixed the comment to be more sensical.
+ finally:
+ if pid:
+ kill(pid)
+
+
+def main():
+ if len(sys.argv) < 3:
+ print >> sys.stderr, (
+ 'Usage: xvfb.py [path to build_dir] [command args...]')
+ return 2
+ return run_executable(sys.argv[2:], sys.argv[1], os.environ.copy())
+
+
+if __name__ == "__main__":
+ sys.exit(main())
« 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