| 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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 raw_result = self._RunTest(test, timeout) | 385 raw_result = self._RunTest(test, timeout) |
| 386 duration_ms = int(time.time()) * 1000 - start_date_ms | 386 duration_ms = int(time.time()) * 1000 - start_date_ms |
| 387 status_code = raw_result.GetStatusCode() | 387 status_code = raw_result.GetStatusCode() |
| 388 if status_code: | 388 if status_code: |
| 389 if self.options.screenshot_failures: | 389 if self.options.screenshot_failures: |
| 390 self._TakeScreenshot(test) | 390 self._TakeScreenshot(test) |
| 391 log = raw_result.GetFailureReason() | 391 log = raw_result.GetFailureReason() |
| 392 if not log: | 392 if not log: |
| 393 log = 'No information.' | 393 log = 'No information.' |
| 394 result_type = base_test_result.ResultType.FAIL | 394 result_type = base_test_result.ResultType.FAIL |
| 395 package = self.device.old_interface.DismissCrashDialogIfNeeded() | 395 # Dismiss any error dialogs. Limit the number in case we have an error |
| 396 # Assume test package convention of ".test" suffix | 396 # loop or we are failing to dismiss. |
| 397 if package and package in self.test_pkg.GetPackageName(): | 397 for _ in xrange(10): |
| 398 result_type = base_test_result.ResultType.CRASH | 398 package = self.device.old_interface.DismissCrashDialogIfNeeded() |
| 399 if not package: |
| 400 break |
| 401 # Assume test package convention of ".test" suffix |
| 402 if package in self.test_pkg.GetPackageName(): |
| 403 result_type = base_test_result.ResultType.CRASH |
| 404 break |
| 399 result = test_result.InstrumentationTestResult( | 405 result = test_result.InstrumentationTestResult( |
| 400 test, result_type, start_date_ms, duration_ms, log=log) | 406 test, result_type, start_date_ms, duration_ms, log=log) |
| 401 else: | 407 else: |
| 402 result = test_result.InstrumentationTestResult( | 408 result = test_result.InstrumentationTestResult( |
| 403 test, base_test_result.ResultType.PASS, start_date_ms, duration_ms) | 409 test, base_test_result.ResultType.PASS, start_date_ms, duration_ms) |
| 404 results.AddResult(result) | 410 results.AddResult(result) |
| 405 # Catch exceptions thrown by StartInstrumentation(). | 411 # Catch exceptions thrown by StartInstrumentation(). |
| 406 # See ../../third_party/android/testrunner/adb_interface.py | 412 # See ../../third_party/android/testrunner/adb_interface.py |
| 407 except (device_errors.CommandTimeoutError, | 413 except (device_errors.CommandTimeoutError, |
| 408 device_errors.DeviceUnreachableError, | 414 device_errors.DeviceUnreachableError, |
| 409 # TODO(jbudorick) Remove these once the underlying implementations | 415 # TODO(jbudorick) Remove these once the underlying implementations |
| 410 # for the above are switched or wrapped. | 416 # for the above are switched or wrapped. |
| 411 android_commands.errors.WaitForResponseTimedOutError, | 417 android_commands.errors.WaitForResponseTimedOutError, |
| 412 android_commands.errors.DeviceUnresponsiveError, | 418 android_commands.errors.DeviceUnresponsiveError, |
| 413 android_commands.errors.InstrumentationError), e: | 419 android_commands.errors.InstrumentationError), e: |
| 414 if start_date_ms: | 420 if start_date_ms: |
| 415 duration_ms = int(time.time()) * 1000 - start_date_ms | 421 duration_ms = int(time.time()) * 1000 - start_date_ms |
| 416 else: | 422 else: |
| 417 start_date_ms = int(time.time()) * 1000 | 423 start_date_ms = int(time.time()) * 1000 |
| 418 duration_ms = 0 | 424 duration_ms = 0 |
| 419 message = str(e) | 425 message = str(e) |
| 420 if not message: | 426 if not message: |
| 421 message = 'No information.' | 427 message = 'No information.' |
| 422 results.AddResult(test_result.InstrumentationTestResult( | 428 results.AddResult(test_result.InstrumentationTestResult( |
| 423 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, | 429 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, |
| 424 log=message)) | 430 log=message)) |
| 425 raw_result = None | 431 raw_result = None |
| 426 self.TestTeardown(test, raw_result) | 432 self.TestTeardown(test, raw_result) |
| 427 return (results, None if results.DidRunPass() else test) | 433 return (results, None if results.DidRunPass() else test) |
| OLD | NEW |