From 17ce8d0fe96d123443cc075e50b7370c7c4222a4 Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Wed, 1 Jun 2016 15:25:03 +0100 Subject: [PATCH 1/2] Revent: Device model name is now used when searching for revent files Previously the WA device name was used when searching for revent files. Since most were `generic_android` this made it difficult to keep revent files for multiple android devices. Now it the device model is used instead. If a file with the device model is not found it will fall back to the WA device name. --- wlauto/common/android/workload.py | 13 ++++-- wlauto/resource_getters/standard.py | 63 ++++++++++++++++++----------- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/wlauto/common/android/workload.py b/wlauto/common/android/workload.py index 97650d15..56b2b56e 100644 --- a/wlauto/common/android/workload.py +++ b/wlauto/common/android/workload.py @@ -321,19 +321,24 @@ class ReventWorkload(Workload): super(ReventWorkload, self).__init__(device, **kwargs) devpath = self.device.path self.on_device_revent_binary = devpath.join(self.device.binaries_directory, 'revent') - self.on_device_setup_revent = devpath.join(self.device.working_directory, '{}.setup.revent'.format(self.device.name)) - self.on_device_run_revent = devpath.join(self.device.working_directory, '{}.run.revent'.format(self.device.name)) self.setup_timeout = kwargs.get('setup_timeout', self.default_setup_timeout) self.run_timeout = kwargs.get('run_timeout', self.default_run_timeout) self.revent_setup_file = None self.revent_run_file = None + self.on_device_setup_revent = None + self.on_device_run_revent = None - def init_resources(self, context): + def initialize(self, context): self.revent_setup_file = context.resolver.get(wlauto.common.android.resources.ReventFile(self, 'setup')) self.revent_run_file = context.resolver.get(wlauto.common.android.resources.ReventFile(self, 'run')) + devpath = self.device.path + self.on_device_setup_revent = devpath.join(self.device.working_directory, + os.path.split(self.revent_setup_file)[-1]) + self.on_device_run_revent = devpath.join(self.device.working_directory, + os.path.split(self.revent_run_file)[-1]) + self._check_revent_files(context) def setup(self, context): - self._check_revent_files(context) self.device.killall('revent') command = '{} replay {}'.format(self.on_device_revent_binary, self.on_device_setup_revent) self.device.execute(command, timeout=self.setup_timeout) diff --git a/wlauto/resource_getters/standard.py b/wlauto/resource_getters/standard.py index b4b8b771..17cbf64c 100644 --- a/wlauto/resource_getters/standard.py +++ b/wlauto/resource_getters/standard.py @@ -86,11 +86,16 @@ class ReventGetter(ResourceGetter): self.resolver.register(self, 'revent', GetterPriority.package) def get(self, resource, **kwargs): - filename = '.'.join([resource.owner.device.name, resource.stage, 'revent']).lower() - location = _d(os.path.join(self.get_base_location(resource), 'revent_files')) - for candidate in os.listdir(location): - if candidate.lower() == filename.lower(): - return os.path.join(location, candidate) + device_model = resource.owner.device.get_device_model() + wa_device_name = resource.owner.device.name + for name in [device_model, wa_device_name]: + if not name: + continue + filename = '.'.join([name, resource.stage, 'revent']).lower() + location = _d(os.path.join(self.get_base_location(resource), 'revent_files')) + for candidate in os.listdir(location): + if candidate.lower() == filename.lower(): + return os.path.join(location, candidate) class PackageApkGetter(PackageFileGetter): @@ -368,6 +373,7 @@ class HttpGetter(ResourceGetter): return requests.get(url, auth=auth, stream=stream) def resolve_resource(self, resource): + # pylint: disable=too-many-branches assets = self.index.get(resource.owner.name, {}) if not assets: return {} @@ -380,11 +386,16 @@ class HttpGetter(ResourceGetter): if a['path'] == found: return a elif resource.name == 'revent': - filename = '.'.join([resource.owner.device.name, resource.stage, 'revent']).lower() - for asset in assets: - pathname = os.path.basename(asset['path']).lower() - if pathname == filename: - return asset + device_model = resource.owner.device.get_device_model() + wa_device_name = resource.owner.device.name + for name in [device_model, wa_device_name]: + if not name: + continue + filename = '.'.join([name, resource.stage, 'revent']).lower() + for asset in assets: + pathname = os.path.basename(asset['path']).lower() + if pathname == filename: + return asset else: # file for asset in assets: if asset['path'].lower() == resource.path.lower(): @@ -446,6 +457,7 @@ class RemoteFilerGetter(ResourceGetter): return local_full_path def get_from(self, resource, version, location): # pylint: disable=no-self-use + # pylint: disable=too-many-branches if resource.name in ['apk', 'jar']: return get_from_location_by_extension(resource, location, resource.name, version) elif resource.name == 'file': @@ -453,19 +465,24 @@ class RemoteFilerGetter(ResourceGetter): if os.path.exists(filepath): return filepath elif resource.name == 'revent': - filename = '.'.join([resource.owner.device.name, resource.stage, 'revent']).lower() - alternate_location = os.path.join(location, 'revent_files') - # There tends to be some confusion as to where revent files should - # be placed. This looks both in the extension's directory, and in - # 'revent_files' subdirectory under it, if it exists. - if os.path.isdir(alternate_location): - for candidate in os.listdir(alternate_location): - if candidate.lower() == filename.lower(): - return os.path.join(alternate_location, candidate) - if os.path.isdir(location): - for candidate in os.listdir(location): - if candidate.lower() == filename.lower(): - return os.path.join(location, candidate) + device_model = resource.owner.device.get_device_model() + wa_device_name = resource.owner.device.name + for name in [device_model, wa_device_name]: + if not name: + continue + filename = '.'.join([name, resource.stage, 'revent']).lower() + alternate_location = os.path.join(location, 'revent_files') + # There tends to be some confusion as to where revent files should + # be placed. This looks both in the extension's directory, and in + # 'revent_files' subdirectory under it, if it exists. + if os.path.isdir(alternate_location): + for candidate in os.listdir(alternate_location): + if candidate.lower() == filename.lower(): + return os.path.join(alternate_location, candidate) + if os.path.isdir(location): + for candidate in os.listdir(location): + if candidate.lower() == filename.lower(): + return os.path.join(location, candidate) else: raise ValueError('Unexpected resource type: {}'.format(resource.name)) From 18d1f9f64962524fa136af5a391da1610892aa1d Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Wed, 1 Jun 2016 15:29:25 +0100 Subject: [PATCH 2/2] ReventWorkload: Now kills all revent instances on teardown Previously revent would be left running if a run was aborted. --- wlauto/common/android/workload.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wlauto/common/android/workload.py b/wlauto/common/android/workload.py index 56b2b56e..e8dda57c 100644 --- a/wlauto/common/android/workload.py +++ b/wlauto/common/android/workload.py @@ -353,6 +353,7 @@ class ReventWorkload(Workload): pass def teardown(self, context): + self.device.killall('revent') self.device.delete_file(self.on_device_setup_revent) self.device.delete_file(self.on_device_run_revent)