OLD | NEW |
| (Empty) |
1 # Copyright (c) 2013 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 import fnmatch | |
6 import logging | |
7 import os | |
8 | |
9 from pylib import cmd_helper | |
10 from pylib.base import base_test_sharder | |
11 from pylib.gtest import test_runner | |
12 | |
13 class TestSharder(base_test_sharder.BaseTestSharder): | |
14 """Responsible for sharding the tests on the connected devices.""" | |
15 | |
16 def __init__(self, attached_devices, test_suite, gtest_filter, | |
17 test_arguments, timeout, cleanup_test_files, tool, | |
18 build_type, in_webkit_checkout): | |
19 super(TestSharder, self).__init__(attached_devices, build_type) | |
20 self.test_suite = test_suite | |
21 self.gtest_filter = gtest_filter or '' | |
22 self.test_arguments = test_arguments | |
23 self.timeout = timeout | |
24 self.cleanup_test_files = cleanup_test_files | |
25 self.tool = tool | |
26 self.in_webkit_checkout = in_webkit_checkout | |
27 self.all_tests = [] | |
28 if not self.gtest_filter: | |
29 # No filter has been specified, let's add all tests then. | |
30 self.all_tests, self.attached_devices = self._GetAllEnabledTests() | |
31 self.tests = self.all_tests | |
32 | |
33 def _GetAllEnabledTests(self): | |
34 """Get all enabled tests and available devices. | |
35 | |
36 Obtains a list of enabled tests from the test package on the device, | |
37 then filters it again using the diabled list on the host. | |
38 | |
39 Returns: | |
40 Tuple of (all enabled tests, available devices). | |
41 | |
42 Raises Exception if all devices failed. | |
43 """ | |
44 # TODO(frankf): This method is doing too much in a non-systematic way. | |
45 # If the intention is to drop flaky devices, why not go through all devices | |
46 # instead of breaking on the first succesfull run? | |
47 available_devices = list(self.attached_devices) | |
48 while available_devices: | |
49 try: | |
50 return (self._GetTestsFromDevice(available_devices[-1]), | |
51 available_devices) | |
52 except Exception as e: | |
53 logging.warning('Failed obtaining tests from %s %s', | |
54 available_devices[-1], e) | |
55 available_devices.pop() | |
56 | |
57 raise Exception('No device available to get the list of tests.') | |
58 | |
59 def _GetTestsFromDevice(self, device): | |
60 logging.info('Obtaining tests from %s', device) | |
61 runner = test_runner.TestRunner( | |
62 device, | |
63 self.test_suite, | |
64 self.gtest_filter, | |
65 self.test_arguments, | |
66 self.timeout, | |
67 self.cleanup_test_files, | |
68 self.tool, | |
69 0, | |
70 self.build_type, | |
71 self.in_webkit_checkout) | |
72 # The executable/apk needs to be copied before we can call GetAllTests. | |
73 runner.test_package.StripAndCopyExecutable() | |
74 all_tests = runner.test_package.GetAllTests() | |
75 disabled_list = runner.GetDisabledTests() | |
76 # Only includes tests that do not have any match in the disabled list. | |
77 all_tests = filter(lambda t: | |
78 not any([fnmatch.fnmatch(t, disabled_pattern) | |
79 for disabled_pattern in disabled_list]), | |
80 all_tests) | |
81 return all_tests | |
82 | |
83 def CreateShardedTestRunner(self, device, index): | |
84 """Creates a suite-specific test runner. | |
85 | |
86 Args: | |
87 device: Device serial where this shard will run. | |
88 index: Index of this device in the pool. | |
89 | |
90 Returns: | |
91 A TestRunner object. | |
92 """ | |
93 device_num = len(self.attached_devices) | |
94 shard_test_list = self.tests[index::device_num] | |
95 test_filter = ':'.join(shard_test_list) + self.gtest_filter | |
96 return test_runner.TestRunner( | |
97 device, | |
98 self.test_suite, | |
99 test_filter, | |
100 self.test_arguments, | |
101 self.timeout, | |
102 self.cleanup_test_files, self.tool, index, | |
103 self.build_type, | |
104 self.in_webkit_checkout) | |
OLD | NEW |