| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 collections | 5 import collections |
| 6 import contextlib | |
| 7 import io | 6 import io |
| 8 import json | 7 import json |
| 9 import logging | 8 import logging |
| 10 import os | 9 import os |
| 11 import pickle | 10 import pickle |
| 12 import shutil | 11 import shutil |
| 13 import tempfile | 12 import tempfile |
| 14 import threading | 13 import threading |
| 15 import time | 14 import time |
| 16 import zipfile | 15 import zipfile |
| 17 | 16 |
| 18 from devil.android import battery_utils | 17 from devil.android import battery_utils |
| 19 from devil.android import device_errors | 18 from devil.android import device_errors |
| 20 from devil.android import device_list | 19 from devil.android import device_list |
| 21 from devil.android import device_utils | 20 from devil.android import device_utils |
| 22 from devil.android import forwarder | 21 from devil.android import forwarder |
| 23 from devil.android.tools import device_recovery | 22 from devil.android.tools import device_recovery |
| 24 from devil.android.tools import device_status | 23 from devil.android.tools import device_status |
| 25 from devil.utils import cmd_helper | 24 from devil.utils import cmd_helper |
| 26 from devil.utils import parallelizer | 25 from devil.utils import parallelizer |
| 27 from devil.utils import reraiser_thread | 26 from devil.utils import reraiser_thread |
| 28 from pylib import constants | 27 from pylib import constants |
| 29 from pylib.base import base_test_result | 28 from pylib.base import base_test_result |
| 30 from pylib.constants import host_paths | 29 from pylib.constants import host_paths |
| 31 from pylib.local.device import local_device_environment | 30 from pylib.local.device import local_device_environment |
| 32 from pylib.local.device import local_device_test_run | 31 from pylib.local.device import local_device_test_run |
| 33 from py_trace_event import trace_event | 32 from py_trace_event import trace_event |
| 33 from py_utils import contextlib_ext |
| 34 | 34 |
| 35 | 35 |
| 36 class HeartBeat(object): | 36 class HeartBeat(object): |
| 37 | 37 |
| 38 def __init__(self, shard, wait_time=60*10): | 38 def __init__(self, shard, wait_time=60*10): |
| 39 """ HeartBeat Logger constructor. | 39 """ HeartBeat Logger constructor. |
| 40 | 40 |
| 41 Args: | 41 Args: |
| 42 shard: A perf test runner device shard. | 42 shard: A perf test runner device shard. |
| 43 wait_time: time to wait between heartbeat messages. | 43 wait_time: time to wait between heartbeat messages. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 def _RunSingleTest(self, test): | 90 def _RunSingleTest(self, test): |
| 91 self._test_instance.WriteBuildBotJson(self._output_dir) | 91 self._test_instance.WriteBuildBotJson(self._output_dir) |
| 92 | 92 |
| 93 timeout = self._tests[test].get('timeout', self._timeout) | 93 timeout = self._tests[test].get('timeout', self._timeout) |
| 94 cmd = self._CreateCmd(test) | 94 cmd = self._CreateCmd(test) |
| 95 cwd = os.path.abspath(host_paths.DIR_SOURCE_ROOT) | 95 cwd = os.path.abspath(host_paths.DIR_SOURCE_ROOT) |
| 96 | 96 |
| 97 self._LogTest(test, cmd, timeout) | 97 self._LogTest(test, cmd, timeout) |
| 98 | 98 |
| 99 @contextlib.contextmanager | |
| 100 def trace_if_enabled(test): | |
| 101 try: | |
| 102 if self._test_instance.trace_output: | |
| 103 trace_event.trace_begin(test) | |
| 104 yield | |
| 105 finally: | |
| 106 if self._test_instance.trace_output: | |
| 107 trace_event.trace_end(test) | |
| 108 | |
| 109 try: | 99 try: |
| 110 start_time = time.time() | 100 start_time = time.time() |
| 111 | 101 |
| 112 with trace_if_enabled(test): | 102 with contextlib_ext.Optional( |
| 103 trace_event.trace(test), |
| 104 self._test_instance.trace_output): |
| 113 exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( | 105 exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( |
| 114 cmd, timeout, cwd=cwd, shell=True) | 106 cmd, timeout, cwd=cwd, shell=True) |
| 115 end_time = time.time() | 107 end_time = time.time() |
| 116 json_output = self._test_instance.ReadChartjsonOutput(self._output_dir) | 108 json_output = self._test_instance.ReadChartjsonOutput(self._output_dir) |
| 117 if exit_code == 0: | 109 if exit_code == 0: |
| 118 result_type = base_test_result.ResultType.PASS | 110 result_type = base_test_result.ResultType.PASS |
| 119 else: | 111 else: |
| 120 result_type = base_test_result.ResultType.FAIL | 112 result_type = base_test_result.ResultType.FAIL |
| 121 except cmd_helper.TimeoutError as e: | 113 except cmd_helper.TimeoutError as e: |
| 122 end_time = time.time() | 114 end_time = time.time() |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 # override | 526 # override |
| 535 def _RunTest(self, _device, _test): | 527 def _RunTest(self, _device, _test): |
| 536 raise NotImplementedError | 528 raise NotImplementedError |
| 537 | 529 |
| 538 | 530 |
| 539 class TestDictVersionError(Exception): | 531 class TestDictVersionError(Exception): |
| 540 pass | 532 pass |
| 541 | 533 |
| 542 class PerfTestRunGetStepsError(Exception): | 534 class PerfTestRunGetStepsError(Exception): |
| 543 pass | 535 pass |
| OLD | NEW |