mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-31 10:11:17 +00:00
commit
e67b77e22b
@ -67,7 +67,7 @@ def get_generic_resource(resource, files):
|
||||
return None
|
||||
if len(matches) > 1:
|
||||
msg = 'Multiple matches for {}: {}'
|
||||
return ResourceError(msg.format(resource, matches))
|
||||
raise ResourceError(msg.format(resource, matches))
|
||||
return matches[0]
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@ from wa.framework.exception import ResourceError
|
||||
from wa.framework.configuration import settings
|
||||
from wa.utils import log
|
||||
from wa.utils.misc import ensure_directory_exists as _d, get_object_name
|
||||
from wa.utils.types import boolean, prioritylist, enum
|
||||
from wa.utils.types import boolean, prioritylist, enum, list_or_string
|
||||
|
||||
|
||||
|
||||
@ -144,17 +144,21 @@ class ApkFile(Resource):
|
||||
kind = 'apk'
|
||||
|
||||
def __init__(self, owner, variant=None, version=None,
|
||||
package=None, uiauto=False):
|
||||
package=None, uiauto=False, exact_abi=False,
|
||||
supported_abi=None):
|
||||
super(ApkFile, self).__init__(owner)
|
||||
self.variant = variant
|
||||
self.version = version
|
||||
self.package = package
|
||||
self.uiauto = uiauto
|
||||
self.exact_abi = exact_abi
|
||||
self.supported_abi = supported_abi
|
||||
|
||||
def match(self, path):
|
||||
name_matches = True
|
||||
version_matches = True
|
||||
package_matches = True
|
||||
abi_matches = True
|
||||
uiauto_matches = uiauto_test_matches(path, self.uiauto)
|
||||
if self.version is not None:
|
||||
version_matches = apk_version_matches(path, self.version)
|
||||
@ -162,8 +166,12 @@ class ApkFile(Resource):
|
||||
name_matches = file_name_matches(path, self.variant)
|
||||
if self.package is not None:
|
||||
package_matches = package_name_matches(path, self.package)
|
||||
if self.supported_abi is not None:
|
||||
abi_matches = apk_abi_matches(path, self.supported_abi,
|
||||
self.exact_abi)
|
||||
return name_matches and version_matches and \
|
||||
uiauto_matches and package_matches
|
||||
uiauto_matches and package_matches and \
|
||||
abi_matches
|
||||
|
||||
|
||||
def __str__(self):
|
||||
@ -271,7 +279,19 @@ def apk_version_matches(path, version):
|
||||
info = ApkInfo(path)
|
||||
if info.version_name == version or info.version_code == version:
|
||||
return True
|
||||
return False
|
||||
return loose_version_matching(version, info.version_name)
|
||||
|
||||
def loose_version_matching(config_version, apk_version):
|
||||
config_version = config_version.split('.')
|
||||
apk_version = apk_version.split('.')
|
||||
|
||||
if len(apk_version) < len(config_version):
|
||||
return False # More specific version requested than available
|
||||
|
||||
for i in xrange(len(config_version)):
|
||||
if config_version[i] != apk_version[i]:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def file_name_matches(path, pattern):
|
||||
@ -289,3 +309,18 @@ def uiauto_test_matches(path, uiauto):
|
||||
def package_name_matches(path, package):
|
||||
info = ApkInfo(path)
|
||||
return info.package == package
|
||||
|
||||
def apk_abi_matches(path, supported_abi, exact_abi=False):
|
||||
supported_abi = list_or_string(supported_abi)
|
||||
info = ApkInfo(path)
|
||||
# If no native code present, suitable for all devices.
|
||||
if not info.native_code:
|
||||
return True
|
||||
|
||||
if exact_abi: # Only check primary
|
||||
return supported_abi[0] in info.native_code
|
||||
else:
|
||||
for abi in supported_abi:
|
||||
if abi in info.native_code:
|
||||
return True
|
||||
return False
|
||||
|
@ -20,7 +20,7 @@ import time
|
||||
from wa import Parameter
|
||||
from wa.framework.plugin import TargetedPlugin
|
||||
from wa.framework.resource import (ApkFile, JarFile, ReventFile, NO_ONE,
|
||||
Executable, File)
|
||||
Executable, File, loose_version_matching)
|
||||
from wa.framework.exception import WorkloadError
|
||||
from wa.utils.types import ParameterDict
|
||||
from wa.utils.revent import ReventRecorder
|
||||
@ -145,6 +145,12 @@ class ApkWorkload(Workload):
|
||||
description="""
|
||||
If ``True``, will uninstall workload\'s APK as part of teardown.'
|
||||
"""),
|
||||
Parameter('exact_abi', kind=bool,
|
||||
default=False,
|
||||
description="""
|
||||
If ``True``, workload will check that the APK matches the target
|
||||
device ABI, otherwise any suitable APK found will be used.
|
||||
""")
|
||||
]
|
||||
|
||||
def __init__(self, target, **kwargs):
|
||||
@ -156,7 +162,8 @@ class ApkWorkload(Workload):
|
||||
version=self.version,
|
||||
force_install=self.force_install,
|
||||
install_timeout=self.install_timeout,
|
||||
uninstall=self.uninstall)
|
||||
uninstall=self.uninstall,
|
||||
exact_abi=self.exact_abi)
|
||||
|
||||
def init_resources(self, context):
|
||||
pass
|
||||
@ -423,7 +430,8 @@ class ReventGUI(object):
|
||||
class PackageHandler(object):
|
||||
|
||||
def __init__(self, owner, install_timeout=300, version=None, variant=None,
|
||||
package=None, strict=False, force_install=False, uninstall=False):
|
||||
package=None, strict=False, force_install=False, uninstall=False,
|
||||
exact_abi=False):
|
||||
self.logger = logging.getLogger('apk')
|
||||
self.owner = owner
|
||||
self.target = self.owner.target
|
||||
@ -434,10 +442,12 @@ class PackageHandler(object):
|
||||
self.strict = strict
|
||||
self.force_install = force_install
|
||||
self.uninstall = uninstall
|
||||
self.exact_abi = exact_abi
|
||||
self.apk_file = None
|
||||
self.apk_info = None
|
||||
self.apk_version = None
|
||||
self.logcat_log = None
|
||||
self.supported_abi = self.target.supported_abi
|
||||
|
||||
def initialize(self, context):
|
||||
self.resolve_package(context)
|
||||
@ -452,10 +462,19 @@ class PackageHandler(object):
|
||||
self.apk_file = context.resolver.get(ApkFile(self.owner,
|
||||
variant=self.variant,
|
||||
version=self.version,
|
||||
package=self.package),
|
||||
package=self.package,
|
||||
exact_abi=self.exact_abi,
|
||||
supported_abi=self.supported_abi),
|
||||
strict=self.strict)
|
||||
if self.apk_file:
|
||||
self.apk_info = ApkInfo(self.apk_file)
|
||||
if self.version:
|
||||
installed_version = self.target.get_package_version(self.apk_info.package)
|
||||
host_version = self.apk_info.version_name
|
||||
if (installed_version != host_version and
|
||||
loose_version_matching(self.version, installed_version)):
|
||||
msg = 'Multiple matching packages found for {}; host version: {}, device version: {}'
|
||||
raise WorkloadError(msg.format(self.owner, host_version, installed_version))
|
||||
else:
|
||||
if not self.owner.package_names and not self.package:
|
||||
msg = 'No package name(s) specified and no matching APK file found on host'
|
||||
@ -475,7 +494,8 @@ class PackageHandler(object):
|
||||
|
||||
if self.version:
|
||||
for package in installed_versions:
|
||||
if self.version == self.target.get_package_version(package):
|
||||
package_version = self.target.get_package_version(package)
|
||||
if loose_version_matching(self.version, package_version):
|
||||
self.package = package
|
||||
break
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user