Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: build/android/buildbot/bb_device_steps.py

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

Powered by Google App Engine
This is Rietveld 408576698