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 re | 10 import re |
11 import shutil | 11 import shutil |
12 import string | 12 import string |
13 import tempfile | 13 import tempfile |
14 import time | 14 import time |
15 import zipfile | 15 import zipfile |
16 | 16 |
17 from devil.utils import zip_utils | 17 from devil.utils import zip_utils |
18 from pylib.base import base_test_result | 18 from pylib.base import base_test_result |
19 from pylib.base import test_run | 19 from pylib.base import test_run |
20 from pylib.remote.device import appurify_constants | 20 from pylib.remote.device import appurify_constants |
21 from pylib.remote.device import appurify_sanitized | 21 from pylib.remote.device import appurify_sanitized |
22 from pylib.remote.device import remote_device_helper | 22 from pylib.remote.device import remote_device_helper |
23 | 23 |
24 _DEVICE_OFFLINE_RE = re.compile('error: device not found') | 24 _DEVICE_OFFLINE_RE = re.compile('error: device not found') |
25 _LONG_MSG_RE = re.compile('longMsg=') | 25 _LONG_MSG_RE = re.compile('longMsg=') |
26 _SHORT_MSG_RE = re.compile('shortMsg=') | 26 _SHORT_MSG_RE = re.compile('shortMsg=') |
27 | 27 |
28 | |
29 class RemoteDeviceTestRun(test_run.TestRun): | 28 class RemoteDeviceTestRun(test_run.TestRun): |
30 """Run tests on a remote device.""" | 29 """Run tests on a remote device.""" |
31 | 30 |
32 _TEST_RUN_KEY = 'test_run' | 31 _TEST_RUN_KEY = 'test_run' |
33 _TEST_RUN_ID_KEY = 'test_run_id' | 32 _TEST_RUN_ID_KEY = 'test_run_id' |
34 | 33 |
35 WAIT_TIME = 5 | 34 WAIT_TIME = 5 |
36 COMPLETE = 'complete' | 35 COMPLETE = 'complete' |
37 HEARTBEAT_INTERVAL = 300 | 36 HEARTBEAT_INTERVAL = 300 |
38 | 37 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 """Run the test.""" | 73 """Run the test.""" |
75 if self._env.trigger: | 74 if self._env.trigger: |
76 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 75 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
77 logging.WARNING): | 76 logging.WARNING): |
78 test_start_res = appurify_sanitized.api.tests_run( | 77 test_start_res = appurify_sanitized.api.tests_run( |
79 self._env.token, self._env.device_type_id, self._app_id, | 78 self._env.token, self._env.device_type_id, self._app_id, |
80 self._test_id) | 79 self._test_id) |
81 remote_device_helper.TestHttpResponse( | 80 remote_device_helper.TestHttpResponse( |
82 test_start_res, 'Unable to run test.') | 81 test_start_res, 'Unable to run test.') |
83 self._test_run_id = test_start_res.json()['response']['test_run_id'] | 82 self._test_run_id = test_start_res.json()['response']['test_run_id'] |
84 logging.info('Test run id: %s' % self._test_run_id) | 83 logging.info('Test run id: %s', self._test_run_id) |
85 | 84 |
86 if self._env.collect: | 85 if self._env.collect: |
87 current_status = '' | 86 current_status = '' |
88 timeout_counter = 0 | 87 timeout_counter = 0 |
89 heartbeat_counter = 0 | 88 heartbeat_counter = 0 |
90 while self._GetTestStatus(self._test_run_id) != self.COMPLETE: | 89 while self._GetTestStatus(self._test_run_id) != self.COMPLETE: |
91 if self._results['detailed_status'] != current_status: | 90 if self._results['detailed_status'] != current_status: |
92 logging.info('Test status: %s', self._results['detailed_status']) | 91 logging.info('Test status: %s', self._results['detailed_status']) |
93 current_status = self._results['detailed_status'] | 92 current_status = self._results['detailed_status'] |
94 timeout_counter = 0 | 93 timeout_counter = 0 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 186 |
188 Args: | 187 Args: |
189 results_path: Path to download appurify results zipfile. | 188 results_path: Path to download appurify results zipfile. |
190 | 189 |
191 Returns: | 190 Returns: |
192 Path to downloaded file. | 191 Path to downloaded file. |
193 """ | 192 """ |
194 | 193 |
195 if self._results_temp_dir is None: | 194 if self._results_temp_dir is None: |
196 self._results_temp_dir = tempfile.mkdtemp() | 195 self._results_temp_dir = tempfile.mkdtemp() |
197 logging.info('Downloading results to %s.' % self._results_temp_dir) | 196 logging.info('Downloading results to %s.', self._results_temp_dir) |
198 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 197 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
199 logging.WARNING): | 198 logging.WARNING): |
200 appurify_sanitized.utils.wget(self._results['results']['url'], | 199 appurify_sanitized.utils.wget(self._results['results']['url'], |
201 self._results_temp_dir + '/results') | 200 self._results_temp_dir + '/results') |
202 if results_path: | 201 if results_path: |
203 logging.info('Copying results to %s', results_path) | 202 logging.info('Copying results to %s', results_path) |
204 if not os.path.exists(os.path.dirname(results_path)): | 203 if not os.path.exists(os.path.dirname(results_path)): |
205 os.makedirs(os.path.dirname(results_path)) | 204 os.makedirs(os.path.dirname(results_path)) |
206 shutil.copy(self._results_temp_dir + '/results', results_path) | 205 shutil.copy(self._results_temp_dir + '/results', results_path) |
207 return self._results_temp_dir + '/results' | 206 return self._results_temp_dir + '/results' |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 with zipfile.ZipFile(test_with_deps.name, 'w') as zip_file: | 239 with zipfile.ZipFile(test_with_deps.name, 'w') as zip_file: |
241 zip_file.write(test_path, host_test, zipfile.ZIP_DEFLATED) | 240 zip_file.write(test_path, host_test, zipfile.ZIP_DEFLATED) |
242 for h, _ in data_deps: | 241 for h, _ in data_deps: |
243 if os.path.isdir(h): | 242 if os.path.isdir(h): |
244 zip_utils.WriteToZipFile(zip_file, h, '.') | 243 zip_utils.WriteToZipFile(zip_file, h, '.') |
245 sdcard_files.extend(os.listdir(h)) | 244 sdcard_files.extend(os.listdir(h)) |
246 else: | 245 else: |
247 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) | 246 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) |
248 sdcard_files.append(os.path.basename(h)) | 247 sdcard_files.append(os.path.basename(h)) |
249 for a in extra_apks or (): | 248 for a in extra_apks or (): |
250 zip_utils.WriteToZipFile(zip_file, a, os.path.basename(a)); | 249 zip_utils.WriteToZipFile(zip_file, a, os.path.basename(a)) |
251 additional_apks.append(os.path.basename(a)) | 250 additional_apks.append(os.path.basename(a)) |
252 | 251 |
253 config['sdcard_files'] = ','.join(sdcard_files) | 252 config['sdcard_files'] = ','.join(sdcard_files) |
254 config['host_test'] = host_test | 253 config['host_test'] = host_test |
255 if additional_apks: | 254 if additional_apks: |
256 config['additional_apks'] = ','.join(additional_apks) | 255 config['additional_apks'] = ','.join(additional_apks) |
257 self._test_id = self._UploadTestToDevice( | 256 self._test_id = self._UploadTestToDevice( |
258 'robotium', test_with_deps.name, app_id=self._app_id) | 257 'robotium', test_with_deps.name, app_id=self._app_id) |
259 else: | 258 else: |
260 self._test_id = self._UploadTestToDevice('robotium', test_path) | 259 self._test_id = self._UploadTestToDevice('robotium', test_path) |
261 | 260 |
262 logging.info('Setting config: %s' % config) | 261 logging.info('Setting config: %s', config) |
263 appurify_configs = {} | 262 appurify_configs = {} |
264 if self._env.network_config: | 263 if self._env.network_config: |
265 appurify_configs['network'] = self._env.network_config | 264 appurify_configs['network'] = self._env.network_config |
266 self._SetTestConfig('robotium', config, **appurify_configs) | 265 self._SetTestConfig('robotium', config, **appurify_configs) |
267 | 266 |
268 def _UploadAppToDevice(self, app_path): | 267 def _UploadAppToDevice(self, app_path): |
269 """Upload app to device.""" | 268 """Upload app to device.""" |
270 logging.info('Uploading %s to remote service as %s.', app_path, | 269 logging.info('Uploading %s to remote service as %s.', app_path, |
271 self._test_instance.suite) | 270 self._test_instance.suite) |
272 with open(app_path, 'rb') as apk_src: | 271 with open(app_path, 'rb') as apk_src: |
273 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 272 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
274 logging.WARNING): | 273 logging.WARNING): |
275 upload_results = appurify_sanitized.api.apps_upload( | 274 upload_results = appurify_sanitized.api.apps_upload( |
276 self._env.token, apk_src, 'raw', name=self._test_instance.suite) | 275 self._env.token, apk_src, 'raw', name=self._test_instance.suite) |
277 remote_device_helper.TestHttpResponse( | 276 remote_device_helper.TestHttpResponse( |
278 upload_results, 'Unable to upload %s.' % app_path) | 277 upload_results, 'Unable to upload %s.' % app_path) |
279 return upload_results.json()['response']['app_id'] | 278 return upload_results.json()['response']['app_id'] |
280 | 279 |
281 def _UploadTestToDevice(self, test_type, test_path, app_id=None): | 280 def _UploadTestToDevice(self, test_type, test_path, app_id=None): |
282 """Upload test to device | 281 """Upload test to device |
283 Args: | 282 Args: |
284 test_type: Type of test that is being uploaded. Ex. uirobot, gtest.. | 283 test_type: Type of test that is being uploaded. Ex. uirobot, gtest.. |
285 """ | 284 """ |
286 logging.info('Uploading %s to remote service.' % test_path) | 285 logging.info('Uploading %s to remote service.', test_path) |
287 with open(test_path, 'rb') as test_src: | 286 with open(test_path, 'rb') as test_src: |
288 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 287 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
289 logging.WARNING): | 288 logging.WARNING): |
290 upload_results = appurify_sanitized.api.tests_upload( | 289 upload_results = appurify_sanitized.api.tests_upload( |
291 self._env.token, test_src, 'raw', test_type, app_id=app_id) | 290 self._env.token, test_src, 'raw', test_type, app_id=app_id) |
292 remote_device_helper.TestHttpResponse(upload_results, | 291 remote_device_helper.TestHttpResponse(upload_results, |
293 'Unable to upload %s.' % test_path) | 292 'Unable to upload %s.' % test_path) |
294 return upload_results.json()['response']['test_id'] | 293 return upload_results.json()['response']['test_id'] |
295 | 294 |
296 def _SetTestConfig(self, runner_type, runner_configs, | 295 def _SetTestConfig(self, runner_type, runner_configs, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 base_test_result.ResultType.UNKNOWN)) | 378 base_test_result.ResultType.UNKNOWN)) |
380 elif self._DidDeviceGoOffline(): | 379 elif self._DidDeviceGoOffline(): |
381 self._LogLogcat() | 380 self._LogLogcat() |
382 self._LogAdbTraceLog() | 381 self._LogAdbTraceLog() |
383 raise remote_device_helper.RemoteDeviceError( | 382 raise remote_device_helper.RemoteDeviceError( |
384 'Remote service unable to reach device.', is_infra_error=True) | 383 'Remote service unable to reach device.', is_infra_error=True) |
385 else: | 384 else: |
386 results.AddResult(base_test_result.BaseTestResult( | 385 results.AddResult(base_test_result.BaseTestResult( |
387 'Remote Service detected error.', | 386 'Remote Service detected error.', |
388 base_test_result.ResultType.UNKNOWN)) | 387 base_test_result.ResultType.UNKNOWN)) |
OLD | NEW |