Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import posixpath | 7 import posixpath |
| 8 import re | 8 import re |
| 9 import time | 9 import time |
| 10 | 10 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 self._CreateFlagChangerIfNeeded(device) | 256 self._CreateFlagChangerIfNeeded(device) |
| 257 self._flag_changers[str(device)].PushFlags( | 257 self._flag_changers[str(device)].PushFlags( |
| 258 add=flags.add, remove=flags.remove) | 258 add=flags.add, remove=flags.remove) |
| 259 | 259 |
| 260 try: | 260 try: |
| 261 device.RunShellCommand( | 261 device.RunShellCommand( |
| 262 ['log', '-p', 'i', '-t', _TAG, 'START %s' % test_name], | 262 ['log', '-p', 'i', '-t', _TAG, 'START %s' % test_name], |
| 263 check_return=True) | 263 check_return=True) |
| 264 time_ms = lambda: int(time.time() * 1e3) | 264 time_ms = lambda: int(time.time() * 1e3) |
| 265 start_ms = time_ms() | 265 start_ms = time_ms() |
| 266 output = device.StartInstrumentation( | 266 output_file = '/tmp/logcat/%s' % test_name |
|
jbudorick
2016/10/25 22:11:33
Use tempfile.NamedTemporaryFile as a context manag
| |
| 267 target, raw=True, extras=extras, timeout=timeout, retries=0) | 267 with device.GetLogcatMonitor(output_file=output_file) as logmon: |
| 268 output = device.StartInstrumentation( | |
| 269 target, raw=True, extras=extras, timeout=timeout, retries=0) | |
| 270 logmon.Close() | |
| 271 logcat = open(output_file, 'r').read() | |
| 272 os.remove(output_file) | |
| 268 finally: | 273 finally: |
| 269 device.RunShellCommand( | 274 device.RunShellCommand( |
| 270 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], | 275 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], |
| 271 check_return=True) | 276 check_return=True) |
| 272 duration_ms = time_ms() - start_ms | 277 duration_ms = time_ms() - start_ms |
| 273 if flags: | 278 if flags: |
| 274 self._flag_changers[str(device)].Restore() | 279 self._flag_changers[str(device)].Restore() |
| 275 if test_timeout_scale: | 280 if test_timeout_scale: |
| 276 valgrind_tools.SetChromeTimeoutScale( | 281 valgrind_tools.SetChromeTimeoutScale( |
| 277 device, self._test_instance.timeout_scale) | 282 device, self._test_instance.timeout_scale) |
| 278 | 283 |
| 279 # TODO(jbudorick): Make instrumentation tests output a JSON so this | 284 # TODO(jbudorick): Make instrumentation tests output a JSON so this |
| 280 # doesn't have to parse the output. | 285 # doesn't have to parse the output. |
| 281 result_code, result_bundle, statuses = ( | 286 result_code, result_bundle, statuses = ( |
| 282 self._test_instance.ParseAmInstrumentRawOutput(output)) | 287 self._test_instance.ParseAmInstrumentRawOutput(output)) |
| 283 results = self._test_instance.GenerateTestResults( | 288 results = self._test_instance.GenerateTestResults( |
| 284 result_code, result_bundle, statuses, start_ms, duration_ms) | 289 result_code, result_bundle, statuses, start_ms, duration_ms) |
| 290 for result in results: | |
| 291 result.SetLogcat(logcat) | |
| 285 | 292 |
| 286 # Update the result name if the test used flags. | 293 # Update the result name if the test used flags. |
| 287 if flags: | 294 if flags: |
| 288 for r in results: | 295 for r in results: |
| 289 if r.GetName() == test_name: | 296 if r.GetName() == test_name: |
| 290 r.SetName(test_display_name) | 297 r.SetName(test_display_name) |
| 291 | 298 |
| 292 # Add UNKNOWN results for any missing tests. | 299 # Add UNKNOWN results for any missing tests. |
| 293 iterable_test = test if isinstance(test, list) else [test] | 300 iterable_test = test if isinstance(test, list) else [test] |
| 294 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) | 301 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 timeout = v | 387 timeout = v |
| 381 break | 388 break |
| 382 else: | 389 else: |
| 383 logging.warning('Using default 1 minute timeout for %s', test_name) | 390 logging.warning('Using default 1 minute timeout for %s', test_name) |
| 384 timeout = 60 | 391 timeout = 60 |
| 385 | 392 |
| 386 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 393 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
| 387 | 394 |
| 388 return timeout | 395 return timeout |
| 389 | 396 |
| OLD | NEW |