OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 | 5 |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 | 8 |
9 from pylib import constants | 9 from pylib import constants |
10 from pylib import ports | 10 from pylib import ports |
11 from pylib.base import test_run | 11 from pylib.base import test_run |
12 from pylib.device import device_errors | 12 from pylib.device import device_errors |
13 from pylib.gtest import gtest_test_instance | 13 from pylib.gtest import gtest_test_instance |
14 | 14 |
15 from pylib.local import local_test_server_spawner | 15 from pylib.local import local_test_server_spawner |
16 from pylib.local.device import local_device_environment | 16 from pylib.local.device import local_device_environment |
17 from pylib.local.device import local_device_test_run | 17 from pylib.local.device import local_device_test_run |
18 from pylib.utils import apk_helper | 18 from pylib.utils import apk_helper |
19 from pylib.utils import device_temp_file | 19 from pylib.utils import device_temp_file |
20 | 20 |
21 _COMMAND_LINE_FLAGS_SUPPORTED = True | 21 _COMMAND_LINE_FLAGS_SUPPORTED = True |
22 | 22 |
23 _EXTRA_COMMAND_LINE_FILE = ( | 23 _EXTRA_COMMAND_LINE_FILE = ( |
24 'org.chromium.native_test.NativeTestActivity.CommandLineFile') | 24 'org.chromium.native_test.NativeTestActivity.CommandLineFile') |
25 _EXTRA_COMMAND_LINE_FLAGS = ( | 25 _EXTRA_COMMAND_LINE_FLAGS = ( |
26 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') | 26 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') |
27 _EXTRA_NATIVE_TEST_ACTIVITY = ( | |
28 'org.chromium.native_test.NativeTestInstrumentationTestRunner' | |
29 '.NativeTestActivity') | |
30 | 27 |
31 _MAX_SHARD_SIZE = 256 | 28 _MAX_SHARD_SIZE = 256 |
32 | 29 |
33 # TODO(jbudorick): Move this up to the test instance if the net test server is | 30 # TODO(jbudorick): Move this up to the test instance if the net test server is |
34 # handled outside of the APK for the remote_device environment. | 31 # handled outside of the APK for the remote_device environment. |
35 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ | 32 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ |
36 'components_browsertests', 'content_unittests', 'content_browsertests', | 33 'components_browsertests', 'content_unittests', 'content_browsertests', |
37 'net_unittests', 'unit_tests' | 34 'net_unittests', 'unit_tests' |
38 ] | 35 ] |
39 | 36 |
40 class _ApkDelegate(object): | 37 class _ApkDelegate(object): |
41 def __init__(self, apk): | 38 def __init__(self, apk): |
42 self._apk = apk | 39 self._apk = apk |
43 | 40 self._package = apk_helper.GetPackageName(self._apk) |
44 helper = apk_helper.ApkHelper(self._apk) | 41 self._runner = apk_helper.GetInstrumentationName(self._apk) |
45 self._activity = helper.GetActivityName() | |
46 self._package = helper.GetPackageName() | |
47 self._runner = helper.GetInstrumentationName() | |
48 self._component = '%s/%s' % (self._package, self._runner) | 42 self._component = '%s/%s' % (self._package, self._runner) |
49 self._enable_test_server_spawner = False | 43 self._enable_test_server_spawner = False |
50 | 44 |
51 def Install(self, device): | 45 def Install(self, device): |
52 device.Install(self._apk) | 46 device.Install(self._apk) |
53 | 47 |
54 def RunWithFlags(self, device, flags, **kwargs): | 48 def RunWithFlags(self, device, flags, **kwargs): |
55 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: | 49 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: |
56 device.WriteFile(command_line_file.name, '_ %s' % flags) | 50 device.WriteFile(command_line_file.name, '_ %s' % flags) |
57 | 51 |
58 extras = { | 52 extras = { |
59 _EXTRA_COMMAND_LINE_FILE: command_line_file.name, | 53 _EXTRA_COMMAND_LINE_FILE: command_line_file.name, |
60 _EXTRA_NATIVE_TEST_ACTIVITY: self._activity, | |
61 } | 54 } |
62 | 55 |
63 return device.StartInstrumentation( | 56 return device.StartInstrumentation( |
64 self._component, extras=extras, raw=False, **kwargs) | 57 self._component, extras=extras, raw=False, **kwargs) |
65 | 58 |
66 def Clear(self, device): | 59 def Clear(self, device): |
67 device.ClearApplicationState(self._package) | 60 device.ClearApplicationState(self._package) |
68 | 61 |
69 | 62 |
70 class _ExeDelegate(object): | 63 class _ExeDelegate(object): |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 125 |
133 if self._test_instance.apk: | 126 if self._test_instance.apk: |
134 self._delegate = _ApkDelegate(self._test_instance.apk) | 127 self._delegate = _ApkDelegate(self._test_instance.apk) |
135 elif self._test_instance.exe: | 128 elif self._test_instance.exe: |
136 self._delegate = _ExeDelegate(self, self._test_instance.exe) | 129 self._delegate = _ExeDelegate(self, self._test_instance.exe) |
137 | 130 |
138 self._servers = {} | 131 self._servers = {} |
139 | 132 |
140 #override | 133 #override |
141 def TestPackage(self): | 134 def TestPackage(self): |
142 return self._test_instance.suite | 135 return self._test_instance._suite |
143 | 136 |
144 #override | 137 #override |
145 def SetUp(self): | 138 def SetUp(self): |
146 | 139 |
147 def individual_device_set_up(dev, host_device_tuples): | 140 def individual_device_set_up(dev, host_device_tuples): |
148 # Install test APK. | 141 # Install test APK. |
149 self._delegate.Install(dev) | 142 self._delegate.Install(dev) |
150 | 143 |
151 # Push data dependencies. | 144 # Push data dependencies. |
152 external_storage = dev.GetExternalStoragePath() | 145 external_storage = dev.GetExternalStoragePath() |
(...skipping 13 matching lines...) Expand all Loading... |
166 | 159 |
167 self._env.parallel_devices.pMap(individual_device_set_up, | 160 self._env.parallel_devices.pMap(individual_device_set_up, |
168 self._test_instance.GetDataDependencies()) | 161 self._test_instance.GetDataDependencies()) |
169 | 162 |
170 #override | 163 #override |
171 def _ShouldShard(self): | 164 def _ShouldShard(self): |
172 return True | 165 return True |
173 | 166 |
174 #override | 167 #override |
175 def _CreateShards(self, tests): | 168 def _CreateShards(self, tests): |
176 if self._test_instance.suite in gtest_test_instance.BROWSER_TEST_SUITES: | 169 device_count = len(self._env.devices) |
177 return tests | 170 shards = [] |
178 else: | 171 for i in xrange(0, device_count): |
179 device_count = len(self._env.devices) | 172 unbounded_shard = tests[i::device_count] |
180 shards = [] | 173 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] |
181 for i in xrange(0, device_count): | 174 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] |
182 unbounded_shard = tests[i::device_count] | 175 return [':'.join(s) for s in shards] |
183 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] | |
184 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] | |
185 return [':'.join(s) for s in shards] | |
186 | 176 |
187 #override | 177 #override |
188 def _GetTests(self): | 178 def _GetTests(self): |
189 tests = self._delegate.RunWithFlags( | 179 tests = self._delegate.RunWithFlags( |
190 self._env.devices[0], '--gtest_list_tests') | 180 self._env.devices[0], '--gtest_list_tests') |
191 tests = gtest_test_instance.ParseGTestListTests(tests) | 181 tests = gtest_test_instance.ParseGTestListTests(tests) |
192 tests = self._test_instance.FilterTests(tests) | 182 tests = self._test_instance.FilterTests(tests) |
193 return tests | 183 return tests |
194 | 184 |
195 #override | 185 #override |
196 def _RunTest(self, device, test): | 186 def _RunTest(self, device, test): |
197 # Run the test. | 187 # Run the test. |
198 output = self._delegate.RunWithFlags( | 188 output = self._delegate.RunWithFlags(device, '--gtest_filter=%s' % test, |
199 device, '--gtest_filter=%s' % test, timeout=900, retries=0) | 189 timeout=900, retries=0) |
200 for s in self._servers[str(device)]: | 190 for s in self._servers[str(device)]: |
201 s.Reset() | 191 s.Reset() |
202 self._delegate.Clear(device) | 192 self._delegate.Clear(device) |
203 | 193 |
204 # Parse the output. | 194 # Parse the output. |
205 # TODO(jbudorick): Transition test scripts away from parsing stdout. | 195 # TODO(jbudorick): Transition test scripts away from parsing stdout. |
206 results = self._test_instance.ParseGTestOutput(output) | 196 results = self._test_instance.ParseGTestOutput(output) |
207 return results | 197 return results |
208 | 198 |
209 #override | 199 #override |
210 def TearDown(self): | 200 def TearDown(self): |
211 def individual_device_tear_down(dev): | 201 def individual_device_tear_down(dev): |
212 for s in self._servers[str(dev)]: | 202 for s in self._servers[str(dev)]: |
213 s.TearDown() | 203 s.TearDown() |
214 | 204 |
215 self._env.parallel_devices.pMap(individual_device_tear_down) | 205 self._env.parallel_devices.pMap(individual_device_tear_down) |
216 | 206 |
OLD | NEW |