1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-02-20 20:09:11 +00:00

Merge pull request #519 from bjackman/requires-network

Add Workload.requires_network
This commit is contained in:
setrofim 2017-10-24 14:36:42 +01:00 committed by GitHub
commit eb0f53c8f6
3 changed files with 28 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import logging
import time
from collections import defaultdict, OrderedDict
from copy import copy
@ -893,7 +894,18 @@ class AndroidRuntimeConfig(RuntimeConfig):
def commit(self):
if 'airplane_mode' in self.config:
self.target.set_airplane_mode(self.config['airplane_mode'])
new_airplane_mode = self.config['airplane_mode']
old_airplane_mode = self.target.get_airplane_mode()
self.target.set_airplane_mode(new_airplane_mode)
# If we've just switched airplane mode off, wait a few seconds to
# enable the network state to stabilise. That's helpful if we're
# about to run a workload that is going to check for network
# connectivity.
if old_airplane_mode and not new_airplane_mode:
self.logger.info('Disabled airplane mode, waiting 5 seconds for network setup')
time.sleep(5)
if 'brightness' in self.config:
self.target.set_brightness(self.config['brightness'])
if 'rotation' in self.config:

View File

@ -50,6 +50,12 @@ class Workload(TargetedPlugin):
prevent this workload from being run accidentally.
"""
requires_network = False
"""
Set this to ``True`` to mark the the workload will fail without a network
connection, this enables it to fail early with a clear message.
"""
def init_resources(self, context):
"""
This method may be used to perform early resource discovery and
@ -77,7 +83,11 @@ class Workload(TargetedPlugin):
This is also the place to perform any on-device checks prior to
attempting to execute the workload.
"""
pass
if self.requires_network and not self.target.is_network_connected():
raise WorkloadError(
'Workload "{}" requires internet. Target does not appear '
'to be connected to the internet.'.format(self.name))
def run(self, context):
"""
@ -193,6 +203,7 @@ class ApkWorkload(Workload):
self.apk.activity)
def setup(self, context):
super(ApkWorkload, self).setup(context)
self.apk.setup(context)
time.sleep(self.loading_time)

View File

@ -100,6 +100,8 @@ class Geekbench(ApkUiautoWorkload):
phones_home = True
requires_network = True
@property
def activity(self):
return self.versions[self.version]['activity']
@ -402,6 +404,7 @@ class GBScoreCalculator(object):
class GeekbenchCorproate(Geekbench):
name = "geekbench-corporate"
is_corporate = True
requires_network = False
versions = ['4.1.0']