| 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', |
| 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 logging.info('Did not find an isolate file for the test suite.') |
| 86 return |
| 85 | 87 |
| 86 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) | 88 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) |
| 87 isolated_abs_path = os.path.join( | 89 isolated_abs_path = os.path.join( |
| 88 product_dir, '%s.isolated' % test_suite) | 90 product_dir, '%s.isolated' % test_suite) |
| 89 assert os.path.exists(isolate_abs_path) | 91 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 = [ | 92 isolate_cmd = [ |
| 94 'python', _ISOLATE_SCRIPT, | 93 'python', _ISOLATE_SCRIPT, |
| 95 'remap', | 94 'remap', |
| 96 '--isolate', isolate_abs_path, | 95 '--isolate', isolate_abs_path, |
| 97 '--isolated', isolated_abs_path, | 96 '--isolated', isolated_abs_path, |
| 98 '-V', 'PRODUCT_DIR=%s' % product_dir, | 97 '-V', 'PRODUCT_DIR=%s' % product_dir, |
| 99 '-V', 'OS=android', | 98 '-V', 'OS=android', |
| 100 '--outdir', deps_dir, | 99 '--outdir', constants.ISOLATE_DEPS_DIR, |
| 101 ] | 100 ] |
| 102 assert not cmd_helper.RunCmd(isolate_cmd) | 101 assert not cmd_helper.RunCmd(isolate_cmd) |
| 103 | 102 |
| 104 # We're relying on the fact that timestamps are preserved | 103 # We're relying on the fact that timestamps are preserved |
| 105 # by the remap command (hardlinked). Otherwise, all the data | 104 # by the remap command (hardlinked). Otherwise, all the data |
| 106 # will be pushed to the device once we move to using time diff | 105 # will be pushed to the device once we move to using time diff |
| 107 # instead of md5sum. Perform a sanity check here. | 106 # instead of md5sum. Perform a sanity check here. |
| 108 for root, _, filenames in os.walk(deps_dir): | 107 for root, _, filenames in os.walk(constants.ISOLATE_DEPS_DIR): |
| 109 if filenames: | 108 if filenames: |
| 110 linked_file = os.path.join(root, filenames[0]) | 109 linked_file = os.path.join(root, filenames[0]) |
| 111 orig_file = os.path.join( | 110 orig_file = os.path.join( |
| 112 constants.DIR_SOURCE_ROOT, | 111 constants.DIR_SOURCE_ROOT, |
| 113 os.path.relpath(linked_file, deps_dir)) | 112 os.path.relpath(linked_file, constants.ISOLATE_DEPS_DIR)) |
| 114 if os.stat(linked_file).st_ino == os.stat(orig_file).st_ino: | 113 if os.stat(linked_file).st_ino == os.stat(orig_file).st_ino: |
| 115 break | 114 break |
| 116 else: | 115 else: |
| 117 raise Exception('isolate remap command did not use hardlinks.') | 116 raise Exception('isolate remap command did not use hardlinks.') |
| 118 | 117 |
| 119 # Delete excluded files as defined by _DEPS_EXCLUSION_LIST. | 118 # Delete excluded files as defined by _DEPS_EXCLUSION_LIST. |
| 120 old_cwd = os.getcwd() | 119 old_cwd = os.getcwd() |
| 121 try: | 120 try: |
| 122 os.chdir(deps_dir) | 121 os.chdir(constants.ISOLATE_DEPS_DIR) |
| 123 excluded_paths = [x for y in _DEPS_EXCLUSION_LIST for x in glob.glob(y)] | 122 excluded_paths = [x for y in _DEPS_EXCLUSION_LIST for x in glob.glob(y)] |
| 124 if excluded_paths: | 123 if excluded_paths: |
| 125 logging.info('Excluding the following from dependency list: %s', | 124 logging.info('Excluding the following from dependency list: %s', |
| 126 excluded_paths) | 125 excluded_paths) |
| 127 for p in excluded_paths: | 126 for p in excluded_paths: |
| 128 if os.path.isdir(p): | 127 if os.path.isdir(p): |
| 129 shutil.rmtree(p) | 128 shutil.rmtree(p) |
| 130 else: | 129 else: |
| 131 os.remove(p) | 130 os.remove(p) |
| 132 finally: | 131 finally: |
| 133 os.chdir(old_cwd) | 132 os.chdir(old_cwd) |
| 134 | 133 |
| 135 # On Android, all pak files need to be in the top-level 'paks' directory. | 134 # On Android, all pak files need to be in the top-level 'paks' directory. |
| 136 paks_dir = os.path.join(deps_dir, 'paks') | 135 paks_dir = os.path.join(constants.ISOLATE_DEPS_DIR, 'paks') |
| 137 os.mkdir(paks_dir) | 136 os.mkdir(paks_dir) |
| 138 for root, _, filenames in os.walk(os.path.join(deps_dir, 'out')): | 137 for root, _, filenames in os.walk(os.path.join(constants.ISOLATE_DEPS_DIR, |
| 138 'out')): |
| 139 for filename in fnmatch.filter(filenames, '*.pak'): | 139 for filename in fnmatch.filter(filenames, '*.pak'): |
| 140 shutil.move(os.path.join(root, filename), paks_dir) | 140 shutil.move(os.path.join(root, filename), paks_dir) |
| 141 | 141 |
| 142 # Move everything in PRODUCT_DIR to top level. | 142 # Move everything in PRODUCT_DIR to top level. |
| 143 deps_product_dir = os.path.join(deps_dir, 'out', build_type) | 143 deps_product_dir = os.path.join(constants.ISOLATE_DEPS_DIR, 'out', build_type) |
| 144 if os.path.isdir(deps_product_dir): | 144 if os.path.isdir(deps_product_dir): |
| 145 for p in os.listdir(deps_product_dir): | 145 for p in os.listdir(deps_product_dir): |
| 146 shutil.move(os.path.join(deps_product_dir, p), deps_dir) | 146 shutil.move(os.path.join(deps_product_dir, p), constants.ISOLATE_DEPS_DIR) |
| 147 os.rmdir(deps_product_dir) | 147 os.rmdir(deps_product_dir) |
| 148 os.rmdir(os.path.join(deps_dir, 'out')) | 148 os.rmdir(os.path.join(constants.ISOLATE_DEPS_DIR, 'out')) |
| 149 | |
| 150 return deps_dir | |
| 151 | 149 |
| 152 | 150 |
| 153 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): | 151 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): |
| 154 """Get a list of absolute paths to test suite targets. | 152 """Get a list of absolute paths to test suite targets. |
| 155 | 153 |
| 156 Args: | 154 Args: |
| 157 exe: if True, use the executable-based test runner. | 155 exe: if True, use the executable-based test runner. |
| 158 option_test_suite: the test_suite specified as an option. | 156 option_test_suite: the test_suite specified as an option. |
| 159 build_type: 'Release' or 'Debug'. | 157 build_type: 'Release' or 'Debug'. |
| 160 | 158 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 attached_devices = android_commands.GetAttachedDevices() | 268 attached_devices = android_commands.GetAttachedDevices() |
| 271 | 269 |
| 272 if not attached_devices: | 270 if not attached_devices: |
| 273 raise Exception('A device must be attached and online.') | 271 raise Exception('A device must be attached and online.') |
| 274 | 272 |
| 275 # Reset the test port allocation. It's important to do it before starting | 273 # Reset the test port allocation. It's important to do it before starting |
| 276 # to dispatch any tests. | 274 # to dispatch any tests. |
| 277 if not ports.ResetTestServerPortAllocation(): | 275 if not ports.ResetTestServerPortAllocation(): |
| 278 raise Exception('Failed to reset test server port.') | 276 raise Exception('Failed to reset test server port.') |
| 279 | 277 |
| 280 deps_dir = _GenerateDepsDirUsingIsolate(suite_name, options.build_type) | 278 _GenerateDepsDirUsingIsolate(suite_name, options.build_type) |
| 281 | 279 |
| 282 # Constructs a new TestRunner with the current options. | 280 # Constructs a new TestRunner with the current options. |
| 283 def RunnerFactory(device, shard_index): | 281 def RunnerFactory(device, shard_index): |
| 284 return test_runner.TestRunner( | 282 return test_runner.TestRunner( |
| 285 device, | 283 device, |
| 286 options.test_suite, | 284 options.test_suite, |
| 287 options.test_arguments, | 285 options.test_arguments, |
| 288 options.timeout, | 286 options.timeout, |
| 289 options.cleanup_test_files, | 287 options.cleanup_test_files, |
| 290 options.tool, | 288 options.tool, |
| 291 options.build_type, | 289 options.build_type, |
| 292 options.webkit, | 290 options.webkit, |
| 293 options.push_deps, | 291 options.push_deps, |
| 294 constants.GTEST_TEST_PACKAGE_NAME, | 292 constants.GTEST_TEST_PACKAGE_NAME, |
| 295 constants.GTEST_TEST_ACTIVITY_NAME, | 293 constants.GTEST_TEST_ACTIVITY_NAME, |
| 296 constants.GTEST_COMMAND_LINE_FILE, | 294 constants.GTEST_COMMAND_LINE_FILE) |
| 297 deps_dir=deps_dir) | |
| 298 | 295 |
| 299 # Get tests and split them up based on the number of devices. | 296 # Get tests and split them up based on the number of devices. |
| 300 if options.test_filter: | 297 if options.test_filter: |
| 301 all_tests = [t for t in options.test_filter.split(':') if t] | 298 all_tests = [t for t in options.test_filter.split(':') if t] |
| 302 else: | 299 else: |
| 303 all_tests = GetAllEnabledTests(RunnerFactory, attached_devices) | 300 all_tests = GetAllEnabledTests(RunnerFactory, attached_devices) |
| 304 num_devices = len(attached_devices) | 301 num_devices = len(attached_devices) |
| 305 tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] | 302 tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] |
| 306 tests = [t for t in tests if t] | 303 tests = [t for t in tests if t] |
| 307 | 304 |
| 308 # Run tests. | 305 # Run tests. |
| 309 test_results, exit_code = shard.ShardAndRunTests( | 306 test_results, exit_code = shard.ShardAndRunTests( |
| 310 RunnerFactory, attached_devices, tests, options.build_type, | 307 RunnerFactory, attached_devices, tests, options.build_type, |
| 311 test_timeout=None, num_retries=options.num_retries) | 308 test_timeout=None, num_retries=options.num_retries) |
| 312 | 309 |
| 313 report_results.LogFull( | 310 report_results.LogFull( |
| 314 results=test_results, | 311 results=test_results, |
| 315 test_type='Unit test', | 312 test_type='Unit test', |
| 316 test_package=suite_name, | 313 test_package=suite_name, |
| 317 build_type=options.build_type, | 314 build_type=options.build_type, |
| 318 flakiness_server=options.flakiness_dashboard_server) | 315 flakiness_server=options.flakiness_dashboard_server) |
| 319 | 316 |
| 317 if os.path.isdir(constants.ISOLATE_DEPS_DIR): |
| 318 shutil.rmtree(constants.ISOLATE_DEPS_DIR) |
| 319 |
| 320 for buildbot_emulator in buildbot_emulators: | 320 for buildbot_emulator in buildbot_emulators: |
| 321 buildbot_emulator.Shutdown() | 321 buildbot_emulator.Shutdown() |
| 322 | 322 |
| 323 return (test_results, exit_code) | 323 return (test_results, exit_code) |
| 324 | 324 |
| 325 | 325 |
| 326 def _ListTestSuites(): | 326 def _ListTestSuites(): |
| 327 """Display a list of available test suites.""" | 327 """Display a list of available test suites.""" |
| 328 print 'Available test suites are:' | 328 print 'Available test suites are:' |
| 329 for test_suite in gtest_config.STABLE_TEST_SUITES: | 329 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 | 361 test_options.test_suite = suite_path |
| 362 test_results, test_exit_code = _RunATestSuite(test_options, suite_name) | 362 test_results, test_exit_code = _RunATestSuite(test_options, suite_name) |
| 363 results.AddTestRunResults(test_results) | 363 results.AddTestRunResults(test_results) |
| 364 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | 364 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 365 exit_code = test_exit_code | 365 exit_code = test_exit_code |
| 366 | 366 |
| 367 if options.use_xvfb: | 367 if options.use_xvfb: |
| 368 framebuffer.Stop() | 368 framebuffer.Stop() |
| 369 | 369 |
| 370 return (results, exit_code) | 370 return (results, exit_code) |
| OLD | NEW |