1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-31 10:11:17 +00:00

Jobs: Fixes job initialize/finalize

Previously initialize and finalize were being called for each iteration
of each workload at the start/end of the run which is incorrect
behaviour. To prevent this, each iteration of a workload now shares a
single instance of the workload combined with the 'once_per_instance' decorator
to ensure that the methods are only invoked once per set of workload
runs.
This commit is contained in:
Marc Bonnici 2017-07-04 15:44:05 +01:00
parent 91c49d9e95
commit 27b488cc56
2 changed files with 16 additions and 8 deletions

View File

@ -6,6 +6,8 @@ from wa.framework.configuration.core import Status
class Job(object): class Job(object):
_workload_cache = {}
@property @property
def id(self): def id(self):
return self.spec.id return self.spec.id
@ -40,11 +42,15 @@ class Job(object):
def load(self, target, loader=pluginloader): def load(self, target, loader=pluginloader):
self.logger.info('Loading job {}'.format(self.id)) self.logger.info('Loading job {}'.format(self.id))
self.workload = loader.get_workload(self.spec.workload_name, if self.iteration == 1:
target, self.workload = loader.get_workload(self.spec.workload_name,
**self.spec.workload_parameters) target,
self.workload.init_resources(self.context) **self.spec.workload_parameters)
self.workload.validate() self.workload.init_resources(self.context)
self.workload.validate()
self._workload_cache[self.id] = self.workload
else:
self.workload = self._workload_cache[self.id]
def initialize(self, context): def initialize(self, context):
self.logger.info('Initializing job {}'.format(self.id)) self.logger.info('Initializing job {}'.format(self.id))

View File

@ -24,7 +24,7 @@ from wa.framework.resource import (ApkFile, JarFile, ReventFile, NO_ONE,
from wa.framework.exception import WorkloadError from wa.framework.exception import WorkloadError
from wa.utils.types import ParameterDict from wa.utils.types import ParameterDict
from wa.utils.revent import ReventRecorder from wa.utils.revent import ReventRecorder
from wa.utils.exec_control import once from wa.utils.exec_control import once_per_instance
from devlib.utils.android import ApkInfo from devlib.utils.android import ApkInfo
from devlib.exception import TargetError from devlib.exception import TargetError
@ -161,6 +161,7 @@ class ApkWorkload(Workload):
def init_resources(self, context): def init_resources(self, context):
pass pass
@once_per_instance
def initialize(self, context): def initialize(self, context):
self.apk.initialize(context) self.apk.initialize(context)
@ -177,7 +178,7 @@ class ApkWorkload(Workload):
def teardown(self, context): def teardown(self, context):
self.apk.teardown() self.apk.teardown()
@once @once_per_instance
def finalize(self, context): def finalize(self, context):
pass pass
@ -192,6 +193,7 @@ class ApkUIWorkload(ApkWorkload):
super(ApkUIWorkload, self).init_resources(context) super(ApkUIWorkload, self).init_resources(context)
self.gui.init_resources(context.resolver) self.gui.init_resources(context.resolver)
@once_per_instance
def initialize(self, context): def initialize(self, context):
super(ApkUIWorkload, self).initialize(context) super(ApkUIWorkload, self).initialize(context)
@ -212,7 +214,7 @@ class ApkUIWorkload(ApkWorkload):
self.gui.teardown() self.gui.teardown()
super(ApkUIWorkload, self).teardown(context) super(ApkUIWorkload, self).teardown(context)
@once @once_per_instance
def finalize(self, context): def finalize(self, context):
super(ApkUIWorkload, self).finalize(context) super(ApkUIWorkload, self).finalize(context)
self.gui.remove() self.gui.remove()