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

Side by Side Diff: build/android/run_tests.py

Issue 8536051: Add xvfb option for running android tests on a bot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix condition when not using xvfb Created 9 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 all the native unit tests. 6 """Runs all the native unit tests.
7 7
8 1. Copy over test binary to /data/local on device. 8 1. Copy over test binary to /data/local on device.
9 2. Resources: chrome/unit_tests requires resources (chrome.pak and en-US.pak) 9 2. Resources: chrome/unit_tests requires resources (chrome.pak and en-US.pak)
10 to be deployed to the device (in /data/local/tmp). 10 to be deployed to the device (in /data/local/tmp).
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 This file is generated by the tests running on devices. If running on emulator, 44 This file is generated by the tests running on devices. If running on emulator,
45 additonal filter file which lists the tests only failed in emulator will be 45 additonal filter file which lists the tests only failed in emulator will be
46 loaded. We don't care about the rare testcases which succeeded on emuatlor, but 46 loaded. We don't care about the rare testcases which succeeded on emuatlor, but
47 failed on device. 47 failed on device.
48 """ 48 """
49 49
50 import logging 50 import logging
51 import os 51 import os
52 import re 52 import re
53 import subprocess
53 import sys 54 import sys
54 55
55 import android_commands 56 import android_commands
56 import cmd_helper 57 import cmd_helper
57 import debug_info 58 import debug_info
58 import emulator 59 import emulator
59 import run_tests_helper 60 import run_tests_helper
60 from single_test_runner import SingleTestRunner 61 from single_test_runner import SingleTestRunner
61 from test_package_executable import TestPackageExecutable 62 from test_package_executable import TestPackageExecutable
62 from test_result import BaseTestResult, TestResults 63 from test_result import BaseTestResult, TestResults
63 64
64 _TEST_SUITES = ['base_unittests', 'sql_unittests', 'ipc_tests'] 65 _TEST_SUITES = ['base_unittests', 'sql_unittests', 'ipc_tests']
65 66
67
68 class Xvfb(object):
69 """Class to start and stop Xvfb if relevant. Nop if not Linux."""
70
71 def __init__(self):
72 self._pid = 0
73
74 def _IsLinux(self):
75 """Return True if on Linux; else False."""
76 return sys.platform.startswith('linux')
77
78 def Start(self):
79 """Start Xvfb and set an appropriate DISPLAY environment. Linux only.
80
81 Copied from tools/code_coverage/coverage_posix.py
82 """
83 if not self._IsLinux():
84 return
85 proc = subprocess.Popen(["Xvfb", ":9", "-screen", "0", "1024x768x24",
86 "-ac"],
87 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
88 self._pid = proc.pid
89 if not self._pid:
90 raise Exception('Could not start Xvfb')
91 os.environ['DISPLAY'] = ":9"
92
93 # Now confirm, giving a chance for it to start if needed.
94 for test in range(10):
95 proc = subprocess.Popen('xdpyinfo >/dev/null', shell=True)
96 pid, retcode = os.waitpid(proc.pid, 0)
97 if retcode == 0:
98 break
99 time.sleep(0.25)
100 if retcode != 0:
101 raise Exception('Could not confirm Xvfb happiness')
102
103 def Stop(self):
104 """Stop Xvfb if needed. Linux only."""
105 if self._pid:
106 try:
107 os.kill(self._pid, signal.SIGKILL)
108 except:
109 pass
110 del os.environ['DISPLAY']
111 self._pid = 0
112
113
66 def RunTests(device, test_suite, gtest_filter, test_arguments, rebaseline, 114 def RunTests(device, test_suite, gtest_filter, test_arguments, rebaseline,
67 timeout, performance_test, cleanup_test_files, tool, 115 timeout, performance_test, cleanup_test_files, tool,
68 log_dump_name): 116 log_dump_name):
69 """Runs the tests. 117 """Runs the tests.
70 118
71 Args: 119 Args:
72 device: Device to run the tests. 120 device: Device to run the tests.
73 test_suite: A specific test suite to run, empty to run all. 121 test_suite: A specific test suite to run, empty to run all.
74 gtest_filter: A gtest_filter flag. 122 gtest_filter: A gtest_filter flag.
75 test_arguments: Additional arguments to pass to the test binary. 123 test_arguments: Additional arguments to pass to the test binary.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 181
134 Returns: 182 Returns:
135 0 if successful, number of failing tests otherwise. 183 0 if successful, number of failing tests otherwise.
136 """ 184 """
137 if options.test_suite == 'help': 185 if options.test_suite == 'help':
138 ListTestSuites() 186 ListTestSuites()
139 return 0 187 return 0
140 buildbot_emulator = None 188 buildbot_emulator = None
141 attached_devices = [] 189 attached_devices = []
142 190
191 if options.use_xvfb:
192 xvfb = Xvfb()
193 xvfb.Start()
194
143 if options.use_emulator: 195 if options.use_emulator:
144 buildbot_emulator = emulator.Emulator() 196 buildbot_emulator = emulator.Emulator()
145 buildbot_emulator.Launch() 197 buildbot_emulator.Launch()
146 attached_devices.append(buildbot_emulator.device) 198 attached_devices.append(buildbot_emulator.device)
147 else: 199 else:
148 attached_devices = android_commands.GetAttachedDevices() 200 attached_devices = android_commands.GetAttachedDevices()
149 201
150 if not attached_devices: 202 if not attached_devices:
151 logging.critical('A device must be attached and online.') 203 logging.critical('A device must be attached and online.')
152 return 1 204 return 1
153 205
154 test_results = RunTests(attached_devices[0], options.test_suite, 206 test_results = RunTests(attached_devices[0], options.test_suite,
155 options.gtest_filter, options.test_arguments, 207 options.gtest_filter, options.test_arguments,
156 options.rebaseline, options.timeout, 208 options.rebaseline, options.timeout,
157 options.performance_test, 209 options.performance_test,
158 options.cleanup_test_files, options.tool, 210 options.cleanup_test_files, options.tool,
159 options.log_dump) 211 options.log_dump)
160 if buildbot_emulator: 212 if buildbot_emulator:
161 buildbot_emulator.Shutdown() 213 buildbot_emulator.Shutdown()
214 if options.use_xvfb:
215 xvfb.Stop()
216
162 return len(test_results.failed) 217 return len(test_results.failed)
163 218
164 def ListTestSuites(): 219 def ListTestSuites():
165 """Display a list of available test suites 220 """Display a list of available test suites
166 """ 221 """
167 print 'Available test suites are:' 222 print 'Available test suites are:'
168 for test_suite in _TEST_SUITES: 223 for test_suite in _TEST_SUITES:
169 print test_suite 224 print test_suite
170 225
171 226
(...skipping 16 matching lines...) Expand all
188 action='store_true', 243 action='store_true',
189 default=False) 244 default=False)
190 option_parser.add_option('-L', dest='log_dump', 245 option_parser.add_option('-L', dest='log_dump',
191 help='file name of log dump, which will be put in' 246 help='file name of log dump, which will be put in'
192 'subfolder debug_info_dumps under the same directory' 247 'subfolder debug_info_dumps under the same directory'
193 'in where the test_suite exists.') 248 'in where the test_suite exists.')
194 option_parser.add_option('-e', '--emulator', dest='use_emulator', 249 option_parser.add_option('-e', '--emulator', dest='use_emulator',
195 help='Run tests in a new instance of emulator', 250 help='Run tests in a new instance of emulator',
196 action='store_true', 251 action='store_true',
197 default=False) 252 default=False)
253 option_parser.add_option('-x', '--xvfb', dest='use_xvfb',
254 action='store_true', default=False,
255 help='Use Xvfb around tests (ignored if not Linux)')
198 options, args = option_parser.parse_args(argv) 256 options, args = option_parser.parse_args(argv)
199 if len(args) > 1: 257 if len(args) > 1:
200 print 'Unknown argument:', args[1:] 258 print 'Unknown argument:', args[1:]
201 option_parser.print_usage() 259 option_parser.print_usage()
202 sys.exit(1) 260 sys.exit(1)
203 run_tests_helper.SetLogLevel(options.verbose_count) 261 run_tests_helper.SetLogLevel(options.verbose_count)
204 return Dispatch(options) 262 return Dispatch(options)
205 263
206 264
207 if __name__ == '__main__': 265 if __name__ == '__main__':
208 sys.exit(main(sys.argv)) 266 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698