1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-19 04:21:17 +00:00

Workload: Added ReventWorkload and updated ReventGUI

Added a new ReventWorkload as a base for revent based workloads.
Updated ReventGui to use `revent_recorder` and now uses `target.model`
instead of `taget.name`.
This commit is contained in:
Marc Bonnici 2017-04-12 16:24:43 +01:00
parent adaa83b6eb
commit 4b84a68038
2 changed files with 114 additions and 43 deletions

View File

@ -14,4 +14,4 @@ from wa.framework.plugin import Plugin, Parameter
from wa.framework.processor import ResultProcessor from wa.framework.processor import ResultProcessor
from wa.framework.resource import (NO_ONE, JarFile, ApkFile, ReventFile, File, from wa.framework.resource import (NO_ONE, JarFile, ApkFile, ReventFile, File,
Executable) Executable)
from wa.framework.workload import Workload, ApkUiautoWorkload from wa.framework.workload import Workload, ApkUiautoWorkload, ReventWorkload

View File

@ -18,8 +18,10 @@ import time
from wa.framework.plugin import TargetedPlugin from wa.framework.plugin import TargetedPlugin
from wa.framework.resource import (ApkFile, JarFile, ReventFile, NO_ONE, from wa.framework.resource import (ApkFile, JarFile, ReventFile, NO_ONE,
Executable) Executable, File)
from wa.framework.exception import WorkloadError from wa.framework.exception import WorkloadError
from wa.utils.revent import ReventRecorder
from wa.utils.exec_control import once
from devlib.utils.android import ApkInfo from devlib.utils.android import ApkInfo
@ -94,25 +96,29 @@ class Workload(TargetedPlugin):
return '<Workload {}>'.format(self.name) return '<Workload {}>'.format(self.name)
class ApkUiautoWorkload(Workload): class ApkUIWorkload(Workload):
platform = 'android' # May be optionally overwritten by subclasses
# Times are in seconds
loading_time = 10
def __init__(self, target, **kwargs): def __init__(self, target, **kwargs):
super(ApkUiautoWorkload, self).__init__(target, **kwargs) super(ApkUIWorkload, self).__init__(target, **kwargs)
self.apk = ApkHander(self) self.apk = None
self.gui = UiAutomatorGUI(self) self.gui = None
def init_resources(self, context): def init_resources(self, context):
self.apk.init_resources(context.resolver) self.apk.init_resources(context.resolver)
self.gui.init_resources(context.resolver) self.gui.init_resources(context.resolver)
self.gui.init_commands() self.gui.init_commands()
@once
def initialize(self, context): def initialize(self, context):
self.gui.deploy() self.gui.deploy()
def setup(self, context): def setup(self, context):
self.apk.setup(context) self.apk.setup(context)
time.sleep(self.loading_time)
self.gui.setup() self.gui.setup()
def run(self, context): def run(self, context):
@ -125,10 +131,40 @@ class ApkUiautoWorkload(Workload):
self.gui.teardown() self.gui.teardown()
self.apk.teardown() self.apk.teardown()
@once
def finalize(self, context): def finalize(self, context):
self.gui.remove() self.gui.remove()
class ApkUiautoWorkload(ApkUIWorkload):
platform = 'android'
def __init__(self, target, **kwargs):
super(ApkUiautoWorkload, self).__init__(target, **kwargs)
self.apk = ApkHander(self)
self.gui = UiAutomatorGUI(self)
class ReventWorkload(ApkUIWorkload):
# May be optionally overwritten by subclasses
# Times are in seconds
setup_timeout = 5 * 60
run_timeout = 10 * 60
extract_results_timeout = 5 * 60
teardown_timeout = 5 * 60
def __init__(self, target, **kwargs):
super(ReventWorkload, self).__init__(target, **kwargs)
self.apk = ApkHander(self)
self.gui = ReventGUI(self, target,
self.setup_timeout,
self.run_timeout,
self.extract_results_timeout,
self.teardown_timeout)
class UiAutomatorGUI(object): class UiAutomatorGUI(object):
stages = ['setup', 'runWorkload', 'extractResults', 'teardown'] stages = ['setup', 'runWorkload', 'extractResults', 'teardown']
@ -209,57 +245,92 @@ class UiAutomatorGUI(object):
class ReventGUI(object): class ReventGUI(object):
def __init__(self, workload, target, setup_timeout=5 * 60, run_timeout=10 * 60): def __init__(self, workload, target, setup_timeout, run_timeout,
extract_results_timeout, teardown_timeout):
self.workload = workload self.workload = workload
self.target = target self.target = target
self.setup_timeout = setup_timeout self.setup_timeout = setup_timeout
self.run_timeout = run_timeout self.run_timeout = run_timeout
self.extract_results_timeout = extract_results_timeout
self.teardown_timeout = teardown_timeout
self.revent_recorder = ReventRecorder(self.target)
self.on_target_revent_binary = self.target.get_workpath('revent') self.on_target_revent_binary = self.target.get_workpath('revent')
self.on_target_setup_revent = self.target.get_workpath('{}.setup.revent'.format(self.target.name)) self.on_target_setup_revent = self.target.get_workpath('{}.setup.revent'.format(self.target.model))
self.on_target_run_revent = self.target.get_workpath('{}.run.revent'.format(self.target.name)) self.on_target_run_revent = self.target.get_workpath('{}.run.revent'.format(self.target.model))
self.on_target_extract_results_revent = self.target.get_workpath('{}.extract_results.revent'.format(self.target.model))
self.on_target_teardown_revent = self.target.get_workpath('{}.teardown.revent'.format(self.target.model))
self.logger = logging.getLogger('revent') self.logger = logging.getLogger('revent')
self.revent_setup_file = None self.revent_setup_file = None
self.revent_run_file = None self.revent_run_file = None
self.revent_extract_results_file = None
self.revent_teardown_file = None
def init_resources(self, context): def init_resources(self, resolver):
self.revent_setup_file = context.resolver.get(ReventFile(self.workload, 'setup')) self.revent_setup_file = resolver.get(ReventFile(owner=self.workload,
self.revent_run_file = context.resolver.get(ReventFile(self.workload, 'run')) stage='setup',
target=self.target.model),
strict=False)
self.revent_run_file = resolver.get(ReventFile(owner=self.workload,
stage='run',
target=self.target.model))
self.revent_extract_results_file = resolver.get(ReventFile(owner=self.workload,
stage='extract_results',
target=self.target.model),
strict=False)
self.revent_teardown_file = resolver.get(resource=ReventFile(owner=self.workload,
stage='teardown',
target=self.target.model),
strict=False)
def setup(self, context): def deploy(self):
self._check_revent_files(context) self.revent_recorder.deploy()
self.target.killall('revent')
command = '{} replay {}'.format(self.on_target_revent_binary, self.on_target_setup_revent)
self.target.execute(command, timeout=self.setup_timeout)
def run(self, context): def setup(self):
command = '{} replay {}'.format(self.on_target_revent_binary, self.on_target_run_revent) self._check_revent_files()
self.logger.debug('Replaying {}'.format(os.path.basename(self.on_target_run_revent))) self.revent_recorder.replay(self.on_target_setup_revent,
self.target.execute(command, timeout=self.run_timeout) timeout=self.setup_timeout)
def run(self):
msg = 'Replaying {}'
self.logger.debug(msg.format(os.path.basename(self.on_target_run_revent)))
self.revent_recorder.replay(self.on_target_run_revent,
timeout=self.run_timeout)
self.logger.debug('Replay completed.') self.logger.debug('Replay completed.')
def teardown(self, context): def extract_results(self):
if self.revent_extract_results_file:
self.revent_recorder.replay(self.on_target_extract_results_revent,
timeout=self.extract_results_timeout)
def teardown(self):
if self.revent_teardown_file:
self.revent_recorder.replay(self.on_target_teardown_revent,
timeout=self.teardown_timeout)
self.target.remove(self.on_target_setup_revent) self.target.remove(self.on_target_setup_revent)
self.target.remove(self.on_target_run_revent) self.target.remove(self.on_target_run_revent)
self.target.remove(self.on_target_extract_results_revent)
self.target.remove(self.on_target_teardown_revent)
def _check_revent_files(self, context): def remove(self):
# check the revent binary self.revent_recorder.remove()
revent_binary = context.resolver.get(Executable(NO_ONE, self.target.abi, 'revent'))
if not os.path.isfile(revent_binary): def init_commands(self):
message = '{} does not exist. '.format(revent_binary) pass
message += 'Please build revent for your system and place it in that location'
raise WorkloadError(message) def _check_revent_files(self):
if not self.revent_setup_file:
# pylint: disable=too-few-format-args
message = '{0}.setup.revent file does not exist, Please provide one for your target, {0}'
raise WorkloadError(message.format(self.target.name))
if not self.revent_run_file: if not self.revent_run_file:
# pylint: disable=too-few-format-args # pylint: disable=too-few-format-args
message = '{0}.run.revent file does not exist, Please provide one for your target, {0}' message = '{0}.run.revent file does not exist, ' \
raise WorkloadError(message.format(self.target.name)) 'Please provide one for your target, {0}'
raise WorkloadError(message.format(self.target.model))
self.on_target_revent_binary = self.target.install(revent_binary)
self.target.push(self.revent_run_file, self.on_target_run_revent) self.target.push(self.revent_run_file, self.on_target_run_revent)
if self.revent_setup_file:
self.target.push(self.revent_setup_file, self.on_target_setup_revent) self.target.push(self.revent_setup_file, self.on_target_setup_revent)
if self.revent_extract_results_file:
self.target.push(self.revent_extract_results_file, self.on_target_extract_results_revent)
if self.revent_teardown_file:
self.target.push(self.revent_teardown_file, self.on_target_teardown_revent)
class ApkHander(object): class ApkHander(object):