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

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

Issue 1411153003: Android GTest Runner: Create flags & test list files only when required (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use null context manager Created 5 years, 2 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
« no previous file with comments | « no previous file | testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 imp 5 import imp
6 import itertools 6 import itertools
7 import os 7 import os
8 import posixpath 8 import posixpath
9 9
10 from devil.android import device_errors 10 from devil.android import device_errors
11 from devil.android import device_temp_file 11 from devil.android import device_temp_file
12 from devil.android import ports 12 from devil.android import ports
13 from incremental_install import installer 13 from incremental_install import installer
14 from pylib import constants 14 from pylib import constants
15 from pylib.gtest import gtest_test_instance 15 from pylib.gtest import gtest_test_instance
16 from pylib.local import local_test_server_spawner 16 from pylib.local import local_test_server_spawner
17 from pylib.local.device import local_device_environment 17 from pylib.local.device import local_device_environment
18 from pylib.local.device import local_device_test_run 18 from pylib.local.device import local_device_test_run
19 19
20 _COMMAND_LINE_FLAGS_SUPPORTED = True 20 _COMMAND_LINE_FLAGS_SUPPORTED = True
21 21
22 _MAX_INLINE_FLAGS_LENGTH = 50 # Arbitrarily chosen.
22 _EXTRA_COMMAND_LINE_FILE = ( 23 _EXTRA_COMMAND_LINE_FILE = (
23 'org.chromium.native_test.NativeTestActivity.CommandLineFile') 24 'org.chromium.native_test.NativeTestActivity.CommandLineFile')
24 _EXTRA_COMMAND_LINE_FLAGS = ( 25 _EXTRA_COMMAND_LINE_FLAGS = (
25 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') 26 'org.chromium.native_test.NativeTestActivity.CommandLineFlags')
26 _EXTRA_TEST_LIST = ( 27 _EXTRA_TEST_LIST = (
27 'org.chromium.native_test.NativeTestInstrumentationTestRunner' 28 'org.chromium.native_test.NativeTestInstrumentationTestRunner'
28 '.TestList') 29 '.TestList')
30 _EXTRA_TEST = (
31 'org.chromium.native_test.NativeTestInstrumentationTestRunner'
32 '.Test')
29 33
30 _MAX_SHARD_SIZE = 256 34 _MAX_SHARD_SIZE = 256
31 _SECONDS_TO_NANOS = int(1e9) 35 _SECONDS_TO_NANOS = int(1e9)
32 36
33 # The amount of time a test executable may run before it gets killed. 37 # The amount of time a test executable may run before it gets killed.
34 _TEST_TIMEOUT_SECONDS = 30*60 38 _TEST_TIMEOUT_SECONDS = 30*60
35 39
36 # TODO(jbudorick): Move this up to the test instance if the net test server is 40 # TODO(jbudorick): Move this up to the test instance if the net test server is
37 # handled outside of the APK for the remote_device environment. 41 # handled outside of the APK for the remote_device environment.
38 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ 42 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [
39 'components_browsertests', 'content_unittests', 'content_browsertests', 43 'components_browsertests', 'content_unittests', 'content_browsertests',
40 'net_unittests', 'unit_tests' 44 'net_unittests', 'unit_tests'
41 ] 45 ]
42 46
47 # No-op context manager. If we used Python 3, we could change this to
48 # contextlib.ExitStack()
49 class _NullContextManager(object):
jbudorick 2015/10/20 21:17:29 I may wind up extracting this at some point should
50 def __enter__(self):
51 pass
52 def __exit__(self, *args):
53 pass
54
55
43 # TODO(jbudorick): Move this inside _ApkDelegate once TestPackageApk is gone. 56 # TODO(jbudorick): Move this inside _ApkDelegate once TestPackageApk is gone.
44 def PullAppFilesImpl(device, package, files, directory): 57 def PullAppFilesImpl(device, package, files, directory):
45 device_dir = device.GetApplicationDataDirectory(package) 58 device_dir = device.GetApplicationDataDirectory(package)
46 host_dir = os.path.join(directory, str(device)) 59 host_dir = os.path.join(directory, str(device))
47 for f in files: 60 for f in files:
48 device_file = posixpath.join(device_dir, f) 61 device_file = posixpath.join(device_dir, f)
49 host_file = os.path.join(host_dir, *f.split(posixpath.sep)) 62 host_file = os.path.join(host_dir, *f.split(posixpath.sep))
50 host_file_base, ext = os.path.splitext(host_file) 63 host_file_base, ext = os.path.splitext(host_file)
51 for i in itertools.count(): 64 for i in itertools.count():
52 host_file = '%s_%d%s' % (host_file_base, i, ext) 65 host_file = '%s_%d%s' % (host_file_base, i, ext)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 127
115 if ('timeout' in kwargs 128 if ('timeout' in kwargs
116 and gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT not in extras): 129 and gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT not in extras):
117 # Make sure the instrumentation doesn't kill the test before the 130 # Make sure the instrumentation doesn't kill the test before the
118 # scripts do. The provided timeout value is in seconds, but the 131 # scripts do. The provided timeout value is in seconds, but the
119 # instrumentation deals with nanoseconds because that's how Android 132 # instrumentation deals with nanoseconds because that's how Android
120 # handles time. 133 # handles time.
121 extras[gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT] = int( 134 extras[gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT] = int(
122 kwargs['timeout'] * _SECONDS_TO_NANOS) 135 kwargs['timeout'] * _SECONDS_TO_NANOS)
123 136
124 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: 137 command_line_file = _NullContextManager()
jbudorick 2015/10/20 21:17:29 hm, not quite what I had in mind but this is fine
125 device.WriteFile(command_line_file.name, '_ %s' % flags if flags else '_') 138 if flags:
126 extras[_EXTRA_COMMAND_LINE_FILE] = command_line_file.name 139 if len(flags) > _MAX_INLINE_FLAGS_LENGTH:
140 command_line_file = device_temp_file.DeviceTempFile(device.adb)
141 device.WriteFile(command_line_file.name, '_ %s' % flags)
142 extras[_EXTRA_COMMAND_LINE_FILE] = command_line_file.name
143 else:
144 extras[_EXTRA_COMMAND_LINE_FLAGS] = flags
127 145
128 with device_temp_file.DeviceTempFile(device.adb) as test_list_file: 146 test_list_file = _NullContextManager()
129 if test: 147 if test:
130 device.WriteFile(test_list_file.name, '\n'.join(test)) 148 if len(test) > 1:
131 extras[_EXTRA_TEST_LIST] = test_list_file.name 149 test_list_file = device_temp_file.DeviceTempFile(device.adb)
150 device.WriteFile(test_list_file.name, '\n'.join(test))
151 extras[_EXTRA_TEST_LIST] = test_list_file.name
152 else:
153 extras[_EXTRA_TEST] = test[0]
132 154
133 try: 155 with command_line_file, test_list_file:
134 return device.StartInstrumentation( 156 try:
135 self._component, extras=extras, raw=False, **kwargs) 157 return device.StartInstrumentation(
136 except Exception: 158 self._component, extras=extras, raw=False, **kwargs)
137 device.ForceStop(self._package) 159 except Exception:
138 raise 160 device.ForceStop(self._package)
161 raise
139 162
140 def PullAppFiles(self, device, files, directory): 163 def PullAppFiles(self, device, files, directory):
141 PullAppFilesImpl(device, self._package, files, directory) 164 PullAppFilesImpl(device, self._package, files, directory)
142 165
143 def Clear(self, device): 166 def Clear(self, device):
144 device.ClearApplicationState(self._package, permissions=self._permissions) 167 device.ClearApplicationState(self._package, permissions=self._permissions)
145 168
146 169
147 class _ExeDelegate(object): 170 class _ExeDelegate(object):
148 def __init__(self, tr, exe): 171 def __init__(self, tr, exe):
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 def TearDown(self): 340 def TearDown(self):
318 @local_device_test_run.handle_shard_failures 341 @local_device_test_run.handle_shard_failures
319 def individual_device_tear_down(dev): 342 def individual_device_tear_down(dev):
320 for s in self._servers.get(str(dev), []): 343 for s in self._servers.get(str(dev), []):
321 s.TearDown() 344 s.TearDown()
322 345
323 tool = self.GetTool(dev) 346 tool = self.GetTool(dev)
324 tool.CleanUpEnvironment() 347 tool.CleanUpEnvironment()
325 348
326 self._env.parallel_devices.pMap(individual_device_tear_down) 349 self._env.parallel_devices.pMap(individual_device_tear_down)
OLDNEW
« no previous file with comments | « no previous file | testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698