Chromium Code Reviews| 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 hashlib | |
| 8 import multiprocessing | 9 import multiprocessing |
| 9 import os | 10 import os |
| 11 import random | |
| 10 import shutil | 12 import shutil |
| 11 import sys | 13 import sys |
| 12 | 14 |
| 13 import bb_utils | 15 import bb_utils |
| 14 import bb_annotations | 16 import bb_annotations |
| 15 | 17 |
| 16 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | 18 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| 17 import provision_devices | 19 import provision_devices |
| 18 from pylib import android_commands | 20 from pylib import android_commands |
| 19 from pylib import constants | 21 from pylib import constants |
| 20 from pylib.gtest import gtest_config | 22 from pylib.gtest import gtest_config |
| 21 | 23 |
| 22 sys.path.append(os.path.join( | 24 sys.path.append(os.path.join( |
| 23 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 25 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
| 24 import errors | 26 import errors |
| 25 | 27 |
| 26 | 28 |
| 27 CHROME_SRC = constants.DIR_SOURCE_ROOT | 29 CHROME_SRC = constants.DIR_SOURCE_ROOT |
| 28 LOGCAT_DIR = os.path.join(CHROME_SRC, 'out', 'logcat') | 30 LOGCAT_DIR = os.path.join(CHROME_SRC, 'out', 'logcat') |
| 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. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 InstallApk(options, test) | 161 InstallApk(options, test) |
| 159 args = ['--test-apk', test.test_apk, '--test_data', test.test_data, | 162 args = ['--test-apk', test.test_apk, '--test_data', test.test_data, |
| 160 '--verbose'] | 163 '--verbose'] |
| 161 if options.target == 'Release': | 164 if options.target == 'Release': |
| 162 args.append('--release') | 165 args.append('--release') |
| 163 if options.asan: | 166 if options.asan: |
| 164 args.append('--tool=asan') | 167 args.append('--tool=asan') |
| 165 if options.flakiness_server: | 168 if options.flakiness_server: |
| 166 args.append('--flakiness-dashboard-server=%s' % | 169 args.append('--flakiness-dashboard-server=%s' % |
| 167 options.flakiness_server) | 170 options.flakiness_server) |
| 171 if options.coverage_bucket: | |
| 172 args.append('--coverage-dir=%s' % options.coverage_dir) | |
| 168 if test.host_driven_root: | 173 if test.host_driven_root: |
| 169 args.append('--host-driven-root=%s' % test.host_driven_root) | 174 args.append('--host-driven-root=%s' % test.host_driven_root) |
| 170 if test.annotation: | 175 if test.annotation: |
| 171 args.extend(['-A', test.annotation]) | 176 args.extend(['-A', test.annotation]) |
| 172 if test.exclude_annotation: | 177 if test.exclude_annotation: |
| 173 args.extend(['-E', test.exclude_annotation]) | 178 args.extend(['-E', test.exclude_annotation]) |
| 174 if test.extra_flags: | 179 if test.extra_flags: |
| 175 args.extend(test.extra_flags) | 180 args.extend(test.extra_flags) |
| 176 if python_only: | 181 if python_only: |
| 177 args.append('-p') | 182 args.append('-p') |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 return [ | 292 return [ |
| 288 ('chromedriver', RunChromeDriverTests), | 293 ('chromedriver', RunChromeDriverTests), |
| 289 ('unit', RunUnitTests), | 294 ('unit', RunUnitTests), |
| 290 ('ui', RunInstrumentationTests), | 295 ('ui', RunInstrumentationTests), |
| 291 ('webkit', RunWebkitTests), | 296 ('webkit', RunWebkitTests), |
| 292 ('webkit_layout', RunWebkitLayoutTests), | 297 ('webkit_layout', RunWebkitLayoutTests), |
| 293 ('webrtc', RunWebRTCTests), | 298 ('webrtc', RunWebRTCTests), |
| 294 ] | 299 ] |
| 295 | 300 |
| 296 | 301 |
| 302 def UploadCoverageData(options, path, coverage_type): | |
|
frankf
2013/08/21 01:13:45
Add docstring
gkanwar1
2013/08/21 01:29:13
Done.
| |
| 303 revision = options.build_properties.get('got_revision', 'testing') | |
| 304 bot_id = options.build_properties.get('buildername', 'testing') | |
| 305 | |
| 306 randhash = hashlib.sha1(str(random.random())).hexdigest() | |
| 307 | |
| 308 RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-R', path, 'gs://%s/%s/%s/%s/%s' % | |
| 309 (options.coverage_bucket, coverage_type, bot_id, revision, randhash)]) | |
|
frankf
2013/08/21 01:13:45
DRY, create a var for gs path
gkanwar1
2013/08/21 01:29:13
Done.
| |
| 310 bb_annotations.PrintLink( | |
| 311 'Coverage report', | |
| 312 'https://storage.googleapis.com/%s/%s/%s/%s/%s/index.html' | |
| 313 % (options.coverage_bucket, coverage_type, bot_id, revision, randhash)) | |
| 314 | |
| 315 | |
| 316 def GenerateJavaCoverageReport(options): | |
| 317 bb_annotations.PrintNamedStep('java_coverage_report') | |
| 318 | |
| 319 coverage_html = os.path.join(options.coverage_dir, 'coverage_html') | |
| 320 RunCmd(['build/android/generate_emma_html.py', | |
| 321 '--coverage-dir', options.coverage_dir, | |
| 322 '--metadata-dir', os.path.join(CHROME_SRC, 'out', options.target), | |
| 323 '--output', os.path.join(coverage_html, 'index.html')]) | |
| 324 UploadCoverageData(options, coverage_html, 'java') | |
| 325 | |
| 326 | |
| 297 def LogcatDump(options): | 327 def LogcatDump(options): |
| 298 # Print logcat, kill logcat monitor | 328 # Print logcat, kill logcat monitor |
| 299 bb_annotations.PrintNamedStep('logcat_dump') | 329 bb_annotations.PrintNamedStep('logcat_dump') |
| 300 logcat_file = os.path.join(CHROME_SRC, 'out', options.target, 'full_log') | 330 logcat_file = os.path.join(CHROME_SRC, 'out', options.target, 'full_log') |
| 301 with open(logcat_file, 'w') as f: | 331 with open(logcat_file, 'w') as f: |
| 302 RunCmd([ | 332 RunCmd([ |
| 303 os.path.join(CHROME_SRC, 'build', 'android', 'adb_logcat_printer.py'), | 333 os.path.join(CHROME_SRC, 'build', 'android', 'adb_logcat_printer.py'), |
| 304 LOGCAT_DIR], stdout=f) | 334 LOGCAT_DIR], stdout=f) |
| 305 RunCmd(['cat', logcat_file]) | 335 RunCmd(['cat', logcat_file]) |
| 306 | 336 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 322 for _, cmd in GetDeviceSetupStepCmds(): | 352 for _, cmd in GetDeviceSetupStepCmds(): |
| 323 cmd(options) | 353 cmd(options) |
| 324 | 354 |
| 325 if options.install: | 355 if options.install: |
| 326 test_obj = INSTRUMENTATION_TESTS[options.install] | 356 test_obj = INSTRUMENTATION_TESTS[options.install] |
| 327 InstallApk(options, test_obj, print_step=True) | 357 InstallApk(options, test_obj, print_step=True) |
| 328 | 358 |
| 329 if options.test_filter: | 359 if options.test_filter: |
| 330 bb_utils.RunSteps(options.test_filter, GetTestStepCmds(), options) | 360 bb_utils.RunSteps(options.test_filter, GetTestStepCmds(), options) |
| 331 | 361 |
| 362 if options.coverage_bucket: | |
| 363 GenerateJavaCoverageReport(options) | |
| 364 | |
| 332 if options.experimental: | 365 if options.experimental: |
| 333 RunTestSuites(options, gtest_config.EXPERIMENTAL_TEST_SUITES) | 366 RunTestSuites(options, gtest_config.EXPERIMENTAL_TEST_SUITES) |
| 334 | 367 |
| 335 finally: | 368 finally: |
| 336 # Run all post test steps | 369 # Run all post test steps |
| 337 LogcatDump(options) | 370 LogcatDump(options) |
| 338 GenerateTestReport(options) | 371 GenerateTestReport(options) |
| 339 # KillHostHeartbeat() has logic to check if heartbeat process is running, | 372 # KillHostHeartbeat() has logic to check if heartbeat process is running, |
| 340 # and kills only if it finds the process is running on the host. | 373 # and kills only if it finds the process is running on the host. |
| 341 provision_devices.KillHostHeartbeat() | 374 provision_devices.KillHostHeartbeat() |
| 342 | 375 |
| 343 | 376 |
| 344 def GetDeviceStepsOptParser(): | 377 def GetDeviceStepsOptParser(): |
| 345 parser = bb_utils.GetParser() | 378 parser = bb_utils.GetParser() |
| 346 parser.add_option('--experimental', action='store_true', | 379 parser.add_option('--experimental', action='store_true', |
| 347 help='Run experiemental tests') | 380 help='Run experiemental tests') |
| 348 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[], | 381 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[], |
| 349 action='append', | 382 action='append', |
| 350 help=('Run a test suite. Test suites: "%s"' % | 383 help=('Run a test suite. Test suites: "%s"' % |
| 351 '", "'.join(VALID_TESTS))) | 384 '", "'.join(VALID_TESTS))) |
| 352 parser.add_option('--asan', action='store_true', help='Run tests with asan.') | 385 parser.add_option('--asan', action='store_true', help='Run tests with asan.') |
| 353 parser.add_option('--install', metavar='<apk name>', | 386 parser.add_option('--install', metavar='<apk name>', |
| 354 help='Install an apk by name') | 387 help='Install an apk by name') |
| 355 parser.add_option('--reboot', action='store_true', | 388 parser.add_option('--reboot', action='store_true', |
| 356 help='Reboot devices before running tests') | 389 help='Reboot devices before running tests') |
| 390 parser.add_option('--coverage-bucket', | |
| 391 help=('Bucket name to store coverage results. Coverage is ' | |
| 392 'only run if this is set.')) | |
| 357 parser.add_option( | 393 parser.add_option( |
| 358 '--flakiness-server', | 394 '--flakiness-server', |
| 359 help='The flakiness dashboard server to which the results should be ' | 395 help='The flakiness dashboard server to which the results should be ' |
| 360 'uploaded.') | 396 'uploaded.') |
| 361 parser.add_option( | 397 parser.add_option( |
| 362 '--auto-reconnect', action='store_true', | 398 '--auto-reconnect', action='store_true', |
| 363 help='Push script to device which restarts adbd on disconnections.') | 399 help='Push script to device which restarts adbd on disconnections.') |
| 364 parser.add_option( | 400 parser.add_option( |
| 365 '--logcat-dump-output', | 401 '--logcat-dump-output', |
| 366 help='The logcat dump output will be "tee"-ed into this file') | 402 help='The logcat dump output will be "tee"-ed into this file') |
| 367 | 403 |
| 368 return parser | 404 return parser |
| 369 | 405 |
| 370 | 406 |
| 371 def main(argv): | 407 def main(argv): |
| 372 parser = GetDeviceStepsOptParser() | 408 parser = GetDeviceStepsOptParser() |
| 373 options, args = parser.parse_args(argv[1:]) | 409 options, args = parser.parse_args(argv[1:]) |
| 374 | 410 |
| 375 if args: | 411 if args: |
| 376 return sys.exit('Unused args %s' % args) | 412 return sys.exit('Unused args %s' % args) |
| 377 | 413 |
| 378 unknown_tests = set(options.test_filter) - VALID_TESTS | 414 unknown_tests = set(options.test_filter) - VALID_TESTS |
| 379 if unknown_tests: | 415 if unknown_tests: |
| 380 return sys.exit('Unknown tests %s' % list(unknown_tests)) | 416 return sys.exit('Unknown tests %s' % list(unknown_tests)) |
| 381 | 417 |
| 382 setattr(options, 'target', options.factory_properties.get('target', 'Debug')) | 418 setattr(options, 'target', options.factory_properties.get('target', 'Debug')) |
| 419 if options.coverage_bucket: | |
| 420 setattr(options, 'coverage_dir', | |
| 421 os.path.join(CHROME_SRC, 'out', options.target, 'coverage')) | |
| 383 | 422 |
| 384 MainTestWrapper(options) | 423 MainTestWrapper(options) |
| 385 | 424 |
| 386 | 425 |
| 387 if __name__ == '__main__': | 426 if __name__ == '__main__': |
| 388 sys.exit(main(sys.argv)) | 427 sys.exit(main(sys.argv)) |
| OLD | NEW |