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

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

Issue 20210002: [Android] Sets up a coverage system for java using EMMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleans up temporary changes, fixes a few more small things Created 7 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
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 import time
12 13
13 import bb_utils 14 import bb_utils
14 import bb_annotations 15 import bb_annotations
15 16
16 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 17 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
17 import provision_devices 18 import provision_devices
18 from pylib import android_commands 19 from pylib import android_commands
19 from pylib import constants 20 from pylib import constants
20 from pylib.gtest import gtest_config 21 from pylib.gtest import gtest_config
21 22
22 sys.path.append(os.path.join( 23 sys.path.append(os.path.join(
23 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) 24 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner'))
24 import errors 25 import errors
25 26
26 27
28 SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave')
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.
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=True,
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'),
54 I('ChromiumTestShell', 58 I('ChromiumTestShell',
55 'ChromiumTestShell.apk', 59 'ChromiumTestShell.apk',
56 'org.chromium.chrome.testshell', 60 'org.chromium.chrome.testshell',
57 'ChromiumTestShellTest', 61 'ChromiumTestShellTest',
58 'chrome:chrome/test/data/android/device_files', 62 'chrome:chrome/test/data/android/device_files',
59 constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR), 63 host_driven_root=constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR),
60 I('AndroidWebView', 64 I('AndroidWebView',
61 'AndroidWebView.apk', 65 'AndroidWebView.apk',
62 'org.chromium.android_webview.shell', 66 'org.chromium.android_webview.shell',
63 'AndroidWebViewTest', 67 'AndroidWebViewTest',
64 'webview:android_webview/test/data/device_files'), 68 'webview:android_webview/test/data/device_files'),
65 ]) 69 ])
66 70
67 VALID_TESTS = set(['chromedriver', 'ui', 'unit', 'webkit', 'webkit_layout', 71 VALID_TESTS = set(['chromedriver', 'ui', 'unit', 'webkit', 'webkit_layout',
68 'webrtc']) 72 'webrtc'])
69 73
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 InstallApk(options, test) 162 InstallApk(options, test)
159 args = ['--test-apk', test.test_apk, '--test_data', test.test_data, 163 args = ['--test-apk', test.test_apk, '--test_data', test.test_data,
160 '--verbose'] 164 '--verbose']
161 if options.target == 'Release': 165 if options.target == 'Release':
162 args.append('--release') 166 args.append('--release')
163 if options.asan: 167 if options.asan:
164 args.append('--tool=asan') 168 args.append('--tool=asan')
165 if options.flakiness_server: 169 if options.flakiness_server:
166 args.append('--flakiness-dashboard-server=%s' % 170 args.append('--flakiness-dashboard-server=%s' %
167 options.flakiness_server) 171 options.flakiness_server)
172 if options.coverage_bucket and test.coverage:
173 args.append('--coverage-dir=%s' % constants.GetCoverageDir(options.target))
168 if test.host_driven_root: 174 if test.host_driven_root:
169 args.append('--host-driven-root=%s' % test.host_driven_root) 175 args.append('--host-driven-root=%s' % test.host_driven_root)
170 if test.annotation: 176 if test.annotation:
171 args.extend(['-A', test.annotation]) 177 args.extend(['-A', test.annotation])
172 if test.exclude_annotation: 178 if test.exclude_annotation:
173 args.extend(['-E', test.exclude_annotation]) 179 args.extend(['-E', test.exclude_annotation])
174 if test.extra_flags: 180 if test.extra_flags:
175 args.extend(test.extra_flags) 181 args.extend(test.extra_flags)
176 if python_only: 182 if python_only:
177 args.append('-p') 183 args.append('-p')
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ('provision_devices', ProvisionDevices), 270 ('provision_devices', ProvisionDevices),
265 ('device_status_check', DeviceStatusCheck) 271 ('device_status_check', DeviceStatusCheck)
266 ] 272 ]
267 273
268 274
269 def RunUnitTests(options): 275 def RunUnitTests(options):
270 RunTestSuites(options, gtest_config.STABLE_TEST_SUITES) 276 RunTestSuites(options, gtest_config.STABLE_TEST_SUITES)
271 277
272 278
273 def RunInstrumentationTests(options): 279 def RunInstrumentationTests(options):
280 coverage_dir = constants.GetCoverageDir(options.target)
281 if options.coverage_bucket:
282 shutil.rmtree(coverage_dir, ignore_errors=True)
283 os.mkdir(coverage_dir)
284
274 for test in INSTRUMENTATION_TESTS.itervalues(): 285 for test in INSTRUMENTATION_TESTS.itervalues():
275 RunInstrumentationSuite(options, test) 286 RunInstrumentationSuite(options, test)
276 287
288 if options.coverage_bucket:
289 bb_annotations.PrintNamedStep('coverage_report')
290
291 RunCmd(['build/android/generate_emma_html.py',
292 '--coverage-dir', coverage_dir,
293 '--metadata-dir', os.path.join(constants.DIR_SOURCE_ROOT,
294 'out', options.target),
295 '--output', os.path.join(coverage_dir, 'coverage.html')])
296
297 revision_file = os.path.join(CHROME_SRC, 'out', options.target,
298 REVISION_FILENAME)
299 # If the revision file doesn't exist, we're just testing the bot
300 if os.path.exists(revision_file):
301 with open(revision_file) as f:
302 revision = f.read()
303 else:
304 revision = 'testing'
305 bot_id = os.environ.get('BUILDBOT_ID')
306 if not bot_id:
307 print 'BUILDBOT_ID requried in the environment to upload coverage data.'
308 return
309
310 timehash = hash(time.time())
311
312 boto_config = os.path.join(bb_utils.BB_BUILD_DIR, 'site_config', '.boto')
313 os.environ['AWS_CREDENTIAL_FILE'] = boto_config
314 os.environ['BOTO_CONFIG'] = boto_config
315 RunCmd([os.path.join(bb_utils.BB_BUILD_DIR, 'third_party',
316 'gsutil', 'gsutil'), 'cp', '-R',
317 coverage_dir, 'gs://%s/%s/%s/%s' %
318 (options.coverage_bucket, bot_id, revision, timehash)])
319 bb_annotations.PrintLink(
320 'Coverage report',
321 'https://storage.googleapis.com/%s/%s/%s/%s/coverage.html'
322 % (options.coverage_bucket, bot_id, revision, timehash))
323
277 324
278 def RunWebkitTests(options): 325 def RunWebkitTests(options):
279 RunTestSuites(options, ['webkit_unit_tests']) 326 RunTestSuites(options, ['webkit_unit_tests'])
280 RunWebkitLint(options.target) 327 RunWebkitLint(options.target)
281 328
282 329
283 def RunWebRTCTests(options): 330 def RunWebRTCTests(options):
284 RunTestSuites(options, gtest_config.WEBRTC_TEST_SUITES) 331 RunTestSuites(options, gtest_config.WEBRTC_TEST_SUITES)
285 332
286 333
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 help='Run experiemental tests') 395 help='Run experiemental tests')
349 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[], 396 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[],
350 action='append', 397 action='append',
351 help=('Run a test suite. Test suites: "%s"' % 398 help=('Run a test suite. Test suites: "%s"' %
352 '", "'.join(VALID_TESTS))) 399 '", "'.join(VALID_TESTS)))
353 parser.add_option('--asan', action='store_true', help='Run tests with asan.') 400 parser.add_option('--asan', action='store_true', help='Run tests with asan.')
354 parser.add_option('--install', metavar='<apk name>', 401 parser.add_option('--install', metavar='<apk name>',
355 help='Install an apk by name') 402 help='Install an apk by name')
356 parser.add_option('--reboot', action='store_true', 403 parser.add_option('--reboot', action='store_true',
357 help='Reboot devices before running tests') 404 help='Reboot devices before running tests')
405 parser.add_option('--coverage-bucket',
406 help=('Bucket name to store coverage results. Coverage is '
407 'only run if this is set.'))
358 parser.add_option( 408 parser.add_option(
359 '--flakiness-server', 409 '--flakiness-server',
360 help='The flakiness dashboard server to which the results should be ' 410 help='The flakiness dashboard server to which the results should be '
361 'uploaded.') 411 'uploaded.')
362 parser.add_option( 412 parser.add_option(
363 '--auto-reconnect', action='store_true', 413 '--auto-reconnect', action='store_true',
364 help='Push script to device which restarts adbd on disconnections.') 414 help='Push script to device which restarts adbd on disconnections.')
365 parser.add_option( 415 parser.add_option(
366 '--logcat-dump-output', 416 '--logcat-dump-output',
367 help='The logcat dump output will be "tee"-ed into this file') 417 help='The logcat dump output will be "tee"-ed into this file')
(...skipping 12 matching lines...) Expand all
380 if unknown_tests: 430 if unknown_tests:
381 return sys.exit('Unknown tests %s' % list(unknown_tests)) 431 return sys.exit('Unknown tests %s' % list(unknown_tests))
382 432
383 setattr(options, 'target', options.factory_properties.get('target', 'Debug')) 433 setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
384 434
385 MainTestWrapper(options) 435 MainTestWrapper(options)
386 436
387 437
388 if __name__ == '__main__': 438 if __name__ == '__main__':
389 sys.exit(main(sys.argv)) 439 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698