mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-11-04 09:02:12 +00:00 
			
		
		
		
	Merge pull request #250 from ep1cman/apk_ver_fixes
Redone APK file resolution
This commit is contained in:
		
							
								
								
									
										57
									
								
								doc/source/apk_workloads.rst
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								doc/source/apk_workloads.rst
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
			
		||||
.. _apk_workload_settings:
 | 
			
		||||
 | 
			
		||||
APK Workloads
 | 
			
		||||
=============
 | 
			
		||||
 | 
			
		||||
APK resolution
 | 
			
		||||
--------------
 | 
			
		||||
 | 
			
		||||
WA has various resource getters that can be configured to locate APK files but for most people APK files
 | 
			
		||||
should be kept in the ``$WA_HOME/dependencies/SOME_WORKLOAD/`` directory. (by default 
 | 
			
		||||
``~/.workload_automation/dependencies/SOME_WORKLOAD/``). The ``WA_HOME`` enviroment variable can be used
 | 
			
		||||
to chnage the location of this folder. The APK files need to be put into the corresponding directories
 | 
			
		||||
for the workload they belong to. The name of the file can be anything but as explained below may need
 | 
			
		||||
to contain certain peices of information.
 | 
			
		||||
 | 
			
		||||
All ApkWorkloads have parameters that affect the way in which APK files are resolved, ``check_abi``,
 | 
			
		||||
``force_install`` and ``check_apk``. Their exact behaviours are outlined below.
 | 
			
		||||
 | 
			
		||||
.. confval:: check_abi
 | 
			
		||||
 | 
			
		||||
   If this setting is enabled WA's resource resolvers will look for the devices ABI within the file name
 | 
			
		||||
   e.g. ``calculator_arm65.apk``. By default this setting is disabled since most apks will work across all
 | 
			
		||||
   devices. You may wish to enable this feature when working with devices that support multiple ABI's (like 
 | 
			
		||||
   64-bit devices that can run 32-bit APK files) and  are specifically trying to test one or the other.
 | 
			
		||||
 | 
			
		||||
.. confval:: force_install
 | 
			
		||||
 | 
			
		||||
   If this setting is enabled WA will *always* use the APK file on the host, and re-install it on every
 | 
			
		||||
   iteration. If there is no APK on the host that is a suitable version and/or ABI for the workload WA
 | 
			
		||||
   will error when ``force_install`` is enabled.
 | 
			
		||||
 | 
			
		||||
.. confval:: check_apk
 | 
			
		||||
 | 
			
		||||
   This parameter is used to specify a preference over host or target versions of the app. When set to
 | 
			
		||||
   ``True`` WA will prefer the host side version of the APK. It will check if the host has the APK and
 | 
			
		||||
   if the host APK meets the version requirements of the workload. If does and the target already has
 | 
			
		||||
   same version nothing will be done, other wise it will overwrite the targets app with the host version.
 | 
			
		||||
   If the hosts is missing the APK or it does not meet version requirements WA will fall back to the app
 | 
			
		||||
   on the target if it has the app and it is of a suitable version. When this parameter is set to 
 | 
			
		||||
   ``false`` WA will prefer to use the version already on the target if it meets the workloads version
 | 
			
		||||
   requirements. If it does not it will fall back to search the host for the correct version. In both modes
 | 
			
		||||
   if neither the host nor target have a suitable version, WA will error and not run the workload.
 | 
			
		||||
 | 
			
		||||
Some workloads will also feature the follow parameters which will alter the way their APK files are resolved.
 | 
			
		||||
 | 
			
		||||
.. confval:: version
 | 
			
		||||
 | 
			
		||||
   This parameter is used to specify which version of uiautomation for the workload is used. In some workloads
 | 
			
		||||
   e.g. ``geekbench`` multiple versions with drastically different UI's are supported. When a workload uses a
 | 
			
		||||
   version it is required for the APK file to contain the uiautomation version in the file name. In the case
 | 
			
		||||
   of antutu the file names could be: ``geekbench_2.apk`` or ``geekbench_3.apk``.
 | 
			
		||||
 | 
			
		||||
.. confval:: variant_name
 | 
			
		||||
 | 
			
		||||
   Some workloads use variants of APK files, this is usually the case with web browser APK files, these work
 | 
			
		||||
   in exactly the same way as the version,  the variant of the apk 
 | 
			
		||||
 | 
			
		||||
@@ -118,6 +118,7 @@ and detailed descriptions of how WA functions under the hood.
 | 
			
		||||
   additional_topics
 | 
			
		||||
   daq_device_setup
 | 
			
		||||
   revent
 | 
			
		||||
   apk_workloads
 | 
			
		||||
   contributing
 | 
			
		||||
 | 
			
		||||
API Reference
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,7 @@ from wlauto.core.workload import Workload
 | 
			
		||||
from wlauto.core.resource import NO_ONE
 | 
			
		||||
from wlauto.common.android.resources import ApkFile
 | 
			
		||||
from wlauto.common.resources import ExtensionAsset, Executable, File
 | 
			
		||||
