OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # | 2 # |
3 # | 3 # |
4 # Copyright 2008, The Android Open Source Project | 4 # Copyright 2008, The Android Open Source Project |
5 # | 5 # |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
9 # | 9 # |
10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 Equivalent to StartInstrumentation, except instrumentation path is | 169 Equivalent to StartInstrumentation, except instrumentation path is |
170 separated into its package and runner components. | 170 separated into its package and runner components. |
171 """ | 171 """ |
172 instrumentation_path = "%s/%s" % (package_name, runner_name) | 172 instrumentation_path = "%s/%s" % (package_name, runner_name) |
173 return self.StartInstrumentation(instrumentation_path, timeout_time=timeout_
time, | 173 return self.StartInstrumentation(instrumentation_path, timeout_time=timeout_
time, |
174 no_window_animation=no_window_animation, | 174 no_window_animation=no_window_animation, |
175 instrumentation_args=instrumentation_args) | 175 instrumentation_args=instrumentation_args) |
176 | 176 |
177 def StartInstrumentation( | 177 def StartInstrumentation( |
178 self, instrumentation_path, timeout_time=60*10, no_window_animation=False, | 178 self, instrumentation_path, timeout_time=60*10, no_window_animation=False, |
179 profile=False, instrumentation_args={}): | 179 profile=False, instrumentation_args={}, silent_log=False): |
180 | 180 |
181 """Runs an instrumentation class on the target. | 181 """Runs an instrumentation class on the target. |
182 | 182 |
183 Returns a dictionary containing the key value pairs from the | 183 Returns a dictionary containing the key value pairs from the |
184 instrumentations result bundle and a list of TestResults. Also handles the | 184 instrumentations result bundle and a list of TestResults. Also handles the |
185 interpreting of error output from the device and raises the necessary | 185 interpreting of error output from the device and raises the necessary |
186 exceptions. | 186 exceptions. |
187 | 187 |
188 Args: | 188 Args: |
189 instrumentation_path: string. It should be the fully classified package | 189 instrumentation_path: string. It should be the fully classified package |
190 name, and instrumentation test runner, separated by "/" | 190 name, and instrumentation test runner, separated by "/" |
191 e.g. com.android.globaltimelaunch/.GlobalTimeLaunch | 191 e.g. com.android.globaltimelaunch/.GlobalTimeLaunch |
192 timeout_time: Timeout value for the am command. | 192 timeout_time: Timeout value for the am command. |
193 no_window_animation: boolean, Whether you want window animations enabled | 193 no_window_animation: boolean, Whether you want window animations enabled |
194 or disabled | 194 or disabled |
195 profile: If True, profiling will be turned on for the instrumentation. | 195 profile: If True, profiling will be turned on for the instrumentation. |
196 instrumentation_args: Dictionary of key value bundle arguments to pass to | 196 instrumentation_args: Dictionary of key value bundle arguments to pass to |
197 instrumentation. | 197 instrumentation. |
| 198 silent_log: If True, the invocation of the instrumentation test runner |
| 199 will not be logged. |
198 | 200 |
199 Returns: | 201 Returns: |
200 (test_results, inst_finished_bundle) | 202 (test_results, inst_finished_bundle) |
201 | 203 |
202 test_results: a list of TestResults | 204 test_results: a list of TestResults |
203 inst_finished_bundle (dict): Key/value pairs contained in the bundle that | 205 inst_finished_bundle (dict): Key/value pairs contained in the bundle that |
204 is passed into ActivityManager.finishInstrumentation(). Included in this | 206 is passed into ActivityManager.finishInstrumentation(). Included in this |
205 bundle is the return code of the Instrumentation process, any error | 207 bundle is the return code of the Instrumentation process, any error |
206 codes reported by the activity manager, and any results explicitly added | 208 codes reported by the activity manager, and any results explicitly added |
207 by the instrumentation code. | 209 by the instrumentation code. |
208 | 210 |
209 Raises: | 211 Raises: |
210 WaitForResponseTimedOutError: if timeout occurred while waiting for | 212 WaitForResponseTimedOutError: if timeout occurred while waiting for |
211 response to adb instrument command | 213 response to adb instrument command |
212 DeviceUnresponsiveError: if device system process is not responding | 214 DeviceUnresponsiveError: if device system process is not responding |
213 InstrumentationError: if instrumentation failed to run | 215 InstrumentationError: if instrumentation failed to run |
214 """ | 216 """ |
215 | 217 |
216 command_string = self._BuildInstrumentationCommandPath( | 218 command_string = self._BuildInstrumentationCommandPath( |
217 instrumentation_path, no_window_animation=no_window_animation, | 219 instrumentation_path, no_window_animation=no_window_animation, |
218 profile=profile, raw_mode=True, | 220 profile=profile, raw_mode=True, |
219 instrumentation_args=instrumentation_args) | 221 instrumentation_args=instrumentation_args) |
220 logger.Log(command_string) | 222 if silent_log: |
| 223 logger.SilentLog(command_string) |
| 224 else: |
| 225 logger.Log(command_string) |
221 (test_results, inst_finished_bundle) = ( | 226 (test_results, inst_finished_bundle) = ( |
222 am_instrument_parser.ParseAmInstrumentOutput( | 227 am_instrument_parser.ParseAmInstrumentOutput( |
223 self.SendShellCommand(command_string, timeout_time=timeout_time, | 228 self.SendShellCommand(command_string, timeout_time=timeout_time, |
224 retry_count=2))) | 229 retry_count=2))) |
225 | |
226 if "code" not in inst_finished_bundle: | 230 if "code" not in inst_finished_bundle: |
| 231 logger.Log('No code available. inst_finished_bundle contains: %s ' |
| 232 % inst_finished_bundle) |
227 raise errors.InstrumentationError("no test results... device setup " | 233 raise errors.InstrumentationError("no test results... device setup " |
228 "correctly?") | 234 "correctly?") |
229 | 235 |
230 if inst_finished_bundle["code"] == "0": | 236 if inst_finished_bundle["code"] == "0": |
231 short_msg_result = "no error message" | 237 long_msg_result = "no error message" |
232 if "shortMsg" in inst_finished_bundle: | 238 if "longMsg" in inst_finished_bundle: |
233 short_msg_result = inst_finished_bundle["shortMsg"] | 239 long_msg_result = inst_finished_bundle["longMsg"] |
234 logger.Log("Error! Test run failed: %s" % short_msg_result) | 240 logger.Log("Error! Test run failed: %s" % long_msg_result) |
235 raise errors.InstrumentationError(short_msg_result) | 241 raise errors.InstrumentationError(long_msg_result) |
236 | 242 |
237 if "INSTRUMENTATION_ABORTED" in inst_finished_bundle: | 243 if "INSTRUMENTATION_ABORTED" in inst_finished_bundle: |
238 logger.Log("INSTRUMENTATION ABORTED!") | 244 logger.Log("INSTRUMENTATION ABORTED!") |
239 raise errors.DeviceUnresponsiveError | 245 raise errors.DeviceUnresponsiveError |
240 | 246 |
241 return (test_results, inst_finished_bundle) | 247 return (test_results, inst_finished_bundle) |
242 | 248 |
243 def StartInstrumentationNoResults( | 249 def StartInstrumentationNoResults( |
244 self, package_name, runner_name, no_window_animation=False, | 250 self, package_name, runner_name, no_window_animation=False, |
245 raw_mode=False, instrumentation_args={}): | 251 raw_mode=False, instrumentation_args={}): |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 # press the MENU key, this will disable key guard if runtime is started | 504 # press the MENU key, this will disable key guard if runtime is started |
499 # with ro.monkey set to 1 | 505 # with ro.monkey set to 1 |
500 self.SendShellCommand("input keyevent 82", retry_count=retry_count) | 506 self.SendShellCommand("input keyevent 82", retry_count=retry_count) |
501 else: | 507 else: |
502 self.WaitForDevicePm() | 508 self.WaitForDevicePm() |
503 return output | 509 return output |
504 | 510 |
505 def GetSerialNumber(self): | 511 def GetSerialNumber(self): |
506 """Returns the serial number of the targeted device.""" | 512 """Returns the serial number of the targeted device.""" |
507 return self.SendCommand("get-serialno").strip() | 513 return self.SendCommand("get-serialno").strip() |
OLD | NEW |