cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / build / android / buildbot / bb_device_steps.py
bloba1eb1bd149a77571f4175428f8cf98273fe0fbc8
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 import collections
7 import glob
8 import hashlib
9 import json
10 import os
11 import random
12 import re
13 import shutil
14 import sys
16 import bb_utils
17 import bb_annotations
19 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
20 import provision_devices
21 from devil.android import device_utils
22 from pylib import constants
23 from pylib.gtest import gtest_config
25 CHROME_SRC_DIR = bb_utils.CHROME_SRC
26 DIR_BUILD_ROOT = os.path.dirname(CHROME_SRC_DIR)
27 CHROME_OUT_DIR = bb_utils.CHROME_OUT_DIR
28 BLINK_SCRIPTS_DIR = 'third_party/WebKit/Tools/Scripts'
30 SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave')
31 LOGCAT_DIR = os.path.join(bb_utils.CHROME_OUT_DIR, 'logcat')
32 GS_URL = 'https://storage.googleapis.com'
33 GS_AUTH_URL = 'https://storage.cloud.google.com'
35 # Describes an instrumation test suite:
36 # test: Name of test we're running.
37 # apk: apk to be installed.
38 # apk_package: package for the apk to be installed.
39 # test_apk: apk to run tests on.
40 # test_data: data folder in format destination:source.
41 # host_driven_root: The host-driven test root directory.
42 # annotation: Annotation of the tests to include.
43 # exclude_annotation: The annotation of the tests to exclude.
44 I_TEST = collections.namedtuple('InstrumentationTest', [
45 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'isolate_file_path',
46 'host_driven_root', 'annotation', 'exclude_annotation', 'extra_flags'])
49 def SrcPath(*path):
50 return os.path.join(CHROME_SRC_DIR, *path)
53 def I(name, apk, apk_package, test_apk, test_data, isolate_file_path=None,
54 host_driven_root=None, annotation=None, exclude_annotation=None,
55 extra_flags=None):
56 return I_TEST(name, apk, apk_package, test_apk, test_data, isolate_file_path,
57 host_driven_root, annotation, exclude_annotation, extra_flags)
59 INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [
60 I('ContentShell',
61 'ContentShell.apk',
62 'org.chromium.content_shell_apk',
63 'ContentShellTest',
64 'content:content/test/data/android/device_files',
65 isolate_file_path='content/content_shell_test_apk.isolate'),
66 I('AndroidWebView',
67 'AndroidWebView.apk',
68 'org.chromium.android_webview.shell',
69 'AndroidWebViewTest',
70 'webview:android_webview/test/data/device_files',
71 isolate_file_path='android_webview/android_webview_test_apk.isolate'),
72 I('ChromeSyncShell',
73 'ChromeSyncShell.apk',
74 'org.chromium.chrome.browser.sync',
75 'ChromeSyncShellTest',
76 None),
79 InstallablePackage = collections.namedtuple('InstallablePackage', [
80 'name', 'apk', 'apk_package'])
82 INSTALLABLE_PACKAGES = dict((package.name, package) for package in (
83 [InstallablePackage(i.name, i.apk, i.apk_package)
84 for i in INSTRUMENTATION_TESTS.itervalues()] +
85 [InstallablePackage('ChromeDriverWebViewShell',
86 'ChromeDriverWebViewShell.apk',
87 'org.chromium.chromedriver_webview_shell')]))
89 VALID_TESTS = set([
90 'base_junit_tests',
91 'chromedriver',
92 'components_browsertests',
93 'gfx_unittests',
94 'gl_unittests',
95 'gpu',
96 'python_unittests',
97 'ui',
98 'unit',
99 'webkit',
100 'webkit_layout'
103 RunCmd = bb_utils.RunCmd
106 def _GetRevision(options):
107 """Get the SVN revision number.
109 Args:
110 options: options object.
112 Returns:
113 The revision number.
115 revision = options.build_properties.get('got_revision')
116 if not revision:
117 revision = options.build_properties.get('revision', 'testing')
118 return revision
121 def _RunTest(options, cmd, suite):
122 """Run test command with runtest.py.
124 Args:
125 options: options object.
126 cmd: the command to run.
127 suite: test name.
129 property_args = bb_utils.EncodeProperties(options)
130 args = [os.path.join(SLAVE_SCRIPTS_DIR, 'runtest.py')] + property_args
131 args += ['--test-platform', 'android']
132 if options.factory_properties.get('generate_gtest_json'):
133 args.append('--generate-json-file')
134 args += ['-o', 'gtest-results/%s' % suite,
135 '--annotate', 'gtest',
136 '--build-number', str(options.build_properties.get('buildnumber',
137 '')),
138 '--builder-name', options.build_properties.get('buildername', '')]
139 if options.target == 'Release':
140 args += ['--target', 'Release']
141 else:
142 args += ['--target', 'Debug']
143 if options.flakiness_server:
144 args += ['--flakiness-dashboard-server=%s' %
145 options.flakiness_server]
146 args += cmd
147 RunCmd(args, cwd=DIR_BUILD_ROOT)
150 def RunTestSuites(options, suites, suites_options=None):
151 """Manages an invocation of test_runner.py for gtests.
153 Args:
154 options: options object.
155 suites: List of suite names to run.
156 suites_options: Command line options dictionary for particular suites.
157 For example,
158 {'content_browsertests', ['--num_retries=1', '--release']}
159 will add the options only to content_browsertests.
162 if not suites_options:
163 suites_options = {}
165 args = ['--verbose']
166 if options.target == 'Release':
167 args.append('--release')
168 if options.asan:
169 args.append('--tool=asan')
170 if options.gtest_filter:
171 args.append('--gtest-filter=%s' % options.gtest_filter)
173 for suite in suites:
174 bb_annotations.PrintNamedStep(suite)
175 cmd = [suite] + args
176 cmd += suites_options.get(suite, [])
177 if suite == 'content_browsertests' or suite == 'components_browsertests':
178 cmd.append('--num_retries=1')
179 _RunTest(options, cmd, suite)
182 def RunJunitSuite(suite):
183 bb_annotations.PrintNamedStep(suite)
184 RunCmd(['build/android/test_runner.py', 'junit', '-s', suite])
187 def RunChromeDriverTests(options):
188 """Run all the steps for running chromedriver tests."""
189 bb_annotations.PrintNamedStep('chromedriver_annotation')
190 RunCmd(['chrome/test/chromedriver/run_buildbot_steps.py',
191 '--android-packages=%s,%s,%s' %
192 ('chrome_stable',
193 'chrome_beta',
194 'chromedriver_webview_shell'),
195 '--revision=%s' % _GetRevision(options),
196 '--update-log'])
199 def InstallApk(options, test, print_step=False):
200 """Install an apk to all phones.
202 Args:
203 options: options object
204 test: An I_TEST namedtuple
205 print_step: Print a buildbot step
207 if print_step:
208 bb_annotations.PrintNamedStep('install_%s' % test.name.lower())
210 args = ['--apk_package', test.apk_package]
211 if options.target == 'Release':
212 args.append('--release')
213 args.append(test.apk)
215 RunCmd(['build/android/adb_install_apk.py'] + args, halt_on_failure=True)
218 def RunInstrumentationSuite(options, test, flunk_on_failure=True,
219 python_only=False, official_build=False):
220 """Manages an invocation of test_runner.py for instrumentation tests.
222 Args:
223 options: options object
224 test: An I_TEST namedtuple
225 flunk_on_failure: Flunk the step if tests fail.
226 Python: Run only host driven Python tests.
227 official_build: Run official-build tests.
229 bb_annotations.PrintNamedStep('%s_instrumentation_tests' % test.name.lower())
231 if test.apk:
232 InstallApk(options, test)
233 args = ['--test-apk', test.test_apk, '--verbose']
234 if test.test_data:
235 args.extend(['--test_data', test.test_data])
236 if options.target == 'Release':
237 args.append('--release')
238 if options.asan:
239 args.append('--tool=asan')
240 if options.flakiness_server:
241 args.append('--flakiness-dashboard-server=%s' %
242 options.flakiness_server)
243 if options.coverage_bucket:
244 args.append('--coverage-dir=%s' % options.coverage_dir)
245 if test.isolate_file_path:
246 args.append('--isolate-file-path=%s' % test.isolate_file_path)
247 if test.host_driven_root:
248 args.append('--host-driven-root=%s' % test.host_driven_root)
249 if test.annotation:
250 args.extend(['-A', test.annotation])
251 if test.exclude_annotation:
252 args.extend(['-E', test.exclude_annotation])
253 if test.extra_flags:
254 args.extend(test.extra_flags)
255 if python_only:
256 args.append('-p')
257 if official_build:
258 # The option needs to be assigned 'True' as it does not have an action
259 # associated with it.
260 args.append('--official-build')
262 RunCmd(['build/android/test_runner.py', 'instrumentation'] + args,
263 flunk_on_failure=flunk_on_failure)
266 def RunWebkitLint():
267 """Lint WebKit's TestExpectation files."""
268 bb_annotations.PrintNamedStep('webkit_lint')
269 RunCmd([SrcPath(os.path.join(BLINK_SCRIPTS_DIR, 'lint-test-expectations'))])
272 def RunWebkitLayoutTests(options):
273 """Run layout tests on an actual device."""
274 bb_annotations.PrintNamedStep('webkit_tests')
275 cmd_args = [
276 '--no-show-results',
277 '--no-new-test-results',
278 '--full-results-html',
279 '--clobber-old-results',
280 '--exit-after-n-failures', '5000',
281 '--exit-after-n-crashes-or-timeouts', '100',
282 '--debug-rwt-logging',
283 '--results-directory', '../layout-test-results',
284 '--target', options.target,
285 '--builder-name', options.build_properties.get('buildername', ''),
286 '--build-number', str(options.build_properties.get('buildnumber', '')),
287 '--master-name', 'ChromiumWebkit', # TODO: Get this from the cfg.
288 '--build-name', options.build_properties.get('buildername', ''),
289 '--platform=android']
291 for flag in 'test_results_server', 'driver_name', 'additional_driver_flag':
292 if flag in options.factory_properties:
293 cmd_args.extend(['--%s' % flag.replace('_', '-'),
294 options.factory_properties.get(flag)])
296 for f in options.factory_properties.get('additional_expectations', []):
297 cmd_args.extend(
298 ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)])
300 # TODO(dpranke): Remove this block after
301 # https://codereview.chromium.org/12927002/ lands.
302 for f in options.factory_properties.get('additional_expectations_files', []):
303 cmd_args.extend(
304 ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)])
306 exit_code = RunCmd(
307 [SrcPath(os.path.join(BLINK_SCRIPTS_DIR, 'run-webkit-tests'))] + cmd_args)
308 if exit_code == 255: # test_run_results.UNEXPECTED_ERROR_EXIT_STATUS
309 bb_annotations.PrintMsg('?? (crashed or hung)')
310 elif exit_code == 254: # test_run_results.NO_DEVICES_EXIT_STATUS
311 bb_annotations.PrintMsg('?? (no devices found)')
312 elif exit_code == 253: # test_run_results.NO_TESTS_EXIT_STATUS
313 bb_annotations.PrintMsg('?? (no tests found)')
314 else:
315 full_results_path = os.path.join('..', 'layout-test-results',
316 'full_results.json')
317 if os.path.exists(full_results_path):
318 full_results = json.load(open(full_results_path))
319 unexpected_passes, unexpected_failures, unexpected_flakes = (
320 _ParseLayoutTestResults(full_results))
321 if unexpected_failures:
322 _PrintDashboardLink('failed', unexpected_failures.keys(),
323 max_tests=25)
324 elif unexpected_passes:
325 _PrintDashboardLink('unexpected passes', unexpected_passes.keys(),
326 max_tests=10)
327 if unexpected_flakes:
328 _PrintDashboardLink('unexpected flakes', unexpected_flakes.keys(),
329 max_tests=10)
331 if exit_code == 0 and (unexpected_passes or unexpected_flakes):
332 # If exit_code != 0, RunCmd() will have already printed an error.
333 bb_annotations.PrintWarning()
334 else:
335 bb_annotations.PrintError()
336 bb_annotations.PrintMsg('?? (results missing)')
338 if options.factory_properties.get('archive_webkit_results', False):
339 bb_annotations.PrintNamedStep('archive_webkit_results')
340 base = 'https://storage.googleapis.com/chromium-layout-test-archives'
341 builder_name = options.build_properties.get('buildername', '')
342 build_number = str(options.build_properties.get('buildnumber', ''))
343 results_link = '%s/%s/%s/layout-test-results/results.html' % (
344 base, EscapeBuilderName(builder_name), build_number)
345 bb_annotations.PrintLink('results', results_link)
346 bb_annotations.PrintLink('(zip)', '%s/%s/%s/layout-test-results.zip' % (
347 base, EscapeBuilderName(builder_name), build_number))
348 gs_bucket = 'gs://chromium-layout-test-archives'
349 RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'chromium',
350 'archive_layout_test_results.py'),
351 '--results-dir', '../../layout-test-results',
352 '--build-number', build_number,
353 '--builder-name', builder_name,
354 '--gs-bucket', gs_bucket],
355 cwd=DIR_BUILD_ROOT)
358 def _ParseLayoutTestResults(results):
359 """Extract the failures from the test run."""
360 # Cloned from third_party/WebKit/Tools/Scripts/print-json-test-results
361 tests = _ConvertTrieToFlatPaths(results['tests'])
362 failures = {}
363 flakes = {}
364 passes = {}
365 for (test, result) in tests.iteritems():
366 if result.get('is_unexpected'):
367 actual_results = result['actual'].split()
368 expected_results = result['expected'].split()
369 if len(actual_results) > 1:
370 # We report the first failure type back, even if the second
371 # was more severe.
372 if actual_results[1] in expected_results:
373 flakes[test] = actual_results[0]
374 else:
375 failures[test] = actual_results[0]
376 elif actual_results[0] == 'PASS':
377 passes[test] = result
378 else:
379 failures[test] = actual_results[0]
381 return (passes, failures, flakes)
384 def _ConvertTrieToFlatPaths(trie, prefix=None):
385 """Flatten the trie of failures into a list."""
386 # Cloned from third_party/WebKit/Tools/Scripts/print-json-test-results
387 result = {}
388 for name, data in trie.iteritems():
389 if prefix:
390 name = prefix + '/' + name
392 if len(data) and 'actual' not in data and 'expected' not in data:
393 result.update(_ConvertTrieToFlatPaths(data, name))
394 else:
395 result[name] = data
397 return result
400 def _PrintDashboardLink(link_text, tests, max_tests):
401 """Add a link to the flakiness dashboard in the step annotations."""
402 if len(tests) > max_tests:
403 test_list_text = ' '.join(tests[:max_tests]) + ' and more'
404 else:
405 test_list_text = ' '.join(tests)
407 dashboard_base = ('http://test-results.appspot.com'
408 '/dashboards/flakiness_dashboard.html#'
409 'master=ChromiumWebkit&tests=')
411 bb_annotations.PrintLink('%d %s: %s' %
412 (len(tests), link_text, test_list_text),
413 dashboard_base + ','.join(tests))
416 def EscapeBuilderName(builder_name):
417 return re.sub('[ ()]', '_', builder_name)
420 def SpawnLogcatMonitor():
421 shutil.rmtree(LOGCAT_DIR, ignore_errors=True)
422 bb_utils.SpawnCmd([
423 os.path.join(CHROME_SRC_DIR, 'build', 'android', 'adb_logcat_monitor.py'),
424 LOGCAT_DIR])
426 # Wait for logcat_monitor to pull existing logcat
427 RunCmd(['sleep', '5'])
430 def ProvisionDevices(options):
431 bb_annotations.PrintNamedStep('provision_devices')
433 if not bb_utils.TESTING:
434 # Restart adb to work around bugs, sleep to wait for usb discovery.
435 device_utils.RestartServer()
436 RunCmd(['sleep', '1'])
437 provision_cmd = ['build/android/provision_devices.py', '-t', options.target]
438 if options.auto_reconnect:
439 provision_cmd.append('--auto-reconnect')
440 if options.skip_wipe:
441 provision_cmd.append('--skip-wipe')
442 if options.disable_location:
443 provision_cmd.append('--disable-location')
444 RunCmd(provision_cmd, halt_on_failure=True)
447 def DeviceStatusCheck(options):
448 bb_annotations.PrintNamedStep('device_status_check')
449 cmd = ['build/android/buildbot/bb_device_status_check.py']
450 if options.restart_usb:
451 cmd.append('--restart-usb')
452 RunCmd(cmd, halt_on_failure=True)
455 def GetDeviceSetupStepCmds():
456 return [
457 ('device_status_check', DeviceStatusCheck),
458 ('provision_devices', ProvisionDevices),
462 def RunUnitTests(options):
463 suites = gtest_config.STABLE_TEST_SUITES
464 if options.asan:
465 suites = [s for s in suites
466 if s not in gtest_config.ASAN_EXCLUDED_TEST_SUITES]
467 RunTestSuites(options, suites)
470 def RunInstrumentationTests(options):
471 for test in INSTRUMENTATION_TESTS.itervalues():
472 RunInstrumentationSuite(options, test)
475 def RunWebkitTests(options):
476 RunTestSuites(options, ['webkit_unit_tests', 'blink_heap_unittests'])
477 RunWebkitLint()
480 def RunGPUTests(options):
481 revision = _GetRevision(options)
482 builder_name = options.build_properties.get('buildername', 'noname')
484 bb_annotations.PrintNamedStep('pixel_tests')
485 RunCmd(['content/test/gpu/run_gpu_test.py',
486 'pixel', '-v',
487 '--browser',
488 'android-content-shell',
489 '--build-revision',
490 str(revision),
491 '--upload-refimg-to-cloud-storage',
492 '--refimg-cloud-storage-bucket',
493 'chromium-gpu-archive/reference-images',
494 '--os-type',
495 'android',
496 '--test-machine-name',
497 EscapeBuilderName(builder_name)])
499 bb_annotations.PrintNamedStep('webgl_conformance_tests')
500 RunCmd(['content/test/gpu/run_gpu_test.py', '-v',
501 '--browser=android-content-shell', 'webgl_conformance',
502 '--webgl-conformance-version=1.0.1'])
504 bb_annotations.PrintNamedStep('android_webview_webgl_conformance_tests')
505 RunCmd(['content/test/gpu/run_gpu_test.py', '-v',
506 '--browser=android-webview-shell', 'webgl_conformance',
507 '--webgl-conformance-version=1.0.1'])
509 bb_annotations.PrintNamedStep('gpu_rasterization_tests')
510 RunCmd(['content/test/gpu/run_gpu_test.py',
511 'gpu_rasterization', '-v',
512 '--browser',
513 'android-content-shell',
514 '--build-revision',
515 str(revision),
516 '--test-machine-name',
517 EscapeBuilderName(builder_name)])
520 def RunPythonUnitTests(_options):
521 for suite in constants.PYTHON_UNIT_TEST_SUITES:
522 bb_annotations.PrintNamedStep(suite)
523 RunCmd(['build/android/test_runner.py', 'python', '-s', suite])
526 def GetTestStepCmds():
527 return [
528 ('base_junit_tests',
529 lambda _options: RunJunitSuite('base_junit_tests')),
530 ('chromedriver', RunChromeDriverTests),
531 ('components_browsertests',
532 lambda options: RunTestSuites(options, ['components_browsertests'])),
533 ('gfx_unittests',
534 lambda options: RunTestSuites(options, ['gfx_unittests'])),
535 ('gl_unittests',
536 lambda options: RunTestSuites(options, ['gl_unittests'])),
537 ('gpu', RunGPUTests),
538 ('python_unittests', RunPythonUnitTests),
539 ('ui', RunInstrumentationTests),
540 ('unit', RunUnitTests),
541 ('webkit', RunWebkitTests),
542 ('webkit_layout', RunWebkitLayoutTests),
546 def MakeGSPath(options, gs_base_dir):
547 revision = _GetRevision(options)
548 bot_id = options.build_properties.get('buildername', 'testing')
549 randhash = hashlib.sha1(str(random.random())).hexdigest()
550 gs_path = '%s/%s/%s/%s' % (gs_base_dir, bot_id, revision, randhash)
551 # remove double slashes, happens with blank revisions and confuses gsutil
552 gs_path = re.sub('/+', '/', gs_path)
553 return gs_path
555 def UploadHTML(options, gs_base_dir, dir_to_upload, link_text,
556 link_rel_path='index.html', gs_url=GS_URL):
557 """Uploads directory at |dir_to_upload| to Google Storage and output a link.
559 Args:
560 options: Command line options.
561 gs_base_dir: The Google Storage base directory (e.g.
562 'chromium-code-coverage/java')
563 dir_to_upload: Absolute path to the directory to be uploaded.
564 link_text: Link text to be displayed on the step.
565 link_rel_path: Link path relative to |dir_to_upload|.
566 gs_url: Google storage URL.
568 gs_path = MakeGSPath(options, gs_base_dir)
569 RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-R', dir_to_upload, 'gs://%s' % gs_path])
570 bb_annotations.PrintLink(link_text,
571 '%s/%s/%s' % (gs_url, gs_path, link_rel_path))
574 def GenerateJavaCoverageReport(options):
575 """Generates an HTML coverage report using EMMA and uploads it."""
576 bb_annotations.PrintNamedStep('java_coverage_report')
578 coverage_html = os.path.join(options.coverage_dir, 'coverage_html')
579 RunCmd(['build/android/generate_emma_html.py',
580 '--coverage-dir', options.coverage_dir,
581 '--metadata-dir', os.path.join(CHROME_OUT_DIR, options.target),
582 '--cleanup',
583 '--output', os.path.join(coverage_html, 'index.html')])
584 return coverage_html
587 def LogcatDump(options):
588 # Print logcat, kill logcat monitor
589 bb_annotations.PrintNamedStep('logcat_dump')
590 logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log.txt')
591 RunCmd([SrcPath('build', 'android', 'adb_logcat_printer.py'),
592 '--output-path', logcat_file, LOGCAT_DIR])
593 gs_path = MakeGSPath(options, 'chromium-android/logcat_dumps')
594 RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-z', 'txt', logcat_file,
595 'gs://%s' % gs_path])
596 bb_annotations.PrintLink('logcat dump', '%s/%s' % (GS_AUTH_URL, gs_path))
599 def RunStackToolSteps(options):
600 """Run stack tool steps.
602 Stack tool is run for logcat dump, optionally for ASAN.
604 bb_annotations.PrintNamedStep('Run stack tool with logcat dump')
605 logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log.txt')
606 RunCmd([os.path.join(CHROME_SRC_DIR, 'third_party', 'android_platform',
607 'development', 'scripts', 'stack'),
608 '--more-info', logcat_file])
609 if options.asan_symbolize:
610 bb_annotations.PrintNamedStep('Run stack tool for ASAN')
611 RunCmd([
612 os.path.join(CHROME_SRC_DIR, 'build', 'android', 'asan_symbolize.py'),
613 '-l', logcat_file])
616 def GenerateTestReport(options):
617 bb_annotations.PrintNamedStep('test_report')
618 for report in glob.glob(
619 os.path.join(CHROME_OUT_DIR, options.target, 'test_logs', '*.log')):
620 RunCmd(['cat', report])
621 os.remove(report)
624 def MainTestWrapper(options):
625 try:
626 # Spawn logcat monitor
627 SpawnLogcatMonitor()
629 # Run all device setup steps
630 for _, cmd in GetDeviceSetupStepCmds():
631 cmd(options)
633 if options.install:
634 for i in options.install:
635 install_obj = INSTALLABLE_PACKAGES[i]
636 InstallApk(options, install_obj, print_step=True)
638 if options.test_filter:
639 bb_utils.RunSteps(options.test_filter, GetTestStepCmds(), options)
641 if options.coverage_bucket:
642 coverage_html = GenerateJavaCoverageReport(options)
643 UploadHTML(options, '%s/java' % options.coverage_bucket, coverage_html,
644 'Coverage Report')
645 shutil.rmtree(coverage_html, ignore_errors=True)
647 if options.experimental:
648 RunTestSuites(options, gtest_config.EXPERIMENTAL_TEST_SUITES)
650 finally:
651 # Run all post test steps
652 LogcatDump(options)
653 if not options.disable_stack_tool:
654 RunStackToolSteps(options)
655 GenerateTestReport(options)
656 # KillHostHeartbeat() has logic to check if heartbeat process is running,
657 # and kills only if it finds the process is running on the host.
658 provision_devices.KillHostHeartbeat()
659 if options.cleanup:
660 shutil.rmtree(os.path.join(CHROME_OUT_DIR, options.target),
661 ignore_errors=True)
664 def GetDeviceStepsOptParser():
665 parser = bb_utils.GetParser()
666 parser.add_option('--experimental', action='store_true',
667 help='Run experiemental tests')
668 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[],
669 action='append',
670 help=('Run a test suite. Test suites: "%s"' %
671 '", "'.join(VALID_TESTS)))
672 parser.add_option('--gtest-filter',
673 help='Filter for running a subset of tests of a gtest test')
674 parser.add_option('--asan', action='store_true', help='Run tests with asan.')
675 parser.add_option('--install', metavar='<apk name>', action="append",
676 help='Install an apk by name')
677 parser.add_option('--no-reboot', action='store_true',
678 help='Do not reboot devices during provisioning.')
679 parser.add_option('--coverage-bucket',
680 help=('Bucket name to store coverage results. Coverage is '
681 'only run if this is set.'))
682 parser.add_option('--restart-usb', action='store_true',
683 help='Restart usb ports before device status check.')
684 parser.add_option(
685 '--flakiness-server',
686 help=('The flakiness dashboard server to which the results should be '
687 'uploaded.'))
688 parser.add_option(
689 '--auto-reconnect', action='store_true',
690 help='Push script to device which restarts adbd on disconnections.')
691 parser.add_option('--skip-wipe', action='store_true',
692 help='Do not wipe devices during provisioning.')
693 parser.add_option('--disable-location', action='store_true',
694 help='Disable location settings.')
695 parser.add_option(
696 '--logcat-dump-output',
697 help='The logcat dump output will be "tee"-ed into this file')
698 # During processing perf bisects, a seperate working directory created under
699 # which builds are produced. Therefore we should look for relevent output
700 # file under this directory.(/b/build/slave/<slave_name>/build/bisect/src/out)
701 parser.add_option(
702 '--chrome-output-dir',
703 help='Chrome output directory to be used while bisecting.')
705 parser.add_option('--disable-stack-tool', action='store_true',
706 help='Do not run stack tool.')
707 parser.add_option('--asan-symbolize', action='store_true',
708 help='Run stack tool for ASAN')
709 parser.add_option('--cleanup', action='store_true',
710 help='Delete out/<target> directory at the end of the run.')
711 return parser
714 def main(argv):
715 parser = GetDeviceStepsOptParser()
716 options, args = parser.parse_args(argv[1:])
718 if args:
719 return sys.exit('Unused args %s' % args)
721 unknown_tests = set(options.test_filter) - VALID_TESTS
722 if unknown_tests:
723 return sys.exit('Unknown tests %s' % list(unknown_tests))
725 setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
727 # pylint: disable=global-statement
728 if options.chrome_output_dir:
729 global CHROME_OUT_DIR
730 global LOGCAT_DIR
731 CHROME_OUT_DIR = options.chrome_output_dir
732 LOGCAT_DIR = os.path.join(CHROME_OUT_DIR, 'logcat')
734 if options.coverage_bucket:
735 setattr(options, 'coverage_dir',
736 os.path.join(CHROME_OUT_DIR, options.target, 'coverage'))
738 MainTestWrapper(options)
741 if __name__ == '__main__':
742 sys.exit(main(sys.argv))