| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Runs all the native unit tests. | 7 """Runs all the native unit tests. |
| 8 | 8 |
| 9 1. Copy over test binary to /data/local on device. | 9 1. Copy over test binary to /data/local on device. |
| 10 2. Resources: chrome/unit_tests requires resources (chrome.pak and en-US.pak) | 10 2. Resources: chrome/unit_tests requires resources (chrome.pak and en-US.pak) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 import fnmatch | 39 import fnmatch |
| 40 import logging | 40 import logging |
| 41 import optparse | 41 import optparse |
| 42 import os | 42 import os |
| 43 import signal | 43 import signal |
| 44 import subprocess | 44 import subprocess |
| 45 import sys | 45 import sys |
| 46 import time | 46 import time |
| 47 | 47 |
| 48 from pylib import android_commands | 48 from pylib import android_commands |
| 49 from pylib import buildbot_report | |
| 50 from pylib import cmd_helper | 49 from pylib import cmd_helper |
| 51 from pylib import ports | 50 from pylib import ports |
| 52 from pylib.base_test_sharder import BaseTestSharder | 51 from pylib.base_test_sharder import BaseTestSharder |
| 53 from pylib.gtest import debug_info | 52 from pylib.gtest import debug_info |
| 53 from pylib.gtest import gtest_config |
| 54 from pylib.gtest.single_test_runner import SingleTestRunner | 54 from pylib.gtest.single_test_runner import SingleTestRunner |
| 55 from pylib.utils import emulator | 55 from pylib.utils import emulator |
| 56 from pylib.utils import run_tests_helper | 56 from pylib.utils import run_tests_helper |
| 57 from pylib.utils import test_options_parser | 57 from pylib.utils import test_options_parser |
| 58 from pylib.utils import time_profile | 58 from pylib.utils import time_profile |
| 59 from pylib.utils import xvfb | 59 from pylib.utils import xvfb |
| 60 | 60 |
| 61 | 61 |
| 62 _TEST_SUITES = ['base_unittests', | |
| 63 'cc_unittests', | |
| 64 'content_unittests', | |
| 65 'gpu_unittests', | |
| 66 'ipc_tests', | |
| 67 'media_unittests', | |
| 68 'net_unittests', | |
| 69 'sql_unittests', | |
| 70 'sync_unit_tests', | |
| 71 'ui_unittests', | |
| 72 'unit_tests', | |
| 73 'webkit_compositor_bindings_unittests', | |
| 74 'android_webview_unittests', | |
| 75 ] | |
| 76 | |
| 77 | |
| 78 def FullyQualifiedTestSuites(exe, option_test_suite, build_type): | 62 def FullyQualifiedTestSuites(exe, option_test_suite, build_type): |
| 79 """Get a list of absolute paths to test suite targets. | 63 """Get a list of absolute paths to test suite targets. |
| 80 | 64 |
| 81 Args: | 65 Args: |
| 82 exe: if True, use the executable-based test runner. | 66 exe: if True, use the executable-based test runner. |
| 83 option_test_suite: the test_suite specified as an option. | 67 option_test_suite: the test_suite specified as an option. |
| 84 build_type: 'Release' or 'Debug'. | 68 build_type: 'Release' or 'Debug'. |
| 85 """ | 69 """ |
| 86 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), build_type) | 70 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), build_type) |
| 87 if option_test_suite: | 71 if option_test_suite: |
| 88 all_test_suites = [option_test_suite] | 72 all_test_suites = [option_test_suite] |
| 89 else: | 73 else: |
| 90 all_test_suites = _TEST_SUITES | 74 all_test_suites = gtest_config.STABLE_TEST_SUITES |
| 91 | 75 |
| 92 if exe: | 76 if exe: |
| 93 qualified_test_suites = [os.path.join(test_suite_dir, t) | 77 qualified_test_suites = [os.path.join(test_suite_dir, t) |
| 94 for t in all_test_suites] | 78 for t in all_test_suites] |
| 95 else: | 79 else: |
| 96 # out/(Debug|Release)/$SUITE_apk/$SUITE-debug.apk | 80 # out/(Debug|Release)/$SUITE_apk/$SUITE-debug.apk |
| 97 qualified_test_suites = [os.path.join(test_suite_dir, | 81 qualified_test_suites = [os.path.join(test_suite_dir, |
| 98 t + '_apk', | 82 t + '_apk', |
| 99 t + '-debug.apk') | 83 t + '-debug.apk') |
| 100 for t in all_test_suites] | 84 for t in all_test_suites] |
| 101 for t, q in zip(all_test_suites, qualified_test_suites): | 85 for t, q in zip(all_test_suites, qualified_test_suites): |
| 102 if not os.path.exists(q): | 86 if not os.path.exists(q): |
| 103 raise Exception('Test suite %s not found in %s.\n' | 87 raise Exception('Test suite %s not found in %s.\n' |
| 104 'Supported test suites:\n %s\n' | 88 'Supported test suites:\n %s\n' |
| 105 'Ensure it has been built.\n' % | 89 'Ensure it has been built.\n' % |
| 106 (t, q, _TEST_SUITES)) | 90 (t, q, gtest_config.STABLE_TEST_SUITES)) |
| 107 return qualified_test_suites | 91 return qualified_test_suites |
| 108 | 92 |
| 109 | 93 |
| 110 class TestSharder(BaseTestSharder): | 94 class TestSharder(BaseTestSharder): |
| 111 """Responsible for sharding the tests on the connected devices.""" | 95 """Responsible for sharding the tests on the connected devices.""" |
| 112 | 96 |
| 113 def __init__(self, attached_devices, test_suite, gtest_filter, | 97 def __init__(self, attached_devices, test_suite, gtest_filter, |
| 114 test_arguments, timeout, cleanup_test_files, tool, | 98 test_arguments, timeout, cleanup_test_files, tool, |
| 115 log_dump_name, build_type, in_webkit_checkout, | 99 log_dump_name, build_type, in_webkit_checkout, |
| 116 flakiness_server=None): | 100 flakiness_server=None): |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 test bundles. If using the emulator, we start it on entry and stop | 216 test bundles. If using the emulator, we start it on entry and stop |
| 233 it on exit. | 217 it on exit. |
| 234 | 218 |
| 235 Args: | 219 Args: |
| 236 options: options for running the tests. | 220 options: options for running the tests. |
| 237 | 221 |
| 238 Returns: | 222 Returns: |
| 239 0 if successful, number of failing tests otherwise. | 223 0 if successful, number of failing tests otherwise. |
| 240 """ | 224 """ |
| 241 step_name = os.path.basename(options.test_suite).replace('-debug.apk', '') | 225 step_name = os.path.basename(options.test_suite).replace('-debug.apk', '') |
| 242 buildbot_report.PrintNamedStep(step_name) | |
| 243 attached_devices = [] | 226 attached_devices = [] |
| 244 buildbot_emulators = [] | 227 buildbot_emulators = [] |
| 245 | 228 |
| 246 if options.use_emulator: | 229 if options.use_emulator: |
| 247 buildbot_emulators = emulator.LaunchEmulators(options.emulator_count, | 230 buildbot_emulators = emulator.LaunchEmulators(options.emulator_count, |
| 248 wait_for_boot=True) | 231 wait_for_boot=True) |
| 249 attached_devices = [e.device for e in buildbot_emulators] | 232 attached_devices = [e.device for e in buildbot_emulators] |
| 250 elif options.test_device: | 233 elif options.test_device: |
| 251 attached_devices = [options.test_device] | 234 attached_devices = [options.test_device] |
| 252 else: | 235 else: |
| 253 attached_devices = android_commands.GetAttachedDevices() | 236 attached_devices = android_commands.GetAttachedDevices() |
| 254 | 237 |
| 255 if not attached_devices: | 238 if not attached_devices: |
| 256 logging.critical('A device must be attached and online.') | 239 logging.critical('A device must be attached and online.') |
| 257 buildbot_report.PrintError() | |
| 258 return 1 | 240 return 1 |
| 259 | 241 |
| 260 # Reset the test port allocation. It's important to do it before starting | 242 # Reset the test port allocation. It's important to do it before starting |
| 261 # to dispatch any tests. | 243 # to dispatch any tests. |
| 262 if not ports.ResetTestServerPortAllocation(): | 244 if not ports.ResetTestServerPortAllocation(): |
| 263 raise Exception('Failed to reset test server port.') | 245 raise Exception('Failed to reset test server port.') |
| 264 | 246 |
| 265 if options.gtest_filter: | 247 if options.gtest_filter: |
| 266 logging.warning('Sharding is not possible with these configurations.') | 248 logging.warning('Sharding is not possible with these configurations.') |
| 267 attached_devices = [attached_devices[0]] | 249 attached_devices = [attached_devices[0]] |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 failures += _RunATestSuite(test_options) | 298 failures += _RunATestSuite(test_options) |
| 317 | 299 |
| 318 if options.use_xvfb: | 300 if options.use_xvfb: |
| 319 framebuffer.Stop() | 301 framebuffer.Stop() |
| 320 return failures | 302 return failures |
| 321 | 303 |
| 322 | 304 |
| 323 def ListTestSuites(): | 305 def ListTestSuites(): |
| 324 """Display a list of available test suites.""" | 306 """Display a list of available test suites.""" |
| 325 print 'Available test suites are:' | 307 print 'Available test suites are:' |
| 326 for test_suite in _TEST_SUITES: | 308 for test_suite in gtest_config.STABLE_TEST_SUITES: |
| 327 print test_suite | 309 print test_suite |
| 328 | 310 |
| 329 | 311 |
| 330 def main(argv): | 312 def main(argv): |
| 331 option_parser = optparse.OptionParser() | 313 option_parser = optparse.OptionParser() |
| 332 test_options_parser.AddGTestOptions(option_parser) | 314 test_options_parser.AddGTestOptions(option_parser) |
| 333 options, args = option_parser.parse_args(argv) | 315 options, args = option_parser.parse_args(argv) |
| 334 | 316 |
| 335 if len(args) > 1: | 317 if len(args) > 1: |
| 336 option_parser.error('Unknown argument: %s' % args[1:]) | 318 option_parser.error('Unknown argument: %s' % args[1:]) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 352 # the batch (this happens because the exit status is a sum of all failures | 334 # the batch (this happens because the exit status is a sum of all failures |
| 353 # from all suites, but the buildbot associates the exit status only with the | 335 # from all suites, but the buildbot associates the exit status only with the |
| 354 # most recent step). | 336 # most recent step). |
| 355 if options.exit_code: | 337 if options.exit_code: |
| 356 return failed_tests_count | 338 return failed_tests_count |
| 357 return 0 | 339 return 0 |
| 358 | 340 |
| 359 | 341 |
| 360 if __name__ == '__main__': | 342 if __name__ == '__main__': |
| 361 sys.exit(main(sys.argv)) | 343 sys.exit(main(sys.argv)) |
| OLD | NEW |