Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: build/android/pylib/remote/device/remote_device_test_run.py

Issue 814653003: Clean up logging and add device randomization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get rid of import Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/remote/device/remote_device_helper.py ('k') | build/android/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import os 8 import os
9 import sys 9 import sys
10 import tempfile 10 import tempfile
(...skipping 19 matching lines...) Expand all
30 env: Environment the tests will run in. 30 env: Environment the tests will run in.
31 test_instance: The test that will be run. 31 test_instance: The test that will be run.
32 """ 32 """
33 super(RemoteDeviceTestRun, self).__init__(env, test_instance) 33 super(RemoteDeviceTestRun, self).__init__(env, test_instance)
34 self._env = env 34 self._env = env
35 self._test_instance = test_instance 35 self._test_instance = test_instance
36 self._app_id = '' 36 self._app_id = ''
37 self._test_id = '' 37 self._test_id = ''
38 self._results = '' 38 self._results = ''
39 self._test_run_id = '' 39 self._test_run_id = ''
40 self._current_status = ''
40 41
41 #override 42 #override
42 def RunTests(self): 43 def RunTests(self):
43 """Run the test.""" 44 """Run the test."""
44 if self._env.trigger: 45 if self._env.trigger:
45 test_start_res = appurify_sanitized.api.tests_run( 46 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
46 self._env.token, self._env.device, self._app_id, self._test_id) 47 logging.WARNING):
48 test_start_res = appurify_sanitized.api.tests_run(
49 self._env.token, self._env.device, self._app_id, self._test_id)
47 remote_device_helper.TestHttpResponse( 50 remote_device_helper.TestHttpResponse(
48 test_start_res, 'Unable to run test.') 51 test_start_res, 'Unable to run test.')
49 self._test_run_id = test_start_res.json()['response']['test_run_id'] 52 self._test_run_id = test_start_res.json()['response']['test_run_id']
50 logging.info('Test run id: %s' % self._test_run_id) 53 logging.info('Test run id: %s' % self._test_run_id)
51 if not self._env.collect: 54 if not self._env.collect:
52 assert isinstance(self._env.trigger, basestring), ( 55 assert isinstance(self._env.trigger, basestring), (
53 'File for storing test_run_id must be a string.') 56 'File for storing test_run_id must be a string.')
54 with open(self._env.trigger, 'w') as test_run_id_file: 57 with open(self._env.trigger, 'w') as test_run_id_file:
55 test_run_id_file.write(self._test_run_id) 58 test_run_id_file.write(self._test_run_id)
56 59
57 if self._env.collect: 60 if self._env.collect:
58 if not self._env.trigger: 61 if not self._env.trigger:
59 assert isinstance(self._env.trigger, basestring), ( 62 assert isinstance(self._env.trigger, basestring), (
60 'File for storing test_run_id must be a string.') 63 'File for storing test_run_id must be a string.')
61 with open(self._env.collect, 'r') as test_run_id_file: 64 with open(self._env.collect, 'r') as test_run_id_file:
62 self._test_run_id = test_run_id_file.read().strip() 65 self._test_run_id = test_run_id_file.read().strip()
63 while self._GetTestStatus(self._test_run_id) != self.COMPLETE: 66 while self._GetTestStatus(self._test_run_id) != self.COMPLETE:
64 time.sleep(self.WAIT_TIME) 67 time.sleep(self.WAIT_TIME)
65 self._DownloadTestResults(self._env.results_path) 68 self._DownloadTestResults(self._env.results_path)
66 return self._ParseTestResults() 69 return self._ParseTestResults()
67 70
68 #override 71 #override
69 def TearDown(self): 72 def TearDown(self):
70 """Tear down the test run.""" 73 """Tear down the test run."""
71 if (self._GetTestStatus(self._test_run_id) != self.COMPLETE 74 if (self._env.collect
72 and self._env.collect): 75 and self._GetTestStatus(self._test_run_id) != self.COMPLETE):
73 test_abort_res = appurify_sanitized.api.tests_abort( 76 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
74 self._env.token, self._test_run_id, reason='Test runner exiting.') 77 logging.WARNING):
78 test_abort_res = appurify_sanitized.api.tests_abort(
79 self._env.token, self._test_run_id, reason='Test runner exiting.')
75 remote_device_helper.TestHttpResponse(test_abort_res, 80 remote_device_helper.TestHttpResponse(test_abort_res,
76 'Unable to abort test.') 81 'Unable to abort test.')
77 82
78 def __enter__(self): 83 def __enter__(self):
79 """Set up the test run when used as a context manager.""" 84 """Set up the test run when used as a context manager."""
80 self.SetUp() 85 self.SetUp()
81 return self 86 return self
82 87
83 def __exit__(self, exc_type, exc_val, exc_tb): 88 def __exit__(self, exc_type, exc_val, exc_tb):
84 """Tear down the test run when used as a context manager.""" 89 """Tear down the test run when used as a context manager."""
(...skipping 11 matching lines...) Expand all
96 101
97 def _ParseTestResults(self): 102 def _ParseTestResults(self):
98 raise NotImplementedError 103 raise NotImplementedError
99 104
100 def _GetTestByName(self, test_name): 105 def _GetTestByName(self, test_name):
101 """Gets test_id for specific test. 106 """Gets test_id for specific test.
102 107
103 Args: 108 Args:
104 test_name: Test to find the ID of. 109 test_name: Test to find the ID of.
105 """ 110 """
106 test_list_res = appurify_sanitized.api.tests_list(self._env.token) 111 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
112 logging.WARNING):
113 test_list_res = appurify_sanitized.api.tests_list(self._env.token)
107 remote_device_helper.TestHttpResponse(test_list_res, 114 remote_device_helper.TestHttpResponse(test_list_res,
108 'Unable to get tests list.') 115 'Unable to get tests list.')
109 for test in test_list_res.json()['response']: 116 for test in test_list_res.json()['response']:
110 if test['test_type'] == test_name: 117 if test['test_type'] == test_name:
111 return test['test_id'] 118 return test['test_id']
112 raise remote_device_helper.RemoteDeviceError( 119 raise remote_device_helper.RemoteDeviceError(
113 'No test found with name %s' % (test_name)) 120 'No test found with name %s' % (test_name))
114 121
115 def _DownloadTestResults(self, results_path): 122 def _DownloadTestResults(self, results_path):
116 """Download the test results from remote device service. 123 """Download the test results from remote device service.
117 124
118 Args: 125 Args:
119 results_path: path to download results to. 126 results_path: path to download results to.
120 """ 127 """
121 if results_path: 128 if results_path:
122 logging.info('Downloading results to %s.' % results_path) 129 logging.info('Downloading results to %s.' % results_path)
123 if not os.path.exists(os.path.basename(results_path)): 130 if not os.path.exists(os.path.basename(results_path)):
124 os.makedirs(os.path.basename(results_path)) 131 os.makedirs(os.path.basename(results_path))
125 appurify_sanitized.utils.wget(self._results['results']['url'], 132 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
126 results_path) 133 logging.WARNING):
134 appurify_sanitized.utils.wget(self._results['results']['url'],
135 results_path)
127 136
128 def _GetTestStatus(self, test_run_id): 137 def _GetTestStatus(self, test_run_id):
129 """Checks the state of the test, and sets self._results 138 """Checks the state of the test, and sets self._results
130 139
131 Args: 140 Args:
132 test_run_id: Id of test on on remote service. 141 test_run_id: Id of test on on remote service.
133 """ 142 """
134 143
135 test_check_res = appurify_sanitized.api.tests_check_result(self._env.token, 144 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
136 test_run_id) 145 logging.WARNING):
146 test_check_res = appurify_sanitized.api.tests_check_result(
147 self._env.token, test_run_id)
137 remote_device_helper.TestHttpResponse(test_check_res, 148 remote_device_helper.TestHttpResponse(test_check_res,
138 'Unable to get test status.') 149 'Unable to get test status.')
139 self._results = test_check_res.json()['response'] 150 self._results = test_check_res.json()['response']
140 logging.info('Test status: %s' % self._results['detailed_status']) 151 if self._results['detailed_status'] != self._current_status:
152 logging.info('Test status: %s', self._results['detailed_status'])
153 self._current_status = self._results['detailed_status']
141 return self._results['status'] 154 return self._results['status']
142 155
143 def _AmInstrumentTestSetup(self, app_path, test_path, runner_package): 156 def _AmInstrumentTestSetup(self, app_path, test_path, runner_package):
144 config = {'runner': runner_package} 157 config = {'runner': runner_package}
145 158
146 self._app_id = self._UploadAppToDevice(app_path) 159 self._app_id = self._UploadAppToDevice(app_path)
147 160
148 data_deps = self._test_instance.GetDataDependencies() 161 data_deps = self._test_instance.GetDataDependencies()
149 if data_deps: 162 if data_deps:
150 with tempfile.NamedTemporaryFile(suffix='.zip') as test_with_deps: 163 with tempfile.NamedTemporaryFile(suffix='.zip') as test_with_deps:
(...skipping 12 matching lines...) Expand all
163 self._test_id = self._UploadTestToDevice( 176 self._test_id = self._UploadTestToDevice(
164 'robotium', test_with_deps.name) 177 'robotium', test_with_deps.name)
165 else: 178 else:
166 self._test_id = self._UploadTestToDevice('robotium', test_path) 179 self._test_id = self._UploadTestToDevice('robotium', test_path)
167 180
168 logging.info('Setting config: %s' % config) 181 logging.info('Setting config: %s' % config)
169 self._SetTestConfig('robotium', config) 182 self._SetTestConfig('robotium', config)
170 183
171 def _UploadAppToDevice(self, app_path): 184 def _UploadAppToDevice(self, app_path):
172 """Upload app to device.""" 185 """Upload app to device."""
173 logging.info('Upload %s to remote service.' % app_path) 186 logging.info('Uploading %s to remote service.', app_path)
174 apk_name = os.path.basename(app_path) 187 apk_name = os.path.basename(app_path)
175 with open(app_path, 'rb') as apk_src: 188 with open(app_path, 'rb') as apk_src:
176 upload_results = appurify_sanitized.api.apps_upload( 189 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
177 self._env.token, apk_src, 'raw', name=apk_name) 190 logging.WARNING):
191 upload_results = appurify_sanitized.api.apps_upload(
192 self._env.token, apk_src, 'raw', name=apk_name)
178 remote_device_helper.TestHttpResponse( 193 remote_device_helper.TestHttpResponse(
179 upload_results, 'Unable to upload %s.' % app_path) 194 upload_results, 'Unable to upload %s.' % app_path)
180 return upload_results.json()['response']['app_id'] 195 return upload_results.json()['response']['app_id']
181 196
182 def _UploadTestToDevice(self, test_type, test_path): 197 def _UploadTestToDevice(self, test_type, test_path):
183 """Upload test to device 198 """Upload test to device
184 Args: 199 Args:
185 test_type: Type of test that is being uploaded. Ex. uirobot, gtest.. 200 test_type: Type of test that is being uploaded. Ex. uirobot, gtest..
186 """ 201 """
187 logging.info('Uploading %s to remote service.' % test_path) 202 logging.info('Uploading %s to remote service.' % test_path)
188 with open(test_path, 'rb') as test_src: 203 with open(test_path, 'rb') as test_src:
189 upload_results = appurify_sanitized.api.tests_upload( 204 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
190 self._env.token, test_src, 'raw', test_type) 205 logging.WARNING):
206 upload_results = appurify_sanitized.api.tests_upload(
207 self._env.token, test_src, 'raw', test_type)
191 remote_device_helper.TestHttpResponse(upload_results, 208 remote_device_helper.TestHttpResponse(upload_results,
192 'Unable to upload %s.' % test_path) 209 'Unable to upload %s.' % test_path)
193 return upload_results.json()['response']['test_id'] 210 return upload_results.json()['response']['test_id']
194 211
195 def _SetTestConfig(self, runner_type, body): 212 def _SetTestConfig(self, runner_type, body):
196 """Generates and uploads config file for test. 213 """Generates and uploads config file for test.
197 Args: 214 Args:
198 extras: Extra arguments to set in the config file. 215 extras: Extra arguments to set in the config file.
199 """ 216 """
200 logging.info('Generating config file for test.') 217 logging.info('Generating config file for test.')
201 with tempfile.TemporaryFile() as config: 218 with tempfile.TemporaryFile() as config:
202 config_data = ['[appurify]', '[%s]' % runner_type] 219 config_data = ['[appurify]', '[%s]' % runner_type]
203 config_data.extend('%s=%s' % (k, v) for k, v in body.iteritems()) 220 config_data.extend('%s=%s' % (k, v) for k, v in body.iteritems())
204 config.write(''.join('%s\n' % l for l in config_data)) 221 config.write(''.join('%s\n' % l for l in config_data))
205 config.flush() 222 config.flush()
206 config.seek(0) 223 config.seek(0)
207 config_response = appurify_sanitized.api.config_upload( 224 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
208 self._env.token, config, self._test_id) 225 logging.WARNING):
226 config_response = appurify_sanitized.api.config_upload(
227 self._env.token, config, self._test_id)
209 remote_device_helper.TestHttpResponse( 228 remote_device_helper.TestHttpResponse(
210 config_response, 'Unable to upload test config.') 229 config_response, 'Unable to upload test config.')
OLDNEW
« no previous file with comments | « build/android/pylib/remote/device/remote_device_helper.py ('k') | build/android/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698