| 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 SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave') |
| 27 CHROME_SRC = constants.DIR_SOURCE_ROOT | 28 CHROME_SRC = constants.DIR_SOURCE_ROOT |
| 28 LOGCAT_DIR = os.path.join(CHROME_SRC, 'out', 'logcat') | 29 LOGCAT_DIR = os.path.join(CHROME_SRC, 'out', 'logcat') |
| 30 COVERAGE_DIR = os.path.join(CHROME_SRC, 'out', 'coverage') |
| 31 REVISION_FILENAME = 'FULL_BUILD_REVISION' |
| 29 | 32 |
| 30 # Describes an instrumation test suite: | 33 # Describes an instrumation test suite: |
| 31 # test: Name of test we're running. | 34 # test: Name of test we're running. |
| 32 # apk: apk to be installed. | 35 # apk: apk to be installed. |
| 33 # apk_package: package for the apk to be installed. | 36 # apk_package: package for the apk to be installed. |
| 34 # test_apk: apk to run tests on. | 37 # test_apk: apk to run tests on. |
| 35 # test_data: data folder in format destination:source. | 38 # test_data: data folder in format destination:source. |
| 36 # host_driven_root: The host-driven test root directory. | 39 # host_driven_root: The host-driven test root directory. |
| 37 # annotation: Annotation of the tests to include. | 40 # annotation: Annotation of the tests to include. |
| 38 # exclude_annotation: The annotation of the tests to exclude. | 41 # exclude_annotation: The annotation of the tests to exclude. |
| 39 I_TEST = collections.namedtuple('InstrumentationTest', [ | 42 I_TEST = collections.namedtuple('InstrumentationTest', [ |
| 40 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'host_driven_root', | 43 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'coverage', |
| 41 'annotation', 'exclude_annotation', 'extra_flags']) | 44 'host_driven_root', 'annotation', 'exclude_annotation', 'extra_flags']) |
| 42 | 45 |
| 43 def I(name, apk, apk_package, test_apk, test_data, host_driven_root=None, | 46 def I(name, apk, apk_package, test_apk, test_data, coverage=False, |
| 44 annotation=None, exclude_annotation=None, extra_flags=None): | 47 host_driven_root=None, annotation=None, exclude_annotation=None, |
| 45 return I_TEST(name, apk, apk_package, test_apk, test_data, host_driven_root, | 48 extra_flags=None): |
| 46 annotation, exclude_annotation, extra_flags) | 49 return I_TEST(name, apk, apk_package, test_apk, test_data, coverage, |
| 50 host_driven_root, annotation, exclude_annotation, extra_flags) |
| 47 | 51 |
| 48 INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ | 52 INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ |
| 49 I('ContentShell', | 53 I('ContentShell', |
| 50 'ContentShell.apk', | 54 'ContentShell.apk', |
| 51 'org.chromium.content_shell_apk', | 55 'org.chromium.content_shell_apk', |
| 52 'ContentShellTest', | 56 'ContentShellTest', |
| 53 'content:content/test/data/android/device_files'), | 57 'content:content/test/data/android/device_files', |
| 58 coverage=True), |
| 54 I('ChromiumTestShell', | 59 I('ChromiumTestShell', |
| 55 'ChromiumTestShell.apk', | 60 'ChromiumTestShell.apk', |
| 56 'org.chromium.chrome.testshell', | 61 'org.chromium.chrome.testshell', |
| 57 'ChromiumTestShellTest', | 62 'ChromiumTestShellTest', |
| 58 'chrome:chrome/test/data/android/device_files', | 63 'chrome:chrome/test/data/android/device_files', |
| 59 constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR), | 64 host_driven_root=constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR), |
| 60 I('AndroidWebView', | 65 I('AndroidWebView', |
| 61 'AndroidWebView.apk', | 66 'AndroidWebView.apk', |
| 62 'org.chromium.android_webview.shell', | 67 'org.chromium.android_webview.shell', |
| 63 'AndroidWebViewTest', | 68 'AndroidWebViewTest', |
| 64 'webview:android_webview/test/data/device_files'), | 69 'webview:android_webview/test/data/device_files'), |
| 65 ]) | 70 ]) |
| 66 | 71 |
| 67 VALID_TESTS = set(['chromedriver', 'ui', 'unit', 'webkit', 'webkit_layout']) | 72 VALID_TESTS = set(['chromedriver', 'ui', 'unit', 'webkit', 'webkit_layout']) |
| 68 | 73 |
| 69 RunCmd = bb_utils.RunCmd | 74 RunCmd = bb_utils.RunCmd |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 InstallApk(options, test) | 162 InstallApk(options, test) |
| 158 args = ['--test-apk', test.test_apk, '--test_data', test.test_data, | 163 args = ['--test-apk', test.test_apk, '--test_data', test.test_data, |
| 159 '--verbose'] | 164 '--verbose'] |
| 160 if options.target == 'Release': | 165 if options.target == 'Release': |
| 161 args.append('--release') | 166 args.append('--release') |
| 162 if options.asan: | 167 if options.asan: |
| 163 args.append('--tool=asan') | 168 args.append('--tool=asan') |
| 164 if options.flakiness_server: | 169 if options.flakiness_server: |
| 165 args.append('--flakiness-dashboard-server=%s' % | 170 args.append('--flakiness-dashboard-server=%s' % |
| 166 options.flakiness_server) | 171 options.flakiness_server) |
| 172 if options.coverage and test.coverage: |
| 173 args.append('--coverage-dir=%s' % COVERAGE_DIR) |
| 167 if test.host_driven_root: | 174 if test.host_driven_root: |
| 168 args.append('--python_test_root=%s' % test.host_driven_root) | 175 args.append('--python_test_root=%s' % test.host_driven_root) |
| 169 if test.annotation: | 176 if test.annotation: |
| 170 args.extend(['-A', test.annotation]) | 177 args.extend(['-A', test.annotation]) |
| 171 if test.exclude_annotation: | 178 if test.exclude_annotation: |
| 172 args.extend(['-E', test.exclude_annotation]) | 179 args.extend(['-E', test.exclude_annotation]) |
| 173 if test.extra_flags: | 180 if test.extra_flags: |
| 174 args.extend(test.extra_flags) | 181 args.extend(test.extra_flags) |
| 175 if python_only: | 182 if python_only: |
| 176 args.append('-p') | 183 args.append('-p') |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 271 |
| 265 | 272 |
| 266 def RunUnitTests(options): | 273 def RunUnitTests(options): |
| 267 RunTestSuites(options, gtest_config.STABLE_TEST_SUITES) | 274 RunTestSuites(options, gtest_config.STABLE_TEST_SUITES) |
| 268 | 275 |
| 269 | 276 |
| 270 def RunInstrumentationTests(options): | 277 def RunInstrumentationTests(options): |
| 271 for test in INSTRUMENTATION_TESTS.itervalues(): | 278 for test in INSTRUMENTATION_TESTS.itervalues(): |
| 272 RunInstrumentationSuite(options, test) | 279 RunInstrumentationSuite(options, test) |
| 273 | 280 |
| 281 if options.coverage: |
| 282 shutil.rmtree(COVERAGE_DIR, ignore_errors=True) |
| 283 os.mkdir(COVERAGE_DIR) |
| 284 RunCmd(['build/android/generate_emma_html.py', |
| 285 '--coverage-dir', COVERAGE_DIR, |
| 286 '--metadata-dir', os.path.join('out', options.target), |
| 287 '--output', os.path.join(COVERAGE_DIR, 'coverage.html')]) |
| 288 revision_file = os.path.join(CHROME_SRC, 'out', options.target, |
| 289 REVISION_FILENAME) |
| 290 |
| 291 # If the revision file doesn't exist, we're just testing the bot |
| 292 if os.path.exists(revision_file): |
| 293 with open(revision_file) as f: |
| 294 revision = f.read() |
| 295 else: |
| 296 revision = 'testing' |
| 297 |
| 298 RunCmd([os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', |
| 299 'slave', 'gsutil_cp_dir.py'), |
| 300 os.path.join(COVERAGE_DIR), 'gs://<bucket>/coverage_%s' % revision]) |
| 301 bb_annotations.PrintLink( |
| 302 'Coverage report', |
| 303 'https://storage.googleapis.com/<bucket>/coverage_%s/coverage.html' |
| 304 % revision) |
| 305 |
| 274 | 306 |
| 275 def RunWebkitTests(options): | 307 def RunWebkitTests(options): |
| 276 RunTestSuites(options, ['webkit_unit_tests']) | 308 RunTestSuites(options, ['webkit_unit_tests']) |
| 277 RunWebkitLint(options.target) | 309 RunWebkitLint(options.target) |
| 278 | 310 |
| 279 | 311 |
| 280 def GetTestStepCmds(): | 312 def GetTestStepCmds(): |
| 281 return [ | 313 return [ |
| 282 ('chromedriver', RunChromeDriverTests), | 314 ('chromedriver', RunChromeDriverTests), |
| 283 ('unit', RunUnitTests), | 315 ('unit', RunUnitTests), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 help='Run experiemental tests') | 372 help='Run experiemental tests') |
| 341 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[], | 373 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[], |
| 342 action='append', | 374 action='append', |
| 343 help=('Run a test suite. Test suites: "%s"' % | 375 help=('Run a test suite. Test suites: "%s"' % |
| 344 '", "'.join(VALID_TESTS))) | 376 '", "'.join(VALID_TESTS))) |
| 345 parser.add_option('--asan', action='store_true', help='Run tests with asan.') | 377 parser.add_option('--asan', action='store_true', help='Run tests with asan.') |
| 346 parser.add_option('--install', metavar='<apk name>', | 378 parser.add_option('--install', metavar='<apk name>', |
| 347 help='Install an apk by name') | 379 help='Install an apk by name') |
| 348 parser.add_option('--reboot', action='store_true', | 380 parser.add_option('--reboot', action='store_true', |
| 349 help='Reboot devices before running tests') | 381 help='Reboot devices before running tests') |
| 382 parser.add_option('--coverage', action='store_true', |
| 383 help='Run instrumentation tests with coverage.') |
| 350 parser.add_option( | 384 parser.add_option( |
| 351 '--flakiness-server', | 385 '--flakiness-server', |
| 352 help='The flakiness dashboard server to which the results should be ' | 386 help='The flakiness dashboard server to which the results should be ' |
| 353 'uploaded.') | 387 'uploaded.') |
| 354 parser.add_option( | 388 parser.add_option( |
| 355 '--auto-reconnect', action='store_true', | 389 '--auto-reconnect', action='store_true', |
| 356 help='Push script to device which restarts adbd on disconnections.') | 390 help='Push script to device which restarts adbd on disconnections.') |
| 357 parser.add_option( | 391 parser.add_option( |
| 358 '--logcat-dump-output', | 392 '--logcat-dump-output', |
| 359 help='The logcat dump output will be "tee"-ed into this file') | 393 help='The logcat dump output will be "tee"-ed into this file') |
| (...skipping 12 matching lines...) Expand all Loading... |
| 372 if unknown_tests: | 406 if unknown_tests: |
| 373 return sys.exit('Unknown tests %s' % list(unknown_tests)) | 407 return sys.exit('Unknown tests %s' % list(unknown_tests)) |
| 374 | 408 |
| 375 setattr(options, 'target', options.factory_properties.get('target', 'Debug')) | 409 setattr(options, 'target', options.factory_properties.get('target', 'Debug')) |
| 376 | 410 |
| 377 MainTestWrapper(options) | 411 MainTestWrapper(options) |
| 378 | 412 |
| 379 | 413 |
| 380 if __name__ == '__main__': | 414 if __name__ == '__main__': |
| 381 sys.exit(main(sys.argv)) | 415 sys.exit(main(sys.argv)) |
| OLD | NEW |