Chromium Code Reviews| 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 logging | 7 import logging |
| 8 | 8 |
| 9 from devil.utils import reraiser_thread | |
| 9 from pylib.base import base_test_result | 10 from pylib.base import base_test_result |
| 10 from pylib.remote.device import appurify_sanitized | 11 from pylib.remote.device import appurify_sanitized |
| 11 from pylib.remote.device import remote_device_test_run | 12 from pylib.remote.device import remote_device_test_run |
| 12 from pylib.remote.device import remote_device_helper | 13 from pylib.remote.device import remote_device_helper |
| 13 | 14 |
| 14 | 15 |
| 15 class RemoteDeviceUirobotTestRun(remote_device_test_run.RemoteDeviceTestRun): | 16 class RemoteDeviceUirobotTestRun(remote_device_test_run.RemoteDeviceTestRun): |
| 16 """Run uirobot tests on a remote device.""" | 17 """Run uirobot tests on a remote device.""" |
| 17 | 18 |
| 18 | 19 |
| 19 def __init__(self, env, test_instance): | 20 def __init__(self, env, test_instance): |
| 20 """Constructor. | 21 """Constructor. |
| 21 | 22 |
| 22 Args: | 23 Args: |
| 23 env: Environment the tests will run in. | 24 env: Environment the tests will run in. |
| 24 test_instance: The test that will be run. | 25 test_instance: The test that will be run. |
| 25 """ | 26 """ |
| 26 super(RemoteDeviceUirobotTestRun, self).__init__(env, test_instance) | 27 super(RemoteDeviceUirobotTestRun, self).__init__(env, test_instance) |
| 27 | 28 |
| 28 #override | 29 #override |
| 30 def _GetAppPath(self): | |
| 31 return self._test_instance.app_under_test | |
| 32 | |
| 33 #override | |
| 34 def _GetTestFramework(self): | |
| 35 if self._env.test_framework: | |
| 36 return self._env.test_framework | |
| 37 elif self._env.device_type == 'Android': | |
| 38 return 'android_robot' | |
| 39 elif self._env.device_type == 'iOS': | |
| 40 return 'ios_robot' | |
| 41 else: | |
| 42 raise remote_device_helper.RemoteDeviceError( | |
| 43 'Unknown device type: %s' % self._env.device_type) | |
| 44 | |
| 45 #override | |
| 46 def _ShouldShard(self): | |
| 47 return False | |
| 48 | |
| 49 #override | |
| 50 def _SetupTestShards(self, num_shards): | |
| 51 test_ids = [] | |
| 52 framework_configs = {'duration': self._test_instance.minutes} | |
| 53 | |
| 54 def upload_test_shards(): | |
| 55 test_id = self._UploadTestToDevice(None) | |
| 56 self._UploadTestConfigToDevice( | |
| 57 test_id, framework_configs, self._appurify_configs) | |
| 58 test_ids.append(test_id) | |
| 59 | |
| 60 workers = reraiser_thread.ReraiserThreadGroup( | |
|
rnephew (Wrong account)
2015/11/04 22:22:03
Since _ShouldShard() returns False, is it necessar
mikecase (-- gone --)
2015/11/05 23:17:41
Yeah, I'll add a RunThreadsSync function to rerais
| |
| 61 [reraiser_thread.ReraiserThread( | |
| 62 upload_test_shards, | |
| 63 name='upload test shard %d' % i) | |
| 64 for i in xrange(num_shards)]) | |
| 65 workers.StartAll() | |
| 66 workers.JoinAll() | |
| 67 return test_ids | |
| 68 | |
| 69 #override | |
| 29 def TestPackage(self): | 70 def TestPackage(self): |
| 30 return self._test_instance.package_name | 71 return self._test_instance.package_name |
| 31 | 72 |
| 32 #override | |
| 33 def _TriggerSetUp(self): | |
| 34 """Set up the triggering of a test run.""" | |
| 35 logging.info('Triggering test run.') | |
| 36 | |
| 37 if self._env.device_type == 'Android': | |
| 38 default_runner_type = 'android_robot' | |
| 39 elif self._env.device_type == 'iOS': | |
| 40 default_runner_type = 'ios_robot' | |
| 41 else: | |
| 42 raise remote_device_helper.RemoteDeviceError( | |
| 43 'Unknown device type: %s' % self._env.device_type) | |
| 44 | |
| 45 self._app_id = self._UploadAppToDevice(self._test_instance.app_under_test) | |
| 46 if not self._env.runner_type: | |
| 47 runner_type = default_runner_type | |
| 48 logging.info('Using default runner type: %s', default_runner_type) | |
| 49 else: | |
| 50 runner_type = self._env.runner_type | |
| 51 | |
| 52 self._test_id = self._UploadTestToDevice( | |
| 53 'android_robot', None, app_id=self._app_id) | |
| 54 config_body = {'duration': self._test_instance.minutes} | |
| 55 self._SetTestConfig(runner_type, config_body) | |
| 56 | |
| 57 | |
| 58 # TODO(rnephew): Switch to base class implementation when supported. | 73 # TODO(rnephew): Switch to base class implementation when supported. |
| 59 #override | 74 #override |
| 60 def _UploadTestToDevice(self, test_type, test_path, app_id=None): | 75 def _UploadTestToDevice(self, test_path): |
| 61 if test_path: | |
| 62 logging.info("Ignoring test path.") | |
| 63 data = { | 76 data = { |
| 64 'access_token':self._env.token, | 77 'access_token': self._env.token, |
| 65 'test_type':test_type, | 78 'test_type': self._GetTestFramework(), |
| 66 'app_id':app_id, | 79 'app_id': self._app_id, |
| 67 } | 80 } |
| 68 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 81 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 69 logging.WARNING): | 82 logging.WARNING): |
| 70 test_upload_res = appurify_sanitized.utils.post('tests/upload', | 83 test_upload_response = appurify_sanitized.utils.post( |
| 71 data, None) | 84 resource='tests/upload', data=data, files=None) |
| 72 remote_device_helper.TestHttpResponse( | 85 remote_device_helper.TestHttpResponse(test_upload_response, |
| 73 test_upload_res, 'Unable to get UiRobot test id.') | 86 'Unable to get UiRobot test id.') |
| 74 return test_upload_res.json()['response']['test_id'] | 87 return test_upload_response.json()['response']['test_id'] |
| 75 | 88 |
| 76 #override | 89 #override |
| 77 def _ParseTestResults(self): | 90 def _ParseTestResults(self, test_output, results_zip): |
| 78 logging.info('Parsing results from remote service.') | 91 logging.info('Parsing results from remote service.') |
| 79 results = base_test_result.TestRunResults() | 92 results = base_test_result.TestRunResults() |
| 80 if self._results['results']['pass']: | 93 if test_output['results']['pass']: |
| 81 result_type = base_test_result.ResultType.PASS | 94 result_type = base_test_result.ResultType.PASS |
| 82 else: | 95 else: |
| 83 result_type = base_test_result.ResultType.FAIL | 96 result_type = base_test_result.ResultType.FAIL |
| 84 results.AddResult(base_test_result.BaseTestResult('uirobot', result_type)) | 97 results.AddResult(base_test_result.BaseTestResult('uirobot', result_type)) |
| 98 remote_device_test_run.DetectPlatformErrors( | |
| 99 results, test_output, results_zip) | |
| 85 return results | 100 return results |
| OLD | NEW |