Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Runs the test with xvfb on linux. Runs the test normally on other platforms. | 6 """Runs the test with xvfb on linux. Runs the test normally on other platforms. |
| 7 | 7 |
| 8 For simplicity in gyp targets, this script just runs the test normal on | 8 For simplicity in gyp targets, this script just runs the test normal on |
| 9 non-linux platforms. | 9 non-linux platforms. |
| 10 """ | 10 """ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 | 48 |
| 49 Args: | 49 Args: |
| 50 xvfb_path: Path to Xvfb. | 50 xvfb_path: Path to Xvfb. |
| 51 """ | 51 """ |
| 52 cmd = [xvfb_path, display, '-screen', '0', '1024x768x24', '-ac'] | 52 cmd = [xvfb_path, display, '-screen', '0', '1024x768x24', '-ac'] |
| 53 try: | 53 try: |
| 54 proc = subprocess.Popen( | 54 proc = subprocess.Popen( |
| 55 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 55 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 56 except OSError: | 56 except OSError: |
| 57 print >> sys.stderr, 'Failed to run %s' % ' '.join(cmd) | 57 print >> sys.stderr, 'Failed to run %s' % ' '.join(cmd) |
| 58 return 0 | 58 return |
| 59 return proc.pid | 59 return proc |
| 60 | 60 |
| 61 | 61 |
| 62 def wait_for_xvfb(xdisplaycheck, env): | 62 def wait_for_xvfb(xdisplaycheck, env): |
| 63 """Waits for xvfb to be fully initialized by using xdisplaycheck.""" | 63 """Waits for xvfb to be fully initialized by using xdisplaycheck.""" |
| 64 try: | 64 try: |
| 65 subprocess.check_call( | 65 _logs = subprocess.check_output( |
| 66 [xdisplaycheck], | 66 [xdisplaycheck], |
| 67 stdout=subprocess.PIPE, | |
| 68 stderr=subprocess.STDOUT, | 67 stderr=subprocess.STDOUT, |
| 69 env=env) | 68 env=env) |
| 70 except OSError: | 69 except OSError: |
| 71 print >> sys.stderr, 'Failed to load %s with cwd=%s' % ( | 70 print >> sys.stderr, 'Failed to load %s with cwd=%s' % ( |
| 72 xdisplaycheck, os.getcwd()) | 71 xdisplaycheck, os.getcwd()) |
| 73 return False | 72 return False |
| 74 except subprocess.CalledProcessError: | 73 except subprocess.CalledProcessError as e: |
| 75 print >> sys.stderr, ( | 74 print >> sys.stderr, ( |
| 76 'Xvfb failed to load properly while trying to run %s' % xdisplaycheck) | 75 'Xvfb failed to load properly (code %d) according to %s' % |
| 76 (e.returncode, xdisplaycheck)) | |
| 77 return False | 77 return False |
| 78 | |
| 78 return True | 79 return True |
| 79 | 80 |
| 80 | 81 |
| 81 def run_executable(cmd, build_dir, env): | 82 def run_executable(cmd, build_dir, env): |
| 82 """Runs an executable within a xvfb buffer on linux or normally on other | 83 """Runs an executable within a xvfb buffer on linux or normally on other |
| 83 platforms. | 84 platforms. |
| 84 | 85 |
| 85 Requires that both xvfb and openbox are installed on linux. | 86 Requires that both xvfb and openbox are installed on linux. |
| 86 | 87 |
| 87 Detects recursion with an environment variable and do not create a recursive X | 88 Detects recursion with an environment variable and do not create a recursive X |
| 88 buffer if present. | 89 buffer if present. |
| 89 """ | 90 """ |
| 90 # First look if we are inside a display. | 91 # First look if we are inside a display. |
| 91 if env.get('_CHROMIUM_INSIDE_XVFB') == '1': | 92 if env.get('_CHROMIUM_INSIDE_XVFB') == '1': |
| 92 # No need to recurse. | 93 # No need to recurse. |
| 93 return test_env.run_executable(cmd, env) | 94 return test_env.run_executable(cmd, env) |
| 94 | 95 |
| 95 pid = None | 96 pid = None |
| 96 xvfb = 'Xvfb' | 97 xvfb = 'Xvfb' |
| 97 try: | 98 try: |
| 98 if sys.platform == 'linux2': | 99 if sys.platform == 'linux2': |
| 99 # Defaults to X display 9. | 100 # Defaults to X display 9. |
| 100 display = ':9' | 101 display = ':9' |
| 101 pid = start_xvfb(xvfb, display) | 102 proc = start_xvfb(xvfb, display) |
|
M-A Ruel
2014/07/14 16:54:35
I'd prefer xvfb_proc just so it's easier to scan t
Peter Mayo
2014/07/14 16:58:08
I agree. Done.
| |
| 102 if not pid: | 103 if not proc or not proc.pid: |
| 103 return 1 | 104 return 1 |
| 104 env['DISPLAY'] = display | 105 env['DISPLAY'] = display |
| 105 if not wait_for_xvfb(os.path.join(build_dir, 'xdisplaycheck'), env): | 106 if not wait_for_xvfb(os.path.join(build_dir, 'xdisplaycheck'), env): |
| 107 rc = proc.poll() | |
| 108 if rc is None: | |
| 109 print 'Xvfb still running, stopping.' | |
| 110 proc.terminate() | |
| 111 else: | |
| 112 print 'Xvfb exited, code %d' % rc | |
| 113 | |
| 114 print 'Xvfb output:' | |
| 115 for l in proc.communicate()[0].splitlines(): | |
| 116 print '> %s' % l | |
| 117 | |
| 106 return 3 | 118 return 3 |
| 107 # Inhibit recursion. | 119 # Inhibit recursion. |
| 108 env['_CHROMIUM_INSIDE_XVFB'] = '1' | 120 env['_CHROMIUM_INSIDE_XVFB'] = '1' |
| 109 # Some ChromeOS tests need a window manager. Technically, it could be | 121 # Some ChromeOS tests need a window manager. Technically, it could be |
| 110 # another script but that would be overkill. | 122 # another script but that would be overkill. |
| 111 try: | 123 try: |
| 112 wm_cmd = ['openbox'] | 124 wm_cmd = ['openbox'] |
| 113 subprocess.Popen( | 125 subprocess.Popen( |
| 114 wm_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) | 126 wm_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) |
| 115 except OSError: | 127 except OSError: |
| 116 print >> sys.stderr, 'Failed to run %s' % ' '.join(wm_cmd) | 128 print >> sys.stderr, 'Failed to run %s' % ' '.join(wm_cmd) |
| 117 return 1 | 129 return 1 |
| 118 return test_env.run_executable(cmd, env) | 130 return test_env.run_executable(cmd, env) |
| 119 finally: | 131 finally: |
| 120 if pid: | 132 if pid: |
| 121 kill(pid) | 133 kill(pid) |
| 122 | 134 |
| 123 | 135 |
| 124 def main(): | 136 def main(): |
| 125 if len(sys.argv) < 3: | 137 if len(sys.argv) < 3: |
| 126 print >> sys.stderr, ( | 138 print >> sys.stderr, ( |
| 127 'Usage: xvfb.py [path to build_dir] [command args...]') | 139 'Usage: xvfb.py [path to build_dir] [command args...]') |
| 128 return 2 | 140 return 2 |
| 129 return run_executable(sys.argv[2:], sys.argv[1], os.environ.copy()) | 141 return run_executable(sys.argv[2:], sys.argv[1], os.environ.copy()) |
| 130 | 142 |
| 131 | 143 |
| 132 if __name__ == "__main__": | 144 if __name__ == "__main__": |
| 133 sys.exit(main()) | 145 sys.exit(main()) |
| OLD | NEW |