OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Class for running instrumentation tests on a single device.""" | 5 """Class for running instrumentation tests on a single device.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 import sys | 10 import sys |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 timeout=(self._GetIndividualTestTimeoutSecs(test) * | 333 timeout=(self._GetIndividualTestTimeoutSecs(test) * |
334 self._GetIndividualTestTimeoutScale(test) * | 334 self._GetIndividualTestTimeoutScale(test) * |
335 self.tool.GetTimeoutScale()) | 335 self.tool.GetTimeoutScale()) |
336 try: | 336 try: |
337 self.TestSetup(test) | 337 self.TestSetup(test) |
338 start_date_ms = int(time.time()) * 1000 | 338 start_date_ms = int(time.time()) * 1000 |
339 raw_result = self._RunTest(test, timeout) | 339 raw_result = self._RunTest(test, timeout) |
340 duration_ms = int(time.time()) * 1000 - start_date_ms | 340 duration_ms = int(time.time()) * 1000 - start_date_ms |
341 status_code = raw_result.GetStatusCode() | 341 status_code = raw_result.GetStatusCode() |
342 if status_code: | 342 if status_code: |
| 343 result_type = base_test_result.ResultType.FAIL |
| 344 if self.options.screenshot_failures: |
| 345 self._TakeScreenshot(test) |
343 log = raw_result.GetFailureReason() | 346 log = raw_result.GetFailureReason() |
344 if not log: | 347 if not log: |
345 log = 'No information.' | 348 log = 'No information.' |
346 if (self.options.screenshot_failures or | 349 elif log.find('INJECT_EVENTS perm') >= 0: |
347 log.find('INJECT_EVENTS perm') >= 0): | 350 package = self.adb.DismissCrashDialogIfNeeded() |
348 self._TakeScreenshot(test) | 351 # Assume test package convention of ".test" suffix |
| 352 if package and package in self.test_pkg.GetPackageName(): |
| 353 result_type = base_test_result.ResultType.CRASH |
349 result = test_result.InstrumentationTestResult( | 354 result = test_result.InstrumentationTestResult( |
350 test, base_test_result.ResultType.FAIL, start_date_ms, duration_ms, | 355 test, result_type, start_date_ms, duration_ms, log=log) |
351 log=log) | |
352 else: | 356 else: |
353 result = test_result.InstrumentationTestResult( | 357 result = test_result.InstrumentationTestResult( |
354 test, base_test_result.ResultType.PASS, start_date_ms, duration_ms) | 358 test, base_test_result.ResultType.PASS, start_date_ms, duration_ms) |
355 results.AddResult(result) | 359 results.AddResult(result) |
356 # Catch exceptions thrown by StartInstrumentation(). | 360 # Catch exceptions thrown by StartInstrumentation(). |
357 # See ../../third_party/android/testrunner/adb_interface.py | 361 # See ../../third_party/android/testrunner/adb_interface.py |
358 except (android_commands.errors.WaitForResponseTimedOutError, | 362 except (android_commands.errors.WaitForResponseTimedOutError, |
359 android_commands.errors.DeviceUnresponsiveError, | 363 android_commands.errors.DeviceUnresponsiveError, |
360 android_commands.errors.InstrumentationError), e: | 364 android_commands.errors.InstrumentationError), e: |
361 if start_date_ms: | 365 if start_date_ms: |
362 duration_ms = int(time.time()) * 1000 - start_date_ms | 366 duration_ms = int(time.time()) * 1000 - start_date_ms |
363 else: | 367 else: |
364 start_date_ms = int(time.time()) * 1000 | 368 start_date_ms = int(time.time()) * 1000 |
365 duration_ms = 0 | 369 duration_ms = 0 |
366 message = str(e) | 370 message = str(e) |
367 if not message: | 371 if not message: |
368 message = 'No information.' | 372 message = 'No information.' |
369 results.AddResult(test_result.InstrumentationTestResult( | 373 results.AddResult(test_result.InstrumentationTestResult( |
370 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, | 374 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, |
371 log=message)) | 375 log=message)) |
372 raw_result = None | 376 raw_result = None |
373 self.TestTeardown(test, raw_result) | 377 self.TestTeardown(test, raw_result) |
374 return (results, None if results.DidRunPass() else test) | 378 return (results, None if results.DidRunPass() else test) |
OLD | NEW |