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 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 = [ |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 | 118 |
115 if ('timeout' in kwargs | 119 if ('timeout' in kwargs |
116 and gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT not in extras): | 120 and gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT not in extras): |
117 # Make sure the instrumentation doesn't kill the test before the | 121 # Make sure the instrumentation doesn't kill the test before the |
118 # scripts do. The provided timeout value is in seconds, but the | 122 # scripts do. The provided timeout value is in seconds, but the |
119 # instrumentation deals with nanoseconds because that's how Android | 123 # instrumentation deals with nanoseconds because that's how Android |
120 # handles time. | 124 # handles time. |
121 extras[gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT] = int( | 125 extras[gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT] = int( |
122 kwargs['timeout'] * _SECONDS_TO_NANOS) | 126 kwargs['timeout'] * _SECONDS_TO_NANOS) |
123 | 127 |
124 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: | 128 command_line_file = None |
jbudorick
2015/10/20 17:41:23
I'll be honest, this is a lot messier than the pre
agrieve
2015/10/20 18:36:55
Did some googling and came up with:
https://docs.p
| |
125 device.WriteFile(command_line_file.name, '_ %s' % flags if flags else '_') | 129 if flags: |
126 extras[_EXTRA_COMMAND_LINE_FILE] = command_line_file.name | 130 if len(flags) > _MAX_INLINE_FLAGS_LENGTH: |
131 command_line_file = device_temp_file.DeviceTempFile(device.adb) | |
132 device.WriteFile(command_line_file.name, '_ %s' % flags) | |
133 extras[_EXTRA_COMMAND_LINE_FILE] = command_line_file.name | |
134 else: | |
135 extras[_EXTRA_COMMAND_LINE_FLAGS] = flags | |
127 | 136 |
128 with device_temp_file.DeviceTempFile(device.adb) as test_list_file: | 137 test_list_file = None |
129 if test: | 138 if test: |
130 device.WriteFile(test_list_file.name, '\n'.join(test)) | 139 if len(test) > 1: |
131 extras[_EXTRA_TEST_LIST] = test_list_file.name | 140 test_list_file = device_temp_file.DeviceTempFile(device.adb) |
141 device.WriteFile(test_list_file.name, '\n'.join(test)) | |
142 extras[_EXTRA_TEST_LIST] = test_list_file.name | |
143 else: | |
144 extras[_EXTRA_TEST] = test[0] | |
132 | 145 |
133 try: | 146 try: |
134 return device.StartInstrumentation( | 147 return device.StartInstrumentation( |
135 self._component, extras=extras, raw=False, **kwargs) | 148 self._component, extras=extras, raw=False, **kwargs) |
136 except Exception: | 149 except Exception: |
137 device.ForceStop(self._package) | 150 device.ForceStop(self._package) |
138 raise | 151 raise |
152 finally: | |
153 if command_line_file: | |
154 command_line_file.close() | |
155 if test_list_file: | |
156 test_list_file.close() | |
139 | 157 |
140 def PullAppFiles(self, device, files, directory): | 158 def PullAppFiles(self, device, files, directory): |
141 PullAppFilesImpl(device, self._package, files, directory) | 159 PullAppFilesImpl(device, self._package, files, directory) |
142 | 160 |
143 def Clear(self, device): | 161 def Clear(self, device): |
144 device.ClearApplicationState(self._package, permissions=self._permissions) | 162 device.ClearApplicationState(self._package, permissions=self._permissions) |
145 | 163 |
146 | 164 |
147 class _ExeDelegate(object): | 165 class _ExeDelegate(object): |
148 def __init__(self, tr, exe): | 166 def __init__(self, tr, exe): |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 def TearDown(self): | 335 def TearDown(self): |
318 @local_device_test_run.handle_shard_failures | 336 @local_device_test_run.handle_shard_failures |
319 def individual_device_tear_down(dev): | 337 def individual_device_tear_down(dev): |
320 for s in self._servers.get(str(dev), []): | 338 for s in self._servers.get(str(dev), []): |
321 s.TearDown() | 339 s.TearDown() |
322 | 340 |
323 tool = self.GetTool(dev) | 341 tool = self.GetTool(dev) |
324 tool.CleanUpEnvironment() | 342 tool.CleanUpEnvironment() |
325 | 343 |
326 self._env.parallel_devices.pMap(individual_device_tear_down) | 344 self._env.parallel_devices.pMap(individual_device_tear_down) |
OLD | NEW |