Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / build / android / pylib / local / device / local_device_test_run.py
blobcc17649882b5ca085ee41c21616f6d098d36d0cc
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.
5 import logging
7 from pylib import valgrind_tools
8 from pylib.base import base_test_result
9 from pylib.base import test_run
10 from pylib.base import test_collection
13 class LocalDeviceTestRun(test_run.TestRun):
15 def __init__(self, env, test_instance):
16 super(LocalDeviceTestRun, self).__init__(env, test_instance)
17 self._tools = {}
19 #override
20 def RunTests(self):
21 tests = self._GetTests()
23 def run_tests_on_device(dev, tests):
24 r = base_test_result.TestRunResults()
25 for test in tests:
26 try:
27 result = self._RunTest(dev, test)
28 if isinstance(result, base_test_result.BaseTestResult):
29 r.AddResult(result)
30 elif isinstance(result, list):
31 r.AddResults(result)
32 else:
33 raise Exception(
34 'Unexpected result type: %s' % type(result).__name__)
35 finally:
36 if isinstance(tests, test_collection.TestCollection):
37 tests.test_completed()
38 logging.info('Finished running tests on this device.')
39 return r
41 tries = 0
42 results = base_test_result.TestRunResults()
43 all_fail_results = {}
44 while tries < self._env.max_tries and tests:
45 logging.info('STARTING TRY #%d/%d', tries + 1, self._env.max_tries)
46 logging.info('Will run %d tests on %d devices: %s',
47 len(tests), len(self._env.devices),
48 ', '.join(str(d) for d in self._env.devices))
49 for t in tests:
50 logging.debug(' %s', t)
52 if self._ShouldShard():
53 tc = test_collection.TestCollection(self._CreateShards(tests))
54 try_results = self._env.parallel_devices.pMap(
55 run_tests_on_device, tc).pGet(None)
56 else:
57 try_results = self._env.parallel_devices.pMap(
58 run_tests_on_device, tests).pGet(None)
60 for try_result in try_results:
61 for result in try_result.GetAll():
62 if result.GetType() in (base_test_result.ResultType.PASS,
63 base_test_result.ResultType.SKIP):
64 results.AddResult(result)
65 else:
66 all_fail_results[result.GetName()] = result
68 results_names = set(r.GetName() for r in results.GetAll())
69 tests = [t for t in tests if self._GetTestName(t) not in results_names]
70 tries += 1
71 logging.info('FINISHED TRY #%d/%d', tries, self._env.max_tries)
72 if tests:
73 logging.info('%d failed tests remain.', len(tests))
74 else:
75 logging.info('All tests completed.')
77 all_unknown_test_names = set(self._GetTestName(t) for t in tests)
78 all_failed_test_names = set(all_fail_results.iterkeys())
80 unknown_tests = all_unknown_test_names.difference(all_failed_test_names)
81 failed_tests = all_failed_test_names.intersection(all_unknown_test_names)
83 if unknown_tests:
84 results.AddResults(
85 base_test_result.BaseTestResult(
86 u, base_test_result.ResultType.UNKNOWN)
87 for u in unknown_tests)
88 if failed_tests:
89 results.AddResults(all_fail_results[f] for f in failed_tests)
91 return results
93 def GetTool(self, device):
94 if not str(device) in self._tools:
95 self._tools[str(device)] = valgrind_tools.CreateTool(
96 self._env.tool, device)
97 return self._tools[str(device)]
99 def _CreateShards(self, tests):
100 raise NotImplementedError
102 def _GetTestName(self, test):
103 return test
105 def _GetTests(self):
106 raise NotImplementedError
108 def _RunTest(self, device, test):
109 raise NotImplementedError
111 def _ShouldShard(self):
112 raise NotImplementedError