Chromium Code Reviews| 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 io | 6 import io |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import pickle | 10 import pickle |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 from devil.android.tools import device_recovery | 22 from devil.android.tools import device_recovery |
| 23 from devil.android.tools import device_status | 23 from devil.android.tools import device_status |
| 24 from devil.utils import cmd_helper | 24 from devil.utils import cmd_helper |
| 25 from devil.utils import parallelizer | 25 from devil.utils import parallelizer |
| 26 from devil.utils import reraiser_thread | 26 from devil.utils import reraiser_thread |
| 27 from pylib import constants | 27 from pylib import constants |
| 28 from pylib.base import base_test_result | 28 from pylib.base import base_test_result |
| 29 from pylib.constants import host_paths | 29 from pylib.constants import host_paths |
| 30 from pylib.local.device import local_device_environment | 30 from pylib.local.device import local_device_environment |
| 31 from pylib.local.device import local_device_test_run | 31 from pylib.local.device import local_device_test_run |
| 32 from py_trace_event import trace_event | |
| 32 | 33 |
| 33 | 34 |
| 34 class HeartBeat(object): | 35 class HeartBeat(object): |
| 35 | 36 |
| 36 def __init__(self, shard, wait_time=60*10): | 37 def __init__(self, shard, wait_time=60*10): |
| 37 """ HeartBeat Logger constructor. | 38 """ HeartBeat Logger constructor. |
| 38 | 39 |
| 39 Args: | 40 Args: |
| 40 shard: A perf test runner device shard. | 41 shard: A perf test runner device shard. |
| 41 wait_time: time to wait between heartbeat messages. | 42 wait_time: time to wait between heartbeat messages. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 self._test_instance.WriteBuildBotJson(self._output_dir) | 90 self._test_instance.WriteBuildBotJson(self._output_dir) |
| 90 | 91 |
| 91 timeout = self._tests[test].get('timeout', self._timeout) | 92 timeout = self._tests[test].get('timeout', self._timeout) |
| 92 cmd = self._CreateCmd(test) | 93 cmd = self._CreateCmd(test) |
| 93 cwd = os.path.abspath(host_paths.DIR_SOURCE_ROOT) | 94 cwd = os.path.abspath(host_paths.DIR_SOURCE_ROOT) |
| 94 | 95 |
| 95 self._LogTest(test, cmd, timeout) | 96 self._LogTest(test, cmd, timeout) |
| 96 | 97 |
| 97 try: | 98 try: |
| 98 start_time = time.time() | 99 start_time = time.time() |
| 100 if self._test_instance.trace_output: | |
|
jbudorick
2016/12/15 20:22:33
My vote would be for a context manager.
In relate
jbudorick
2016/12/15 20:22:59
that and tempdir as a context manager.
rnephew (Reviews Here)
2016/12/15 21:24:04
Moved to context manager.
| |
| 101 trace_event.trace_begin(test) | |
| 99 exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( | 102 exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( |
| 100 cmd, timeout, cwd=cwd, shell=True) | 103 cmd, timeout, cwd=cwd, shell=True) |
| 104 if self._test_instance.trace_output: | |
| 105 trace_event.trace_end(test) | |
| 101 end_time = time.time() | 106 end_time = time.time() |
| 102 json_output = self._test_instance.ReadChartjsonOutput(self._output_dir) | 107 json_output = self._test_instance.ReadChartjsonOutput(self._output_dir) |
| 103 if exit_code == 0: | 108 if exit_code == 0: |
| 104 result_type = base_test_result.ResultType.PASS | 109 result_type = base_test_result.ResultType.PASS |
| 105 else: | 110 else: |
| 106 result_type = base_test_result.ResultType.FAIL | 111 result_type = base_test_result.ResultType.FAIL |
| 107 except cmd_helper.TimeoutError as e: | 112 except cmd_helper.TimeoutError as e: |
| 108 end_time = time.time() | 113 end_time = time.time() |
| 109 exit_code = -1 | 114 exit_code = -1 |
| 110 output = e.output | 115 output = e.output |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 'affinity to work properly, it must be passed.') | 408 'affinity to work properly, it must be passed.') |
| 404 devices = active_devices | 409 devices = active_devices |
| 405 except IOError as e: | 410 except IOError as e: |
| 406 logging.error('Unable to find %s [%s]', devices_path, e) | 411 logging.error('Unable to find %s [%s]', devices_path, e) |
| 407 devices = active_devices | 412 devices = active_devices |
| 408 return sorted(devices) | 413 return sorted(devices) |
| 409 | 414 |
| 410 #override | 415 #override |
| 411 def RunTests(self): | 416 def RunTests(self): |
| 412 # Affinitize the tests. | 417 # Affinitize the tests. |
| 418 if self._test_instance.trace_output: | |
| 419 assert not trace_event.trace_is_enabled(), 'Tracing already running.' | |
| 420 trace_event.trace_enable(self._test_instance.trace_output) | |
| 413 self._SplitTestsByAffinity() | 421 self._SplitTestsByAffinity() |
| 414 if not self._test_buckets and not self._no_device_tests: | 422 if not self._test_buckets and not self._no_device_tests: |
| 415 raise local_device_test_run.NoTestsError() | 423 raise local_device_test_run.NoTestsError() |
| 416 | 424 |
| 417 def run_no_devices_tests(): | 425 def run_no_devices_tests(): |
| 418 if not self._no_device_tests: | 426 if not self._no_device_tests: |
| 419 return [] | 427 return [] |
| 420 s = HostTestShard(self._env, self._test_instance, self._no_device_tests, | 428 s = HostTestShard(self._env, self._test_instance, self._no_device_tests, |
| 421 retries=3, timeout=self._timeout) | 429 retries=3, timeout=self._timeout) |
| 422 return [s.RunTestsOnShard()] | 430 return [s.RunTestsOnShard()] |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 440 self._devices = self._GetAllDevices( | 448 self._devices = self._GetAllDevices( |
| 441 self._env.devices, self._test_instance.known_devices_file) | 449 self._env.devices, self._test_instance.known_devices_file) |
| 442 | 450 |
| 443 device_indices = range(min(len(self._devices), len(self._test_buckets))) | 451 device_indices = range(min(len(self._devices), len(self._test_buckets))) |
| 444 shards = parallelizer.Parallelizer(device_indices).pMap( | 452 shards = parallelizer.Parallelizer(device_indices).pMap( |
| 445 device_shard_helper) | 453 device_shard_helper) |
| 446 return [x for x in shards.pGet(self._timeout) if x is not None] | 454 return [x for x in shards.pGet(self._timeout) if x is not None] |
| 447 | 455 |
| 448 host_test_results, device_test_results = reraiser_thread.RunAsync( | 456 host_test_results, device_test_results = reraiser_thread.RunAsync( |
| 449 [run_no_devices_tests, run_devices_tests]) | 457 [run_no_devices_tests, run_devices_tests]) |
| 458 if self._test_instance.trace_output: | |
| 459 assert trace_event.trace_is_enabled(), 'Tracing not running.' | |
| 460 trace_event.trace_disable() | |
| 450 return host_test_results + device_test_results | 461 return host_test_results + device_test_results |
| 451 | 462 |
| 452 # override | 463 # override |
| 453 def TestPackage(self): | 464 def TestPackage(self): |
| 454 return 'perf' | 465 return 'perf' |
| 455 | 466 |
| 456 # override | 467 # override |
| 457 def _CreateShards(self, _tests): | 468 def _CreateShards(self, _tests): |
| 458 raise NotImplementedError | 469 raise NotImplementedError |
| 459 | 470 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 # override | 523 # override |
| 513 def _RunTest(self, _device, _test): | 524 def _RunTest(self, _device, _test): |
| 514 raise NotImplementedError | 525 raise NotImplementedError |
| 515 | 526 |
| 516 | 527 |
| 517 class TestDictVersionError(Exception): | 528 class TestDictVersionError(Exception): |
| 518 pass | 529 pass |
| 519 | 530 |
| 520 class PerfTestRunGetStepsError(Exception): | 531 class PerfTestRunGetStepsError(Exception): |
| 521 pass | 532 pass |
| OLD | NEW |