Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: build/android/pylib/local/device/local_device_gtest_run.py

Issue 1358593002: [Android] Switch gtests to platform mode. (RELAND) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import itertools 5 import itertools
6 import logging
7 import os 6 import os
8 import posixpath 7 import posixpath
9 8
10 from devil.android import device_errors 9 from devil.android import device_errors
11 from devil.android import device_temp_file 10 from devil.android import device_temp_file
12 from devil.android import ports 11 from devil.android import ports
13 from pylib import constants 12 from pylib import constants
14 from pylib.gtest import gtest_test_instance 13 from pylib.gtest import gtest_test_instance
15 from pylib.local import local_test_server_spawner 14 from pylib.local import local_test_server_spawner
16 from pylib.local.device import local_device_environment 15 from pylib.local.device import local_device_environment
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 100
102 def Install(self, device): 101 def Install(self, device):
103 # TODO(jbudorick): Look into merging this with normal data deps pushing if 102 # TODO(jbudorick): Look into merging this with normal data deps pushing if
104 # executables become supported on nonlocal environments. 103 # executables become supported on nonlocal environments.
105 host_device_tuples = [(self._exe_host_path, self._exe_device_path)] 104 host_device_tuples = [(self._exe_host_path, self._exe_device_path)]
106 if self._deps_host_path: 105 if self._deps_host_path:
107 host_device_tuples.append((self._deps_host_path, self._deps_device_path)) 106 host_device_tuples.append((self._deps_host_path, self._deps_device_path))
108 device.PushChangedFiles(host_device_tuples) 107 device.PushChangedFiles(host_device_tuples)
109 108
110 def Run(self, test, device, flags=None, **kwargs): 109 def Run(self, test, device, flags=None, **kwargs):
111 cmd = [ 110 tool = self._test_run.GetTool(device).GetTestWrapper()
112 self._test_run.GetTool(device).GetTestWrapper(), 111 if tool:
113 self._exe_device_path, 112 cmd = [tool]
114 ] 113 else:
114 cmd = []
115 cmd.append(self._exe_device_path)
116
115 if test: 117 if test:
116 cmd.append('--gtest_filter=%s' % ':'.join(test)) 118 cmd.append('--gtest_filter=%s' % ':'.join(test))
117 if flags: 119 if flags:
118 cmd.append(flags) 120 cmd.append(flags)
119 cwd = constants.TEST_EXECUTABLE_DIR 121 cwd = constants.TEST_EXECUTABLE_DIR
120 122
121 env = { 123 env = {
122 'LD_LIBRARY_PATH': 124 'LD_LIBRARY_PATH':
123 '%s/%s_deps' % (constants.TEST_EXECUTABLE_DIR, self._exe_file_name), 125 '%s/%s_deps' % (constants.TEST_EXECUTABLE_DIR, self._exe_file_name),
124 } 126 }
125 try: 127 try:
126 gcov_strip_depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP'] 128 gcov_strip_depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
127 external = device.GetExternalStoragePath() 129 external = device.GetExternalStoragePath()
128 env['GCOV_PREFIX'] = '%s/gcov' % external 130 env['GCOV_PREFIX'] = '%s/gcov' % external
129 env['GCOV_PREFIX_STRIP'] = gcov_strip_depth 131 env['GCOV_PREFIX_STRIP'] = gcov_strip_depth
130 except (device_errors.CommandFailedError, KeyError): 132 except (device_errors.CommandFailedError, KeyError):
131 pass 133 pass
132 134
133 # TODO(jbudorick): Switch to just RunShellCommand once perezju@'s CL 135 output = device.RunShellCommand(
134 # for long shell commands lands. 136 cmd, cwd=cwd, env=env, check_return=True, large_output=True, **kwargs)
135 with device_temp_file.DeviceTempFile(device.adb) as script_file:
136 script_contents = ' '.join(cmd)
137 logging.info('script contents: %r', script_contents)
138 device.WriteFile(script_file.name, script_contents)
139 output = device.RunShellCommand(['sh', script_file.name], cwd=cwd,
140 env=env, **kwargs)
141 return output 137 return output
142 138
143 def PullAppFiles(self, device, files, directory): 139 def PullAppFiles(self, device, files, directory):
144 pass 140 pass
145 141
146 def Clear(self, device): 142 def Clear(self, device):
147 device.KillAll(self._exe_file_name, blocking=True, timeout=30, quiet=True) 143 device.KillAll(self._exe_file_name, blocking=True, timeout=30, quiet=True)
148 144
149 145
150 class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): 146 class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun):
(...skipping 10 matching lines...) Expand all
161 157
162 self._servers = {} 158 self._servers = {}
163 159
164 #override 160 #override
165 def TestPackage(self): 161 def TestPackage(self):
166 return self._test_instance.suite 162 return self._test_instance.suite
167 163
168 #override 164 #override
169 def SetUp(self): 165 def SetUp(self):
170 166
167 @local_device_test_run.handle_shard_failures
171 def individual_device_set_up(dev, host_device_tuples): 168 def individual_device_set_up(dev, host_device_tuples):
172 # Install test APK. 169 # Install test APK.
173 self._delegate.Install(dev) 170 self._delegate.Install(dev)
174 171
175 # Push data dependencies. 172 # Push data dependencies.
176 external_storage = dev.GetExternalStoragePath() 173 external_storage = dev.GetExternalStoragePath()
177 host_device_tuples = [ 174 host_device_tuples = [
178 (h, d if d is not None else external_storage) 175 (h, d if d is not None else external_storage)
179 for h, d in host_device_tuples] 176 for h, d in host_device_tuples]
180 dev.PushChangedFiles(host_device_tuples) 177 dev.PushChangedFiles(host_device_tuples)
(...skipping 19 matching lines...) Expand all
200 device_count = len(self._env.devices) 197 device_count = len(self._env.devices)
201 shards = [] 198 shards = []
202 for i in xrange(0, device_count): 199 for i in xrange(0, device_count):
203 unbounded_shard = tests[i::device_count] 200 unbounded_shard = tests[i::device_count]
204 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] 201 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE]
205 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] 202 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)]
206 return shards 203 return shards
207 204
208 #override 205 #override
209 def _GetTests(self): 206 def _GetTests(self):
210 tests = self._delegate.Run( 207 @local_device_test_run.handle_shard_failures
211 None, self._env.devices[0], flags='--gtest_list_tests') 208 def list_tests(dev):
212 tests = gtest_test_instance.ParseGTestListTests(tests) 209 tests = self._delegate.Run(
213 tests = self._test_instance.FilterTests(tests) 210 None, dev, flags='--gtest_list_tests', timeout=10)
211 tests = gtest_test_instance.ParseGTestListTests(tests)
212 tests = self._test_instance.FilterTests(tests)
213 return tests
214
215 test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None)
216 tests = list(sorted(set().union(*[set(tl) for tl in test_lists if tl])))
214 return tests 217 return tests
215 218
216 #override 219 #override
217 def _RunTest(self, device, test): 220 def _RunTest(self, device, test):
218 # Run the test. 221 # Run the test.
219 timeout = 900 * self.GetTool(device).GetTimeoutScale() 222 timeout = 900 * self.GetTool(device).GetTimeoutScale()
220 output = self._delegate.Run( 223 output = self._delegate.Run(
221 test, device, timeout=timeout, retries=0) 224 test, device, timeout=timeout, retries=0)
222 for s in self._servers[str(device)]: 225 for s in self._servers[str(device)]:
223 s.Reset() 226 s.Reset()
224 if self._test_instance.app_files: 227 if self._test_instance.app_files:
225 self._delegate.PullAppFiles(device, self._test_instance.app_files, 228 self._delegate.PullAppFiles(device, self._test_instance.app_files,
226 self._test_instance.app_file_dir) 229 self._test_instance.app_file_dir)
227 self._delegate.Clear(device) 230 self._delegate.Clear(device)
228 231
229 # Parse the output. 232 # Parse the output.
230 # TODO(jbudorick): Transition test scripts away from parsing stdout. 233 # TODO(jbudorick): Transition test scripts away from parsing stdout.
231 results = self._test_instance.ParseGTestOutput(output) 234 results = self._test_instance.ParseGTestOutput(output)
232 return results 235 return results
233 236
234 #override 237 #override
235 def TearDown(self): 238 def TearDown(self):
239 @local_device_test_run.handle_shard_failures
236 def individual_device_tear_down(dev): 240 def individual_device_tear_down(dev):
237 for s in self._servers[str(dev)]: 241 for s in self._servers[str(dev)]:
238 s.TearDown() 242 s.TearDown()
239 243
240 self._env.parallel_devices.pMap(individual_device_tear_down) 244 self._env.parallel_devices.pMap(individual_device_tear_down)
241 245
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698