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

Unified Diff: build/android/pylib/remote/device/remote_device_environment.py

Issue 1415533007: [Android] Add sharding for AMP instrumentation tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor change to uirobot SetupTestShards. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/remote/device/remote_device_environment.py
diff --git a/build/android/pylib/remote/device/remote_device_environment.py b/build/android/pylib/remote/device/remote_device_environment.py
index 7923f3ade13d5f8170481f884050b8321470426a..5d1f2c90de5869351375436dd855abef315a43c4 100644
--- a/build/android/pylib/remote/device/remote_device_environment.py
+++ b/build/android/pylib/remote/device/remote_device_environment.py
@@ -8,21 +8,20 @@ import distutils.version
import json
import logging
import os
-import random
import sys
from devil.utils import reraiser_thread
from devil.utils import timeout_retry
from pylib.base import environment
+from pylib.remote.device import appurify_constants
from pylib.remote.device import appurify_sanitized
from pylib.remote.device import remote_device_helper
class RemoteDeviceEnvironment(environment.Environment):
"""An environment for running on remote devices."""
- _ENV_KEY = 'env'
- _DEVICE_KEY = 'device'
_DEFAULT_RETRIES = 0
+ _DEFAULT_SHARD_COUNT = 6
def __init__(self, args, error_func):
"""Constructor.
@@ -33,14 +32,14 @@ class RemoteDeviceEnvironment(environment.Environment):
"""
super(RemoteDeviceEnvironment, self).__init__()
self._access_token = None
- self._device = None
+ self._devices = []
self._device_type = args.device_type
self._verbose_count = args.verbose_count
self._timeouts = {
'queueing': 60 * 10,
'installing': 60 * 10,
'in-progress': 60 * 30,
- 'unknown': 60 * 5
+ 'unknown': 60 * 5,
}
# Example config file:
# {
@@ -73,16 +72,20 @@ class RemoteDeviceEnvironment(environment.Environment):
self._device_oem = device_json.get('device_oem', None)
self._device_type = device_json.get('device_type', 'Android')
self._network_config = device_json.get('network_config', None)
+ self._num_shards = device_json.get('num_shards', None)
+ self._pcap_config = device_json.get('pcap_config', 0)
+ self._profiler_config = device_json.get('profiler_config', 0)
self._remote_device = device_json.get('remote_device', None)
self._remote_device_minimum_os = device_json.get(
'remote_device_minimum_os', None)
self._remote_device_os = device_json.get('remote_device_os', None)
self._remote_device_timeout = device_json.get(
'remote_device_timeout', None)
- self._results_path = device_json.get('results_path', None)
+ self._results_dir = device_json.get('results_dir', None)
self._runner_package = device_json.get('runner_package', None)
- self._runner_type = device_json.get('runner_type', None)
+ self._test_framework = device_json.get('test_framework', None)
self._timeouts.update(device_json.get('timeouts', {}))
+ self._videocapture_config = device_json.get('videocapture_config', 0)
def command_line_override(
file_value, cmd_line_value, desc, print_value=True):
@@ -108,6 +111,8 @@ class RemoteDeviceEnvironment(environment.Environment):
self._device_type, args.device_type, 'device_type')
self._network_config = command_line_override(
self._network_config, args.network_config, 'network_config')
+ self._num_shards = command_line_override(
+ self._num_shards, args.num_shards, 'num_shards')
self._remote_device = command_line_override(
self._remote_device, args.remote_device, 'remote_device')
self._remote_device_minimum_os = command_line_override(
@@ -118,14 +123,14 @@ class RemoteDeviceEnvironment(environment.Environment):
self._remote_device_timeout = command_line_override(
self._remote_device_timeout, args.remote_device_timeout,
'remote_device_timeout')
- self._results_path = command_line_override(
- self._results_path, args.results_path, 'results_path')
+ self._results_dir = command_line_override(
+ self._results_dir, args.results_dir, 'results_dir')
self._runner_package = command_line_override(
self._runner_package, args.runner_package, 'runner_package')
- self._runner_type = command_line_override(
- self._runner_type, args.runner_type, 'runner_type')
self._timeouts["in-progress"] = command_line_override(
self._timeouts["in-progress"], args.test_timeout, 'test_timeout')
+ self._test_framework = command_line_override(
+ self._test_framework, args.test_framework, 'test_framework')
if args.api_key_file:
with open(args.api_key_file) as api_key_file:
@@ -169,9 +174,9 @@ class RemoteDeviceEnvironment(environment.Environment):
logging.info('Remote device OEM: %s', self._device_oem)
logging.info('Remote device type: %s', self._device_type)
logging.info('Remote device timout: %s', self._remote_device_timeout)
- logging.info('Results Path: %s', self._results_path)
+ logging.info('Results directory: %s', self._results_dir)
logging.info('Runner package: %s', self._runner_package)
- logging.info('Runner type: %s', self._runner_type)
+ logging.info('Test framework: %s', self._test_framework)
logging.info('Timeouts: %s', self._timeouts)
if not args.trigger and not args.collect:
@@ -189,7 +194,7 @@ class RemoteDeviceEnvironment(environment.Environment):
os.environ['APPURIFY_STATUS_BASE_URL'] = 'none'
self._GetAccessToken()
if self._trigger:
- self._SelectDevice()
+ self._SelectDevices()
def TearDown(self):
"""Teardown the test environment."""
@@ -208,16 +213,6 @@ class RemoteDeviceEnvironment(environment.Environment):
"""Tears down the test run when used as a context manager."""
self.TearDown()
- def DumpTo(self, persisted_data):
- env_data = {
- self._DEVICE_KEY: self._device,
- }
- persisted_data[self._ENV_KEY] = env_data
-
- def LoadFrom(self, persisted_data):
- env_data = persisted_data[self._ENV_KEY]
- self._device = env_data[self._DEVICE_KEY]
-
def _GetAccessToken(self):
"""Generates access token for remote device service."""
logging.info('Generating remote service access token')
@@ -239,22 +234,25 @@ class RemoteDeviceEnvironment(environment.Environment):
remote_device_helper.TestHttpResponse(revoke_token_results,
'Unable to revoke access token.')
- def _SelectDevice(self):
+ def _SelectDevices(self):
if self._remote_device_timeout:
try:
- timeout_retry.Run(self._FindDeviceWithTimeout,
+ timeout_retry.Run(self._FindDevicesWithTimeout,
self._remote_device_timeout, self._DEFAULT_RETRIES)
except reraiser_thread.TimeoutError:
self._NoDeviceFound()
else:
- if not self._FindDevice():
+ if not self._FindDevices():
self._NoDeviceFound()
- def _FindDevice(self):
- """Find which device to use."""
- logging.info('Finding device to run tests on.')
+ def _FindDevices(self):
+ """Find which devices to use.
+
+ Returns:
+ False if no devices were found and True otherwise.
+ """
+ logging.info('Finding devices to run tests on.')
device_list = self._GetDeviceList()
- random.shuffle(device_list)
for device in device_list:
if device['os_name'] != self._device_type:
continue
@@ -270,15 +268,15 @@ class RemoteDeviceEnvironment(environment.Environment):
< distutils.version.LooseVersion(self._remote_device_minimum_os)):
continue
if device['has_available_device']:
- logging.info('Found device: %s %s',
+ logging.info('Found %s available %s %s',
+ device['available_devices_count'],
device['name'], device['os_version'])
- self._device = device
- return True
- return False
+ self._devices.append(device)
+ return True if self._devices else False
- def _FindDeviceWithTimeout(self):
+ def _FindDevicesWithTimeout(self):
"""Find which device to use with timeout."""
- timeout_retry.WaitFor(self._FindDevice, wait_period=1)
+ timeout_retry.WaitFor(self._FindDevices, wait_period=1)
def _PrintAvailableDevices(self, device_list):
def compare_devices(a, b):
@@ -309,10 +307,11 @@ class RemoteDeviceEnvironment(environment.Environment):
def _GetDeviceList(self):
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.')
- return dev_list_res.json()['response']
+ device_list_response = appurify_sanitized.api.devices_list(
+ access_token=self._access_token)
+ remote_device_helper.TestHttpResponse(device_list_response,
+ 'Unable to generate access token.')
+ return device_list_response.json()['response']
def _NoDeviceFound(self):
self._PrintAvailableDevices(self._GetDeviceList())
@@ -324,24 +323,46 @@ class RemoteDeviceEnvironment(environment.Environment):
return self._collect
@property
- def device_type_id(self):
- return self._device['device_type_id']
+ def device_type(self):
+ return self._device_type
+
+ @property
+ def device_ids(self):
+ device_ids = []
+ for d in self._devices:
+ device_ids.extend([d['device_type_id']]*d['available_devices_count'])
+ return device_ids
@property
def network_config(self):
- return self._network_config
+ """Config to specify the network environment."""
+ return self._network_config or appurify_constants.NETWORK.WIFI_1_BAR
+
+ @property
+ def num_shards(self):
+ return self._num_shards or self._DEFAULT_SHARD_COUNT
+
+ @property
+ def pcap_config(self):
+ """Config to record the of network traffic from the device."""
+ return self._pcap_config
@property
- def results_path(self):
- return self._results_path
+ def profiler_config(self):
+ """Config to record CPU, memory, and network transfer usage."""
+ return self._profiler_config
+
+ @property
+ def results_dir(self):
+ return self._results_dir
@property
def runner_package(self):
return self._runner_package
@property
- def runner_type(self):
- return self._runner_type
+ def test_framework(self):
+ return self._test_framework
@property
def timeouts(self):
@@ -360,5 +381,6 @@ class RemoteDeviceEnvironment(environment.Environment):
return self._verbose_count
@property
- def device_type(self):
- return self._device_type
+ def videocapture_config(self):
+ """Config to set video capture during the tests."""
+ return self._videocapture_config

Powered by Google App Engine
This is Rietveld 408576698