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.
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
)
21 tests
= self
._GetTests
()
23 def run_tests_on_device(dev
, tests
):
24 r
= base_test_result
.TestRunResults()
27 result
= self
._RunTest
(dev
, test
)
28 if isinstance(result
, base_test_result
.BaseTestResult
):
30 elif isinstance(result
, list):
34 'Unexpected result type: %s' % type(result
).__name
__)
36 if isinstance(tests
, test_collection
.TestCollection
):
37 tests
.test_completed()
38 logging
.info('Finished running tests on this device.')
42 results
= base_test_result
.TestRunResults()
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
))
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)
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
)
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
]
71 logging
.info('FINISHED TRY #%d/%d', tries
, self
._env
.max_tries
)
73 logging
.info('%d failed tests remain.', len(tests
))
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
)
85 base_test_result
.BaseTestResult(
86 u
, base_test_result
.ResultType
.UNKNOWN
)
87 for u
in unknown_tests
)
89 results
.AddResults(all_fail_results
[f
] for f
in failed_tests
)
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
):
106 raise NotImplementedError
108 def _RunTest(self
, device
, test
):
109 raise NotImplementedError
111 def _ShouldShard(self
):
112 raise NotImplementedError