From 520cbbb594c4889ecbdf78839521f271644b3b0b Mon Sep 17 00:00:00 2001 From: mikecase Date: Tue, 21 Apr 2015 11:51:18 -0700 Subject: Add ability to set additional appurify configs. As part of the low end device testing, I am going to need to set some appurify configs like network=. This change will make this possible from the script. BUG= Review URL: https://codereview.chromium.org/963913002 Cr-Commit-Position: refs/heads/master@{#326084} --- .../pylib/remote/device/appurify_constants.py | 57 ++++++++++++++++++++++ .../remote/device/remote_device_environment.py | 11 +++-- .../pylib/remote/device/remote_device_test_run.py | 35 +++++++++---- build/android/test_runner.py | 3 ++ 4 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 build/android/pylib/remote/device/appurify_constants.py (limited to 'build') diff --git a/build/android/pylib/remote/device/appurify_constants.py b/build/android/pylib/remote/device/appurify_constants.py new file mode 100644 index 0000000..9343178 --- /dev/null +++ b/build/android/pylib/remote/device/appurify_constants.py @@ -0,0 +1,57 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Defines a set of constants specific to appurify.""" + +# Appurify network config constants. +class NETWORK(object): + WIFI_1_BAR = 1 + SPRINT_4G_LTE_4_BARS = 2 + SPRINT_3G_5_BARS = 3 + SPRINT_3G_4_BARS = 4 + SPRINT_3G_3_BARS = 5 + SPRINT_3G_2_BARS = 6 + SPRINT_3G_1_BAR = 7 + SPRING_4G_1_BAR = 8 + VERIZON_3G_5_BARS = 9 + VERIZON_3G_4_BARS = 10 + VERIZON_3G_3_BARS = 11 + VERIZON_3G_2_BARS = 12 + VERIZON_3G_1_BAR = 13 + VERIZON_4G_1_BAR = 14 + ATANDT_3G_5_BARS = 15 + ATANDT_3G_4_BARS = 16 + ATANDT_3G_3_BARS = 17 + ATANDT_3G_2_BARS = 18 + ATANDT_3G_1_BAR = 19 + GENERIC_2G_4_BARS = 20 + GENERIC_2G_3_BARS = 21 + GENERIC_EVOLVED_EDGE = 22 + GENERIC_GPRS = 23 + GENERIC_ENHANCED_GPRS = 24 + GENERIC_LTE = 25 + GENERIC_HIGH_LATENCY_DNS = 26 + GENERIC_100_PERCENT_PACKET_LOSS = 27 + ATANDT_HSPA_PLUS = 28 + ATANDT_4G_LTE_4_BARS = 29 + VERIZON_4G_LTE_4_BARS = 30 + GENERIC_DIGITAL_SUBSCRIBE_LINE = 31 + WIFI_STARBUCKS_3_BARS = 32 + WIFI_STARBUCKS_4_BARS = 33 + WIFI_STARBUCKS_HIGH_TRAFFIC = 34 + WIFI_TARGET_1_BAR = 35 + WIFI_TARGET_3_BARS = 36 + WIFI_TARGET_4_BARS = 37 + PUBLIC_WIFI_MCDONALDS_5_BARS = 38 + PUBLIC_WIFI_MCDONALDS_4_BARS = 39 + PUBLIC_WIFI_MCDONALDS_2_BARS = 40 + PUBLIC_WIFI_MCDONALDS_1_BAR = 41 + PUBLIC_WIFI_KOHLS_5_BARS = 42 + PUBLIC_WIFI_KOHLS_4_BARS = 43 + PUBLIC_WIFI_KOHLS_2_BARS = 44 + PUBLIC_WIFI_ATANDT_5_BARS = 45 + PUBLIC_WIFI_ATANDT_4_BARS = 46 + PUBLIC_WIFI_ATANDT_2_BARS = 47 + PUBLIC_WIFI_ATANDT_1_BAR = 48 + BOINGO = 49 \ No newline at end of file diff --git a/build/android/pylib/remote/device/remote_device_environment.py b/build/android/pylib/remote/device/remote_device_environment.py index 8875096..b69c7b2 100644 --- a/build/android/pylib/remote/device/remote_device_environment.py +++ b/build/android/pylib/remote/device/remote_device_environment.py @@ -73,6 +73,7 @@ class RemoteDeviceEnvironment(environment.Environment): self._api_secret = device_json.get('api_secret', None) 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._remote_device = device_json.get('remote_device', None) self._remote_device_minimum_os = device_json.get( 'remote_device_minimum_os', None) @@ -81,9 +82,7 @@ class RemoteDeviceEnvironment(environment.Environment): self._results_path = device_json.get('results_path', None) self._runner_package = device_json.get('runner_package', None) self._runner_type = device_json.get('runner_type', None) - if 'timeouts' in device_json: - for key in device_json['timeouts']: - self._timeouts[key] = device_json['timeouts'][key] + self._timeouts.update(device_json.get('timeouts', {})) def command_line_override( file_value, cmd_line_value, desc, print_value=True): @@ -107,6 +106,8 @@ class RemoteDeviceEnvironment(environment.Environment): self._device_oem, args.device_oem, 'device_oem') self._device_type = command_line_override( self._device_type, args.device_type, 'device_type') + self._network_config = command_line_override( + self._network_config, args.network_config, 'network_config') self._remote_device = command_line_override( self._remote_device, args.remote_device, 'remote_device') self._remote_device_minimum_os = command_line_override( @@ -325,6 +326,10 @@ class RemoteDeviceEnvironment(environment.Environment): return self._device['device_type_id'] @property + def network_config(self): + return self._network_config + + @property def only_output_failures(self): # TODO(jbudorick): Remove this once b/18981674 is fixed. return True 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 4a155ac..7aa91ae 100644 --- a/build/android/pylib/remote/device/remote_device_test_run.py +++ b/build/android/pylib/remote/device/remote_device_test_run.py @@ -14,6 +14,7 @@ import zipfile from pylib import constants from pylib.base import test_run +from pylib.remote.device import appurify_constants from pylib.remote.device import appurify_sanitized from pylib.remote.device import remote_device_helper from pylib.utils import zip_utils @@ -230,7 +231,10 @@ class RemoteDeviceTestRun(test_run.TestRun): self._test_id = self._UploadTestToDevice('robotium', test_path) logging.info('Setting config: %s' % config) - self._SetTestConfig('robotium', config) + appurify_configs = {} + if self._env.network_config: + appurify_configs['network'] = self._env.network_config + self._SetTestConfig('robotium', config, **appurify_configs) def _UploadAppToDevice(self, app_path): """Upload app to device.""" @@ -259,21 +263,32 @@ class RemoteDeviceTestRun(test_run.TestRun): 'Unable to upload %s.' % test_path) return upload_results.json()['response']['test_id'] - def _SetTestConfig(self, runner_type, body): + def _SetTestConfig(self, runner_type, runner_configs, + network=appurify_constants.NETWORK.WIFI_1_BAR, + pcap=0, profiler=0, videocapture=0): """Generates and uploads config file for test. Args: - extras: Extra arguments to set in the config file. + runner_configs: Configs specific to the runner you are using. + network: Config to specify the network environment the devices running + the tests will be in. + pcap: Option to set the recording the of network traffic from the device. + profiler: Option to set the recording of CPU, memory, and network + transfer usage in the tests. + videocapture: Option to set video capture during the tests. + """ logging.info('Generating config file for test.') with tempfile.TemporaryFile() as config: config_data = [ - '[appurify]', - 'pcap=0', - 'profiler=0', - 'videocapture=0', - '[%s]' % runner_type + '[appurify]', + 'network=%s' % network, + 'pcap=%s' % pcap, + 'profiler=%s' % profiler, + 'videocapture=%s' % videocapture, + '[%s]' % runner_type ] - config_data.extend('%s=%s' % (k, v) for k, v in body.iteritems()) + config_data.extend( + '%s=%s' % (k, v) for k, v in runner_configs.iteritems()) config.write(''.join('%s\n' % l for l in config_data)) config.flush() config.seek(0) @@ -282,4 +297,4 @@ class RemoteDeviceTestRun(test_run.TestRun): 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.') + config_response, 'Unable to upload test config.') \ No newline at end of file diff --git a/build/android/test_runner.py b/build/android/test_runner.py index 23d46b7..c54ed28 100755 --- a/build/android/test_runner.py +++ b/build/android/test_runner.py @@ -152,6 +152,9 @@ def AddRemoteDeviceOptions(parser): 'Overrides all other flags.')) group.add_argument('--remote-device-timeout', type=int, help='Times to retry finding remote device') + group.add_argument('--network-config', type=int, + help='Integer that specifies the network environment ' + 'that the tests will be run in.') device_os_group = group.add_mutually_exclusive_group() device_os_group.add_argument('--remote-device-minimum-os', -- cgit v1.1