Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 """Dispatches GTests.""" | 5 """Dispatches GTests.""" |
| 6 | 6 |
| 7 import copy | 7 import copy |
| 8 import fnmatch | 8 import fnmatch |
| 9 import glob | 9 import glob |
| 10 import logging | 10 import logging |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 # TODO(frankf): Add more test targets here after making sure we don't | 28 # TODO(frankf): Add more test targets here after making sure we don't |
| 29 # blow up the dependency size (and the world). | 29 # blow up the dependency size (and the world). |
| 30 _ISOLATE_FILE_PATHS = { | 30 _ISOLATE_FILE_PATHS = { |
| 31 'base_unittests': 'base/base_unittests.isolate', | 31 'base_unittests': 'base/base_unittests.isolate', |
| 32 'breakpad_unittests': 'breakpad/breakpad_unittests.isolate', | 32 'breakpad_unittests': 'breakpad/breakpad_unittests.isolate', |
| 33 'cc_perftests': 'cc/cc_perftests.isolate', | 33 'cc_perftests': 'cc/cc_perftests.isolate', |
| 34 'components_unittests': 'components/components_unittests.isolate', | 34 'components_unittests': 'components/components_unittests.isolate', |
| 35 'content_browsertests': 'content/content_browsertests.isolate', | 35 'content_browsertests': 'content/content_browsertests.isolate', |
| 36 'content_unittests': 'content/content_unittests.isolate', | 36 'content_unittests': 'content/content_unittests.isolate', |
| 37 'media_unittests': 'media/media_unittests.isolate', | 37 'media_unittests': 'media/media_unittests.isolate', |
| 38 'modules_unittests': 'third_party/webrtc/modules/modules_unittests.isolate', | |
|
hellner1
2013/07/15 20:43:41
We are still hard coding the .isolate-path. Will t
frankf
2013/07/15 21:46:34
So, all these targets have identical dependencies?
hellner1
2013/07/15 21:57:14
Can the script use the .isolate paths provided in
| |
| 38 'net_unittests': 'net/net_unittests.isolate', | 39 'net_unittests': 'net/net_unittests.isolate', |
| 39 'ui_unittests': 'ui/ui_unittests.isolate', | 40 'ui_unittests': 'ui/ui_unittests.isolate', |
| 40 'unit_tests': 'chrome/unit_tests.isolate', | 41 'unit_tests': 'chrome/unit_tests.isolate', |
| 41 } | 42 } |
| 42 | 43 |
| 43 # Used for filtering large data deps at a finer grain than what's allowed in | 44 # Used for filtering large data deps at a finer grain than what's allowed in |
| 44 # isolate files since pushing deps to devices is expensive. | 45 # isolate files since pushing deps to devices is expensive. |
| 45 # Wildcards are allowed. | 46 # Wildcards are allowed. |
| 46 _DEPS_EXCLUSION_LIST = [ | 47 _DEPS_EXCLUSION_LIST = [ |
| 47 'chrome/test/data/extensions/api_test', | 48 'chrome/test/data/extensions/api_test', |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 65 _ISOLATE_SCRIPT = os.path.join( | 66 _ISOLATE_SCRIPT = os.path.join( |
| 66 constants.DIR_SOURCE_ROOT, 'tools', 'swarm_client', 'isolate.py') | 67 constants.DIR_SOURCE_ROOT, 'tools', 'swarm_client', 'isolate.py') |
| 67 | 68 |
| 68 | 69 |
| 69 def _GenerateDepsDirUsingIsolate(test_suite, build_type): | 70 def _GenerateDepsDirUsingIsolate(test_suite, build_type): |
| 70 """Generate the dependency dir for the test suite using isolate. | 71 """Generate the dependency dir for the test suite using isolate. |
| 71 | 72 |
| 72 Args: | 73 Args: |
| 73 test_suite: The test suite basename (e.g. base_unittests). | 74 test_suite: The test suite basename (e.g. base_unittests). |
| 74 build_type: Release/Debug | 75 build_type: Release/Debug |
| 75 | |
| 76 Returns: | |
| 77 If an isolate file exists, returns path to dependency dir on the host. | |
| 78 Otherwise, returns False. | |
| 79 """ | 76 """ |
| 80 product_dir = os.path.join(cmd_helper.OutDirectory.get(), build_type) | 77 product_dir = os.path.join(cmd_helper.OutDirectory.get(), build_type) |
| 81 assert os.path.isabs(product_dir) | 78 assert os.path.isabs(product_dir) |
| 79 | |
| 80 if os.path.isdir(constants.ISOLATE_DEPS_DIR): | |
| 81 shutil.rmtree(constants.ISOLATE_DEPS_DIR) | |
| 82 | |
| 82 isolate_rel_path = _ISOLATE_FILE_PATHS.get(test_suite) | 83 isolate_rel_path = _ISOLATE_FILE_PATHS.get(test_suite) |
| 83 if not isolate_rel_path: | 84 if not isolate_rel_path: |
| 84 return False | 85 return False |
|
hellner1
2013/07/15 20:43:41
Function still seems to have a return value. Shoul
hellner1
2013/07/15 21:57:14
Please don't forget this one.
frankf
2013/07/15 22:06:06
Done.
| |
| 85 | 86 |
| 86 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) | 87 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) |
| 87 isolated_abs_path = os.path.join( | 88 isolated_abs_path = os.path.join( |
| 88 product_dir, '%s.isolated' % test_suite) | 89 product_dir, '%s.isolated' % test_suite) |
| 89 assert os.path.exists(isolate_abs_path) | 90 assert os.path.exists(isolate_abs_path) |
| 90 deps_dir = os.path.join(product_dir, 'isolate_deps_dir') | |
| 91 if os.path.isdir(deps_dir): | |
| 92 shutil.rmtree(deps_dir) | |
| 93 isolate_cmd = [ | 91 isolate_cmd = [ |
| 94 'python', _ISOLATE_SCRIPT, | 92 'python', _ISOLATE_SCRIPT, |
| 95 'remap', | 93 'remap', |
| 96 '--isolate', isolate_abs_path, | 94 '--isolate', isolate_abs_path, |
| 97 '--isolated', isolated_abs_path, | 95 '--isolated', isolated_abs_path, |
| 98 '-V', 'PRODUCT_DIR=%s' % product_dir, | 96 '-V', 'PRODUCT_DIR=%s' % product_dir, |
| 99 '-V', 'OS=android', | 97 '-V', 'OS=android', |
| 100 '--outdir', deps_dir, | 98 '--outdir', constants.ISOLATE_DEPS_DIR, |
| 101 ] | 99 ] |
| 102 assert not cmd_helper.RunCmd(isolate_cmd) | 100 assert not cmd_helper.RunCmd(isolate_cmd) |
| 103 | 101 |
| 104 # We're relying on the fact that timestamps are preserved | 102 # We're relying on the fact that timestamps are preserved |
| 105 # by the remap command (hardlinked). Otherwise, all the data | 103 # by the remap command (hardlinked). Otherwise, all the data |
| 106 # will be pushed to the device once we move to using time diff | 104 # will be pushed to the device once we move to using time diff |
| 107 # instead of md5sum. Perform a sanity check here. | 105 # instead of md5sum. Perform a sanity check here. |
| 108 for root, _, filenames in os.walk(deps_dir): | 106 for root, _, filenames in os.walk(constants.ISOLATE_DEPS_DIR): |
| 109 if filenames: | 107 if filenames: |
| 110 linked_file = os.path.join(root, filenames[0]) | 108 linked_file = os.path.join(root, filenames[0]) |
| 111 orig_file = os.path.join( | 109 orig_file = os.path.join( |
| 112 constants.DIR_SOURCE_ROOT, | 110 constants.DIR_SOURCE_ROOT, |
| 113 os.path.relpath(linked_file, deps_dir)) | 111 os.path.relpath(linked_file, constants.ISOLATE_DEPS_DIR)) |
| 114 if os.stat(linked_file).st_ino == os.stat(orig_file).st_ino: | 112 if os.stat(linked_file).st_ino == os.stat(orig_file).st_ino: |
| 115 break | 113 break |
| 116 else: | 114 else: |
| 117 raise Exception('isolate remap command did not use hardlinks.') | 115 raise Exception('isolate remap command did not use hardlinks.') |
| 118 | 116 |
| 119 # Delete excluded files as defined by _DEPS_EXCLUSION_LIST. | 117 # Delete excluded files as defined by _DEPS_EXCLUSION_LIST. |
| 120 old_cwd = os.getcwd() | 118 old_cwd = os.getcwd() |
| 121 try: | 119 try: |
| 122 os.chdir(deps_dir) | 120 os.chdir(constants.ISOLATE_DEPS_DIR) |
| 123 excluded_paths = [x for y in _DEPS_EXCLUSION_LIST for x in glob.glob(y)] | 121 excluded_paths = [x for y in _DEPS_EXCLUSION_LIST for x in glob.glob(y)] |
| 124 if excluded_paths: | 122 if excluded_paths: |
| 125 logging.info('Excluding the following from dependency list: %s', | 123 logging.info('Excluding the following from dependency list: %s', |
| 126 excluded_paths) | 124 excluded_paths) |
| 127 for p in excluded_paths: | 125 for p in excluded_paths: |
| 128 if os.path.isdir(p): | 126 if os.path.isdir(p): |
| 129 shutil.rmtree(p) | 127 shutil.rmtree(p) |
| 130 else: | 128 else: |
| 131 os.remove(p) | 129 os.remove(p) |
| 132 finally: | 130 finally: |
| 133 os.chdir(old_cwd) | 131 os.chdir(old_cwd) |
| 134 | 132 |
| 135 # On Android, all pak files need to be in the top-level 'paks' directory. | 133 # On Android, all pak files need to be in the top-level 'paks' directory. |
| 136 paks_dir = os.path.join(deps_dir, 'paks') | 134 paks_dir = os.path.join(constants.ISOLATE_DEPS_DIR, 'paks') |
| 137 os.mkdir(paks_dir) | 135 os.mkdir(paks_dir) |
| 138 for root, _, filenames in os.walk(os.path.join(deps_dir, 'out')): | 136 for root, _, filenames in os.walk(os.path.join(constants.ISOLATE_DEPS_DIR, |
| 137 'out')): | |
| 139 for filename in fnmatch.filter(filenames, '*.pak'): | 138 for filename in fnmatch.filter(filenames, '*.pak'): |
| 140 shutil.move(os.path.join(root, filename), paks_dir) | 139 shutil.move(os.path.join(root, filename), paks_dir) |
| 141 | 140 |
| 142 # Move everything in PRODUCT_DIR to top level. | 141 # Move everything in PRODUCT_DIR to top level. |
| 143 deps_product_dir = os.path.join(deps_dir, 'out', build_type) | 142 deps_product_dir = os.path.join(constants.ISOLATE_DEPS_DIR, 'out', build_type) |
| 144 if os.path.isdir(deps_product_dir): | 143 if os.path.isdir(deps_product_dir): |
| 145 for p in os.listdir(deps_product_dir): | 144 for p in os.listdir(deps_product_dir): |
| 146 shutil.move(os.path.join(deps_product_dir, p), deps_dir) | 145 shutil.move(os.path.join(deps_product_dir, p), constants.ISOLATE_DEPS_DIR) |
| 147 os.rmdir(deps_product_dir) | 146 os.rmdir(deps_product_dir) |
| 148 os.rmdir(os.path.join(deps_dir, 'out')) | 147 os.rmdir(os.path.join(constants.ISOLATE_DEPS_DIR, 'out')) |
| 149 | |
| 150 return deps_dir | |
| 151 | 148 |
| 152 | 149 |
| 153 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): | 150 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): |
| 154 """Get a list of absolute paths to test suite targets. | 151 """Get a list of absolute paths to test suite targets. |
| 155 | 152 |
| 156 Args: | 153 Args: |
| 157 exe: if True, use the executable-based test runner. | 154 exe: if True, use the executable-based test runner. |
| 158 option_test_suite: the test_suite specified as an option. | 155 option_test_suite: the test_suite specified as an option. |
| 159 build_type: 'Release' or 'Debug'. | 156 build_type: 'Release' or 'Debug'. |
| 160 | 157 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 attached_devices = android_commands.GetAttachedDevices() | 267 attached_devices = android_commands.GetAttachedDevices() |
| 271 | 268 |
| 272 if not attached_devices: | 269 if not attached_devices: |
| 273 raise Exception('A device must be attached and online.') | 270 raise Exception('A device must be attached and online.') |
| 274 | 271 |
| 275 # Reset the test port allocation. It's important to do it before starting | 272 # Reset the test port allocation. It's important to do it before starting |
| 276 # to dispatch any tests. | 273 # to dispatch any tests. |
| 277 if not ports.ResetTestServerPortAllocation(): | 274 if not ports.ResetTestServerPortAllocation(): |
| 278 raise Exception('Failed to reset test server port.') | 275 raise Exception('Failed to reset test server port.') |
| 279 | 276 |
| 280 deps_dir = _GenerateDepsDirUsingIsolate(suite_name, options.build_type) | 277 _GenerateDepsDirUsingIsolate(suite_name, options.build_type) |
| 281 | 278 |
| 282 # Constructs a new TestRunner with the current options. | 279 # Constructs a new TestRunner with the current options. |
| 283 def RunnerFactory(device, shard_index): | 280 def RunnerFactory(device, shard_index): |
| 284 return test_runner.TestRunner( | 281 return test_runner.TestRunner( |
| 285 device, | 282 device, |
| 286 options.test_suite, | 283 options.test_suite, |
| 287 options.test_arguments, | 284 options.test_arguments, |
| 288 options.timeout, | 285 options.timeout, |
| 289 options.cleanup_test_files, | 286 options.cleanup_test_files, |
| 290 options.tool, | 287 options.tool, |
| 291 options.build_type, | 288 options.build_type, |
| 292 options.webkit, | 289 options.webkit, |
| 293 options.push_deps, | 290 options.push_deps, |
| 294 constants.GTEST_TEST_PACKAGE_NAME, | 291 constants.GTEST_TEST_PACKAGE_NAME, |
| 295 constants.GTEST_TEST_ACTIVITY_NAME, | 292 constants.GTEST_TEST_ACTIVITY_NAME, |
| 296 constants.GTEST_COMMAND_LINE_FILE, | 293 constants.GTEST_COMMAND_LINE_FILE) |
| 297 deps_dir=deps_dir) | |
| 298 | 294 |
| 299 # Get tests and split them up based on the number of devices. | 295 # Get tests and split them up based on the number of devices. |
| 300 if options.test_filter: | 296 if options.test_filter: |
| 301 all_tests = [t for t in options.test_filter.split(':') if t] | 297 all_tests = [t for t in options.test_filter.split(':') if t] |
| 302 else: | 298 else: |
| 303 all_tests = GetAllEnabledTests(RunnerFactory, attached_devices) | 299 all_tests = GetAllEnabledTests(RunnerFactory, attached_devices) |
| 304 num_devices = len(attached_devices) | 300 num_devices = len(attached_devices) |
| 305 tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] | 301 tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] |
| 306 tests = [t for t in tests if t] | 302 tests = [t for t in tests if t] |
| 307 | 303 |
| 308 # Run tests. | 304 # Run tests. |
| 309 test_results, exit_code = shard.ShardAndRunTests( | 305 test_results, exit_code = shard.ShardAndRunTests( |
| 310 RunnerFactory, attached_devices, tests, options.build_type, | 306 RunnerFactory, attached_devices, tests, options.build_type, |
| 311 test_timeout=None, num_retries=options.num_retries) | 307 test_timeout=None, num_retries=options.num_retries) |
| 312 | 308 |
| 313 report_results.LogFull( | 309 report_results.LogFull( |
| 314 results=test_results, | 310 results=test_results, |
| 315 test_type='Unit test', | 311 test_type='Unit test', |
| 316 test_package=suite_name, | 312 test_package=suite_name, |
| 317 build_type=options.build_type, | 313 build_type=options.build_type, |
| 318 flakiness_server=options.flakiness_dashboard_server) | 314 flakiness_server=options.flakiness_dashboard_server) |
| 319 | 315 |
| 316 if os.path.isdir(constants.ISOLATE_DEPS_DIR): | |
| 317 shutil.rmtree(constants.ISOLATE_DEPS_DIR) | |
| 318 | |
| 320 for buildbot_emulator in buildbot_emulators: | 319 for buildbot_emulator in buildbot_emulators: |
| 321 buildbot_emulator.Shutdown() | 320 buildbot_emulator.Shutdown() |
| 322 | 321 |
| 323 return (test_results, exit_code) | 322 return (test_results, exit_code) |
| 324 | 323 |
| 325 | 324 |
| 326 def _ListTestSuites(): | 325 def _ListTestSuites(): |
| 327 """Display a list of available test suites.""" | 326 """Display a list of available test suites.""" |
| 328 print 'Available test suites are:' | 327 print 'Available test suites are:' |
| 329 for test_suite in gtest_config.STABLE_TEST_SUITES: | 328 for test_suite in gtest_config.STABLE_TEST_SUITES: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 test_options.test_suite = suite_path | 360 test_options.test_suite = suite_path |
| 362 test_results, test_exit_code = _RunATestSuite(test_options, suite_name) | 361 test_results, test_exit_code = _RunATestSuite(test_options, suite_name) |
| 363 results.AddTestRunResults(test_results) | 362 results.AddTestRunResults(test_results) |
| 364 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | 363 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 365 exit_code = test_exit_code | 364 exit_code = test_exit_code |
| 366 | 365 |
| 367 if options.use_xvfb: | 366 if options.use_xvfb: |
| 368 framebuffer.Stop() | 367 framebuffer.Stop() |
| 369 | 368 |
| 370 return (results, exit_code) | 369 return (results, exit_code) |
| OLD | NEW |