def _GetTestsFromRunner(self): test_apk_path = self._test_instance.test_apk.path pickle_path = '%s-runner.pickle' % test_apk_path try: return instrumentation_test_instance.GetTestsFromPickle( pickle_path, test_apk_path) except instrumentation_test_instance.TestListPickleException as e: logging.info('Could not get tests from pickle: %s', e) logging.info('Getting tests by having %s list them.', self._test_instance.junit4_runner_class) def list_tests(d): def _run(dev): with device_temp_file.DeviceTempFile( dev.adb, suffix='.json', dir=dev. GetExternalStoragePath()) as dev_test_list_json: junit4_runner_class = self._test_instance.junit4_runner_class test_package = self._test_instance.test_package extras = {} extras['log'] = 'true' extras[_EXTRA_TEST_LIST] = dev_test_list_json.name target = '%s/%s' % (test_package, junit4_runner_class) kwargs = {} if self._test_instance.wait_for_java_debugger: kwargs['timeout'] = None test_list_run_output = dev.StartInstrumentation( target, extras=extras, retries=0, **kwargs) if any(test_list_run_output): logging.error('Unexpected output while listing tests:') for line in test_list_run_output: logging.error(' %s', line) with tempfile_ext.NamedTemporaryDirectory() as host_dir: host_file = os.path.join(host_dir, 'list_tests.json') dev.PullFile(dev_test_list_json.name, host_file) with open(host_file, 'r') as host_file: return json.load(host_file) return crash_handler.RetryOnSystemCrash(_run, d) raw_test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None) # If all devices failed to list tests, raise an exception. # Check that tl is not None and is not empty. if all(not tl for tl in raw_test_lists): raise device_errors.CommandFailedError( 'Failed to list tests on any device') # Get the first viable list of raw tests raw_tests = [tl for tl in raw_test_lists if tl][0] instrumentation_test_instance.SaveTestsToPickle( pickle_path, test_apk_path, raw_tests) return raw_tests
def _GetTestsFromRunner(self): test_apk_path = self._test_instance.test_apk.path pickle_path = '%s-runner.pickle' % test_apk_path # For incremental APKs, the code doesn't live in the apk, so instead check # the timestamp of the target's .stamp file. if self._test_instance.test_apk_incremental_install_json: with open(self._test_instance.test_apk_incremental_install_json ) as f: data = json.load(f) out_dir = constants.GetOutDirectory() test_mtime = max( os.path.getmtime(os.path.join(out_dir, p)) for p in data['dex_files']) else: test_mtime = os.path.getmtime(test_apk_path) try: return instrumentation_test_instance.GetTestsFromPickle( pickle_path, test_mtime) except instrumentation_test_instance.TestListPickleException as e: logging.info('Could not get tests from pickle: %s', e) logging.info('Getting tests by having %s list them.', self._test_instance.junit4_runner_class) def list_tests(d): def _run(dev): with device_temp_file.DeviceTempFile( dev.adb, suffix='.json', dir=dev. GetExternalStoragePath()) as dev_test_list_json: junit4_runner_class = self._test_instance.junit4_runner_class test_package = self._test_instance.test_package extras = { 'log': 'true', # Workaround for https://github.com/mockito/mockito/issues/922 'notPackage': 'net.bytebuddy', } extras[_EXTRA_TEST_LIST] = dev_test_list_json.name target = '%s/%s' % (test_package, junit4_runner_class) timeout = 120 if self._test_instance.wait_for_java_debugger: timeout = None test_list_run_output = dev.StartInstrumentation( target, extras=extras, retries=0, timeout=timeout) if any(test_list_run_output): logging.error('Unexpected output while listing tests:') for line in test_list_run_output: logging.error(' %s', line) with tempfile_ext.NamedTemporaryDirectory() as host_dir: host_file = os.path.join(host_dir, 'list_tests.json') dev.PullFile(dev_test_list_json.name, host_file) with open(host_file, 'r') as host_file: return json.load(host_file) return crash_handler.RetryOnSystemCrash(_run, d) raw_test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None) # If all devices failed to list tests, raise an exception. # Check that tl is not None and is not empty. if all(not tl for tl in raw_test_lists): raise device_errors.CommandFailedError( 'Failed to list tests on any device') # Get the first viable list of raw tests raw_tests = [tl for tl in raw_test_lists if tl][0] instrumentation_test_instance.SaveTestsToPickle(pickle_path, raw_tests) return raw_tests