Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: build/android/pylib/local/device/local_device_instrumentation_test_run.py

Issue 2935503002: List Java Instru Test Information From JUnit Runner (Closed)
Patch Set: address issues Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 json
6 import logging 7 import logging
7 import os 8 import os
8 import posixpath 9 import posixpath
9 import re 10 import re
10 import sys 11 import sys
11 import tempfile 12 import tempfile
12 import time 13 import time
13 14
14 from devil.android import crash_handler 15 from devil.android import crash_handler
15 from devil.android import device_errors 16 from devil.android import device_errors
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 LOGCAT_FILTERS = ['*:e', 'chromium:v', 'cr_*:v', 'DEBUG:I', 59 LOGCAT_FILTERS = ['*:e', 'chromium:v', 'cr_*:v', 'DEBUG:I',
59 'StrictMode:D', '%s:I' % _TAG] 60 'StrictMode:D', '%s:I' % _TAG]
60 61
61 EXTRA_SCREENSHOT_FILE = ( 62 EXTRA_SCREENSHOT_FILE = (
62 'org.chromium.base.test.ScreenshotOnFailureStatement.ScreenshotFile') 63 'org.chromium.base.test.ScreenshotOnFailureStatement.ScreenshotFile')
63 64
64 EXTRA_UI_CAPTURE_DIR = ( 65 EXTRA_UI_CAPTURE_DIR = (
65 'org.chromium.base.test.util.Screenshooter.ScreenshotDir') 66 'org.chromium.base.test.util.Screenshooter.ScreenshotDir')
66 67
68 _EXTRA_TEST_LIST = (
69 'org.chromium.base.test.BaseChromiumAndroidJUnitRunner.TestList')
70
67 UI_CAPTURE_DIRS = ['chromium_tests_root', 'UiCapture'] 71 UI_CAPTURE_DIRS = ['chromium_tests_root', 'UiCapture']
68 72
69 FEATURE_ANNOTATION = 'Feature' 73 FEATURE_ANNOTATION = 'Feature'
70 RENDER_TEST_FEATURE_ANNOTATION = 'RenderTest' 74 RENDER_TEST_FEATURE_ANNOTATION = 'RenderTest'
71 75
72 # This needs to be kept in sync with formatting in |RenderUtils.imageName| 76 # This needs to be kept in sync with formatting in |RenderUtils.imageName|
73 RE_RENDER_IMAGE_NAME = re.compile( 77 RE_RENDER_IMAGE_NAME = re.compile(
74 r'(?P<test_class>\w+)\.' 78 r'(?P<test_class>\w+)\.'
75 r'(?P<description>\w+)\.' 79 r'(?P<description>\w+)\.'
76 r'(?P<device_model>\w+)\.' 80 r'(?P<device_model>\w+)\.'
77 r'(?P<orientation>port|land)\.png') 81 r'(?P<orientation>port|land)\.png')
78 82
79 @contextlib.contextmanager 83 @contextlib.contextmanager
80 def _LogTestEndpoints(device, test_name): 84 def _LogTestEndpoints(device, test_name):
81 device.RunShellCommand( 85 device.RunShellCommand(
82 ['log', '-p', 'i', '-t', _TAG, 'START %s' % test_name], 86 ['log', '-p', 'i', '-t', _TAG, 'START %s' % test_name],
83 check_return=True) 87 check_return=True)
84 try: 88 try:
85 yield 89 yield
86 finally: 90 finally:
87 device.RunShellCommand( 91 device.RunShellCommand(
88 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], 92 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name],
89 check_return=True) 93 check_return=True)
90 94
91 # TODO(jbudorick): Make this private once the instrumentation test_runner is 95 # TODO(jbudorick): Make this private once the instrumentation test_runner
92 # deprecated. 96 # is deprecated.
93 def DidPackageCrashOnDevice(package_name, device): 97 def DidPackageCrashOnDevice(package_name, device):
94 # Dismiss any error dialogs. Limit the number in case we have an error 98 # Dismiss any error dialogs. Limit the number in case we have an error
95 # loop or we are failing to dismiss. 99 # loop or we are failing to dismiss.
96 try: 100 try:
97 for _ in xrange(10): 101 for _ in xrange(10):
98 package = device.DismissCrashDialogIfNeeded() 102 package = device.DismissCrashDialogIfNeeded()
99 if not package: 103 if not package:
100 return False 104 return False
101 # Assume test package convention of ".test" suffix 105 # Assume test package convention of ".test" suffix
102 if package in package_name: 106 if package in package_name:
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 if not str(device) in self._flag_changers: 303 if not str(device) in self._flag_changers:
300 self._flag_changers[str(device)] = flag_changer.FlagChanger( 304 self._flag_changers[str(device)] = flag_changer.FlagChanger(
301 device, self._test_instance.package_info.cmdline_file) 305 device, self._test_instance.package_info.cmdline_file)
302 306
303 #override 307 #override
304 def _CreateShards(self, tests): 308 def _CreateShards(self, tests):
305 return tests 309 return tests
306 310
307 #override 311 #override
308 def _GetTests(self): 312 def _GetTests(self):
309 tests = self._test_instance.GetTests() 313 tests = None
314 if self._test_instance.junit4_runner_class:
315 raw_tests = self._GetTestsFromRunner()
316 tests = self._test_instance.ProcessRawTests(raw_tests)
317 else:
318 tests = self._test_instance.GetTests()
310 tests = self._ApplyExternalSharding( 319 tests = self._ApplyExternalSharding(
311 tests, self._test_instance.external_shard_index, 320 tests, self._test_instance.external_shard_index,
312 self._test_instance.total_external_shards) 321 self._test_instance.total_external_shards)
313 return tests 322 return tests
314 323
315 #override 324 #override
316 def _GetUniqueTestName(self, test): 325 def _GetUniqueTestName(self, test):
317 return instrumentation_test_instance.GetUniqueTestName(test) 326 return instrumentation_test_instance.GetUniqueTestName(test)
318 327
319 #override 328 #override
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 extras.update( 373 extras.update(
365 self._test_instance.GetDriverEnvironmentVars( 374 self._test_instance.GetDriverEnvironmentVars(
366 test_list=test_names)) 375 test_list=test_names))
367 timeout = sum(timeouts) 376 timeout = sum(timeouts)
368 else: 377 else:
369 test_name = instrumentation_test_instance.GetTestName(test) 378 test_name = instrumentation_test_instance.GetTestName(test)
370 test_display_name = self._GetUniqueTestName(test) 379 test_display_name = self._GetUniqueTestName(test)
371 if test['is_junit4']: 380 if test['is_junit4']:
372 target = '%s/%s' % ( 381 target = '%s/%s' % (
373 self._test_instance.test_package, 382 self._test_instance.test_package,
374 self._test_instance.test_runner_junit4) 383 self._test_instance.junit4_runner_class)
375 else: 384 else:
376 target = '%s/%s' % ( 385 target = '%s/%s' % (
377 self._test_instance.test_package, self._test_instance.test_runner) 386 self._test_instance.test_package,
387 self._test_instance.junit3_runner_class)
378 extras['class'] = test_name 388 extras['class'] = test_name
379 if 'flags' in test and test['flags']: 389 if 'flags' in test and test['flags']:
380 flags_to_add.extend(test['flags']) 390 flags_to_add.extend(test['flags'])
381 timeout = self._GetTimeoutFromAnnotations( 391 timeout = self._GetTimeoutFromAnnotations(
382 test['annotations'], test_display_name) 392 test['annotations'], test_display_name)
383 393
384 test_timeout_scale = self._GetTimeoutScaleFromAnnotations( 394 test_timeout_scale = self._GetTimeoutScaleFromAnnotations(
385 test['annotations']) 395 test['annotations'])
386 if test_timeout_scale and test_timeout_scale != 1: 396 if test_timeout_scale and test_timeout_scale != 1:
387 valgrind_tools.SetChromeTimeoutScale( 397 valgrind_tools.SetChromeTimeoutScale(
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()), 554 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()),
545 device.serial) 555 device.serial)
546 tombstones_url = logdog_helper.text( 556 tombstones_url = logdog_helper.text(
547 stream_name, '\n'.join(resolved_tombstones)) 557 stream_name, '\n'.join(resolved_tombstones))
548 result.SetLink('tombstones', tombstones_url) 558 result.SetLink('tombstones', tombstones_url)
549 559
550 if self._env.concurrent_adb: 560 if self._env.concurrent_adb:
551 post_test_step_thread_group.JoinAll() 561 post_test_step_thread_group.JoinAll()
552 return results, None 562 return results, None
553 563
564 def _GetTestsFromRunner(self):
565 test_apk_path = self._test_instance.test_apk.path
566 pickle_path = '%s-runner.pickle' % test_apk_path
567 try:
568 raw_tests = instrumentation_test_instance.GetTestsFromPickle(
569 pickle_path, test_apk_path)
570 except instrumentation_test_instance.TestListPickleException as e:
571 junit4_runner_class = self._test_instance.junit4_runner_class
572 test_package = self._test_instance.test_package
573 logging.info('Could not get tests from pickle: %s', e)
574 logging.info('Getting tests by having %s list them.',
575 self._test_instance.junit4_runner_class)
576 def list_tests(dev):
jbudorick 2017/07/24 22:24:38 nit: this is a lot to do in an exception; could yo
the real yoland 2017/07/24 23:25:42 Done
577 with device_temp_file.DeviceTempFile(
578 dev.adb, suffix='.json',
579 dir=dev.GetExternalStoragePath()) as dev_test_list_json:
580 extras = {}
581 extras['log'] = 'true'
582 extras['package'] = '.'.join(
583 self._test_instance.test_package.split('.')[:2])
584 extras[_EXTRA_TEST_LIST] = dev_test_list_json.name
585 target = '%s/%s' % (test_package, junit4_runner_class)
586 output_string = ''.join(dev.StartInstrumentation(
587 target, extras=extras))
588 if output_string:
589 raise device_errors.CommandFailedError(
590 ('Test listing through %s failed on dev:\n%s. Are you using'
jbudorick 2017/07/24 22:24:38 nit: for a multi-line string like this with multip
the real yoland 2017/07/24 23:25:42 Done
591 + ' the right JUnit runner (org.chromium.base.test.'
592 + 'BaseChromiumAndroidJUnitRunner)?') % (
593 junit4_runner_class, output_string), dev.serial)
594 with tempfile_ext.NamedTemporaryDirectory() as host_dir:
595 host_file = os.path.join(host_dir, 'list_tests.json')
596 dev.PullFile(dev_test_list_json.name, host_file)
597 with open(host_file, 'r') as host_file:
598 return json.load(host_file)
599
600 raw_test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None)
601
602 # If all devices failed to list tests, raise an exception.
603 # Check that tl is not None and is not empty.
604 if all(not tl for tl in raw_test_lists):
605 raise device_errors.CommandFailedError(
606 'Failed to list tests on any device')
607
608 raw_tests = [tl for tl in raw_test_lists if tl][0]
the real yoland 2017/07/24 21:08:34 Here I am simply getting the first viable raw test
609
610 instrumentation_test_instance.SaveTestsToPickle(
611 pickle_path, test_apk_path, raw_tests)
612 return raw_tests
613
554 def _SaveScreenshot(self, device, screenshot_host_dir, screenshot_device_file, 614 def _SaveScreenshot(self, device, screenshot_host_dir, screenshot_device_file,
555 test_name, results): 615 test_name, results):
556 if screenshot_host_dir: 616 if screenshot_host_dir:
557 screenshot_host_file = os.path.join( 617 screenshot_host_file = os.path.join(
558 screenshot_host_dir, 618 screenshot_host_dir,
559 '%s-%s.png' % ( 619 '%s-%s.png' % (
560 test_name, 620 test_name,
561 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()))) 621 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime())))
562 if device.FileExists(screenshot_device_file.name): 622 if device.FileExists(screenshot_device_file.name):
563 try: 623 try:
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) 773 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations)
714 774
715 return timeout 775 return timeout
716 776
717 def _IsRenderTest(test): 777 def _IsRenderTest(test):
718 """Determines if a test or list of tests has a RenderTest amongst them.""" 778 """Determines if a test or list of tests has a RenderTest amongst them."""
719 if not isinstance(test, list): 779 if not isinstance(test, list):
720 test = [test] 780 test = [test]
721 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( 781 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get(
722 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) 782 FEATURE_ANNOTATION, {}).get('value', ()) for t in test])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698