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

Side by Side Diff: build/android/pylib/single_test_runner.py

Issue 10689132: [android] Upstream / sync most of build/android and build/android/pylib. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | « build/android/pylib/run_tests_helper.py ('k') | build/android/pylib/test_options_parser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import glob
5 import logging 6 import logging
6 import os 7 import os
7 import sys 8 import sys
8 9
9 from base_test_runner import BaseTestRunner 10 from base_test_runner import BaseTestRunner
10 import debug_info 11 import debug_info
12 import constants
11 import run_tests_helper 13 import run_tests_helper
12 from test_package_apk import TestPackageApk 14 from test_package_apk import TestPackageApk
13 from test_package_executable import TestPackageExecutable 15 from test_package_executable import TestPackageExecutable
14 from test_result import TestResults 16 from test_result import TestResults
15 17
16 18
17 class SingleTestRunner(BaseTestRunner): 19 class SingleTestRunner(BaseTestRunner):
18 """Single test suite attached to a single device. 20 """Single test suite attached to a single device.
19 21
20 Args: 22 Args:
21 device: Device to run the tests. 23 device: Device to run the tests.
22 test_suite: A specific test suite to run, empty to run all. 24 test_suite: A specific test suite to run, empty to run all.
23 gtest_filter: A gtest_filter flag. 25 gtest_filter: A gtest_filter flag.
24 test_arguments: Additional arguments to pass to the test binary. 26 test_arguments: Additional arguments to pass to the test binary.
25 timeout: Timeout for each test. 27 timeout: Timeout for each test.
26 rebaseline: Whether or not to run tests in isolation and update the filter. 28 rebaseline: Whether or not to run tests in isolation and update the filter.
27 performance_test: Whether or not performance test(s). 29 performance_test: Whether or not performance test(s).
28 cleanup_test_files: Whether or not to cleanup test files on device. 30 cleanup_test_files: Whether or not to cleanup test files on device.
29 tool: Name of the Valgrind tool. 31 tool: Name of the Valgrind tool.
30 shard_index: index number of the shard on which the test suite will run. 32 shard_index: index number of the shard on which the test suite will run.
31 dump_debug_info: Whether or not to dump debug information. 33 dump_debug_info: Whether or not to dump debug information.
32 """ 34 """
33 35
34 def __init__(self, device, test_suite, gtest_filter, test_arguments, timeout, 36 def __init__(self, device, test_suite, gtest_filter, test_arguments, timeout,
35 rebaseline, performance_test, cleanup_test_files, tool, 37 rebaseline, performance_test, cleanup_test_files, tool_name,
36 shard_index, dump_debug_info=False, 38 shard_index, dump_debug_info=False,
37 fast_and_loose=False): 39 fast_and_loose=False):
38 BaseTestRunner.__init__(self, device, shard_index) 40 BaseTestRunner.__init__(self, device, tool_name, shard_index)
39 self._running_on_emulator = self.device.startswith('emulator') 41 self._running_on_emulator = self.device.startswith('emulator')
40 self._gtest_filter = gtest_filter 42 self._gtest_filter = gtest_filter
41 self._test_arguments = test_arguments 43 self._test_arguments = test_arguments
42 self.test_results = TestResults() 44 self.test_results = TestResults()
43 if dump_debug_info: 45 if dump_debug_info:
44 self.dump_debug_info = debug_info.GTestDebugInfo(self.adb, device, 46 self.dump_debug_info = debug_info.GTestDebugInfo(self.adb, device,
45 os.path.basename(test_suite), gtest_filter) 47 os.path.basename(test_suite), gtest_filter)
46 else: 48 else:
47 self.dump_debug_info = None 49 self.dump_debug_info = None
48 self.fast_and_loose = fast_and_loose 50 self.fast_and_loose = fast_and_loose
49 51
50 if os.path.splitext(test_suite)[1] == '.apk': 52 if os.path.splitext(test_suite)[1] == '.apk':
51 self.test_package = TestPackageApk( 53 self.test_package = TestPackageApk(self.adb, device,
52 self.adb, device,
53 test_suite, timeout, rebaseline, performance_test, cleanup_test_files, 54 test_suite, timeout, rebaseline, performance_test, cleanup_test_files,
54 tool, self.dump_debug_info) 55 self.tool, self.dump_debug_info)
55 else: 56 else:
56 self.test_package = TestPackageExecutable( 57 self.test_package = TestPackageExecutable(
57 self.adb, device, 58 self.adb, device,
58 test_suite, timeout, rebaseline, performance_test, cleanup_test_files, 59 test_suite, timeout, rebaseline, performance_test, cleanup_test_files,
59 tool, self.dump_debug_info) 60 self.tool, self.dump_debug_info)
60
61 def _GetHttpServerDocumentRootForTestSuite(self):
62 """Returns the document root needed by the test suite."""
63 if self.test_package.test_suite_basename == 'page_cycler_tests':
64 return os.path.join(run_tests_helper.CHROME_DIR, 'data', 'page_cycler')
65 return None
66
67 61
68 def _TestSuiteRequiresMockTestServer(self): 62 def _TestSuiteRequiresMockTestServer(self):
69 """Returns True if the test suite requires mock test server.""" 63 """Returns True if the test suite requires mock test server."""
70 return False 64 return False
71 # TODO(yfriedman): Disabled because of flakiness. 65 # TODO(yfriedman): Disabled because of flakiness.
72 # (self.test_package.test_suite_basename == 'unit_tests' or 66 # (self.test_package.test_suite_basename == 'unit_tests' or
73 # self.test_package.test_suite_basename == 'net_unittests' or 67 # self.test_package.test_suite_basename == 'net_unittests' or
74 # False) 68 # False)
75 69
76 def _GetFilterFileName(self): 70 def _GetFilterFileName(self):
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 filter_file.close() 134 filter_file.close()
141 135
142 def GetDataFilesForTestSuite(self): 136 def GetDataFilesForTestSuite(self):
143 """Returns a list of data files/dirs needed by the test suite.""" 137 """Returns a list of data files/dirs needed by the test suite."""
144 # Ideally, we'd just push all test data. However, it has >100MB, and a lot 138 # Ideally, we'd just push all test data. However, it has >100MB, and a lot
145 # of the files are not relevant (some are used for browser_tests, others for 139 # of the files are not relevant (some are used for browser_tests, others for
146 # features not supported, etc..). 140 # features not supported, etc..).
147 if self.test_package.test_suite_basename in ['base_unittests', 141 if self.test_package.test_suite_basename in ['base_unittests',
148 'sql_unittests', 142 'sql_unittests',
149 'unit_tests']: 143 'unit_tests']:
150 return [ 144 test_files = [
151 'base/data/json/bom_feff.json', 145 'base/data/json/bom_feff.json',
146 'base/data/file_util_unittest',
152 'net/data/cache_tests/insert_load1', 147 'net/data/cache_tests/insert_load1',
153 'net/data/cache_tests/dirty_entry5', 148 'net/data/cache_tests/dirty_entry5',
149 'net/data/ssl/certificates/',
154 'ui/base/test/data/data_pack_unittest', 150 'ui/base/test/data/data_pack_unittest',
155 'chrome/test/data/bookmarks/History_with_empty_starred', 151 'chrome/test/data/download-test1.lib',
156 'chrome/test/data/bookmarks/History_with_starred', 152 'chrome/test/data/extensions/bad_magic.crx',
153 'chrome/test/data/extensions/good.crx',
154 'chrome/test/data/extensions/icon1.png',
155 'chrome/test/data/extensions/icon2.png',
156 'chrome/test/data/extensions/icon3.png',
157 'chrome/test/data/extensions/allow_silent_upgrade/',
158 'chrome/test/data/extensions/app/',
159 'chrome/test/data/extensions/bad/',
160 'chrome/test/data/extensions/effective_host_permissions/',
161 'chrome/test/data/extensions/empty_manifest/',
162 'chrome/test/data/extensions/good/Extensions/',
163 'chrome/test/data/extensions/manifest_tests/',
164 'chrome/test/data/extensions/page_action/',
165 'chrome/test/data/extensions/permissions/',
166 'chrome/test/data/extensions/script_and_capture/',
167 'chrome/test/data/extensions/unpacker/',
168 'chrome/test/data/bookmarks/',
169 'chrome/test/data/components/',
157 'chrome/test/data/extensions/json_schema_test.js', 170 'chrome/test/data/extensions/json_schema_test.js',
158 'chrome/test/data/History/', 171 'chrome/test/data/History/',
159 'chrome/test/data/json_schema_validator/', 172 'chrome/test/data/json_schema_validator/',
173 'chrome/test/data/pref_service/',
160 'chrome/test/data/serializer_nested_test.js', 174 'chrome/test/data/serializer_nested_test.js',
161 'chrome/test/data/serializer_test.js', 175 'chrome/test/data/serializer_test.js',
162 'chrome/test/data/serializer_test_nowhitespace.js', 176 'chrome/test/data/serializer_test_nowhitespace.js',
163 'chrome/test/data/top_sites/', 177 'chrome/test/data/top_sites/',
178 'chrome/test/data/web_app_info/',
164 'chrome/test/data/web_database', 179 'chrome/test/data/web_database',
180 'chrome/test/data/webui/',
165 'chrome/test/data/zip', 181 'chrome/test/data/zip',
166 ] 182 'chrome/third_party/mock4js/',
183 ]
184 if self.test_package.test_suite_basename == 'unit_tests':
185 test_files += ['chrome/test/data/simple_open_search.xml']
186 # The following are spell check data. Now only list the data under
187 # third_party/hunspell_dictionaries which are used by unit tests.
188 old_cwd = os.getcwd()
189 os.chdir(constants.CHROME_DIR)
190 test_files += glob.glob('third_party/hunspell_dictionaries/*.bdic')
191 os.chdir(old_cwd)
192 return test_files
167 elif self.test_package.test_suite_basename == 'net_unittests': 193 elif self.test_package.test_suite_basename == 'net_unittests':
168 return [ 194 return [
169 'net/data/cache_tests', 195 'net/data/cache_tests',
170 'net/data/filter_unittests', 196 'net/data/filter_unittests',
171 'net/data/ftp', 197 'net/data/ftp',
172 'net/data/proxy_resolver_v8_unittest', 198 'net/data/proxy_resolver_v8_unittest',
173 'net/data/ssl/certificates', 199 'net/data/ssl/certificates',
200 'net/data/url_request_unittest/',
201 'net/data/proxy_script_fetcher_unittest'
174 ] 202 ]
175 elif self.test_package.test_suite_basename == 'ui_tests': 203 elif self.test_package.test_suite_basename == 'ui_tests':
176 return [ 204 return [
177 'chrome/test/data/dromaeo', 205 'chrome/test/data/dromaeo',
178 'chrome/test/data/json2.js', 206 'chrome/test/data/json2.js',
179 'chrome/test/data/sunspider', 207 'chrome/test/data/sunspider',
180 'chrome/test/data/v8_benchmark', 208 'chrome/test/data/v8_benchmark',
181 'chrome/test/ui/sunspider_uitest.js', 209 'chrome/test/perf/sunspider_uitest.js',
182 'chrome/test/ui/v8_benchmark_uitest.js', 210 'chrome/test/perf/v8_benchmark_uitest.js',
183 ] 211 ]
184 elif self.test_package.test_suite_basename == 'page_cycler_tests': 212 elif self.test_package.test_suite_basename == 'page_cycler_tests':
185 data = [ 213 data = [
186 'tools/page_cycler', 214 'tools/page_cycler',
187 'data/page_cycler', 215 'data/page_cycler',
188 ] 216 ]
189 for d in data: 217 for d in data:
190 if not os.path.exists(d): 218 if not os.path.exists(d):
191 raise Exception('Page cycler data not found.') 219 raise Exception('Page cycler data not found.')
192 return data 220 return data
193 elif self.test_package.test_suite_basename == 'webkit_unit_tests': 221 elif self.test_package.test_suite_basename == 'webkit_unit_tests':
194 return [ 222 return [
195 'third_party/WebKit/Source/WebKit/chromium/tests/data', 223 'third_party/WebKit/Source/WebKit/chromium/tests/data',
196 ] 224 ]
197 elif self.test_package.test_suite_basename == 'content_unittests': 225 elif self.test_package.test_suite_basename == 'content_unittests':
198 return [ 226 return [
227 'chrome/test/gpu/webgl_conformance_test_expectations.txt',
228 'net/data/ssl/certificates/',
199 'webkit/data/dom_storage/webcore_test_database.localstorage', 229 'webkit/data/dom_storage/webcore_test_database.localstorage',
200 ] 230 ]
201 return [] 231 return []
202 232
203 def LaunchHelperToolsForTestSuite(self): 233 def LaunchHelperToolsForTestSuite(self):
204 """Launches helper tools for the test suite. 234 """Launches helper tools for the test suite.
205 235
206 Sometimes one test may need to run some helper tools first in order to 236 Sometimes one test may need to run some helper tools first in order to
207 successfully complete the test. 237 successfully complete the test.
208 """ 238 """
209 document_root = self._GetHttpServerDocumentRootForTestSuite()
210 if document_root:
211 self.LaunchTestHttpServer(document_root)
212 if self._TestSuiteRequiresMockTestServer(): 239 if self._TestSuiteRequiresMockTestServer():
213 self.LaunchChromeTestServerSpawner() 240 self.LaunchChromeTestServerSpawner()
214 241
215 def StripAndCopyFiles(self): 242 def StripAndCopyFiles(self):
216 """Strips and copies the required data files for the test suite.""" 243 """Strips and copies the required data files for the test suite."""
217 self.test_package.StripAndCopyExecutable() 244 self.test_package.StripAndCopyExecutable()
218 self.test_package.PushDataAndPakFiles() 245 self.test_package.PushDataAndPakFiles()
219 self.test_package.tool.CopyFiles() 246 self.tool.CopyFiles()
220 test_data = self.GetDataFilesForTestSuite() 247 test_data = self.GetDataFilesForTestSuite()
221 if test_data and not self.fast_and_loose: 248 if test_data and not self.fast_and_loose:
222 if self.test_package.test_suite_basename == 'page_cycler_tests': 249 # Due to the large size of certain test data, we use sdcard to store the
223 # Since the test data for page cycler are huge (around 200M), we use 250 # test data and create symbolic links to map them to data/local/tmp/.
224 # sdcard to store the data and create symbol links to map them to 251 for data in test_data:
225 # data/local/tmp/ later. 252 self.CopyTestData([data], '/sdcard/')
226 self.CopyTestData(test_data, '/sdcard/') 253 self.LinkSdCardPathsToTempDir(test_data)
227 for p in [os.path.dirname(d) for d in test_data if os.path.isdir(d)]:
228 mapped_device_path = '/data/local/tmp/' + p
229 # Unlink the mapped_device_path at first in case it was mapped to
230 # a wrong path. Add option '-r' becuase the old path could be a dir.
231 self.adb.RunShellCommand('rm -r %s' % mapped_device_path)
232 self.adb.RunShellCommand(
233 'ln -s /sdcard/%s %s' % (p, mapped_device_path))
234 else:
235 self.CopyTestData(test_data, '/data/local/tmp/')
236 254
237 def RunTestsWithFilter(self): 255 def RunTestsWithFilter(self):
238 """Runs a tests via a small, temporary shell script.""" 256 """Runs a tests via a small, temporary shell script."""
239 self.test_package.CreateTestRunnerScript(self._gtest_filter, 257 self.test_package.CreateTestRunnerScript(self._gtest_filter,
240 self._test_arguments) 258 self._test_arguments)
241 self.test_results = self.test_package.RunTestsAndListResults() 259 self.test_results = self.test_package.RunTestsAndListResults()
242 260
243 def RebaselineTests(self): 261 def RebaselineTests(self):
244 """Runs all available tests, restarting in case of failures.""" 262 """Runs all available tests, restarting in case of failures."""
245 if self._gtest_filter: 263 if self._gtest_filter:
246 all_tests = set(self._gtest_filter.split(':')) 264 all_tests = set(self._gtest_filter.split(':'))
247 else: 265 else:
248 all_tests = set(self.test_package.GetAllTests()) 266 all_tests = set(self.test_package.GetAllTests())
249 failed_results = set() 267 failed_results = set()
250 executed_results = set() 268 executed_results = set()
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if not self._gtest_filter: 303 if not self._gtest_filter:
286 self._gtest_filter = ('-' + ':'.join(self.GetDisabledTests()) + ':' + 304 self._gtest_filter = ('-' + ':'.join(self.GetDisabledTests()) + ':' +
287 ':'.join(['*.' + x + '*' for x in 305 ':'.join(['*.' + x + '*' for x in
288 self.test_package.GetDisabledPrefixes()])) 306 self.test_package.GetDisabledPrefixes()]))
289 self.RunTestsWithFilter() 307 self.RunTestsWithFilter()
290 return self.test_results 308 return self.test_results
291 309
292 def SetUp(self): 310 def SetUp(self):
293 """Sets up necessary test enviroment for the test suite.""" 311 """Sets up necessary test enviroment for the test suite."""
294 super(SingleTestRunner, self).SetUp() 312 super(SingleTestRunner, self).SetUp()
313 self.adb.ClearApplicationState(constants.CHROME_PACKAGE)
295 if self.test_package.performance_test: 314 if self.test_package.performance_test:
296 if run_tests_helper.IsRunningAsBuildbot():
297 self.adb.SetJavaAssertsEnabled(enable=False)
298 self.adb.Reboot(full_reboot=False)
299 self.adb.SetupPerformanceTest() 315 self.adb.SetupPerformanceTest()
300 if self.dump_debug_info: 316 if self.dump_debug_info:
301 self.dump_debug_info.StartRecordingLog(True) 317 self.dump_debug_info.StartRecordingLog(True)
302 self.StripAndCopyFiles() 318 self.StripAndCopyFiles()
303 self.LaunchHelperToolsForTestSuite() 319 self.LaunchHelperToolsForTestSuite()
304 self.test_package.tool.SetupEnvironment() 320 self.tool.SetupEnvironment()
305 321
306 def TearDown(self): 322 def TearDown(self):
307 """Cleans up the test enviroment for the test suite.""" 323 """Cleans up the test enviroment for the test suite."""
308 self.test_package.tool.CleanUpEnvironment() 324 self.tool.CleanUpEnvironment()
309 if self.test_package.cleanup_test_files: 325 if self.test_package.cleanup_test_files:
310 self.adb.RemovePushedFiles() 326 self.adb.RemovePushedFiles()
311 if self.dump_debug_info: 327 if self.dump_debug_info:
312 self.dump_debug_info.StopRecordingLog() 328 self.dump_debug_info.StopRecordingLog()
313 if self.test_package.performance_test: 329 if self.test_package.performance_test:
314 self.adb.TearDownPerformanceTest() 330 self.adb.TearDownPerformanceTest()
315 super(SingleTestRunner, self).TearDown() 331 super(SingleTestRunner, self).TearDown()
OLDNEW
« no previous file with comments | « build/android/pylib/run_tests_helper.py ('k') | build/android/pylib/test_options_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698