Index: build/android/buildbot/bb_device_steps.py |
diff --git a/build/android/buildbot/bb_device_steps.py b/build/android/buildbot/bb_device_steps.py |
index f020281bb7d751434151ee4f9f9d4c5ddfd4affc..df86bcc0582f318a169a203e32964f18c0e1871a 100755 |
--- a/build/android/buildbot/bb_device_steps.py |
+++ b/build/android/buildbot/bb_device_steps.py |
@@ -9,6 +9,7 @@ import multiprocessing |
import os |
import shutil |
import sys |
+import time |
import bb_utils |
import bb_annotations |
@@ -24,8 +25,10 @@ sys.path.append(os.path.join( |
import errors |
+SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave') |
CHROME_SRC = constants.DIR_SOURCE_ROOT |
LOGCAT_DIR = os.path.join(CHROME_SRC, 'out', 'logcat') |
+REVISION_FILENAME = 'FULL_BUILD_REVISION' |
# Describes an instrumation test suite: |
# test: Name of test we're running. |
@@ -37,13 +40,14 @@ LOGCAT_DIR = os.path.join(CHROME_SRC, 'out', 'logcat') |
# annotation: Annotation of the tests to include. |
# exclude_annotation: The annotation of the tests to exclude. |
I_TEST = collections.namedtuple('InstrumentationTest', [ |
- 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'host_driven_root', |
- 'annotation', 'exclude_annotation', 'extra_flags']) |
+ 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'coverage', |
+ 'host_driven_root', 'annotation', 'exclude_annotation', 'extra_flags']) |
-def I(name, apk, apk_package, test_apk, test_data, host_driven_root=None, |
- annotation=None, exclude_annotation=None, extra_flags=None): |
- return I_TEST(name, apk, apk_package, test_apk, test_data, host_driven_root, |
- annotation, exclude_annotation, extra_flags) |
+def I(name, apk, apk_package, test_apk, test_data, coverage=True, |
+ host_driven_root=None, annotation=None, exclude_annotation=None, |
+ extra_flags=None): |
+ return I_TEST(name, apk, apk_package, test_apk, test_data, coverage, |
+ host_driven_root, annotation, exclude_annotation, extra_flags) |
INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ |
I('ContentShell', |
@@ -56,7 +60,7 @@ INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ |
'org.chromium.chrome.testshell', |
'ChromiumTestShellTest', |
'chrome:chrome/test/data/android/device_files', |
- constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR), |
+ host_driven_root=constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR), |
I('AndroidWebView', |
'AndroidWebView.apk', |
'org.chromium.android_webview.shell', |
@@ -165,6 +169,8 @@ def RunInstrumentationSuite(options, test, flunk_on_failure=True, |
if options.flakiness_server: |
args.append('--flakiness-dashboard-server=%s' % |
options.flakiness_server) |
+ if options.coverage_bucket and test.coverage: |
+ args.append('--coverage-dir=%s' % constants.GetCoverageDir(options.target)) |
if test.host_driven_root: |
args.append('--host-driven-root=%s' % test.host_driven_root) |
if test.annotation: |
@@ -271,9 +277,50 @@ def RunUnitTests(options): |
def RunInstrumentationTests(options): |
+ coverage_dir = constants.GetCoverageDir(options.target) |
+ if options.coverage_bucket: |
+ shutil.rmtree(coverage_dir, ignore_errors=True) |
+ os.mkdir(coverage_dir) |
+ |
for test in INSTRUMENTATION_TESTS.itervalues(): |
RunInstrumentationSuite(options, test) |
+ if options.coverage_bucket: |
+ bb_annotations.PrintNamedStep('coverage_report') |
+ |
+ RunCmd(['build/android/generate_emma_html.py', |
+ '--coverage-dir', coverage_dir, |
+ '--metadata-dir', os.path.join(constants.DIR_SOURCE_ROOT, |
+ 'out', options.target), |
+ '--output', os.path.join(coverage_dir, 'coverage.html')]) |
+ |
+ revision_file = os.path.join(CHROME_SRC, 'out', options.target, |
+ REVISION_FILENAME) |
+ # If the revision file doesn't exist, we're just testing the bot |
+ if os.path.exists(revision_file): |
+ with open(revision_file) as f: |
+ revision = f.read() |
+ else: |
+ revision = 'testing' |
+ bot_id = os.environ.get('BUILDBOT_ID') |
+ if not bot_id: |
+ print 'BUILDBOT_ID requried in the environment to upload coverage data.' |
+ return |
+ |
+ timehash = hash(time.time()) |
+ |
+ boto_config = os.path.join(bb_utils.BB_BUILD_DIR, 'site_config', '.boto') |
+ os.environ['AWS_CREDENTIAL_FILE'] = boto_config |
+ os.environ['BOTO_CONFIG'] = boto_config |
+ RunCmd([os.path.join(bb_utils.BB_BUILD_DIR, 'third_party', |
+ 'gsutil', 'gsutil'), 'cp', '-R', |
+ coverage_dir, 'gs://%s/%s/%s/%s' % |
+ (options.coverage_bucket, bot_id, revision, timehash)]) |
+ bb_annotations.PrintLink( |
+ 'Coverage report', |
+ 'https://storage.googleapis.com/%s/%s/%s/%s/coverage.html' |
+ % (options.coverage_bucket, bot_id, revision, timehash)) |
+ |
def RunWebkitTests(options): |
RunTestSuites(options, ['webkit_unit_tests']) |
@@ -355,6 +402,9 @@ def GetDeviceStepsOptParser(): |
help='Install an apk by name') |
parser.add_option('--reboot', action='store_true', |
help='Reboot devices before running tests') |
+ parser.add_option('--coverage-bucket', |
+ help=('Bucket name to store coverage results. Coverage is ' |
+ 'only run if this is set.')) |
parser.add_option( |
'--flakiness-server', |
help='The flakiness dashboard server to which the results should be ' |