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

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: remove system println 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):
313 if self._test_instance.junit4_runner_class:
314 self._SaveTestsFromRunner()
jbudorick 2017/07/21 19:35:08 This is more complicated than it needs to be. Rath
the real yoland 2017/07/21 22:24:09 Done
309 tests = self._test_instance.GetTests() 315 tests = self._test_instance.GetTests()
310 tests = self._ApplyExternalSharding( 316 tests = self._ApplyExternalSharding(
311 tests, self._test_instance.external_shard_index, 317 tests, self._test_instance.external_shard_index,
312 self._test_instance.total_external_shards) 318 self._test_instance.total_external_shards)
313 return tests 319 return tests
314 320
315 #override 321 #override
316 def _GetUniqueTestName(self, test): 322 def _GetUniqueTestName(self, test):
317 return instrumentation_test_instance.GetUniqueTestName(test) 323 return instrumentation_test_instance.GetUniqueTestName(test)
318 324
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 extras.update( 370 extras.update(
365 self._test_instance.GetDriverEnvironmentVars( 371 self._test_instance.GetDriverEnvironmentVars(
366 test_list=test_names)) 372 test_list=test_names))
367 timeout = sum(timeouts) 373 timeout = sum(timeouts)
368 else: 374 else:
369 test_name = instrumentation_test_instance.GetTestName(test) 375 test_name = instrumentation_test_instance.GetTestName(test)
370 test_display_name = self._GetUniqueTestName(test) 376 test_display_name = self._GetUniqueTestName(test)
371 if test['is_junit4']: 377 if test['is_junit4']:
372 target = '%s/%s' % ( 378 target = '%s/%s' % (
373 self._test_instance.test_package, 379 self._test_instance.test_package,
374 self._test_instance.test_runner_junit4) 380 self._test_instance.junit4_runner_class)
375 else: 381 else:
376 target = '%s/%s' % ( 382 target = '%s/%s' % (
377 self._test_instance.test_package, self._test_instance.test_runner) 383 self._test_instance.test_package,
384 self._test_instance.junit3_runner_class)
378 extras['class'] = test_name 385 extras['class'] = test_name
379 if 'flags' in test and test['flags']: 386 if 'flags' in test and test['flags']:
380 flags_to_add.extend(test['flags']) 387 flags_to_add.extend(test['flags'])
381 timeout = self._GetTimeoutFromAnnotations( 388 timeout = self._GetTimeoutFromAnnotations(
382 test['annotations'], test_display_name) 389 test['annotations'], test_display_name)
383 390
384 test_timeout_scale = self._GetTimeoutScaleFromAnnotations( 391 test_timeout_scale = self._GetTimeoutScaleFromAnnotations(
385 test['annotations']) 392 test['annotations'])
386 if test_timeout_scale and test_timeout_scale != 1: 393 if test_timeout_scale and test_timeout_scale != 1:
387 valgrind_tools.SetChromeTimeoutScale( 394 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()), 551 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()),
545 device.serial) 552 device.serial)
546 tombstones_url = logdog_helper.text( 553 tombstones_url = logdog_helper.text(
547 stream_name, '\n'.join(resolved_tombstones)) 554 stream_name, '\n'.join(resolved_tombstones))
548 result.SetLink('tombstones', tombstones_url) 555 result.SetLink('tombstones', tombstones_url)
549 556
550 if self._env.concurrent_adb: 557 if self._env.concurrent_adb:
551 post_test_step_thread_group.JoinAll() 558 post_test_step_thread_group.JoinAll()
552 return results, None 559 return results, None
553 560
561 def _SaveTestsFromRunner(self):
jbudorick 2017/07/21 19:35:08 This should be _GetTestsFromRunner
the real yoland 2017/07/21 22:24:09 Done
562 try:
563 raw_tests = self._test_instance.GetAllTestsFromRunnerPickle()
564 self._test_instance.SetTestsFromRunner(raw_tests)
565 except instrumentation_test_instance.TestListPickleException as e:
566 junit4_runner_class = self._test_instance.junit4_runner_class
567 test_package = self._test_instance.test_package
568 logging.info('Could not get tests from pickle: %s', e)
569 logging.info('Getting tests by having %s list them.',
570 self._test_instance.junit4_runner_class)
571 device = self._env.devices[0]
572 with device_temp_file.DeviceTempFile(
573 device.adb, suffix='.json',
574 dir=device.GetExternalStoragePath()) as device_test_list_json:
575 extras = {}
576 extras[_EXTRA_TEST_LIST] = device_test_list_json.name
577 extras['log'] = 'true'
578 extras['package'] = '.'.join(
579 self._test_instance.test_package.split('.')[:2])
580 target = '%s/%s' % (test_package, junit4_runner_class)
581 output_string = ''.join(device.StartInstrumentation(
582 target, extras=extras))
583 if output_string:
jbudorick 2017/07/21 19:35:08 What could this output that would indicate failure
the real yoland 2017/07/21 22:24:09 I had incidents where it printed out the tests bec
584 raise Exception('Test listing through %s failed on device:\n%s' % (
jbudorick 2017/07/21 19:35:08 I don't think this should be a raw Exception. Mayb
the real yoland 2017/07/21 22:24:09 Done
585 junit4_runner_class, output_string))
586 with tempfile_ext.NamedTemporaryDirectory() as host_dir:
587 host_file = os.path.join(host_dir, 'list_tests.json')
588 device.PullFile(device_test_list_json.name, host_file)
589 with open(host_file, 'r') as host_file:
590 json_string = host_file.read()
591 raw_tests = json.loads(json_string)
592 self._test_instance.SaveTestsToPickle(raw_tests)
jbudorick 2017/07/21 19:35:08 nit: do this outside of the temporary context mana
the real yoland 2017/07/21 22:24:09 Done
593 self._test_instance.SetTestsFromRunner(raw_tests)
594
554 def _SaveScreenshot(self, device, screenshot_host_dir, screenshot_device_file, 595 def _SaveScreenshot(self, device, screenshot_host_dir, screenshot_device_file,
555 test_name, results): 596 test_name, results):
556 if screenshot_host_dir: 597 if screenshot_host_dir:
557 screenshot_host_file = os.path.join( 598 screenshot_host_file = os.path.join(
558 screenshot_host_dir, 599 screenshot_host_dir,
559 '%s-%s.png' % ( 600 '%s-%s.png' % (
560 test_name, 601 test_name,
561 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()))) 602 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime())))
562 if device.FileExists(screenshot_device_file.name): 603 if device.FileExists(screenshot_device_file.name):
563 try: 604 try:
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) 754 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations)
714 755
715 return timeout 756 return timeout
716 757
717 def _IsRenderTest(test): 758 def _IsRenderTest(test):
718 """Determines if a test or list of tests has a RenderTest amongst them.""" 759 """Determines if a test or list of tests has a RenderTest amongst them."""
719 if not isinstance(test, list): 760 if not isinstance(test, list):
720 test = [test] 761 test = [test]
721 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( 762 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get(
722 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) 763 FEATURE_ANNOTATION, {}).get('value', ()) for t in test])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698