from wlauto.exceptions import WorkloadError, ResourceError, ConfigError, DeviceError
 | 
			
		||||
from wlauto.exceptions import WorkloadError, ResourceError, DeviceError
 | 
			
		||||
from wlauto.utils.android import ApkInfo, ANDROID_NORMAL_PERMISSIONS, UNSUPPORTED_PACKAGES
 | 
			
		||||
from wlauto.utils.types import boolean
 | 
			
		||||
from wlauto.utils.revent import ReventParser
 | 
			
		||||
@@ -35,12 +35,12 @@ import wlauto.common.android.resources
 | 
			
		||||
 | 
			
		||||
DELAY = 5
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Due to the way `super` works you have to call it at every level but WA executes some
 | 
			
		||||
# methods conditionally and so has to do them directly via the class, this breaks super
 | 
			
		||||
# methods conditionally and so has to call them directly via the class, this breaks super
 | 
			
		||||
# and causes it to run things mutiple times ect. As a work around for this untill workloads
 | 
			
		||||
# are reworked everything that subclasses workload calls parent methods explicitly
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class UiAutomatorWorkload(Workload):
 | 
			
		||||
    """
 | 
			
		||||
    Base class for all workloads that rely on a UI Automator JAR file.
 | 
			
		||||
@@ -173,13 +173,16 @@ class ApkWorkload(Workload):
 | 
			
		||||
                  description='Timeout for the installation of the apk.'),
 | 
			
		||||
        Parameter('check_apk', kind=boolean, default=True,
 | 
			
		||||
                  description='''
 | 
			
		||||
                  Discover the APK for this workload on the host, and check that
 | 
			
		||||
                  the version matches the one on device (if already installed).
 | 
			
		||||
                  When set to True the APK file on the host will be prefered if
 | 
			
		||||
                  it is a valid version and ABI, if not it will fall back to the
 | 
			
		||||
                  version on the targer. When set to False the target version is
 | 
			
		||||
                  prefered.
 | 
			
		||||
                  '''),
 | 
			
		||||
        Parameter('force_install', kind=boolean, default=False,
 | 
			
		||||
                  description='''
 | 
			
		||||
                  Always re-install the APK, even if matching version is found already installed
 | 
			
		||||
                  on the device. Runs ``adb install -r`` to ensure existing APK is replaced.
 | 
			
		||||
                  on the device. Runs ``adb install -r`` to ensure existing APK is replaced. When
 | 
			
		||||
                  this is set, check_apk is ignored.
 | 
			
		||||
                  '''),
 | 
			
		||||
        Parameter('uninstall_apk', kind=boolean, default=False,
 | 
			
		||||
                  description='If ``True``, will uninstall workload\'s APK as part of teardown.'),
 | 
			
		||||
@@ -199,88 +202,149 @@ class ApkWorkload(Workload):
 | 
			
		||||
 | 
			
		||||
    def setup(self, context):
 | 
			
		||||
        Workload.setup(self, context)
 | 
			
		||||
        # Get APK for the correct version and device ABI
 | 
			
		||||
 | 
			
		||||
        # Get target version
 | 
			
		||||
        target_version = self.device.get_installed_package_version(self.package)
 | 
			
		||||
        if target_version:
 | 
			
		||||
            target_version = LooseVersion(target_version)
 | 
			
		||||
            self.logger.debug("Found version '{}' on target device".format(target_version))
 | 
			
		||||
 | 
			
		||||
        # Get host version
 | 
			
		||||
        self.apk_file = context.resolver.get(ApkFile(self, self.device.abi),
 | 
			
		||||
                                             version=getattr(self, 'version', None),
 | 
			
		||||
                                             check_abi=getattr(self, 'check_abi', False),
 | 
			
		||||
                                             variant_name=getattr(self, 'variant_name', None),
 | 
			
		||||
                                             strict=self.check_apk)
 | 
			
		||||
        # Validate the APK
 | 
			
		||||
        if self.check_apk:
 | 
			
		||||
            if not self.apk_file:
 | 
			
		||||
                raise WorkloadError('No APK file found for workload {}.'.format(self.name))
 | 
			
		||||
                                             strict=False)
 | 
			
		||||
        host_version = None
 | 
			
		||||
        if self.apk_file is not None:
 | 
			
		||||
            host_version = ApkInfo(self.apk_file).version_name
 | 
			
		||||
            if host_version:
 | 
			
		||||
                host_version = LooseVersion(host_version)
 | 
			
		||||
            self.logger.debug("Found version '{}' on host".format(host_version))
 | 
			
		||||
 | 
			
		||||
        # Error if apk was not found anywhere
 | 
			
		||||
        if target_version is None and host_version is None:
 | 
			
		||||
            msg = "Could not find APK for '{}' on the host or target device"
 | 
			
		||||
            raise ResourceError(msg.format(self.name))
 | 
			
		||||
 | 
			
		||||
        # Ensure the apk is setup on the device
 | 
			
		||||
        if self.force_install:
 | 
			
		||||
            self.force_install_apk(context, host_version, target_version)
 | 
			
		||||
        elif self.check_apk:
 | 
			
		||||
            self.prefer_host_apk(context, host_version, target_version)
 | 
			
		||||
        else:
 | 
			
		||||
            if self.force_install:
 | 
			
		||||
                raise ConfigError('force_install cannot be "True" when check_apk is set to "False".')
 | 
			
		||||
            self.prefer_target_apk(context, host_version, target_version)
 | 
			
		||||
 | 
			
		||||
        self.initialize_package(context)
 | 
			
		||||
 | 
			
		||||
        # Check the APK version against the min and max versions compatible
 | 
			
		||||
        # with the workload before launching the package. Note: must be called
 | 
			
		||||
        # after initialize_package() to get self.apk_version.
 | 
			
		||||
        if self.check_apk:
 | 
			
		||||
            self.check_apk_version()
 | 
			
		||||
        self.reset(context)
 | 
			
		||||
        self.apk_version = self.device.get_installed_package_version(self.package)
 | 
			
		||||
        context.add_classifiers(apk_version=self.apk_version)
 | 
			
		||||
 | 
			
		||||
        if self.launch_main:
 | 
			
		||||
            self.launch_package()  # launch default activity without intent data
 | 
			
		||||
            self.launch_package() # launch default activity without intent data
 | 
			
		||||
        self.device.execute('am kill-all')  # kill all *background* activities
 | 
			
		||||
        self.device.clear_logcat()
 | 
			
		||||
 | 
			
		||||
    def initialize_package(self, context):
 | 
			
		||||
        installed_version = self.device.get_installed_package_version(self.package)
 | 
			
		||||
        if self.check_apk:
 | 
			
		||||
            self.initialize_with_host_apk(context, installed_version)
 | 
			
		||||
        else:
 | 
			
		||||
            if not installed_version:
 | 
			
		||||
                message = '''{} not found on the device and check_apk is set to "False"
 | 
			
		||||
                             so host version was not checked.'''
 | 
			
		||||
                raise WorkloadError(message.format(self.package))
 | 
			
		||||
            message = 'Version {} installed on device; skipping host APK check.'
 | 
			
		||||
            self.logger.debug(message.format(installed_version))
 | 
			
		||||
            self.reset(context)
 | 
			
		||||
            self.apk_version = installed_version
 | 
			
		||||
        context.add_classifiers(apk_version=self.apk_version)
 | 
			
		||||
    def force_install_apk(self, context, host_version, target_version):
 | 
			
		||||
        if host_version is None:
 | 
			
		||||
            raise ResourceError("force_install is 'True' but could not find APK on the host")
 | 
			
		||||
        try:
 | 
			
		||||
            self.validate_version(host_version)
 | 
			
		||||
        except ResourceError as e:
 | 
			
		||||
            msg = "force_install is 'True' but the host version is invalid:\n\t{}"
 | 
			
		||||
            raise ResourceError(msg.format(str(e)))
 | 
			
		||||
        self.install_apk(context, replace=(target_version is not None))
 | 
			
		||||
 | 
			
		||||
    def initialize_with_host_apk(self, context, installed_version):
 | 
			
		||||
        host_version = ApkInfo(self.apk_file).version_name
 | 
			
		||||
        if installed_version != host_version:
 | 
			
		||||
            if installed_version:
 | 
			
		||||
                message = '{} host version: {}, device version: {}; re-installing...'
 | 
			
		||||
                self.logger.debug(message.format(os.path.basename(self.apk_file),
 | 
			
		||||
                                                 host_version, installed_version))
 | 
			
		||||
    def prefer_host_apk(self, context, host_version, target_version):
 | 
			
		||||
        msg = "check_apk is 'True' "
 | 
			
		||||
        if host_version is None:
 | 
			
		||||
            try:
 | 
			
		||||
                self.validate_version(target_version)
 | 
			
		||||
            except ResourceError as e:
 | 
			
		||||
                msg += "but the APK was not found on the host and the target version is invalid:\n\t{}"
 | 
			
		||||
                raise ResourceError(msg.format(str(e)))
 | 
			
		||||
            else:
 | 
			
		||||
                message = '{} host version: {}, not found on device; installing...'
 | 
			
		||||
                self.logger.debug(message.format(os.path.basename(self.apk_file),
 | 
			
		||||
                                                 host_version))
 | 
			
		||||
            self.force_install = True  # pylint: disable=attribute-defined-outside-init
 | 
			
		||||
        else:
 | 
			
		||||
            message = '{} version {} found on both device and host.'
 | 
			
		||||
            self.logger.debug(message.format(os.path.basename(self.apk_file),
 | 
			
		||||
                                             host_version))
 | 
			
		||||
        if self.force_install:
 | 
			
		||||
            if installed_version:
 | 
			
		||||
                self.device.uninstall(self.package)
 | 
			
		||||
            # It's possible that the uninstall above fails, which might result in a warning
 | 
			
		||||
            # and/or failure during installation. However execution should proceed, so need
 | 
			
		||||
            # to make sure that the right apk_vesion is reported in the end.
 | 
			
		||||
            if self.install_apk(context):
 | 
			
		||||
                self.apk_version = host_version
 | 
			
		||||
                msg += "but the APK was not found on the host, using target version"
 | 
			
		||||
                self.logger.debug(msg)
 | 
			
		||||
                return
 | 
			
		||||
        try:
 | 
			
		||||
            self.validate_version(host_version)
 | 
			
		||||
        except ResourceError as e1:
 | 
			
		||||
            msg += "but the host APK version is invalid:\n\t{}\n"
 | 
			
		||||
            if target_version is None:
 | 
			
		||||
                msg += "The target does not have the app either"
 | 
			
		||||
                raise ResourceError(msg.format(str(e1)))
 | 
			
		||||
            try:
 | 
			
		||||
                self.validate_version(target_version)
 | 
			
		||||
            except ResourceError as e2:
 | 
			
		||||
                msg += "The target version is also invalid:\n\t{}"
 | 
			
		||||
                raise ResourceError(msg.format(str(e1), str(e2)))
 | 
			
		||||
            else:
 | 
			
		||||
                self.apk_version = installed_version
 | 
			
		||||
                msg += "using the target version instead"
 | 
			
		||||
                self.logger.debug(msg.format(str(e1)))
 | 
			
		||||
        else:  # Host version is valid
 | 
			
		||||
            if target_version is not None and target_version == host_version:
 | 
			
		||||
                msg += " and a matching version is alread on the device, doing nothing"
 | 
			
		||||
                self.logger.debug(msg)
 | 
			
		||||
                return
 | 
			
		||||
            msg += " and the host version is not on the target, installing APK"
 | 
			
		||||
            self.logger.debug(msg)
 | 
			
		||||
            self.install_apk(context, replace=(target_version is not None))
 | 
			
		||||
 | 
			
		||||
    def prefer_target_apk(self, context, host_version, target_version):
 | 
			
		||||
        msg = "check_apk is 'False' "
 | 
			
		||||
        if target_version is None:
 | 
			
		||||
            try:
 | 
			
		||||
                self.validate_version(host_version)
 | 
			
		||||
            except ResourceError as e:
 | 
			
		||||
                msg += "but the app was not found on the target and the host version is invalid:\n\t{}"
 | 
			
		||||
                raise ResourceError(msg.format(str(e)))
 | 
			
		||||
            else:
 | 
			
		||||
                msg += "and the app was not found on the target, using host version"
 | 
			
		||||
                self.logger.debug(msg)
 | 
			
		||||
                self.install_apk(context)
 | 
			
		||||
                return
 | 
			
		||||
        try:
 | 
			
		||||
            self.validate_version(target_version)
 | 
			
		||||
        except ResourceError as e1:
 | 
			
		||||
            msg += "but the target app version is invalid:\n\t{}\n"
 | 
			
		||||
            if host_version is None:
 | 
			
		||||
                msg += "The host does not have the APK either"
 | 
			
		||||
                raise ResourceError(msg.format(str(e1)))
 | 
			
		||||
            try:
 | 
			
		||||
                self.validate_version(host_version)
 | 
			
		||||
            except ResourceError as e2:
 | 
			
		||||
                msg += "The host version is also invalid:\n\t{}"
 | 
			
		||||
                raise ResourceError(msg.format(str(e1), str(e2)))
 | 
			
		||||
            else:
 | 
			
		||||
                msg += "Using the host APK instead"
 | 
			
		||||
                self.logger.debug(msg.format(str(e1)))
 | 
			
		||||
                self.install_apk(context, replace=True)
 | 
			
		||||
        else:
 | 
			
		||||
            self.apk_version = installed_version
 | 
			
		||||
            self.reset(context)
 | 
			
		||||
            msg += "and a valid version of the app is already on the target, using target app"
 | 
			
		||||
            self.logger.debug(msg)
 | 
			
		||||
 | 
			
		||||
    def check_apk_version(self):
 | 
			
		||||
        if self.min_apk_version:
 | 
			
		||||
            if LooseVersion(self.apk_version) < LooseVersion(self.min_apk_version):
 | 
			
		||||
                message = "APK version not supported. Minimum version required: {}"
 | 
			
		||||
                raise WorkloadError(message.format(self.min_apk_version))
 | 
			
		||||
    def validate_version(self, version):
 | 
			
		||||
        min_apk_version = getattr(self, 'min_apk_version', None)
 | 
			
		||||
        max_apk_version = getattr(self, 'max_apk_version', None)
 | 
			
		||||
 | 
			
		||||
        if self.max_apk_version:
 | 
			
		||||
            if LooseVersion(self.apk_version) > LooseVersion(self.max_apk_version):
 | 
			
		||||
                message = "APK version not supported. Maximum version supported: {}"
 | 
			
		||||
                raise WorkloadError(message.format(self.max_apk_version))
 | 
			
		||||
        if min_apk_version is not None and max_apk_version is not None:
 | 
			
		||||
            if version < LooseVersion(min_apk_version) or \
 | 
			
		||||
                    version > LooseVersion(max_apk_version):
 | 
			
		||||
                msg = "version '{}' not supported. " \
 | 
			
		||||
                      "Minimum version required: '{}', Maximum version known to work: '{}'"
 | 
			
		||||
                raise ResourceError(msg.format(version, min_apk_version))
 | 
			
		||||
 | 
			
		||||
        elif min_apk_version is not None:
 | 
			
		||||
            if version < LooseVersion(min_apk_version):
 | 
			
		||||
                msg = "version '{}' not supported. " \
 | 
			
		||||
                      "Minimum version required: '{}'"
 | 
			
		||||
                raise ResourceError(msg.format(version, min_apk_version))
 | 
			
		||||
 | 
			
		||||
        elif max_apk_version is not None:
 | 
			
		||||
            if version > LooseVersion(max_apk_version):
 | 
			
		||||
                msg = "version '{}' not supported. " \
 | 
			
		||||
                      "Maximum version known to work: '{}'"
 | 
			
		||||
                raise ResourceError(msg.format(version, min_apk_version))
 | 
			
		||||
 | 
			
		||||
    def launch_package(self):
 | 
			
		||||
        if not self.activity:
 | 
			
		||||
@@ -302,9 +366,9 @@ class ApkWorkload(Workload):
 | 
			
		||||
        if self.device.get_sdk_version() >= 23:
 | 
			
		||||
            self._grant_requested_permissions()
 | 
			
		||||
 | 
			
		||||
    def install_apk(self, context):
 | 
			
		||||
    def install_apk(self, context, replace=False):
 | 
			
		||||
        success = False
 | 
			
		||||
        output = self.device.install(self.apk_file, self.install_timeout, replace=self.force_install)
 | 
			
		||||
        output = self.device.install(self.apk_file, self.install_timeout, replace=replace)
 | 
			
		||||
        if 'Failure' in output:
 | 
			
		||||
            if 'ALREADY_EXISTS' in output:
 | 
			
		||||
                self.logger.warn('Using already installed APK (did not unistall properly?)')
 | 
			
		||||
 
 | 
			
		||||
@@ -56,7 +56,8 @@ from wlauto.core.extension_loader import ExtensionLoader
 | 
			
		||||
from wlauto.core.resolver import ResourceResolver
 | 
			
		||||
from wlauto.core.result import ResultManager, IterationResult, RunResult
 | 
			
		||||
from wlauto.exceptions import (WAError, ConfigError, TimeoutError, InstrumentError,
 | 
			
		||||
                               DeviceError, DeviceNotRespondingError)
 | 
			
		||||
                               DeviceError, DeviceNotRespondingError, ResourceError,
 | 
			
		||||
                               HostError)
 | 
			
		||||
from wlauto.utils.misc import ensure_directory_exists as _d, get_traceback, merge_dicts, format_duration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -756,17 +757,21 @@ class Runner(object):
 | 
			
		||||
            if self.current_job:
 | 
			
		||||
                self.current_job.result.status = on_error_status
 | 
			
		||||
                self.current_job.result.add_event(str(we))
 | 
			
		||||
            try:
 | 
			
		||||
                self._take_screenshot('error.png')
 | 
			
		||||
                if self.device.platform == 'android':
 | 
			
		||||
                    self._take_uiautomator_dump('error.xml')
 | 
			
		||||
            except Exception, e:  # pylint: disable=W0703
 | 
			
		||||
                # We're already in error state, so the fact that taking a
 | 
			
		||||
                # screenshot failed is not surprising...
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
            # There is no point in taking a screenshot ect if the issue is not
 | 
			
		||||
            # with the device but with the host or a missing resource
 | 
			
		||||
            if not (isinstance(we, ResourceError) or isinstance(we, HostError)):
 | 
			
		||||
                try:
 | 
			
		||||
                    self._take_screenshot('error.png')
 | 
			
		||||
                    if self.device.platform == 'android':
 | 
			
		||||
                        self._take_uiautomator_dump('error.xml')
 | 
			
		||||
                except Exception, e:  # pylint: disable=W0703
 | 
			
		||||
                    # We're already in error state, so the fact that taking a
 | 
			
		||||
                    # screenshot failed is not surprising...
 | 
			
		||||
                    pass
 | 
			
		||||
            if action:
 | 
			
		||||
                action = action[0].lower() + action[1:]
 | 
			
		||||
            self.logger.error('Error while {}:\n\t{}'.format(action, we))
 | 
			
		||||
            self.logger.error('Error while {}:\n\t{}'.format(action, str(we).replace("\n", "\n\t")))
 | 
			
		||||
        except Exception, e:  # pylint: disable=W0703
 | 
			
		||||
            error_text = '{}("{}")'.format(e.__class__.__name__, e)
 | 
			
		||||
            if self.current_job:
 | 
			
		||||
 
 | 
			
		||||
@@ -48,7 +48,7 @@ class Antutu(AndroidUiAutoBenchmark):
 | 
			
		||||
    activity = ".ABenchMarkStart"
 | 
			
		||||
    summary_metrics = ['score', 'Overall_Score']
 | 
			
		||||
 | 
			
		||||
    valid_versions = ['3.3.2', '4.0.3', '5.3', '5.3.0', '6.0.1']
 | 
			
		||||
    valid_versions = ['3.3.2', '4.0.3', '5.3.0', '6.0.1']
 | 
			
		||||
 | 
			
		||||
    device_prefs_directory = '/data/data/com.antutu.ABenchMark/shared_prefs'
 | 
			
		||||
    device_prefs_file = '/'.join([device_prefs_directory, 'com.antutu.ABenchMark_preferences.xml'])
 | 
			
		||||
@@ -70,8 +70,6 @@ class Antutu(AndroidUiAutoBenchmark):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, device, **kwargs):  # pylint: disable=W0613
 | 
			
		||||
        super(Antutu, self).__init__(device, **kwargs)
 | 
			
		||||
        if self.version == '5.3.0':
 | 
			
		||||
            self.version = '5.3'
 | 
			
		||||
        self.run_timeout = 10 * 60 * self.times
 | 
			
		||||
        self.uiauto_params['version'] = self.version
 | 
			
		||||
        self.uiauto_params['times'] = self.times
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -66,7 +66,7 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
            while (true) {
 | 
			
		||||
                    if(version.equals("6.0.1"))
 | 
			
		||||
                        hitTestButtonVersion5(TestButton6);
 | 
			
		||||
                    else if (version.equals("5.3")) {
 | 
			
		||||
                    else if (version.equals("5.3.0")) {
 | 
			
		||||
                        hitTestButton();
 | 
			
		||||
                        hitTestButtonVersion5(TestButton5);
 | 
			
		||||
                    }
 | 
			
		||||
@@ -308,7 +308,7 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
 | 
			
		||||
    public void returnToTestScreen(String version) throws Exception {
 | 
			
		||||
        getUiDevice().pressBack();
 | 
			
		||||
        if (version.equals("5.3"))
 | 
			
		||||
        if (version.equals("5.3.0"))
 | 
			
		||||
        {
 | 
			
		||||
            UiSelector selector = new UiSelector();
 | 
			
		||||
            UiObject detailsButton = new UiObject(new UiSelector().className("android.widget.Button")
 | 
			
		||||
 
 | 
			
		||||
@@ -59,11 +59,11 @@ class Geekbench(AndroidUiAutoBenchmark):
 | 
			
		||||
    """
 | 
			
		||||
    summary_metrics = ['score', 'multicore_score']
 | 
			
		||||
    versions = {
 | 
			
		||||
        '3.0.0': {
 | 
			
		||||
        '3': {
 | 
			
		||||
            'package': 'com.primatelabs.geekbench3',
 | 
			
		||||
            'activity': '.HomeActivity',
 | 
			
		||||
        },
 | 
			
		||||
        '2.2.7': {
 | 
			
		||||
        '2': {
 | 
			
		||||
            'package': 'ca.primatelabs.geekbench2',
 | 
			
		||||
            'activity': '.HomeActivity',
 | 
			
		||||
        },
 | 
			
		||||
@@ -73,8 +73,7 @@ class Geekbench(AndroidUiAutoBenchmark):
 | 
			
		||||
    replace_regex = re.compile(r'<[^>]*>')
 | 
			
		||||
 | 
			
		||||
    parameters = [
 | 
			
		||||
        Parameter('version', default=sorted(versions.keys())[-1], allowed_values=sorted(versions.keys() +
 | 
			
		||||
                                                                                        ['2', '3']),
 | 
			
		||||
        Parameter('version', default=sorted(versions.keys())[-1], allowed_values=sorted(versions.keys()),
 | 
			
		||||
                  description='Specifies which version of the workload should be run.'),
 | 
			
		||||
        Parameter('times', kind=int, default=1,
 | 
			
		||||
                  description=('Specfies the number of times the benchmark will be run in a "tight '
 | 
			
		||||
@@ -91,16 +90,12 @@ class Geekbench(AndroidUiAutoBenchmark):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, device, **kwargs):
 | 
			
		||||
        super(Geekbench, self).__init__(device, **kwargs)
 | 
			
		||||
        if self.version == '3':
 | 
			
		||||
            self.version = '3.0.0'
 | 
			
		||||
        elif self.version == '2':
 | 
			
		||||
            self.version = '2.2.7'
 | 
			
		||||
        self.uiauto_params['version'] = self.version
 | 
			
		||||
        self.uiauto_params['times'] = self.times
 | 
			
		||||
        self.run_timeout = 5 * 60 * self.times
 | 
			
		||||
 | 
			
		||||
    def initialize(self, context):
 | 
			
		||||
        if self.version == '3.0.0' and not self.device.is_rooted:
 | 
			
		||||
        if self.version == '3' and not self.device.is_rooted:
 | 
			
		||||
            raise WorkloadError('Geekbench workload only works on rooted devices.')
 | 
			
		||||
 | 
			
		||||
    def init_resources(self, context):
 | 
			
		||||
@@ -113,14 +108,12 @@ class Geekbench(AndroidUiAutoBenchmark):
 | 
			
		||||
 | 
			
		||||
    def update_result(self, context):
 | 
			
		||||
        super(Geekbench, self).update_result(context)
 | 
			
		||||
        if self.version == "2.2.7":
 | 
			
		||||
            self.update_result_2(context)
 | 
			
		||||
        else:
 | 
			
		||||
            self.update_result_3(context)
 | 
			
		||||
        update_method = getattr(self, 'update_result_{}'.format(self.version))
 | 
			
		||||
        update_method(context)
 | 
			
		||||
 | 
			
		||||
    def validate(self):
 | 
			
		||||
        if (self.times > 1) and (self.version == '2.2.7'):
 | 
			
		||||
            raise ConfigError('times parameter is not supported for version 2.2.7 of Geekbench.')
 | 
			
		||||
        if (self.times > 1) and (self.version == '2'):
 | 
			
		||||
            raise ConfigError('times parameter is not supported for version 2 of Geekbench.')
 | 
			
		||||
 | 
			
		||||
    def update_result_2(self, context):
 | 
			
		||||
        score_calculator = GBScoreCalculator()
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -32,26 +32,26 @@ import com.android.uiautomator.testrunner.UiAutomatorTestCase;
 | 
			
		||||
 | 
			
		||||
import com.arm.wlauto.uiauto.BaseUiAutomation;
 | 
			
		||||
 | 
			
		||||
public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
public class UiAutomation extends BaseUiAutomation {   
 | 
			
		||||
 | 
			
		||||
    public static String TAG = "geekbench";
 | 
			
		||||
 | 
			
		||||
    public void runUiAutomation() throws Exception {
 | 
			
		||||
        Bundle params = getParams();
 | 
			
		||||
        String version = params.getString("version");
 | 
			
		||||
        int version = Integer.parseInt(params.getString("version"));
 | 
			
		||||
        int times = Integer.parseInt(params.getString("times"));
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < times; i++) {
 | 
			
		||||
                runBenchmarks();
 | 
			
		||||
                if(version.equals("2.2.7")) {
 | 
			
		||||
                switch(version) {
 | 
			
		||||
                case 2: 
 | 
			
		||||
                        // In version 2, we scroll through the results WebView to make sure
 | 
			
		||||
                        // all results appear on the screen, which causes them to be dumped into
 | 
			
		||||
                        // logcat by the Linaro hacks.
 | 
			
		||||
                        waitForResultsv2();
 | 
			
		||||
                        scrollThroughResults();
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
                else if(version.equals("3.0.0")) {
 | 
			
		||||
                case 3: 
 | 
			
		||||
                        // Attempting to share the results will generate the .gb3 file with
 | 
			
		||||
                        // results that can then be pulled from the device. This is not possible
 | 
			
		||||
                        // in verison 2 of Geekbench (Share option was added later).
 | 
			
		||||
 
 | 
			
		||||
@@ -57,14 +57,14 @@ class Glb(AndroidUiAutoBenchmark):
 | 
			
		||||
    view = 'com.glbenchmark.glbenchmark27/com.glbenchmark.activities.GLBRender'
 | 
			
		||||
 | 
			
		||||
    packages = {
 | 
			
		||||
        '2.7': 'com.glbenchmark.glbenchmark27',
 | 
			
		||||
        '2.5': 'com.glbenchmark.glbenchmark25',
 | 
			
		||||
        '2.7.0': 'com.glbenchmark.glbenchmark27',
 | 
			
		||||
        '2.5.1': 'com.glbenchmark.glbenchmark25',
 | 
			
		||||
    }
 | 
			
		||||
    # If usecase is not specified the default usecase is the first supported usecase alias
 | 
			
		||||
    # for the specified version.
 | 
			
		||||
    supported_usecase_aliases = {
 | 
			
		||||
        '2.7': ['t-rex', 'egypt'],
 | 
			
		||||
        '2.5': ['egypt-classic', 'egypt'],
 | 
			
		||||
        '2.7.0': ['t-rex', 'egypt'],
 | 
			
		||||
        '2.5.1': ['egypt-classic', 'egypt'],
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    default_iterations = 1
 | 
			
		||||
@@ -73,15 +73,15 @@ class Glb(AndroidUiAutoBenchmark):
 | 
			
		||||
    regex = re.compile(r'GLBenchmark (metric|FPS): (.*)')
 | 
			
		||||
 | 
			
		||||
    parameters = [
 | 
			
		||||
        Parameter('version', default='2.7', allowed_values=['2.7', '2.7.0', '2.5', '2.5.1'],
 | 
			
		||||
        Parameter('version', default='2.7.0', allowed_values=['2.7.0', '2.5.1'],
 | 
			
		||||
                  description=('Specifies which version of the benchmark to run (different versions '
 | 
			
		||||
                               'support different use cases).')),
 | 
			
		||||
        Parameter('use_case', default=None,
 | 
			
		||||
                  description="""Specifies which usecase to run, as listed in the benchmark menu; e.g.
 | 
			
		||||
                                 ``'GLBenchmark 2.5 Egypt HD'``. For convenience, two aliases are provided
 | 
			
		||||
                                 for the most common use cases: ``'egypt'`` and ``'t-rex'``. These could
 | 
			
		||||
                                 be use instead of the full use case title. For version ``'2.7'`` it defaults
 | 
			
		||||
                                 to ``'t-rex'``, for version ``'2.5'`` it defaults to ``'egypt-classic'``.
 | 
			
		||||
                                 be use instead of the full use case title. For version ``'2.7.0'`` it defaults
 | 
			
		||||
                                 to ``'t-rex'``, for version ``'2.5.1'`` it defaults to ``'egypt-classic'``.
 | 
			
		||||
                  """),
 | 
			
		||||
        Parameter('variant', default='onscreen',
 | 
			
		||||
                  description="""Specifies which variant of the use case to run, as listed in the benchmarks
 | 
			
		||||
@@ -111,10 +111,6 @@ class Glb(AndroidUiAutoBenchmark):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, device, **kwargs):
 | 
			
		||||
        super(Glb, self).__init__(device, **kwargs)
 | 
			
		||||
        if self.version == '2.7.0':
 | 
			
		||||
            self.version = '2.7'
 | 
			
		||||
        elif self.version == '2.5.1':
 | 
			
		||||
            self.version = '2.5'
 | 
			
		||||
        self.uiauto_params['version'] = self.version
 | 
			
		||||
 | 
			
		||||
        if self.use_case is None:
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -33,7 +33,7 @@ import com.android.uiautomator.testrunner.UiAutomatorTestCase;
 | 
			
		||||
 | 
			
		||||
import com.arm.wlauto.uiauto.BaseUiAutomation;
 | 
			
		||||
 | 
			
		||||
public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
public class UiAutomation extends BaseUiAutomation {   
 | 
			
		||||
 | 
			
		||||
    public static String TAG = "glb";
 | 
			
		||||
    public static int maxScrolls = 15;
 | 
			
		||||
@@ -63,7 +63,7 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
                extractResults();
 | 
			
		||||
                iterations -= 1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        Bundle status = new Bundle();
 | 
			
		||||
        getAutomationSupport().sendStatus(Activity.RESULT_OK, status);
 | 
			
		||||
    }
 | 
			
		||||
@@ -81,9 +81,9 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
        UiObject useCaseText = new UiObject(selector.className("android.widget.TextView")
 | 
			
		||||
                                                    .text(useCase)
 | 
			
		||||
                                           );
 | 
			
		||||
        if (version.equals("2.7")){
 | 
			
		||||
        if (version.equals("2.7.0")){
 | 
			
		||||
                UiObject variantText =  useCaseText.getFromParent(selector.className("android.widget.TextView")
 | 
			
		||||
                                                                          .text(variant));
 | 
			
		||||
                                                                          .text(variant));    
 | 
			
		||||
                int scrolls = 0;
 | 
			
		||||
                while(!variantText.exists()) {
 | 
			
		||||
                        testList.scrollForward();
 | 
			
		||||
@@ -94,7 +94,7 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
                }
 | 
			
		||||
                variantText.click();
 | 
			
		||||
        }
 | 
			
		||||
        else if (version.equals("2.5")){
 | 
			
		||||
        else if (version.equals("2.5.1")){
 | 
			
		||||
                int scrolls = 0;
 | 
			
		||||
                while(!useCaseText.exists()) {
 | 
			
		||||
                        testList.scrollForward();
 | 
			
		||||
@@ -123,7 +123,7 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
    public void waitForResults(String version, String useCase, int timeout) throws Exception {
 | 
			
		||||
        UiSelector selector = new UiSelector();
 | 
			
		||||
        UiObject results = null;
 | 
			
		||||
        if (version.equals("2.7"))
 | 
			
		||||
        if (version.equals("2.7.0"))
 | 
			
		||||
                results = new UiObject(selector.text("Results").className("android.widget.TextView"));
 | 
			
		||||
        else
 | 
			
		||||
                results =  new UiObject(selector.text(useCase).className("android.widget.TextView"));
 | 
			
		||||
@@ -135,7 +135,7 @@ public class UiAutomation extends BaseUiAutomation {
 | 
			
		||||
	// starting GLB.
 | 
			
		||||
        if (!results.waitForExists(TimeUnit.SECONDS.toMillis(timeout))) {
 | 
			
		||||
		Log.v(TAG, "Results screen not found. Attempting to bring to foreground.");
 | 
			
		||||
		String[] commandLine = {"am", "start",
 | 
			
		||||
		String[] commandLine = {"am", "start", 
 | 
			
		||||
					"-a", "android.intent.action.MAIN",
 | 
			
		||||
					"-c", "android.intent.category.LAUNCHER",
 | 
			
		||||
					"-n", "com.glbenchmark.glbenchmark27/com.glbenchmark.activities.GLBenchmarkDownloaderActivity"};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user