| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import posixpath | 7 import posixpath |
| 8 import re | 8 import re |
| 9 import tempfile | 9 import tempfile |
| 10 import time | 10 import time |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 if r.GetType() == base_test_result.ResultType.UNKNOWN: | 363 if r.GetType() == base_test_result.ResultType.UNKNOWN: |
| 364 r.SetType(base_test_result.ResultType.CRASH) | 364 r.SetType(base_test_result.ResultType.CRASH) |
| 365 | 365 |
| 366 # Handle failures by: | 366 # Handle failures by: |
| 367 # - optionally taking a screenshot | 367 # - optionally taking a screenshot |
| 368 # - logging the raw output at INFO level | 368 # - logging the raw output at INFO level |
| 369 # - clearing the application state while persisting permissions | 369 # - clearing the application state while persisting permissions |
| 370 if any(r.GetType() not in (base_test_result.ResultType.PASS, | 370 if any(r.GetType() not in (base_test_result.ResultType.PASS, |
| 371 base_test_result.ResultType.SKIP) | 371 base_test_result.ResultType.SKIP) |
| 372 for r in results): | 372 for r in results): |
| 373 if self._test_instance.screenshot_dir: | 373 |
| 374 file_name = '%s-%s.png' % ( | 374 with contextlib_ext.Optional( |
| 375 test_display_name, | 375 tempfile_ext.NamedTemporaryDirectory(), |
| 376 time.strftime('%Y%m%dT%H%M%S', time.localtime())) | 376 self._test_instance.screenshot_dir is None |
| 377 screenshot_file = device.TakeScreenshot( | 377 and self._test_instance.should_save_images) as screenshot_dir: |
| 378 os.path.join(self._test_instance.screenshot_dir, file_name)) | 378 |
| 379 logging.info( | 379 screenshot_dir = self._test_instance.screenshot_dir or screenshot_dir |
| 380 'Saved screenshot for %s to %s.', | 380 if screenshot_dir: |
| 381 test_display_name, screenshot_file) | 381 file_name = '%s-%s.png' % ( |
| 382 if self._test_instance.should_save_images: | 382 test_display_name, |
| 383 link = google_storage_helper.upload( | 383 time.strftime('%Y%m%dT%H%M%S', time.localtime())) |
| 384 google_storage_helper.unique_name('screenshot', device=device), | 384 screenshot_file = device.TakeScreenshot( |
| 385 screenshot_file, | 385 os.path.join(self._test_instance.screenshot_dir, file_name)) |
| 386 bucket='chromium-render-tests') | 386 logging.info( |
| 387 for result in results: | 387 'Saved screenshot for %s to %s.', |
| 388 result.SetLink('failure_screenshot', link) | 388 test_display_name, screenshot_file) |
| 389 if self._test_instance.should_save_images: |
| 390 link = google_storage_helper.upload( |
| 391 google_storage_helper.unique_name('screenshot', device=device), |
| 392 screenshot_file, |
| 393 bucket='chromium-render-tests') |
| 394 for result in results: |
| 395 result.SetLink('failure_screenshot', link) |
| 389 | 396 |
| 390 logging.info('detected failure in %s. raw output:', test_display_name) | 397 logging.info('detected failure in %s. raw output:', test_display_name) |
| 391 for l in output: | 398 for l in output: |
| 392 logging.info(' %s', l) | 399 logging.info(' %s', l) |
| 393 if (not self._env.skip_clear_data | 400 if (not self._env.skip_clear_data |
| 394 and self._test_instance.package_info): | 401 and self._test_instance.package_info): |
| 395 permissions = ( | 402 permissions = ( |
| 396 self._test_instance.apk_under_test.GetPermissions() | 403 self._test_instance.apk_under_test.GetPermissions() |
| 397 if self._test_instance.apk_under_test | 404 if self._test_instance.apk_under_test |
| 398 else None) | 405 else None) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 timeout = v | 550 timeout = v |
| 544 break | 551 break |
| 545 else: | 552 else: |
| 546 logging.warning('Using default 1 minute timeout for %s', test_name) | 553 logging.warning('Using default 1 minute timeout for %s', test_name) |
| 547 timeout = 60 | 554 timeout = 60 |
| 548 | 555 |
| 549 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 556 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
| 550 | 557 |
| 551 return timeout | 558 return timeout |
| 552 | 559 |
| OLD | NEW |