OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 |
| 6 from pylib.base import base_test_result |
| 7 from pylib.base import test_run |
| 8 from pylib.base import test_collection |
| 9 |
| 10 |
| 11 class LocalDeviceTestRun(test_run.TestRun): |
| 12 |
| 13 #override |
| 14 def RunTests(self): |
| 15 tests = self._GetTests() |
| 16 |
| 17 def run_tests_on_device(dev, tests): |
| 18 r = base_test_result.TestRunResults() |
| 19 for test in tests: |
| 20 result = self._RunTest(dev, test) |
| 21 if isinstance(result, base_test_result.BaseTestResult): |
| 22 r.AddResult(result) |
| 23 elif isinstance(result, list): |
| 24 r.AddResults(result) |
| 25 else: |
| 26 raise Exception('Unexpected result type: %s' % type(result).__name__) |
| 27 if isinstance(tests, test_collection.TestCollection): |
| 28 tests.test_completed() |
| 29 return r |
| 30 |
| 31 tries = 0 |
| 32 results = base_test_result.TestRunResults() |
| 33 while tries < self._env.max_tries and tests: |
| 34 if self._ShouldShard(): |
| 35 tests = test_collection.TestCollection(self._CreateShards(tests)) |
| 36 try_results = self._env.parallel_devices.pMap( |
| 37 run_tests_on_device, tests).pGet(None) |
| 38 fail_results = [] |
| 39 for try_result in try_results: |
| 40 for result in try_result.GetAll(): |
| 41 if result.GetType() in (base_test_result.ResultType.PASS, |
| 42 base_test_result.ResultType.SKIP): |
| 43 results.AddResult(result) |
| 44 else: |
| 45 fail_results.append(result) |
| 46 tests = [f.GetName() for f in fail_results] |
| 47 tries += 1 |
| 48 |
| 49 if fail_results: |
| 50 results.AddTestResults(fail_results) |
| 51 return results |
| 52 |
| 53 def _CreateShards(self, tests): |
| 54 raise NotImplementedError |
| 55 |
| 56 def _GetTests(self): |
| 57 raise NotImplementedError |
| 58 |
| 59 def _RunTest(self, device, test): |
| 60 raise NotImplementedError |
| 61 |
| 62 def _ShouldShard(self): |
| 63 raise NotImplementedError |
OLD | NEW |