| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import collections | 6 import collections |
| 7 import glob | 7 import glob |
| 8 import multiprocessing | 8 import multiprocessing |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 import bb_utils | 13 import bb_utils |
| 14 import bb_annotations | 14 import bb_annotations |
| 15 | 15 |
| 16 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | 16 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| 17 import provision_devices | 17 import provision_devices |
| 18 from pylib import android_commands | 18 from pylib import android_commands |
| 19 from pylib import constants | 19 from pylib import constants |
| 20 from pylib.gtest import gtest_config | 20 from pylib.gtest import gtest_config |
| 21 | 21 |
| 22 sys.path.append(os.path.join( | 22 sys.path.append(os.path.join( |
| 23 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 23 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
| 24 import errors | 24 import errors |
| 25 | 25 |
| 26 | 26 |
| 27 CHROME_SRC = constants.DIR_SOURCE_ROOT | 27 CHROME_SRC = constants.DIR_SOURCE_ROOT |
| 28 LOGCAT_DIR = os.path.join(CHROME_SRC, 'out', 'logcat') | 28 LOGCAT_DIR = os.path.join(CHROME_SRC, 'out', 'logcat') |
| 29 COVERAGE_DIR = os.path.join(CHROME_SRC, 'out', 'coverage') |
| 29 | 30 |
| 30 # Describes an instrumation test suite: | 31 # Describes an instrumation test suite: |
| 31 # test: Name of test we're running. | 32 # test: Name of test we're running. |
| 32 # apk: apk to be installed. | 33 # apk: apk to be installed. |
| 33 # apk_package: package for the apk to be installed. | 34 # apk_package: package for the apk to be installed. |
| 34 # test_apk: apk to run tests on. | 35 # test_apk: apk to run tests on. |
| 35 # test_data: data folder in format destination:source. | 36 # test_data: data folder in format destination:source. |
| 36 # host_driven_root: The host-driven test root directory. | 37 # host_driven_root: The host-driven test root directory. |
| 37 # annotation: Annotation of the tests to include. | 38 # annotation: Annotation of the tests to include. |
| 38 # exclude_annotation: The annotation of the tests to exclude. | 39 # exclude_annotation: The annotation of the tests to exclude. |
| 39 I_TEST = collections.namedtuple('InstrumentationTest', [ | 40 I_TEST = collections.namedtuple('InstrumentationTest', [ |
| 40 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'host_driven_root', | 41 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'coverage', |
| 41 'annotation', 'exclude_annotation', 'extra_flags']) | 42 'host_driven_root', 'annotation', 'exclude_annotation', 'extra_flags']) |
| 42 | 43 |
| 43 def I(name, apk, apk_package, test_apk, test_data, host_driven_root=None, | 44 def I(name, apk, apk_package, test_apk, test_data, coverage=False, |
| 44 annotation=None, exclude_annotation=None, extra_flags=None): | 45 host_driven_root=None, annotation=None, exclude_annotation=None, |
| 45 return I_TEST(name, apk, apk_package, test_apk, test_data, host_driven_root, | 46 extra_flags=None): |
| 46 annotation, exclude_annotation, extra_flags) | 47 return I_TEST(name, apk, apk_package, test_apk, test_data, coverage, |
| 48 host_driven_root, annotation, exclude_annotation, extra_flags) |
| 47 | 49 |
| 48 INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ | 50 INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ |
| 49 I('ContentShell', | 51 I('ContentShell', |
| 50 'ContentShell.apk', | 52 'ContentShell.apk', |
| 51 'org.chromium.content_shell_apk', | 53 'org.chromium.content_shell_apk', |
| 52 'ContentShellTest', | 54 'ContentShellTest', |
| 53 'content:content/test/data/android/device_files'), | 55 'content:content/test/data/android/device_files', |
| 56 coverage=True), |
| 54 I('ChromiumTestShell', | 57 I('ChromiumTestShell', |
| 55 'ChromiumTestShell.apk', | 58 'ChromiumTestShell.apk', |
| 56 'org.chromium.chrome.testshell', | 59 'org.chromium.chrome.testshell', |
| 57 'ChromiumTestShellTest', | 60 'ChromiumTestShellTest', |
| 58 'chrome:chrome/test/data/android/device_files', | 61 'chrome:chrome/test/data/android/device_files', |
| 59 constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR), | 62 host_driven_root=constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR), |
| 60 I('AndroidWebView', | 63 I('AndroidWebView', |
| 61 'AndroidWebView.apk', | 64 'AndroidWebView.apk', |
| 62 'org.chromium.android_webview.shell', | 65 'org.chromium.android_webview.shell', |
| 63 'AndroidWebViewTest', | 66 'AndroidWebViewTest', |
| 64 'webview:android_webview/test/data/device_files'), | 67 'webview:android_webview/test/data/device_files'), |
| 65 ]) | 68 ]) |
| 66 | 69 |
| 67 VALID_TESTS = set(['chromedriver', 'ui', 'unit', 'webkit', 'webkit_layout']) | 70 VALID_TESTS = set(['chromedriver', 'ui', 'unit', 'webkit', 'webkit_layout']) |
| 68 | 71 |
| 69 RunCmd = bb_utils.RunCmd | 72 RunCmd = bb_utils.RunCmd |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 InstallApk(options, test) | 160 InstallApk(options, test) |
| 158 args = ['--test-apk', test.test_apk, '--test_data', test.test_data, | 161 args = ['--test-apk', test.test_apk, '--test_data', test.test_data, |
| 159 '--verbose'] | 162 '--verbose'] |
| 160 if options.target == 'Release': | 163 if options.target == 'Release': |
| 161 args.append('--release') | 164 args.append('--release') |
| 162 if options.asan: | 165 if options.asan: |
| 163 args.append('--tool=asan') | 166 args.append('--tool=asan') |
| 164 if options.flakiness_server: | 167 if options.flakiness_server: |
| 165 args.append('--flakiness-dashboard-server=%s' % | 168 args.append('--flakiness-dashboard-server=%s' % |
| 166 options.flakiness_server) | 169 options.flakiness_server) |
| 170 if options.coverage and test.coverage: |
| 171 args.append('--coverage-dir=%s' % COVERAGE_DIR) |
| 167 if test.host_driven_root: | 172 if test.host_driven_root: |
| 168 args.append('--python_test_root=%s' % test.host_driven_root) | 173 args.append('--python_test_root=%s' % test.host_driven_root) |
| 169 if test.annotation: | 174 if test.annotation: |
| 170 args.extend(['-A', test.annotation]) | 175 args.extend(['-A', test.annotation]) |
| 171 if test.exclude_annotation: | 176 if test.exclude_annotation: |
| 172 args.extend(['-E', test.exclude_annotation]) | 177 args.extend(['-E', test.exclude_annotation]) |
| 173 if test.extra_flags: | 178 if test.extra_flags: |
| 174 args.extend(test.extra_flags) | 179 args.extend(test.extra_flags) |
| 175 if python_only: | 180 if python_only: |
| 176 args.append('-p') | 181 args.append('-p') |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 269 |
| 265 | 270 |
| 266 def RunUnitTests(options): | 271 def RunUnitTests(options): |
| 267 RunTestSuites(options, gtest_config.STABLE_TEST_SUITES) | 272 RunTestSuites(options, gtest_config.STABLE_TEST_SUITES) |
| 268 | 273 |
| 269 | 274 |
| 270 def RunInstrumentationTests(options): | 275 def RunInstrumentationTests(options): |
| 271 for test in INSTRUMENTATION_TESTS.itervalues(): | 276 for test in INSTRUMENTATION_TESTS.itervalues(): |
| 272 RunInstrumentationSuite(options, test) | 277 RunInstrumentationSuite(options, test) |
| 273 | 278 |
| 279 if options.coverage: |
| 280 RunCmd(['build/android/generate_emma_html.py', |
| 281 '--coverage-dir', COVERAGE_DIR, |
| 282 '--metadata-dir', os.path.join('out', options.target), |
| 283 '--output', os.path.join(COVERAGE_DIR, 'coverage.html')]) |
| 284 |
| 274 | 285 |
| 275 def RunWebkitTests(options): | 286 def RunWebkitTests(options): |
| 276 RunTestSuites(options, ['webkit_unit_tests']) | 287 RunTestSuites(options, ['webkit_unit_tests']) |
| 277 RunWebkitLint(options.target) | 288 RunWebkitLint(options.target) |
| 278 | 289 |
| 279 | 290 |
| 280 def GetTestStepCmds(): | 291 def GetTestStepCmds(): |
| 281 return [ | 292 return [ |
| 282 ('chromedriver', RunChromeDriverTests), | 293 ('chromedriver', RunChromeDriverTests), |
| 283 ('unit', RunUnitTests), | 294 ('unit', RunUnitTests), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 help='Run experiemental tests') | 351 help='Run experiemental tests') |
| 341 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[], | 352 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[], |
| 342 action='append', | 353 action='append', |
| 343 help=('Run a test suite. Test suites: "%s"' % | 354 help=('Run a test suite. Test suites: "%s"' % |
| 344 '", "'.join(VALID_TESTS))) | 355 '", "'.join(VALID_TESTS))) |
| 345 parser.add_option('--asan', action='store_true', help='Run tests with asan.') | 356 parser.add_option('--asan', action='store_true', help='Run tests with asan.') |
| 346 parser.add_option('--install', metavar='<apk name>', | 357 parser.add_option('--install', metavar='<apk name>', |
| 347 help='Install an apk by name') | 358 help='Install an apk by name') |
| 348 parser.add_option('--reboot', action='store_true', | 359 parser.add_option('--reboot', action='store_true', |
| 349 help='Reboot devices before running tests') | 360 help='Reboot devices before running tests') |
| 361 parser.add_option('--coverage', action='store_true', |
| 362 help='Run instrumentation tests with coverage.') |
| 350 parser.add_option( | 363 parser.add_option( |
| 351 '--flakiness-server', | 364 '--flakiness-server', |
| 352 help='The flakiness dashboard server to which the results should be ' | 365 help='The flakiness dashboard server to which the results should be ' |
| 353 'uploaded.') | 366 'uploaded.') |
| 354 parser.add_option( | 367 parser.add_option( |
| 355 '--auto-reconnect', action='store_true', | 368 '--auto-reconnect', action='store_true', |
| 356 help='Push script to device which restarts adbd on disconnections.') | 369 help='Push script to device which restarts adbd on disconnections.') |
| 357 parser.add_option( | 370 parser.add_option( |
| 358 '--logcat-dump-output', | 371 '--logcat-dump-output', |
| 359 help='The logcat dump output will be "tee"-ed into this file') | 372 help='The logcat dump output will be "tee"-ed into this file') |
| (...skipping 12 matching lines...) Expand all Loading... |
| 372 if unknown_tests: | 385 if unknown_tests: |
| 373 return sys.exit('Unknown tests %s' % list(unknown_tests)) | 386 return sys.exit('Unknown tests %s' % list(unknown_tests)) |
| 374 | 387 |
| 375 setattr(options, 'target', options.factory_properties.get('target', 'Debug')) | 388 setattr(options, 'target', options.factory_properties.get('target', 'Debug')) |
| 376 | 389 |
| 377 MainTestWrapper(options) | 390 MainTestWrapper(options) |
| 378 | 391 |
| 379 | 392 |
| 380 if __name__ == '__main__': | 393 if __name__ == '__main__': |
| 381 sys.exit(main(sys.argv)) | 394 sys.exit(main(sys.argv)) |
| OLD | NEW |