1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-05-08 02:15:21 +01:00

utils/types: Add version_tuple

Allow for `version_tuple` to be used more generically to enable
natural comparing of versions encoded as strings.
This commit is contained in:
Marc Bonnici 2019-06-28 11:58:41 +01:00 committed by setrofim
parent 8910234448
commit f46851a3b4
4 changed files with 12 additions and 8 deletions
wa
framework
utils
workloads/geekbench

@ -284,8 +284,8 @@ def apk_version_matches(path, version):
def loose_version_matching(config_version, apk_version): def loose_version_matching(config_version, apk_version):
config_version = config_version.split('.') config_version = version_tuple(config_version)
apk_version = apk_version.split('.') apk_version = version_tuple(apk_version)
if len(apk_version) < len(config_version): if len(apk_version) < len(config_version):
return False # More specific version requested than available return False # More specific version requested than available

@ -28,7 +28,7 @@ from wa.framework.plugin import TargetedPlugin, Parameter
from wa.framework.resource import (ApkFile, ReventFile, from wa.framework.resource import (ApkFile, ReventFile,
File, loose_version_matching) File, loose_version_matching)
from wa.framework.exception import WorkloadError, ConfigError from wa.framework.exception import WorkloadError, ConfigError
from wa.utils.types import ParameterDict, list_or_string from wa.utils.types import ParameterDict, list_or_string, version_tuple
from wa.utils.revent import ReventRecorder from wa.utils.revent import ReventRecorder
from wa.utils.exec_control import once_per_instance from wa.utils.exec_control import once_per_instance

@ -208,6 +208,13 @@ def regex(value):
return re.compile(value) return re.compile(value)
def version_tuple(v):
"""
Converts a version string into a tuple of ints that can be used for natural comparison.
"""
return tuple(map(int, (v.split("."))))
__counters = defaultdict(int) __counters = defaultdict(int)

@ -23,6 +23,7 @@ from collections import defaultdict
from wa import ApkUiautoWorkload, Parameter from wa import ApkUiautoWorkload, Parameter
from wa.framework.exception import ConfigError, WorkloadError from wa.framework.exception import ConfigError, WorkloadError
from wa.utils.misc import capitalize from wa.utils.misc import capitalize
from wa.utils.types import version_tuple
class Geekbench(ApkUiautoWorkload): class Geekbench(ApkUiautoWorkload):
@ -101,7 +102,7 @@ class Geekbench(ApkUiautoWorkload):
def update_output(self, context): def update_output(self, context):
super(Geekbench, self).update_output(context) super(Geekbench, self).update_output(context)
if not self.disable_update_result: if not self.disable_update_result:
major_version = versiontuple(self.version)[0] major_version = version_tuple(self.version)[0]
update_method = getattr(self, 'update_result_{}'.format(major_version)) update_method = getattr(self, 'update_result_{}'.format(major_version))
update_method(context) update_method(context)
@ -367,7 +368,3 @@ class GeekbenchCorproate(Geekbench): # pylint: disable=too-many-ancestors
def namemify(basename, i): def namemify(basename, i):
return basename + (' {}'.format(i) if i else '') return basename + (' {}'.format(i) if i else '')
def versiontuple(v):
return tuple(map(int, (v.split("."))))