| 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 contextlib | 5 import contextlib |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import posixpath | 8 import posixpath |
| 9 import re | 9 import re |
| 10 import sys | 10 import sys |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 312 |
| 313 #override | 313 #override |
| 314 def _GetUniqueTestName(self, test): | 314 def _GetUniqueTestName(self, test): |
| 315 return instrumentation_test_instance.GetUniqueTestName(test) | 315 return instrumentation_test_instance.GetUniqueTestName(test) |
| 316 | 316 |
| 317 #override | 317 #override |
| 318 def _RunTest(self, device, test): | 318 def _RunTest(self, device, test): |
| 319 extras = {} | 319 extras = {} |
| 320 | 320 |
| 321 flags_to_add = [] | 321 flags_to_add = [] |
| 322 flags_to_remove = [] | |
| 323 test_timeout_scale = None | 322 test_timeout_scale = None |
| 324 if self._test_instance.coverage_directory: | 323 if self._test_instance.coverage_directory: |
| 325 coverage_basename = '%s.ec' % ('%s_group' % test[0]['method'] | 324 coverage_basename = '%s.ec' % ('%s_group' % test[0]['method'] |
| 326 if isinstance(test, list) else test['method']) | 325 if isinstance(test, list) else test['method']) |
| 327 extras['coverage'] = 'true' | 326 extras['coverage'] = 'true' |
| 328 coverage_directory = os.path.join( | 327 coverage_directory = os.path.join( |
| 329 device.GetExternalStoragePath(), 'chrome', 'test', 'coverage') | 328 device.GetExternalStoragePath(), 'chrome', 'test', 'coverage') |
| 330 coverage_device_file = os.path.join( | 329 coverage_device_file = os.path.join( |
| 331 coverage_directory, coverage_basename) | 330 coverage_directory, coverage_basename) |
| 332 extras['coverageFile'] = coverage_device_file | 331 extras['coverageFile'] = coverage_device_file |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 test_name = instrumentation_test_instance.GetTestName(test) | 367 test_name = instrumentation_test_instance.GetTestName(test) |
| 369 test_display_name = self._GetUniqueTestName(test) | 368 test_display_name = self._GetUniqueTestName(test) |
| 370 if test['is_junit4']: | 369 if test['is_junit4']: |
| 371 target = '%s/%s' % ( | 370 target = '%s/%s' % ( |
| 372 self._test_instance.test_package, | 371 self._test_instance.test_package, |
| 373 self._test_instance.test_runner_junit4) | 372 self._test_instance.test_runner_junit4) |
| 374 else: | 373 else: |
| 375 target = '%s/%s' % ( | 374 target = '%s/%s' % ( |
| 376 self._test_instance.test_package, self._test_instance.test_runner) | 375 self._test_instance.test_package, self._test_instance.test_runner) |
| 377 extras['class'] = test_name | 376 extras['class'] = test_name |
| 378 if 'flags' in test: | 377 if 'flags' in test and test['flags']: |
| 379 flags_to_add.extend(test['flags'].add) | 378 flags_to_add.extend(test['flags']) |
| 380 flags_to_remove.extend(test['flags'].remove) | |
| 381 timeout = self._GetTimeoutFromAnnotations( | 379 timeout = self._GetTimeoutFromAnnotations( |
| 382 test['annotations'], test_display_name) | 380 test['annotations'], test_display_name) |
| 383 | 381 |
| 384 test_timeout_scale = self._GetTimeoutScaleFromAnnotations( | 382 test_timeout_scale = self._GetTimeoutScaleFromAnnotations( |
| 385 test['annotations']) | 383 test['annotations']) |
| 386 if test_timeout_scale and test_timeout_scale != 1: | 384 if test_timeout_scale and test_timeout_scale != 1: |
| 387 valgrind_tools.SetChromeTimeoutScale( | 385 valgrind_tools.SetChromeTimeoutScale( |
| 388 device, test_timeout_scale * self._test_instance.timeout_scale) | 386 device, test_timeout_scale * self._test_instance.timeout_scale) |
| 389 | 387 |
| 390 logging.info('preparing to run %s: %s', test_display_name, test) | 388 logging.info('preparing to run %s: %s', test_display_name, test) |
| 391 | 389 |
| 392 render_tests_device_output_dir = None | 390 render_tests_device_output_dir = None |
| 393 if _IsRenderTest(test): | 391 if _IsRenderTest(test): |
| 394 # TODO(mikecase): Add DeviceTempDirectory class and use that instead. | 392 # TODO(mikecase): Add DeviceTempDirectory class and use that instead. |
| 395 render_tests_device_output_dir = posixpath.join( | 393 render_tests_device_output_dir = posixpath.join( |
| 396 device.GetExternalStoragePath(), | 394 device.GetExternalStoragePath(), |
| 397 'render_test_output_dir') | 395 'render_test_output_dir') |
| 398 flags_to_add.append('--render-test-output-dir=%s' % | 396 flags_to_add.append('--render-test-output-dir=%s' % |
| 399 render_tests_device_output_dir) | 397 render_tests_device_output_dir) |
| 400 | 398 |
| 401 if flags_to_add or flags_to_remove: | 399 if flags_to_add: |
| 402 self._CreateFlagChangerIfNeeded(device) | 400 self._CreateFlagChangerIfNeeded(device) |
| 403 self._flag_changers[str(device)].PushFlags( | 401 self._flag_changers[str(device)].PushFlags(add=flags_to_add) |
| 404 add=flags_to_add, remove=flags_to_remove) | |
| 405 | 402 |
| 406 time_ms = lambda: int(time.time() * 1e3) | 403 time_ms = lambda: int(time.time() * 1e3) |
| 407 start_ms = time_ms() | 404 start_ms = time_ms() |
| 408 | 405 |
| 409 stream_name = 'logcat_%s_%s_%s' % ( | 406 stream_name = 'logcat_%s_%s_%s' % ( |
| 410 test_name.replace('#', '.'), | 407 test_name.replace('#', '.'), |
| 411 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()), | 408 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()), |
| 412 device.serial) | 409 device.serial) |
| 413 logmon = logdog_logcat_monitor.LogdogLogcatMonitor( | 410 logmon = logdog_logcat_monitor.LogdogLogcatMonitor( |
| 414 device.adb, stream_name, filter_specs=LOGCAT_FILTERS) | 411 device.adb, stream_name, filter_specs=LOGCAT_FILTERS) |
| 415 | 412 |
| 416 with contextlib_ext.Optional( | 413 with contextlib_ext.Optional( |
| 417 logmon, self._test_instance.should_save_logcat): | 414 logmon, self._test_instance.should_save_logcat): |
| 418 with _LogTestEndpoints(device, test_name): | 415 with _LogTestEndpoints(device, test_name): |
| 419 with contextlib_ext.Optional( | 416 with contextlib_ext.Optional( |
| 420 trace_event.trace(test_name), | 417 trace_event.trace(test_name), |
| 421 self._env.trace_output): | 418 self._env.trace_output): |
| 422 output = device.StartInstrumentation( | 419 output = device.StartInstrumentation( |
| 423 target, raw=True, extras=extras, timeout=timeout, retries=0) | 420 target, raw=True, extras=extras, timeout=timeout, retries=0) |
| 424 | 421 |
| 425 logcat_url = logmon.GetLogcatURL() | 422 logcat_url = logmon.GetLogcatURL() |
| 426 duration_ms = time_ms() - start_ms | 423 duration_ms = time_ms() - start_ms |
| 427 if flags_to_add or flags_to_remove: | 424 if flags_to_add: |
| 428 self._flag_changers[str(device)].Restore() | 425 self._flag_changers[str(device)].Restore() |
| 429 if test_timeout_scale: | 426 if test_timeout_scale: |
| 430 valgrind_tools.SetChromeTimeoutScale( | 427 valgrind_tools.SetChromeTimeoutScale( |
| 431 device, self._test_instance.timeout_scale) | 428 device, self._test_instance.timeout_scale) |
| 432 | 429 |
| 433 # TODO(jbudorick): Make instrumentation tests output a JSON so this | 430 # TODO(jbudorick): Make instrumentation tests output a JSON so this |
| 434 # doesn't have to parse the output. | 431 # doesn't have to parse the output. |
| 435 result_code, result_bundle, statuses = ( | 432 result_code, result_bundle, statuses = ( |
| 436 self._test_instance.ParseAmInstrumentRawOutput(output)) | 433 self._test_instance.ParseAmInstrumentRawOutput(output)) |
| 437 results = self._test_instance.GenerateTestResults( | 434 results = self._test_instance.GenerateTestResults( |
| 438 result_code, result_bundle, statuses, start_ms, duration_ms) | 435 result_code, result_bundle, statuses, start_ms, duration_ms) |
| 439 for result in results: | 436 for result in results: |
| 440 if logcat_url: | 437 if logcat_url: |
| 441 result.SetLink('logcat', logcat_url) | 438 result.SetLink('logcat', logcat_url) |
| 442 | 439 |
| 443 if _IsRenderTest(test): | 440 if _IsRenderTest(test): |
| 444 # Render tests do not cause test failure by default. So we have to check | 441 # Render tests do not cause test failure by default. So we have to check |
| 445 # to see if any failure images were generated even if the test does not | 442 # to see if any failure images were generated even if the test does not |
| 446 # fail. | 443 # fail. |
| 447 try: | 444 try: |
| 448 self._ProcessRenderTestResults( | 445 self._ProcessRenderTestResults( |
| 449 device, render_tests_device_output_dir, results) | 446 device, render_tests_device_output_dir, results) |
| 450 finally: | 447 finally: |
| 451 device.RemovePath(render_tests_device_output_dir, | 448 device.RemovePath(render_tests_device_output_dir, |
| 452 recursive=True, force=True) | 449 recursive=True, force=True) |
| 453 | 450 |
| 454 # Update the result name if the test used flags. | 451 # Update the result name if the test used flags. |
| 455 if flags_to_add or flags_to_remove: | 452 if flags_to_add: |
| 456 for r in results: | 453 for r in results: |
| 457 if r.GetName() == test_name: | 454 if r.GetName() == test_name: |
| 458 r.SetName(test_display_name) | 455 r.SetName(test_display_name) |
| 459 | 456 |
| 460 # Add UNKNOWN results for any missing tests. | 457 # Add UNKNOWN results for any missing tests. |
| 461 iterable_test = test if isinstance(test, list) else [test] | 458 iterable_test = test if isinstance(test, list) else [test] |
| 462 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) | 459 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) |
| 463 results_names = set(r.GetName() for r in results) | 460 results_names = set(r.GetName() for r in results) |
| 464 results.extend( | 461 results.extend( |
| 465 base_test_result.BaseTestResult(u, base_test_result.ResultType.UNKNOWN) | 462 base_test_result.BaseTestResult(u, base_test_result.ResultType.UNKNOWN) |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 686 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
| 690 | 687 |
| 691 return timeout | 688 return timeout |
| 692 | 689 |
| 693 def _IsRenderTest(test): | 690 def _IsRenderTest(test): |
| 694 """Determines if a test or list of tests has a RenderTest amongst them.""" | 691 """Determines if a test or list of tests has a RenderTest amongst them.""" |
| 695 if not isinstance(test, list): | 692 if not isinstance(test, list): |
| 696 test = [test] | 693 test = [test] |
| 697 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( | 694 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( |
| 698 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) | 695 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) |
| OLD | NEW |