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) |
(...skipping 11 matching lines...) Expand all Loading... |
426 duration_ms = time_ms() - start_ms | 423 duration_ms = time_ms() - start_ms |
427 | 424 |
428 # TODO(jbudorick): Make instrumentation tests output a JSON so this | 425 # TODO(jbudorick): Make instrumentation tests output a JSON so this |
429 # doesn't have to parse the output. | 426 # doesn't have to parse the output. |
430 result_code, result_bundle, statuses = ( | 427 result_code, result_bundle, statuses = ( |
431 self._test_instance.ParseAmInstrumentRawOutput(output)) | 428 self._test_instance.ParseAmInstrumentRawOutput(output)) |
432 results = self._test_instance.GenerateTestResults( | 429 results = self._test_instance.GenerateTestResults( |
433 result_code, result_bundle, statuses, start_ms, duration_ms) | 430 result_code, result_bundle, statuses, start_ms, duration_ms) |
434 | 431 |
435 def restore_flags(): | 432 def restore_flags(): |
436 if flags_to_add or flags_to_remove: | 433 if flags_to_add: |
437 self._flag_changers[str(device)].Restore() | 434 self._flag_changers[str(device)].Restore() |
438 | 435 |
439 def restore_timeout_scale(): | 436 def restore_timeout_scale(): |
440 if test_timeout_scale: | 437 if test_timeout_scale: |
441 valgrind_tools.SetChromeTimeoutScale( | 438 valgrind_tools.SetChromeTimeoutScale( |
442 device, self._test_instance.timeout_scale) | 439 device, self._test_instance.timeout_scale) |
443 | 440 |
444 def handle_coverage_data(): | 441 def handle_coverage_data(): |
445 if self._test_instance.coverage_directory: | 442 if self._test_instance.coverage_directory: |
446 device.PullFile(coverage_directory, | 443 device.PullFile(coverage_directory, |
(...skipping 26 matching lines...) Expand all Loading... |
473 post_test_step_thread_group.StartAll(will_block=True) | 470 post_test_step_thread_group.StartAll(will_block=True) |
474 else: | 471 else: |
475 for step in post_test_steps: | 472 for step in post_test_steps: |
476 step() | 473 step() |
477 | 474 |
478 for result in results: | 475 for result in results: |
479 if logcat_url: | 476 if logcat_url: |
480 result.SetLink('logcat', logcat_url) | 477 result.SetLink('logcat', logcat_url) |
481 | 478 |
482 # Update the result name if the test used flags. | 479 # Update the result name if the test used flags. |
483 if flags_to_add or flags_to_remove: | 480 if flags_to_add: |
484 for r in results: | 481 for r in results: |
485 if r.GetName() == test_name: | 482 if r.GetName() == test_name: |
486 r.SetName(test_display_name) | 483 r.SetName(test_display_name) |
487 | 484 |
488 # Add UNKNOWN results for any missing tests. | 485 # Add UNKNOWN results for any missing tests. |
489 iterable_test = test if isinstance(test, list) else [test] | 486 iterable_test = test if isinstance(test, list) else [test] |
490 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) | 487 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) |
491 results_names = set(r.GetName() for r in results) | 488 results_names = set(r.GetName() for r in results) |
492 results.extend( | 489 results.extend( |
493 base_test_result.BaseTestResult(u, base_test_result.ResultType.UNKNOWN) | 490 base_test_result.BaseTestResult(u, base_test_result.ResultType.UNKNOWN) |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 711 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
715 | 712 |
716 return timeout | 713 return timeout |
717 | 714 |
718 def _IsRenderTest(test): | 715 def _IsRenderTest(test): |
719 """Determines if a test or list of tests has a RenderTest amongst them.""" | 716 """Determines if a test or list of tests has a RenderTest amongst them.""" |
720 if not isinstance(test, list): | 717 if not isinstance(test, list): |
721 test = [test] | 718 test = [test] |
722 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( | 719 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( |
723 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) | 720 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) |
OLD | NEW |