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

Side by Side Diff: build/android/pylib/gtest/test_runner.py

Issue 18233018: [Android] Use isolate remap instead of check. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed all comments Created 7 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
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
6 import logging 5 import logging
7 import os 6 import os
8 import sys
9 7
10 from pylib import android_commands 8 from pylib import android_commands
11 from pylib import cmd_helper
12 from pylib import constants 9 from pylib import constants
13 from pylib import perf_tests_helper
14 from pylib.android_commands import errors 10 from pylib.android_commands import errors
15 from pylib.base import base_test_result 11 from pylib.base import base_test_result
16 from pylib.base import base_test_runner 12 from pylib.base import base_test_runner
17 from pylib.utils import run_tests_helper 13 from pylib.utils import run_tests_helper
18 14
19 import test_package_apk 15 import test_package_apk
20 import test_package_executable 16 import test_package_executable
21 17
22 sys.path.insert(
23 0, os.path.join(constants.DIR_SOURCE_ROOT, 'tools', 'swarm_client'))
24 import run_isolated
25 18
26 19 # We're moving to using isolate files instead of harcoding
27 _ISOLATE_FILE_PATHS = { 20 # dependencies here. Look at the TODO in dispatch.py.
28 #'base_unittests': 'base/base_unittests.isolate', 21 def _GetDataFilesForTestSuite(test_suite_basename):
29 #'net_unittests': 'net/net_unittests.isolate',
30 #'unit_tests': 'chrome/unit_tests.isolate',
31 #'content_browsertests': 'content/content_browsertests.isolate',
32 #'content_unittests': 'content/content_unittests.isolate',
33 }
34 _ISOLATE_SCRIPT = os.path.join(
35 constants.DIR_SOURCE_ROOT, 'tools', 'swarm_client', 'isolate.py')
36
37
38 def _GetDataFilesForTestSuite(product_dir, test_suite_basename):
39 """Returns a list of data files/dirs needed by the test suite. 22 """Returns a list of data files/dirs needed by the test suite.
40 23
41 Args: 24 Args:
42 product_dir: Absolute path to product directory (e.g. /../out/Debug).
43 test_suite_basename: The test suite basename (e.g. base_unittests). 25 test_suite_basename: The test suite basename (e.g. base_unittests).
44 26
45 Returns: 27 Returns:
46 A list of test file and directory paths. 28 A list of test file and directory paths.
47 """ 29 """
48 # TODO(frankf): *.isolated should be generated by gyp using foo_tests_run
49 # targets. This is a stop-gap solution as currently there are no such
50 # targets for content_unittests and content_browsertests.
51 isolate_rel_path = _ISOLATE_FILE_PATHS.get(test_suite_basename)
52 if isolate_rel_path:
53 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path)
54 isolated_abs_path = os.path.join(
55 product_dir, '%s.isolated' % test_suite_basename)
56 assert os.path.exists(isolate_abs_path)
57 isolate_cmd = [
58 'python', _ISOLATE_SCRIPT,
59 'check',
60 '--isolate=%s' % isolate_abs_path,
61 '--isolated=%s' % isolated_abs_path,
62 '-V', 'PRODUCT_DIR=%s' % product_dir,
63 '-V', 'OS=android',
64 '--outdir=%s' % product_dir,
65 ]
66 assert not cmd_helper.RunCmd(isolate_cmd)
67 with open(isolated_abs_path) as f:
68 isolated_content = run_isolated.load_isolated(f.read(),
69 os_flavor='android')
70 assert isolated_content['os'] == 'android'
71 return isolated_content['files'].keys()
72
73 logging.info('Did not find an isolate file for the test suite.')
74 # Ideally, we'd just push all test data. However, it has >100MB, and a lot 30 # Ideally, we'd just push all test data. However, it has >100MB, and a lot
75 # of the files are not relevant (some are used for browser_tests, others for 31 # of the files are not relevant (some are used for browser_tests, others for
76 # features not supported, etc..). 32 # features not supported, etc..).
77 if test_suite_basename == 'base_unittests': 33 if test_suite_basename == 'media_unittests':
78 return [
79 'base/test/data/',
80 ]
81 elif test_suite_basename == 'unit_tests':
82 test_files = [
83 'base/test/data/',
84 'chrome/test/data/download-test1.lib',
85 'chrome/test/data/extensions/bad_magic.crx',
86 'chrome/test/data/extensions/good.crx',
87 'chrome/test/data/extensions/icon1.png',
88 'chrome/test/data/extensions/icon2.png',
89 'chrome/test/data/extensions/icon3.png',
90 'chrome/test/data/extensions/allow_silent_upgrade/',
91 'chrome/test/data/extensions/app/',
92 'chrome/test/data/extensions/bad/',
93 'chrome/test/data/extensions/effective_host_permissions/',
94 'chrome/test/data/extensions/empty_manifest/',
95 'chrome/test/data/extensions/good/Extensions/',
96 'chrome/test/data/extensions/manifest_tests/',
97 'chrome/test/data/extensions/page_action/',
98 'chrome/test/data/extensions/permissions/',
99 'chrome/test/data/extensions/script_and_capture/',
100 'chrome/test/data/extensions/unpacker/',
101 'chrome/test/data/bookmarks/',
102 'chrome/test/data/components/',
103 'chrome/test/data/extensions/json_schema_test.js',
104 'chrome/test/data/History/',
105 'chrome/test/data/json_schema_validator/',
106 'chrome/test/data/pref_service/',
107 'chrome/test/data/simple_open_search.xml',
108 'chrome/test/data/top_sites/',
109 'chrome/test/data/web_app_info/',
110 'chrome/test/data/webui/',
111 'chrome/third_party/mock4js/',
112 'components/test/data/web_database',
113 'net/data/ssl/certificates',
114 'third_party/accessibility-developer-tools/gen/axs_testing.js',
115 'third_party/zlib/google/test/data',
116 ]
117 # The following are spell check data. Now only list the data under
118 # third_party/hunspell_dictionaries which are used by unit tests.
119 old_cwd = os.getcwd()
120 os.chdir(constants.DIR_SOURCE_ROOT)
121 test_files += glob.glob('third_party/hunspell_dictionaries/*.bdic')
122 os.chdir(old_cwd)
123 return test_files
124 elif test_suite_basename == 'media_unittests':
125 return [ 34 return [
126 'media/test/data', 35 'media/test/data',
127 ] 36 ]
128 elif test_suite_basename == 'net_unittests': 37 elif test_suite_basename == 'net_unittests':
129 return [ 38 return [
130 'chrome/test/data/animate1.gif', 39 'chrome/test/data/animate1.gif',
131 'chrome/test/data/simple.html', 40 'chrome/test/data/simple.html',
132 'net/data/cache_tests', 41 'net/data/cache_tests',
133 'net/data/filter_unittests', 42 'net/data/filter_unittests',
134 'net/data/ftp', 43 'net/data/ftp',
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 test_arguments: Additional arguments to pass to the test binary. 169 test_arguments: Additional arguments to pass to the test binary.
261 timeout: Timeout for each test. 170 timeout: Timeout for each test.
262 cleanup_test_files: Whether or not to cleanup test files on device. 171 cleanup_test_files: Whether or not to cleanup test files on device.
263 tool_name: Name of the Valgrind tool. 172 tool_name: Name of the Valgrind tool.
264 build_type: 'Release' or 'Debug'. 173 build_type: 'Release' or 'Debug'.
265 in_webkit_checkout: Whether the suite is being run from a WebKit checkout. 174 in_webkit_checkout: Whether the suite is being run from a WebKit checkout.
266 push_deps: If True, push all dependencies to the device. 175 push_deps: If True, push all dependencies to the device.
267 test_apk_package_name: Apk package name for tests running in APKs. 176 test_apk_package_name: Apk package name for tests running in APKs.
268 test_activity_name: Test activity to invoke for APK tests. 177 test_activity_name: Test activity to invoke for APK tests.
269 command_line_file: Filename to use to pass arguments to tests. 178 command_line_file: Filename to use to pass arguments to tests.
179 deps_dir: The path to the dependency dir on the host to push to the device.
270 """ 180 """
271 181
272 def __init__(self, device, test_suite, test_arguments, timeout, 182 def __init__(self, device, test_suite, test_arguments, timeout,
273 cleanup_test_files, tool_name, build_type, 183 cleanup_test_files, tool_name, build_type,
274 in_webkit_checkout, push_deps, test_apk_package_name=None, 184 in_webkit_checkout, push_deps, test_apk_package_name=None,
275 test_activity_name=None, command_line_file=None): 185 test_activity_name=None, command_line_file=None, deps_dir=None):
276 super(TestRunner, self).__init__(device, tool_name, build_type, push_deps) 186 super(TestRunner, self).__init__(device, tool_name, build_type, push_deps)
277 self._running_on_emulator = self.device.startswith('emulator') 187 self._running_on_emulator = self.device.startswith('emulator')
278 self._test_arguments = test_arguments 188 self._test_arguments = test_arguments
279 self.in_webkit_checkout = in_webkit_checkout 189 self.in_webkit_checkout = in_webkit_checkout
280 self._cleanup_test_files = cleanup_test_files 190 self._cleanup_test_files = cleanup_test_files
191 self._deps_dir = deps_dir
281 192
282 logging.warning('Test suite: ' + test_suite) 193 logging.warning('Test suite: ' + test_suite)
283 if os.path.splitext(test_suite)[1] == '.apk': 194 if os.path.splitext(test_suite)[1] == '.apk':
284 self.test_package = test_package_apk.TestPackageApk( 195 self.test_package = test_package_apk.TestPackageApk(
285 self.adb, 196 self.adb,
286 device, 197 device,
287 test_suite, 198 test_suite,
288 timeout, 199 timeout,
289 self._cleanup_test_files, 200 self._cleanup_test_files,
290 self.tool, 201 self.tool,
(...skipping 13 matching lines...) Expand all
304 self._cleanup_test_files, 215 self._cleanup_test_files,
305 self.tool, 216 self.tool,
306 symbols_dir) 217 symbols_dir)
307 218
308 #override 219 #override
309 def InstallTestPackage(self): 220 def InstallTestPackage(self):
310 self.test_package.StripAndCopyExecutable() 221 self.test_package.StripAndCopyExecutable()
311 222
312 #override 223 #override
313 def PushDataDeps(self): 224 def PushDataDeps(self):
225 self.adb.WaitForSdCardReady(20)
314 self.test_package.PushDataAndPakFiles() 226 self.test_package.PushDataAndPakFiles()
315 self.tool.CopyFiles() 227 self.tool.CopyFiles()
316 test_data = _GetDataFilesForTestSuite(self.test_package.test_suite_dirname,
317 self.test_package.test_suite_basename)
318 if test_data:
319 # Make sure SD card is ready.
320 self.adb.WaitForSdCardReady(20)
321 self.CopyTestData(test_data, self.adb.GetExternalStorage())
322 if self.test_package.test_suite_basename == 'webkit_unit_tests': 228 if self.test_package.test_suite_basename == 'webkit_unit_tests':
323 self.PushWebKitUnitTestsData() 229 self.PushWebKitUnitTestsData()
230 return
231
232 if not self._deps_dir:
233 logging.info('Did not find an isolate file for the test suite.')
234 for p in _GetDataFilesForTestSuite(self.test_package.test_suite_basename):
235 self.adb.PushIfNeeded(
236 os.path.join(constants.DIR_SOURCE_ROOT, p),
237 os.path.join(self.adb.GetExternalStorage(), p))
238 return
239
240 for p in os.listdir(self._deps_dir):
241 self.adb.PushIfNeeded(
242 os.path.join(self._deps_dir, p),
243 os.path.join(self.adb.GetExternalStorage(), p))
324 244
325 def PushWebKitUnitTestsData(self): 245 def PushWebKitUnitTestsData(self):
326 """Pushes the webkit_unit_tests data files to the device. 246 """Pushes the webkit_unit_tests data files to the device.
327 247
328 The path of this directory is different when the suite is being run as 248 The path of this directory is different when the suite is being run as
329 part of a WebKit check-out. 249 part of a WebKit check-out.
330 """ 250 """
331 webkit_src = os.path.join(constants.DIR_SOURCE_ROOT, 'third_party', 251 webkit_src = os.path.join(constants.DIR_SOURCE_ROOT, 'third_party',
332 'WebKit') 252 'WebKit')
333 if self.in_webkit_checkout: 253 if self.in_webkit_checkout:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 self.LaunchChromeTestServerSpawner() 313 self.LaunchChromeTestServerSpawner()
394 self.tool.SetupEnvironment() 314 self.tool.SetupEnvironment()
395 315
396 #override 316 #override
397 def TearDown(self): 317 def TearDown(self):
398 """Cleans up the test enviroment for the test suite.""" 318 """Cleans up the test enviroment for the test suite."""
399 self.tool.CleanUpEnvironment() 319 self.tool.CleanUpEnvironment()
400 if self._cleanup_test_files: 320 if self._cleanup_test_files:
401 self.adb.RemovePushedFiles() 321 self.adb.RemovePushedFiles()
402 super(TestRunner, self).TearDown() 322 super(TestRunner, self).TearDown()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698