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 tests with Xvfb and Openbox on Linux and normally on other platforms.""" | 6 """Runs tests with Xvfb and Openbox on Linux and normally on other platforms.""" |
7 | 7 |
8 import os | 8 import os |
9 import os.path | 9 import os.path |
10 import platform | 10 import platform |
(...skipping 30 matching lines...) Expand all Loading... |
41 thread.join(timeout_in_seconds) | 41 thread.join(timeout_in_seconds) |
42 if thread.is_alive(): | 42 if thread.is_alive(): |
43 print >> sys.stderr, 'Xvfb running after SIGTERM and SIGKILL; good luck!' | 43 print >> sys.stderr, 'Xvfb running after SIGTERM and SIGKILL; good luck!' |
44 | 44 |
45 | 45 |
46 def run_executable(cmd, env): | 46 def run_executable(cmd, env): |
47 """Runs an executable within Xvfb on Linux or normally on other platforms. | 47 """Runs an executable within Xvfb on Linux or normally on other platforms. |
48 | 48 |
49 Returns the exit code of the specified commandline, or 1 on failure. | 49 Returns the exit code of the specified commandline, or 1 on failure. |
50 """ | 50 """ |
51 if sys.platform == 'linux2': | 51 |
| 52 # It might seem counterintuitive to support a --no-xvfb flag in a script |
| 53 # whose only job is to start xvfb, but doing so allows us to consolidate |
| 54 # the logic in the layers of buildbot scripts so that we *always* use |
| 55 # xvfb by default and don't have to worry about the distinction, it |
| 56 # can remain solely under the control of the test invocation itself. |
| 57 use_xvfb = True |
| 58 if '--no-xvfb' in cmd: |
| 59 use_xvfb = False |
| 60 cmd.remove('--no-xvfb') |
| 61 |
| 62 if sys.platform == 'linux2' and use_xvfb: |
52 if env.get('_CHROMIUM_INSIDE_XVFB') == '1': | 63 if env.get('_CHROMIUM_INSIDE_XVFB') == '1': |
53 openbox_proc = None | 64 openbox_proc = None |
54 xcompmgr_proc = None | 65 xcompmgr_proc = None |
55 try: | 66 try: |
56 # Some ChromeOS tests need a window manager. | 67 # Some ChromeOS tests need a window manager. |
57 openbox_proc = subprocess.Popen('openbox', stdout=subprocess.PIPE, | 68 openbox_proc = subprocess.Popen('openbox', stdout=subprocess.PIPE, |
58 stderr=subprocess.STDOUT, env=env) | 69 stderr=subprocess.STDOUT, env=env) |
59 | 70 |
60 # Some tests need a compositing wm to make use of transparent visuals. | 71 # Some tests need a compositing wm to make use of transparent visuals. |
61 xcompmgr_proc = subprocess.Popen('xcompmgr', stdout=subprocess.PIPE, | 72 xcompmgr_proc = subprocess.Popen('xcompmgr', stdout=subprocess.PIPE, |
(...skipping 12 matching lines...) Expand all Loading... |
74 if xvfb_script.endswith('.pyc'): | 85 if xvfb_script.endswith('.pyc'): |
75 xvfb_script = xvfb_script[:-1] | 86 xvfb_script = xvfb_script[:-1] |
76 return subprocess.call(['xvfb-run', '-a', "--server-args=-screen 0 " | 87 return subprocess.call(['xvfb-run', '-a', "--server-args=-screen 0 " |
77 "1280x800x24 -ac -nolisten tcp -dpi 96", | 88 "1280x800x24 -ac -nolisten tcp -dpi 96", |
78 xvfb_script] + cmd, env=env) | 89 xvfb_script] + cmd, env=env) |
79 else: | 90 else: |
80 return test_env.run_executable(cmd, env) | 91 return test_env.run_executable(cmd, env) |
81 | 92 |
82 | 93 |
83 def main(): | 94 def main(): |
84 USAGE = 'Usage: xvfb.py [command args...]' | 95 USAGE = 'Usage: xvfb.py [command [--no-xvfb] args...]' |
85 if len(sys.argv) < 2: | 96 if len(sys.argv) < 2: |
86 print >> sys.stderr, USAGE | 97 print >> sys.stderr, USAGE |
87 return 2 | 98 return 2 |
88 | 99 |
89 # If the user still thinks the first argument is the execution directory then | 100 # If the user still thinks the first argument is the execution directory then |
90 # print a friendly error message and quit. | 101 # print a friendly error message and quit. |
91 if os.path.isdir(sys.argv[1]): | 102 if os.path.isdir(sys.argv[1]): |
92 print >> sys.stderr, ( | 103 print >> sys.stderr, ( |
93 'Invalid command: \"%s\" is a directory' % sys.argv[1]) | 104 'Invalid command: \"%s\" is a directory' % sys.argv[1]) |
94 print >> sys.stderr, USAGE | 105 print >> sys.stderr, USAGE |
95 return 3 | 106 return 3 |
96 | 107 |
97 return run_executable(sys.argv[1:], os.environ.copy()) | 108 return run_executable(sys.argv[1:], os.environ.copy()) |
98 | 109 |
99 | 110 |
100 if __name__ == "__main__": | 111 if __name__ == "__main__": |
101 sys.exit(main()) | 112 sys.exit(main()) |
OLD | NEW |