| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class RemoteDeviceTestRun(test_run.TestRun): | 22 class RemoteDeviceTestRun(test_run.TestRun): |
| 23 """Run tests on a remote device.""" | 23 """Run tests on a remote device.""" |
| 24 | 24 |
| 25 _TEST_RUN_KEY = 'test_run' | 25 _TEST_RUN_KEY = 'test_run' |
| 26 _TEST_RUN_ID_KEY = 'test_run_id' | 26 _TEST_RUN_ID_KEY = 'test_run_id' |
| 27 | 27 |
| 28 WAIT_TIME = 5 | 28 WAIT_TIME = 5 |
| 29 COMPLETE = 'complete' | 29 COMPLETE = 'complete' |
| 30 HEARTBEAT_INTERVAL = 300 | 30 HEARTBEAT_INTERVAL = 300 |
| 31 | 31 |
| 32 _RESULTS_FILE = 'appurify_results/result.txt' | |
| 33 | |
| 34 def __init__(self, env, test_instance): | 32 def __init__(self, env, test_instance): |
| 35 """Constructor. | 33 """Constructor. |
| 36 | 34 |
| 37 Args: | 35 Args: |
| 38 env: Environment the tests will run in. | 36 env: Environment the tests will run in. |
| 39 test_instance: The test that will be run. | 37 test_instance: The test that will be run. |
| 40 """ | 38 """ |
| 41 super(RemoteDeviceTestRun, self).__init__(env, test_instance) | 39 super(RemoteDeviceTestRun, self).__init__(env, test_instance) |
| 42 self._env = env | 40 self._env = env |
| 43 self._test_instance = test_instance | 41 self._test_instance = test_instance |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 """ | 177 """ |
| 180 if results_path: | 178 if results_path: |
| 181 logging.info('Downloading results to %s.' % results_path) | 179 logging.info('Downloading results to %s.' % results_path) |
| 182 if not os.path.exists(os.path.dirname(results_path)): | 180 if not os.path.exists(os.path.dirname(results_path)): |
| 183 os.makedirs(os.path.dirname(results_path)) | 181 os.makedirs(os.path.dirname(results_path)) |
| 184 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 182 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 185 logging.WARNING): | 183 logging.WARNING): |
| 186 appurify_sanitized.utils.wget(self._results['results']['url'], | 184 appurify_sanitized.utils.wget(self._results['results']['url'], |
| 187 results_path) | 185 results_path) |
| 188 | 186 |
| 189 def _GetRawTestOutput(self): | |
| 190 """Returns the test output.""" | |
| 191 # TODO(mikecase): Remove getting results from zip when b/18981674 is fixed. | |
| 192 results_zipfile = self._env.results_path | |
| 193 if results_zipfile and os.path.exists(results_zipfile): | |
| 194 with zipfile.ZipFile(results_zipfile) as z: | |
| 195 with z.open(self._RESULTS_FILE, 'r') as r: | |
| 196 return r.read() | |
| 197 else: | |
| 198 logging.warning( | |
| 199 'If the test output is too long, some test results may get cut off.') | |
| 200 logging.warning( | |
| 201 'Use the --results-path option to ensure you get the full results.') | |
| 202 return self._results['results']['output'] | |
| 203 | |
| 204 def _GetTestStatus(self, test_run_id): | 187 def _GetTestStatus(self, test_run_id): |
| 205 """Checks the state of the test, and sets self._results | 188 """Checks the state of the test, and sets self._results |
| 206 | 189 |
| 207 Args: | 190 Args: |
| 208 test_run_id: Id of test on on remote service. | 191 test_run_id: Id of test on on remote service. |
| 209 """ | 192 """ |
| 210 | 193 |
| 211 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 194 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 212 logging.WARNING): | 195 logging.WARNING): |
| 213 test_check_res = appurify_sanitized.api.tests_check_result( | 196 test_check_res = appurify_sanitized.api.tests_check_result( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 '%s=%s' % (k, v) for k, v in runner_configs.iteritems()) | 299 '%s=%s' % (k, v) for k, v in runner_configs.iteritems()) |
| 317 config.write(''.join('%s\n' % l for l in config_data)) | 300 config.write(''.join('%s\n' % l for l in config_data)) |
| 318 config.flush() | 301 config.flush() |
| 319 config.seek(0) | 302 config.seek(0) |
| 320 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 303 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 321 logging.WARNING): | 304 logging.WARNING): |
| 322 config_response = appurify_sanitized.api.config_upload( | 305 config_response = appurify_sanitized.api.config_upload( |
| 323 self._env.token, config, self._test_id) | 306 self._env.token, config, self._test_id) |
| 324 remote_device_helper.TestHttpResponse( | 307 remote_device_helper.TestHttpResponse( |
| 325 config_response, 'Unable to upload test config.') | 308 config_response, 'Unable to upload test config.') |
| OLD | NEW |