OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Class for running instrumentation tests on a single device.""" | 5 """Class for running instrumentation tests on a single device.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 import sys | 10 import sys |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 if TestRunner._DEVICE_HAS_TEST_FILES.get(self.device, False): | 99 if TestRunner._DEVICE_HAS_TEST_FILES.get(self.device, False): |
100 logging.warning('Already copied test files to device %s, skipping.', | 100 logging.warning('Already copied test files to device %s, skipping.', |
101 self.device.old_interface.GetDevice()) | 101 self.device.old_interface.GetDevice()) |
102 return | 102 return |
103 | 103 |
104 test_data = _GetDataFilesForTestSuite(self.test_pkg.GetApkName()) | 104 test_data = _GetDataFilesForTestSuite(self.test_pkg.GetApkName()) |
105 if test_data: | 105 if test_data: |
106 # Make sure SD card is ready. | 106 # Make sure SD card is ready. |
107 self.device.WaitUntilFullyBooted(timeout=20) | 107 self.device.WaitUntilFullyBooted(timeout=20) |
108 for p in test_data: | 108 for p in test_data: |
109 self.device.old_interface.PushIfNeeded( | 109 self.device.PushChangedFiles( |
110 os.path.join(constants.DIR_SOURCE_ROOT, p), | 110 os.path.join(constants.DIR_SOURCE_ROOT, p), |
111 os.path.join(self.device.GetExternalStoragePath(), p)) | 111 os.path.join(self.device.GetExternalStoragePath(), p)) |
112 | 112 |
113 # TODO(frankf): Specify test data in this file as opposed to passing | 113 # TODO(frankf): Specify test data in this file as opposed to passing |
114 # as command-line. | 114 # as command-line. |
115 for dest_host_pair in self.options.test_data: | 115 for dest_host_pair in self.options.test_data: |
116 dst_src = dest_host_pair.split(':', 1) | 116 dst_src = dest_host_pair.split(':', 1) |
117 dst_layer = dst_src[0] | 117 dst_layer = dst_src[0] |
118 host_src = dst_src[1] | 118 host_src = dst_src[1] |
119 host_test_files_path = '%s/%s' % (constants.DIR_SOURCE_ROOT, host_src) | 119 host_test_files_path = '%s/%s' % (constants.DIR_SOURCE_ROOT, host_src) |
120 if os.path.exists(host_test_files_path): | 120 if os.path.exists(host_test_files_path): |
121 self.device.old_interface.PushIfNeeded( | 121 self.device.PushChangedFiles( |
122 host_test_files_path, | 122 host_test_files_path, |
123 '%s/%s/%s' % ( | 123 '%s/%s/%s' % ( |
124 self.device.GetExternalStoragePath(), | 124 self.device.GetExternalStoragePath(), |
125 TestRunner._DEVICE_DATA_DIR, | 125 TestRunner._DEVICE_DATA_DIR, |
126 dst_layer)) | 126 dst_layer)) |
127 self.tool.CopyFiles() | 127 self.tool.CopyFiles() |
128 TestRunner._DEVICE_HAS_TEST_FILES[ | 128 TestRunner._DEVICE_HAS_TEST_FILES[ |
129 self.device.old_interface.GetDevice()] = True | 129 self.device.old_interface.GetDevice()] = True |
130 | 130 |
131 def _GetInstrumentationArgs(self): | 131 def _GetInstrumentationArgs(self): |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 228 |
229 self.tool.CleanUpEnvironment() | 229 self.tool.CleanUpEnvironment() |
230 | 230 |
231 # The logic below relies on the test passing. | 231 # The logic below relies on the test passing. |
232 if not raw_result or raw_result.GetStatusCode(): | 232 if not raw_result or raw_result.GetStatusCode(): |
233 return | 233 return |
234 | 234 |
235 self.TearDownPerfMonitoring(test) | 235 self.TearDownPerfMonitoring(test) |
236 | 236 |
237 if self.coverage_dir: | 237 if self.coverage_dir: |
238 self.device.old_interface.Adb().Pull( | 238 self.device.PullFile( |
239 self.coverage_device_file, self.coverage_host_file) | 239 self.coverage_device_file, self.coverage_host_file) |
240 self.device.RunShellCommand( | 240 self.device.RunShellCommand( |
241 'rm -f %s' % self.coverage_device_file) | 241 'rm -f %s' % self.coverage_device_file) |
242 | 242 |
243 def TearDownPerfMonitoring(self, test): | 243 def TearDownPerfMonitoring(self, test): |
244 """Cleans up performance monitoring if the specified test required it. | 244 """Cleans up performance monitoring if the specified test required it. |
245 | 245 |
246 Args: | 246 Args: |
247 test: The name of the test that was just run. | 247 test: The name of the test that was just run. |
248 Raises: | 248 Raises: |
(...skipping 10 matching lines...) Expand all Loading... |
259 # If the test is set to run on a specific device type only (IE: only | 259 # If the test is set to run on a specific device type only (IE: only |
260 # tablet or phone) and it is being run on the wrong device, the test | 260 # tablet or phone) and it is being run on the wrong device, the test |
261 # just quits and does not do anything. The java test harness will still | 261 # just quits and does not do anything. The java test harness will still |
262 # print the appropriate annotation for us, but will add --NORUN-- for | 262 # print the appropriate annotation for us, but will add --NORUN-- for |
263 # us so we know to ignore the results. | 263 # us so we know to ignore the results. |
264 # The --NORUN-- tag is managed by MainActivityTestBase.java | 264 # The --NORUN-- tag is managed by MainActivityTestBase.java |
265 if regex.group(1) != '--NORUN--': | 265 if regex.group(1) != '--NORUN--': |
266 | 266 |
267 # Obtain the relevant perf data. The data is dumped to a | 267 # Obtain the relevant perf data. The data is dumped to a |
268 # JSON formatted file. | 268 # JSON formatted file. |
269 json_string = self.device.old_interface.GetProtectedFileContents( | 269 json_string = self.device.ReadFile( |
270 '/data/data/com.google.android.apps.chrome/files/PerfTestData.txt') | 270 '/data/data/com.google.android.apps.chrome/files/PerfTestData.txt', |
| 271 as_root=True) |
271 | 272 |
272 if json_string: | 273 if json_string: |
273 json_string = '\n'.join(json_string) | 274 json_string = '\n'.join(json_string) |
274 else: | 275 else: |
275 raise Exception('Perf file does not exist or is empty') | 276 raise Exception('Perf file does not exist or is empty') |
276 | 277 |
277 if self.options.save_perf_json: | 278 if self.options.save_perf_json: |
278 json_local_file = '/tmp/chromium-android-perf-json-' + raw_test_name | 279 json_local_file = '/tmp/chromium-android-perf-json-' + raw_test_name |
279 with open(json_local_file, 'w') as f: | 280 with open(json_local_file, 'w') as f: |
280 f.write(json_string) | 281 f.write(json_string) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 duration_ms = 0 | 387 duration_ms = 0 |
387 message = str(e) | 388 message = str(e) |
388 if not message: | 389 if not message: |
389 message = 'No information.' | 390 message = 'No information.' |
390 results.AddResult(test_result.InstrumentationTestResult( | 391 results.AddResult(test_result.InstrumentationTestResult( |
391 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, | 392 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, |
392 log=message)) | 393 log=message)) |
393 raw_result = None | 394 raw_result = None |
394 self.TestTeardown(test, raw_result) | 395 self.TestTeardown(test, raw_result) |
395 return (results, None if results.DidRunPass() else test) | 396 return (results, None if results.DidRunPass() else test) |
OLD | NEW |