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