From 6ab1ae74a69e3f18ba48232d0d2905e265e21d88 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Mon, 7 Jan 2019 11:19:03 +0000 Subject: [PATCH] wa/apk_workloads: Update to not specify a default apk version. No longer specify a default version to allow any available apks to be detected and then choose the appropriate automation based on the detected version. Refactor to support new supported_versions attribute and since APK resolution needs to have happened before setting uiauto parameter move assignments to ``initialize``. --- wa/workloads/exoplayer/__init__.py | 4 ++-- wa/workloads/geekbench/__init__.py | 31 +++++++++------------------- wa/workloads/glbenchmark/__init__.py | 14 +++++-------- wa/workloads/vellamo/__init__.py | 10 ++++----- 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/wa/workloads/exoplayer/__init__.py b/wa/workloads/exoplayer/__init__.py index 64064b5c..f4293b65 100644 --- a/wa/workloads/exoplayer/__init__.py +++ b/wa/workloads/exoplayer/__init__.py @@ -77,13 +77,13 @@ class ExoPlayer(ApkWorkload): video_directory = os.path.join(settings.dependencies_directory, name) package_names = ['com.google.android.exoplayer2.demo'] - versions = ['2.4', '2.5', '2.6'] + supported_versions = ['2.4', '2.5', '2.6'] action = 'com.google.android.exoplayer.demo.action.VIEW' default_format = 'mov_720p' view = 'SurfaceView - com.google.android.exoplayer2.demo/com.google.android.exoplayer2.demo.PlayerActivity' parameters = [ - Parameter('version', allowed_values=versions, default=versions[-1], override=True), + Parameter('version', allowed_values=supported_versions, override=True), Parameter('duration', kind=int, default=20, description=""" Playback duration of the video file. This becomes the duration of the workload. diff --git a/wa/workloads/geekbench/__init__.py b/wa/workloads/geekbench/__init__.py index 724c6074..ef7ff664 100644 --- a/wa/workloads/geekbench/__init__.py +++ b/wa/workloads/geekbench/__init__.py @@ -78,12 +78,13 @@ class Geekbench(ApkUiautoWorkload): 'activity': '.HomeActivity', }, } + supported_versions = sorted(versions.keys()) begin_regex = re.compile(r'^\s*D/WebViewClassic.loadDataWithBaseURL\(\s*\d+\s*\)' r'\s*:\s*(?P\<.*)\s*$') replace_regex = re.compile(r'<[^>]*>') parameters = [ - Parameter('version', default=sorted(versions.keys())[-1], allowed_values=sorted(versions.keys()), + Parameter('version', allowed_values=supported_versions, description='Specifies which version of the workload should be run.', override=True), Parameter('loops', kind=int, default=1, aliases=['times'], @@ -109,23 +110,16 @@ class Geekbench(ApkUiautoWorkload): def activity(self): return self.versions[self.version]['activity'] - @property - def package(self): - return self.versions[self.version]['package'] - @property def package_names(self): - return [self.package] + return set(self.versions[v]['package'] for v in self.versions) - def __init__(self, *args, **kwargs): - super(Geekbench, self).__init__(*args, **kwargs) + def initialize(self, context): + super(Geekbench, self).initialize(context) self.gui.uiauto_params['version'] = self.version self.gui.uiauto_params['loops'] = self.loops self.gui.uiauto_params['is_corporate'] = self.is_corporate self.gui.timeout = self.timeout - - def initialize(self, context): - super(Geekbench, self).initialize(context) if not self.disable_update_result and not self.target.is_rooted: raise WorkloadError( 'Geekbench workload requires root to collect results. ' @@ -135,7 +129,6 @@ class Geekbench(ApkUiautoWorkload): def setup(self, context): super(Geekbench, self).setup(context) self.run_timeout = self.timeout * self.loops - self.exact_apk_version = self.version def update_output(self, context): super(Geekbench, self).update_output(context) @@ -154,7 +147,7 @@ class Geekbench(ApkUiautoWorkload): score_calculator.update_results(context) def update_result_3(self, context): - outfile_glob = self.target.path.join(self.target.package_data_directory, self.package, 'files', '*gb3') + outfile_glob = self.target.path.join(self.target.package_data_directory, self.apk.package, 'files', '*gb3') on_target_output_files = [f.strip() for f in self.target.execute('ls {}'.format(outfile_glob), as_root=True).split('\n') if f] for i, on_target_output_file in enumerate(on_target_output_files): @@ -176,7 +169,7 @@ class Geekbench(ApkUiautoWorkload): section['multicore_score']) def update_result_4(self, context): - outfile_glob = self.target.path.join(self.target.package_data_directory, self.package, 'files', '*gb*') + outfile_glob = self.target.path.join(self.target.package_data_directory, self.apk.package, 'files', '*gb*') on_target_output_files = [f.strip() for f in self.target.execute('ls {}'.format(outfile_glob), as_root=True).split('\n') if f] for i, on_target_output_file in enumerate(on_target_output_files): @@ -395,16 +388,12 @@ class GeekbenchCorproate(Geekbench): # pylint: disable=too-many-ancestors name = "geekbench-corporate" is_corporate = True requires_network = False - - versions = ['4.1.0', '5.0.0'] - + supported_versions = ['4.1.0', '5.0.0'] + package_names = ['com.primatelabs.geekbench4.corporate'] activity = 'com.primatelabs.geekbench.HomeActivity' - package = 'com.primatelabs.geekbench4.corporate' parameters = [ - Parameter('version', - default=sorted(versions)[-1], allowed_values=versions, - override=True) + Parameter('version', allowed_values=supported_versions, override=True) ] diff --git a/wa/workloads/glbenchmark/__init__.py b/wa/workloads/glbenchmark/__init__.py index dd38d95b..bf4d0489 100644 --- a/wa/workloads/glbenchmark/__init__.py +++ b/wa/workloads/glbenchmark/__init__.py @@ -56,10 +56,8 @@ class Glb(ApkUiautoWorkload): view = 'com.glbenchmark.glbenchmark27/com.glbenchmark.activities.GLBRender' package_names = ['com.glbenchmark.glbenchmark27', 'com.glbenchmark.glbenchmark25'] - packages = { - '2.7': 'com.glbenchmark.glbenchmark27', - '2.5': 'com.glbenchmark.glbenchmark25', - } + supported_versions = ['2.7', '2.5'] + # If usecase is not specified the default usecase is the first supported usecase alias # for the specified version. supported_usecase_aliases = { @@ -74,7 +72,7 @@ class Glb(ApkUiautoWorkload): regex = re.compile(r'GLBenchmark (metric|FPS): (.*)') parameters = [ - Parameter('version', default='2.7', allowed_values=['2.7', '2.5'], override=True, + Parameter('version', allowed_values=supported_versions, override=True, description=('Specifies which version of the benchmark to run (different versions ' 'support different use cases).')), Parameter('use_case', default=None, @@ -107,10 +105,9 @@ class Glb(ApkUiautoWorkload): Alias('t-rex_offscreen', use_case='t-rex', type='offscreen'), ] - def __init__(self, target, **kwargs): - super(Glb, self).__init__(target, **kwargs) + def initialize(self, context): + super(Glb, self).initialize(context) self.gui.uiauto_params['version'] = self.version - if self.use_case is None: self.use_case = self.supported_usecase_aliases[self.version][0] if self.use_case.lower() in USE_CASE_MAP: @@ -124,7 +121,6 @@ class Glb(ApkUiautoWorkload): self.gui.uiauto_params['usecase_type'] = self.type.replace(' ', '_') self.gui.uiauto_params['timeout'] = self.run_timeout - self.package_names = [self.packages[self.version]] def update_output(self, context): super(Glb, self).update_output(context) diff --git a/wa/workloads/vellamo/__init__.py b/wa/workloads/vellamo/__init__.py index c8a4b76e..29529b43 100644 --- a/wa/workloads/vellamo/__init__.py +++ b/wa/workloads/vellamo/__init__.py @@ -48,11 +48,11 @@ class Vellamo(ApkUiautoWorkload): '3.0': ['Browser', 'Metal', 'Multi'], '3.2.4': ['Browser', 'Metal', 'Multi'], } - valid_versions = list(benchmark_types.keys()) + supported_versions = list(benchmark_types.keys()) summary_metrics = None parameters = [ - Parameter('version', kind=str, allowed_values=valid_versions, default=sorted(benchmark_types, reverse=True)[0], override=True, + Parameter('version', kind=str, allowed_values=supported_versions, override=True, description=('Specify the version of Vellamo to be run. ' 'If not specified, the latest available version will be used.')), Parameter('benchmarks', kind=list_of_strs, allowed_values=benchmark_types['3.0'], default=benchmark_types['3.0'], @@ -66,15 +66,15 @@ class Vellamo(ApkUiautoWorkload): ] def setup(self, context): + super(Vellamo, self).setup(context) self.gui.uiauto_params['version'] = self.version self.gui.uiauto_params['browserToUse'] = self.browser self.gui.uiauto_params['metal'] = 'Metal' in self.benchmarks self.gui.uiauto_params['browser'] = 'Browser' in self.benchmarks self.gui.uiauto_params['multicore'] = 'Multi' in self.benchmarks - super(Vellamo, self).setup(context) - def validate(self): - super(Vellamo, self).validate() + def initialize(self, context): + super(Vellamo, self).initialize(context) if self.version == '2.0.3' or not self.benchmarks: # pylint: disable=access-member-before-definition self.benchmarks = self.benchmark_types[self.version] # pylint: disable=attribute-defined-outside-init else: