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 io | 5 import io |
6 import json | 6 import json |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import pickle | 9 import pickle |
10 import shutil | 10 import shutil |
11 import tempfile | 11 import tempfile |
12 import threading | 12 import threading |
13 import time | 13 import time |
14 import zipfile | 14 import zipfile |
15 | 15 |
16 from devil.android import battery_utils | 16 from devil.android import battery_utils |
17 from devil.android import device_errors | 17 from devil.android import device_errors |
18 from devil.android import device_list | 18 from devil.android import device_list |
19 from devil.android import device_utils | 19 from devil.android import device_utils |
20 from devil.android import forwarder | 20 from devil.android import forwarder |
21 from devil.android.tools import device_recovery | 21 from devil.android.tools import device_recovery |
22 from devil.android.tools import device_status | 22 from devil.android.tools import device_status |
23 from devil.utils import cmd_helper | 23 from devil.utils import cmd_helper |
24 from devil.utils import parallelizer | 24 from devil.utils import parallelizer |
| 25 from devil.utils import reraiser_thread |
25 from pylib import constants | 26 from pylib import constants |
26 from pylib.base import base_test_result | 27 from pylib.base import base_test_result |
27 from pylib.constants import host_paths | 28 from pylib.constants import host_paths |
28 from pylib.local.device import local_device_environment | 29 from pylib.local.device import local_device_environment |
29 from pylib.local.device import local_device_test_run | 30 from pylib.local.device import local_device_test_run |
30 | 31 |
31 | 32 |
32 class HeartBeat(object): | 33 class HeartBeat(object): |
33 | 34 |
34 def __init__(self, shard, wait_time=60*10): | 35 def __init__(self, shard, wait_time=60*10): |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 293 |
293 class HostTestShard(TestShard): | 294 class HostTestShard(TestShard): |
294 def __init__(self, env, test_instance, tests, retries=3, timeout=None): | 295 def __init__(self, env, test_instance, tests, retries=3, timeout=None): |
295 super(HostTestShard, self).__init__( | 296 super(HostTestShard, self).__init__( |
296 env, test_instance, tests, retries, timeout) | 297 env, test_instance, tests, retries, timeout) |
297 | 298 |
298 @local_device_environment.handle_shard_failures | 299 @local_device_environment.handle_shard_failures |
299 def RunTestsOnShard(self): | 300 def RunTestsOnShard(self): |
300 results = base_test_result.TestRunResults() | 301 results = base_test_result.TestRunResults() |
301 for test in self._tests: | 302 for test in self._tests: |
302 tries_left = self._retries | 303 tries_left = self._retries + 1 |
303 result_type = None | 304 result_type = None |
304 while (result_type != base_test_result.ResultType.PASS | 305 while (result_type != base_test_result.ResultType.PASS |
305 and tries_left > 0): | 306 and tries_left > 0): |
306 try: | 307 try: |
307 self._TestSetUp(test) | 308 self._TestSetUp(test) |
308 result_type = self._RunSingleTest(test) | 309 result_type = self._RunSingleTest(test) |
309 finally: | 310 finally: |
310 self._TestTearDown() | 311 self._TestTearDown() |
311 results.AddResult(base_test_result.BaseTestResult(test, result_type)) | 312 results.AddResult(base_test_result.BaseTestResult(test, result_type)) |
312 return results | 313 return results |
(...skipping 14 matching lines...) Expand all Loading... |
327 def __init__(self, env, test_instance): | 328 def __init__(self, env, test_instance): |
328 super(LocalDevicePerfTestRun, self).__init__(env, test_instance) | 329 super(LocalDevicePerfTestRun, self).__init__(env, test_instance) |
329 self._devices = None | 330 self._devices = None |
330 self._env = env | 331 self._env = env |
331 self._no_device_tests = {} | 332 self._no_device_tests = {} |
332 self._test_buckets = [] | 333 self._test_buckets = [] |
333 self._test_instance = test_instance | 334 self._test_instance = test_instance |
334 self._timeout = None if test_instance.no_timeout else self._DEFAULT_TIMEOUT | 335 self._timeout = None if test_instance.no_timeout else self._DEFAULT_TIMEOUT |
335 | 336 |
336 def SetUp(self): | 337 def SetUp(self): |
337 self._devices = self._GetAllDevices(self._env.devices, | |
338 self._test_instance.known_devices_file) | |
339 | |
340 if os.path.exists(constants.PERF_OUTPUT_DIR): | 338 if os.path.exists(constants.PERF_OUTPUT_DIR): |
341 shutil.rmtree(constants.PERF_OUTPUT_DIR) | 339 shutil.rmtree(constants.PERF_OUTPUT_DIR) |
342 os.makedirs(constants.PERF_OUTPUT_DIR) | 340 os.makedirs(constants.PERF_OUTPUT_DIR) |
343 | 341 |
344 def TearDown(self): | 342 def TearDown(self): |
345 pass | 343 pass |
346 | 344 |
347 def _GetStepsFromDict(self): | 345 def _GetStepsFromDict(self): |
348 # From where this is called one of these two must be set. | 346 # From where this is called one of these two must be set. |
349 if self._test_instance.single_step: | 347 if self._test_instance.single_step: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 devices = active_devices | 403 devices = active_devices |
406 return sorted(devices) | 404 return sorted(devices) |
407 | 405 |
408 #override | 406 #override |
409 def RunTests(self): | 407 def RunTests(self): |
410 # Affinitize the tests. | 408 # Affinitize the tests. |
411 self._SplitTestsByAffinity() | 409 self._SplitTestsByAffinity() |
412 if not self._test_buckets and not self._no_device_tests: | 410 if not self._test_buckets and not self._no_device_tests: |
413 raise local_device_test_run.NoTestsError() | 411 raise local_device_test_run.NoTestsError() |
414 | 412 |
415 def run_perf_tests(shard_id): | 413 def run_no_devices_tests(): |
416 if shard_id is None: | 414 if not self._no_device_tests: |
417 s = HostTestShard(self._env, self._test_instance, self._no_device_tests, | 415 return [] |
418 retries=3, timeout=self._timeout) | 416 s = HostTestShard(self._env, self._test_instance, self._no_device_tests, |
419 else: | 417 retries=3, timeout=self._timeout) |
420 if device_status.IsBlacklisted( | 418 return [s.RunTestsOnShard()] |
421 str(self._devices[shard_id]), self._env.blacklist): | 419 |
422 logging.warning('Device %s is not active. Will not create shard %s.', | 420 def device_shard_helper(shard_id): |
423 str(self._devices[shard_id]), shard_id) | 421 if device_status.IsBlacklisted( |
424 return None | 422 str(self._devices[shard_id]), self._env.blacklist): |
425 s = DeviceTestShard(self._env, self._test_instance, | 423 logging.warning('Device %s is not active. Will not create shard %s.', |
426 self._devices[shard_id], shard_id, | 424 str(self._devices[shard_id]), shard_id) |
427 self._test_buckets[shard_id], | 425 return None |
428 retries=self._env.max_tries, timeout=self._timeout) | 426 s = DeviceTestShard(self._env, self._test_instance, |
| 427 self._devices[shard_id], shard_id, |
| 428 self._test_buckets[shard_id], |
| 429 retries=self._env.max_tries, timeout=self._timeout) |
429 return s.RunTestsOnShard() | 430 return s.RunTestsOnShard() |
430 | 431 |
431 device_indices = range(min(len(self._devices), len(self._test_buckets))) | 432 def run_devices_tests(): |
432 if self._no_device_tests: | 433 if not self._test_buckets: |
433 device_indices.append(None) | 434 return [] |
434 shards = parallelizer.Parallelizer(device_indices).pMap(run_perf_tests) | 435 if self._devices is None: |
435 return [x for x in shards.pGet(self._timeout) if x is not None] | 436 self._devices = self._GetAllDevices( |
| 437 self._env.devices, self._test_instance.known_devices_file) |
| 438 |
| 439 device_indices = range(min(len(self._devices), len(self._test_buckets))) |
| 440 shards = parallelizer.Parallelizer(device_indices).pMap( |
| 441 device_shard_helper) |
| 442 return [x for x in shards.pGet(self._timeout) if x is not None] |
| 443 |
| 444 host_test_results, device_test_results = reraiser_thread.RunAsync( |
| 445 [run_no_devices_tests, run_devices_tests]) |
| 446 return host_test_results + device_test_results |
436 | 447 |
437 # override | 448 # override |
438 def TestPackage(self): | 449 def TestPackage(self): |
439 return 'perf' | 450 return 'perf' |
440 | 451 |
441 # override | 452 # override |
442 def _CreateShards(self, _tests): | 453 def _CreateShards(self, _tests): |
443 raise NotImplementedError | 454 raise NotImplementedError |
444 | 455 |
445 # override | 456 # override |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 # override | 508 # override |
498 def _RunTest(self, _device, _test): | 509 def _RunTest(self, _device, _test): |
499 raise NotImplementedError | 510 raise NotImplementedError |
500 | 511 |
501 | 512 |
502 class TestDictVersionError(Exception): | 513 class TestDictVersionError(Exception): |
503 pass | 514 pass |
504 | 515 |
505 class PerfTestRunGetStepsError(Exception): | 516 class PerfTestRunGetStepsError(Exception): |
506 pass | 517 pass |
OLD | NEW |