summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorrnephew <rnephew@chromium.org>2015-01-07 11:34:53 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-07 19:35:41 +0000
commitb74dd0630e0b7b24bc83eb27c9945e1c819c3550 (patch)
tree50c6bdeb075a97fc6528f7e1f39919bbd828bd1f /build
parent6f89af56a0696b30f86941a9e3752a278a37f2e1 (diff)
downloadchromium_src-b74dd0630e0b7b24bc83eb27c9945e1c819c3550.zip
chromium_src-b74dd0630e0b7b24bc83eb27c9945e1c819c3550.tar.gz
chromium_src-b74dd0630e0b7b24bc83eb27c9945e1c819c3550.tar.bz2
Clean up logging and add device randomization.
If no device_name is picked and os_version is, will pick random device with given os; and vice versa. If neither is picked, both are randomly picked. Clean up logging. Disable appurify/requests logging if verbosity is less than 2. BUG=428729 Review URL: https://codereview.chromium.org/814653003 Cr-Commit-Position: refs/heads/master@{#310337}
Diffstat (limited to 'build')
-rw-r--r--build/android/pylib/remote/device/appurify_sanitized.py13
-rw-r--r--build/android/pylib/remote/device/remote_device_environment.py42
-rw-r--r--build/android/pylib/remote/device/remote_device_helper.py1
-rw-r--r--build/android/pylib/remote/device/remote_device_test_run.py57
-rwxr-xr-xbuild/android/test_runner.py4
5 files changed, 84 insertions, 33 deletions
diff --git a/build/android/pylib/remote/device/appurify_sanitized.py b/build/android/pylib/remote/device/appurify_sanitized.py
index 3367610..9f6ab40 100644
--- a/build/android/pylib/remote/device/appurify_sanitized.py
+++ b/build/android/pylib/remote/device/appurify_sanitized.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import contextlib
import logging
import os
import sys
@@ -25,3 +26,15 @@ while new_handler:
api = appurify.api
utils = appurify.utils
+
+# This is not thread safe. If multiple threads are ever supported with appurify
+# this may cause logging messages to go missing.
+@contextlib.contextmanager
+def SanitizeLogging(verbose_count, level):
+ if verbose_count < 2:
+ logging.disable(level)
+ yield True
+ logging.disable(logging.NOTSET)
+ else:
+ yield False
+
diff --git a/build/android/pylib/remote/device/remote_device_environment.py b/build/android/pylib/remote/device/remote_device_environment.py
index eff4e90..87ff73d 100644
--- a/build/android/pylib/remote/device/remote_device_environment.py
+++ b/build/android/pylib/remote/device/remote_device_environment.py
@@ -6,6 +6,7 @@
import logging
import os
+import random
import sys
from pylib import constants
@@ -60,6 +61,8 @@ class RemoteDeviceEnvironment(environment.Environment):
self._runner_package = args.runner_package
self._runner_type = args.runner_type
self._device = ''
+ self._verbose_count = args.verbose_count
+
if not args.trigger and not args.collect:
self._trigger = True
self._collect = True
@@ -96,8 +99,10 @@ class RemoteDeviceEnvironment(environment.Environment):
def _GetAccessToken(self):
"""Generates access token for remote device service."""
logging.info('Generating remote service access token')
- access_token_results = appurify_sanitized.api.access_token_generate(
- self._api_key, self._api_secret)
+ with appurify_sanitized.SanitizeLogging(self._verbose_count,
+ logging.WARNING):
+ access_token_results = appurify_sanitized.api.access_token_generate(
+ self._api_key, self._api_secret)
remote_device_helper.TestHttpResponse(access_token_results,
'Unable to generate access token.')
self._access_token = access_token_results.json()['response']['access_token']
@@ -105,22 +110,34 @@ class RemoteDeviceEnvironment(environment.Environment):
def _RevokeAccessToken(self):
"""Destroys access token for remote device service."""
logging.info('Revoking remote service access token')
- revoke_token_results = appurify_sanitized.api.access_token_revoke(
- self._access_token)
+ with appurify_sanitized.SanitizeLogging(self._verbose_count,
+ logging.WARNING):
+ revoke_token_results = appurify_sanitized.api.access_token_revoke(
+ self._access_token)
remote_device_helper.TestHttpResponse(revoke_token_results,
'Unable to revoke access token.')
def _SelectDevice(self):
"""Select which device to use."""
- logging.info('Finding %s with %s to run tests on.' %
- (self._remote_device, self._remote_device_os))
- dev_list_res = appurify_sanitized.api.devices_list(self._access_token)
+ logging.info('Finding device to run tests on.')
+ with appurify_sanitized.SanitizeLogging(self._verbose_count,
+ logging.WARNING):
+ dev_list_res = appurify_sanitized.api.devices_list(self._access_token)
remote_device_helper.TestHttpResponse(dev_list_res,
'Unable to generate access token.')
device_list = dev_list_res.json()['response']
+ random.shuffle(device_list)
for device in device_list:
- if (device['name'] == self._remote_device
- and device['os_version'] == self._remote_device_os):
+ if device['os_name'] != 'Android':
+ continue
+ if self._remote_device and device['name'] != self._remote_device:
+ continue
+ if (self._remote_device_os
+ and device['os_version'] != self._remote_device_os):
+ continue
+ if device['available_devices_count'] > 0:
+ logging.info('Found device: %s %s',
+ device['name'], device['os_version'])
return device['device_type_id']
self._NoDeviceFound(device_list)
@@ -139,8 +156,7 @@ class RemoteDeviceEnvironment(environment.Environment):
def _NoDeviceFound(self, device_list):
self._PrintAvailableDevices(device_list)
- raise remote_device_helper.RemoteDeviceError('No device found: %s %s' %
- (self._remote_device, self._remote_device_os))
+ raise remote_device_helper.RemoteDeviceError('No device found.')
@property
def device(self):
@@ -169,3 +185,7 @@ class RemoteDeviceEnvironment(environment.Environment):
@property
def collect(self):
return self._collect
+
+ @property
+ def verbose_count(self):
+ return self._verbose_count
diff --git a/build/android/pylib/remote/device/remote_device_helper.py b/build/android/pylib/remote/device/remote_device_helper.py
index a4cd4887..71603c3 100644
--- a/build/android/pylib/remote/device/remote_device_helper.py
+++ b/build/android/pylib/remote/device/remote_device_helper.py
@@ -4,7 +4,6 @@
"""Common functions and Exceptions for remote_device_*"""
-
class RemoteDeviceError(Exception):
"""Exception to throw when problems occur with remote device service."""
pass
diff --git a/build/android/pylib/remote/device/remote_device_test_run.py b/build/android/pylib/remote/device/remote_device_test_run.py
index dfa22d5..2144e24 100644
--- a/build/android/pylib/remote/device/remote_device_test_run.py
+++ b/build/android/pylib/remote/device/remote_device_test_run.py
@@ -37,13 +37,16 @@ class RemoteDeviceTestRun(test_run.TestRun):
self._test_id = ''
self._results = ''
self._test_run_id = ''
+ self._current_status = ''
#override
def RunTests(self):
"""Run the test."""
if self._env.trigger:
- test_start_res = appurify_sanitized.api.tests_run(
- self._env.token, self._env.device, self._app_id, self._test_id)
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
+ logging.WARNING):
+ test_start_res = appurify_sanitized.api.tests_run(
+ self._env.token, self._env.device, self._app_id, self._test_id)
remote_device_helper.TestHttpResponse(
test_start_res, 'Unable to run test.')
self._test_run_id = test_start_res.json()['response']['test_run_id']
@@ -68,10 +71,12 @@ class RemoteDeviceTestRun(test_run.TestRun):
#override
def TearDown(self):
"""Tear down the test run."""
- if (self._GetTestStatus(self._test_run_id) != self.COMPLETE
- and self._env.collect):
- test_abort_res = appurify_sanitized.api.tests_abort(
- self._env.token, self._test_run_id, reason='Test runner exiting.')
+ if (self._env.collect
+ and self._GetTestStatus(self._test_run_id) != self.COMPLETE):
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
+ logging.WARNING):
+ test_abort_res = appurify_sanitized.api.tests_abort(
+ self._env.token, self._test_run_id, reason='Test runner exiting.')
remote_device_helper.TestHttpResponse(test_abort_res,
'Unable to abort test.')
@@ -103,7 +108,9 @@ class RemoteDeviceTestRun(test_run.TestRun):
Args:
test_name: Test to find the ID of.
"""
- test_list_res = appurify_sanitized.api.tests_list(self._env.token)
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
+ logging.WARNING):
+ test_list_res = appurify_sanitized.api.tests_list(self._env.token)
remote_device_helper.TestHttpResponse(test_list_res,
'Unable to get tests list.')
for test in test_list_res.json()['response']:
@@ -122,8 +129,10 @@ class RemoteDeviceTestRun(test_run.TestRun):
logging.info('Downloading results to %s.' % results_path)
if not os.path.exists(os.path.basename(results_path)):
os.makedirs(os.path.basename(results_path))
- appurify_sanitized.utils.wget(self._results['results']['url'],
- results_path)
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
+ logging.WARNING):
+ appurify_sanitized.utils.wget(self._results['results']['url'],
+ results_path)
def _GetTestStatus(self, test_run_id):
"""Checks the state of the test, and sets self._results
@@ -132,12 +141,16 @@ class RemoteDeviceTestRun(test_run.TestRun):
test_run_id: Id of test on on remote service.
"""
- test_check_res = appurify_sanitized.api.tests_check_result(self._env.token,
- test_run_id)
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
+ logging.WARNING):
+ test_check_res = appurify_sanitized.api.tests_check_result(
+ self._env.token, test_run_id)
remote_device_helper.TestHttpResponse(test_check_res,
'Unable to get test status.')
self._results = test_check_res.json()['response']
- logging.info('Test status: %s' % self._results['detailed_status'])
+ if self._results['detailed_status'] != self._current_status:
+ logging.info('Test status: %s', self._results['detailed_status'])
+ self._current_status = self._results['detailed_status']
return self._results['status']
def _AmInstrumentTestSetup(self, app_path, test_path, runner_package):
@@ -170,11 +183,13 @@ class RemoteDeviceTestRun(test_run.TestRun):
def _UploadAppToDevice(self, app_path):
"""Upload app to device."""
- logging.info('Upload %s to remote service.' % app_path)
+ logging.info('Uploading %s to remote service.', app_path)
apk_name = os.path.basename(app_path)
with open(app_path, 'rb') as apk_src:
- upload_results = appurify_sanitized.api.apps_upload(
- self._env.token, apk_src, 'raw', name=apk_name)
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
+ logging.WARNING):
+ upload_results = appurify_sanitized.api.apps_upload(
+ self._env.token, apk_src, 'raw', name=apk_name)
remote_device_helper.TestHttpResponse(
upload_results, 'Unable to upload %s.' % app_path)
return upload_results.json()['response']['app_id']
@@ -186,8 +201,10 @@ class RemoteDeviceTestRun(test_run.TestRun):
"""
logging.info('Uploading %s to remote service.' % test_path)
with open(test_path, 'rb') as test_src:
- upload_results = appurify_sanitized.api.tests_upload(
- self._env.token, test_src, 'raw', test_type)
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
+ logging.WARNING):
+ upload_results = appurify_sanitized.api.tests_upload(
+ self._env.token, test_src, 'raw', test_type)
remote_device_helper.TestHttpResponse(upload_results,
'Unable to upload %s.' % test_path)
return upload_results.json()['response']['test_id']
@@ -204,7 +221,9 @@ class RemoteDeviceTestRun(test_run.TestRun):
config.write(''.join('%s\n' % l for l in config_data))
config.flush()
config.seek(0)
- config_response = appurify_sanitized.api.config_upload(
- self._env.token, config, self._test_id)
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
+ logging.WARNING):
+ config_response = appurify_sanitized.api.config_upload(
+ self._env.token, config, self._test_id)
remote_device_helper.TestHttpResponse(
config_response, 'Unable to upload test config.')
diff --git a/build/android/test_runner.py b/build/android/test_runner.py
index cc00781..c1fb450 100755
--- a/build/android/test_runner.py
+++ b/build/android/test_runner.py
@@ -128,9 +128,9 @@ def AddRemoteDeviceOptions(parser):
group.add_argument('--collect', default='',
help=('Only collects the test results if set. '
'Gets test_run_id from given file path.'))
- group.add_argument('--remote-device', default='Nexus 5',
+ group.add_argument('--remote-device', default='',
help=('Device type to run test on.'))
- group.add_argument('--remote-device-os', default='4.4.2',
+ group.add_argument('--remote-device-os', default='',
help=('OS to have on the device.'))
group.add_argument('--results-path', default='',
help=('File path to download results to.'))