| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Run specific test on specific environment.""" | 5 """Run specific test on specific environment.""" |
| 6 | 6 |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 import tempfile | 11 import tempfile |
| 12 import time | 12 import time |
| 13 import zipfile | 13 import zipfile |
| 14 | 14 |
| 15 from pylib import constants | 15 from pylib import constants |
| 16 from pylib.base import test_run | 16 from pylib.base import test_run |
| 17 from pylib.remote.device import appurify_constants |
| 17 from pylib.remote.device import appurify_sanitized | 18 from pylib.remote.device import appurify_sanitized |
| 18 from pylib.remote.device import remote_device_helper | 19 from pylib.remote.device import remote_device_helper |
| 19 from pylib.utils import zip_utils | 20 from pylib.utils import zip_utils |
| 20 | 21 |
| 21 class RemoteDeviceTestRun(test_run.TestRun): | 22 class RemoteDeviceTestRun(test_run.TestRun): |
| 22 """Run tests on a remote device.""" | 23 """Run tests on a remote device.""" |
| 23 | 24 |
| 24 _TEST_RUN_KEY = 'test_run' | 25 _TEST_RUN_KEY = 'test_run' |
| 25 _TEST_RUN_ID_KEY = 'test_run_id' | 26 _TEST_RUN_ID_KEY = 'test_run_id' |
| 26 | 27 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) | 224 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) |
| 224 sdcard_files.append(os.path.basename(h)) | 225 sdcard_files.append(os.path.basename(h)) |
| 225 config['sdcard_files'] = ','.join(sdcard_files) | 226 config['sdcard_files'] = ','.join(sdcard_files) |
| 226 config['host_test'] = host_test | 227 config['host_test'] = host_test |
| 227 self._test_id = self._UploadTestToDevice( | 228 self._test_id = self._UploadTestToDevice( |
| 228 'robotium', test_with_deps.name, app_id=self._app_id) | 229 'robotium', test_with_deps.name, app_id=self._app_id) |
| 229 else: | 230 else: |
| 230 self._test_id = self._UploadTestToDevice('robotium', test_path) | 231 self._test_id = self._UploadTestToDevice('robotium', test_path) |
| 231 | 232 |
| 232 logging.info('Setting config: %s' % config) | 233 logging.info('Setting config: %s' % config) |
| 233 self._SetTestConfig('robotium', config) | 234 appurify_configs = {} |
| 235 if self._env.network_config: |
| 236 appurify_configs['network'] = self._env.network_config |
| 237 self._SetTestConfig('robotium', config, **appurify_configs) |
| 234 | 238 |
| 235 def _UploadAppToDevice(self, app_path): | 239 def _UploadAppToDevice(self, app_path): |
| 236 """Upload app to device.""" | 240 """Upload app to device.""" |
| 237 logging.info('Uploading %s to remote service.', app_path) | 241 logging.info('Uploading %s to remote service.', app_path) |
| 238 with open(app_path, 'rb') as apk_src: | 242 with open(app_path, 'rb') as apk_src: |
| 239 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 243 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 240 logging.WARNING): | 244 logging.WARNING): |
| 241 upload_results = appurify_sanitized.api.apps_upload( | 245 upload_results = appurify_sanitized.api.apps_upload( |
| 242 self._env.token, apk_src, 'raw', name=self._test_instance.suite) | 246 self._env.token, apk_src, 'raw', name=self._test_instance.suite) |
| 243 remote_device_helper.TestHttpResponse( | 247 remote_device_helper.TestHttpResponse( |
| 244 upload_results, 'Unable to upload %s.' % app_path) | 248 upload_results, 'Unable to upload %s.' % app_path) |
| 245 return upload_results.json()['response']['app_id'] | 249 return upload_results.json()['response']['app_id'] |
| 246 | 250 |
| 247 def _UploadTestToDevice(self, test_type, test_path, app_id=None): | 251 def _UploadTestToDevice(self, test_type, test_path, app_id=None): |
| 248 """Upload test to device | 252 """Upload test to device |
| 249 Args: | 253 Args: |
| 250 test_type: Type of test that is being uploaded. Ex. uirobot, gtest.. | 254 test_type: Type of test that is being uploaded. Ex. uirobot, gtest.. |
| 251 """ | 255 """ |
| 252 logging.info('Uploading %s to remote service.' % test_path) | 256 logging.info('Uploading %s to remote service.' % test_path) |
| 253 with open(test_path, 'rb') as test_src: | 257 with open(test_path, 'rb') as test_src: |
| 254 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 258 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 255 logging.WARNING): | 259 logging.WARNING): |
| 256 upload_results = appurify_sanitized.api.tests_upload( | 260 upload_results = appurify_sanitized.api.tests_upload( |
| 257 self._env.token, test_src, 'raw', test_type, app_id=app_id) | 261 self._env.token, test_src, 'raw', test_type, app_id=app_id) |
| 258 remote_device_helper.TestHttpResponse(upload_results, | 262 remote_device_helper.TestHttpResponse(upload_results, |
| 259 'Unable to upload %s.' % test_path) | 263 'Unable to upload %s.' % test_path) |
| 260 return upload_results.json()['response']['test_id'] | 264 return upload_results.json()['response']['test_id'] |
| 261 | 265 |
| 262 def _SetTestConfig(self, runner_type, body): | 266 def _SetTestConfig(self, runner_type, runner_configs, |
| 267 network=appurify_constants.NETWORK.WIFI_1_BAR, |
| 268 pcap=0, profiler=0, videocapture=0): |
| 263 """Generates and uploads config file for test. | 269 """Generates and uploads config file for test. |
| 264 Args: | 270 Args: |
| 265 extras: Extra arguments to set in the config file. | 271 runner_configs: Configs specific to the runner you are using. |
| 272 network: Config to specify the network environment the devices running |
| 273 the tests will be in. |
| 274 pcap: Option to set the recording the of network traffic from the device. |
| 275 profiler: Option to set the recording of CPU, memory, and network |
| 276 transfer usage in the tests. |
| 277 videocapture: Option to set video capture during the tests. |
| 278 |
| 266 """ | 279 """ |
| 267 logging.info('Generating config file for test.') | 280 logging.info('Generating config file for test.') |
| 268 with tempfile.TemporaryFile() as config: | 281 with tempfile.TemporaryFile() as config: |
| 269 config_data = [ | 282 config_data = [ |
| 270 '[appurify]', | 283 '[appurify]', |
| 271 'pcap=0', | 284 'network=%s' % network, |
| 272 'profiler=0', | 285 'pcap=%s' % pcap, |
| 273 'videocapture=0', | 286 'profiler=%s' % profiler, |
| 274 '[%s]' % runner_type | 287 'videocapture=%s' % videocapture, |
| 288 '[%s]' % runner_type |
| 275 ] | 289 ] |
| 276 config_data.extend('%s=%s' % (k, v) for k, v in body.iteritems()) | 290 config_data.extend( |
| 291 '%s=%s' % (k, v) for k, v in runner_configs.iteritems()) |
| 277 config.write(''.join('%s\n' % l for l in config_data)) | 292 config.write(''.join('%s\n' % l for l in config_data)) |
| 278 config.flush() | 293 config.flush() |
| 279 config.seek(0) | 294 config.seek(0) |
| 280 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 295 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 281 logging.WARNING): | 296 logging.WARNING): |
| 282 config_response = appurify_sanitized.api.config_upload( | 297 config_response = appurify_sanitized.api.config_upload( |
| 283 self._env.token, config, self._test_id) | 298 self._env.token, config, self._test_id) |
| 284 remote_device_helper.TestHttpResponse( | 299 remote_device_helper.TestHttpResponse( |
| 285 config_response, 'Unable to upload test config.') | 300 config_response, 'Unable to upload test config.') |
| OLD | NEW |