diff --git a/wa/framework/job.py b/wa/framework/job.py index e4c14dc8..1de6625b 100644 --- a/wa/framework/job.py +++ b/wa/framework/job.py @@ -6,6 +6,8 @@ from wa.framework.configuration.core import Status class Job(object): + _workload_cache = {} + @property def id(self): return self.spec.id @@ -40,11 +42,15 @@ class Job(object): def load(self, target, loader=pluginloader): self.logger.info('Loading job {}'.format(self.id)) - self.workload = loader.get_workload(self.spec.workload_name, - target, - **self.spec.workload_parameters) - self.workload.init_resources(self.context) - self.workload.validate() + if self.iteration == 1: + self.workload = loader.get_workload(self.spec.workload_name, + target, + **self.spec.workload_parameters) + 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): self.logger.info('Initializing job {}'.format(self.id)) diff --git a/wa/framework/workload.py b/wa/framework/workload.py index 051f8534..3a24f657 100644 --- a/wa/framework/workload.py +++ b/wa/framework/workload.py @@ -24,7 +24,7 @@ from wa.framework.resource import (ApkFile, JarFile, ReventFile, NO_ONE, from wa.framework.exception import WorkloadError from wa.utils.types import ParameterDict 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.exception import TargetError @@ -161,6 +161,7 @@ class ApkWorkload(Workload): def init_resources(self, context): pass + @once_per_instance def initialize(self, context): self.apk.initialize(context) @@ -177,7 +178,7 @@ class ApkWorkload(Workload): def teardown(self, context): self.apk.teardown() - @once + @once_per_instance def finalize(self, context): pass @@ -192,6 +193,7 @@ class ApkUIWorkload(ApkWorkload): super(ApkUIWorkload, self).init_resources(context) self.gui.init_resources(context.resolver) + @once_per_instance def initialize(self, context): super(ApkUIWorkload, self).initialize(context) @@ -212,7 +214,7 @@ class ApkUIWorkload(ApkWorkload): self.gui.teardown() super(ApkUIWorkload, self).teardown(context) - @once + @once_per_instance def finalize(self, context): super(ApkUIWorkload, self).finalize(context) self.gui.remove()