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

cleaning up initialize()

- standardisded on a single context argument
- removed Device.init() no longer necessary as initilize now
  automatically gets propagated up the hierarchy. Renamed the existing
  use of it to "initilize".
- related pylint cleanup.
This commit is contained in:
Sergei Trofimov 2015-06-17 17:41:24 +01:00
parent 55b38556fe
commit 73d85c2b4e
18 changed files with 46 additions and 68 deletions

View File

@ -177,7 +177,7 @@ class CreateCommand(Command):
formatter_class = argparse.RawDescriptionHelpFormatter
subcmd_classes = [CreateWorkloadSubcommand, CreatePackageSubcommand]
def initialize(self):
def initialize(self, context):
subparsers = self.parser.add_subparsers(dest='what')
self.subcommands = [] # pylint: disable=W0201
for subcmd_cls in self.subcmd_classes:

View File

@ -24,7 +24,7 @@ class ListCommand(Command):
name = 'list'
description = 'List available WA extensions with a short description of each.'
def initialize(self):
def initialize(self, context):
extension_types = ['{}s'.format(ext.name) for ext in settings.extensions]
self.parser.add_argument('kind', metavar='KIND',
help=('Specify the kind of extension to list. Must be '

View File

@ -30,7 +30,7 @@ class RunCommand(Command):
name = 'run'
description = 'Execute automated workloads on a remote device and process the resulting output.'
def initialize(self):
def initialize(self, context):
self.parser.add_argument('agenda', metavar='AGENDA',
help='Agenda for this workload automation run. This defines which workloads will ' +
'be executed, how many times, with which tunables, etc. ' +

View File

@ -33,7 +33,7 @@ class ShowCommand(Command):
Display documentation for the specified extension (workload, instrument, etc.).
"""
def initialize(self):
def initialize(self, context):
self.parser.add_argument('name', metavar='EXTENSION',
help='''The name of the extension for which information will
be shown.''')

View File

@ -182,7 +182,7 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
self._just_rebooted = False
self._is_ready = True
def initialize(self, context, *args, **kwargs):
def initialize(self, context):
self.execute('mkdir -p {}'.format(self.working_directory))
if self.is_rooted:
if not self.executable_is_installed('busybox'):
@ -193,7 +193,6 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
self.disable_selinux()
if self.enable_screen_check:
self.ensure_screen_is_on()
self.init(context, *args, **kwargs)
def disconnect(self):
if self._logcat_poller:

View File

@ -131,7 +131,7 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
"""
if self._number_of_cores is None:
corere = re.compile('^\s*cpu\d+\s*$')
corere = re.compile(r'^\s*cpu\d+\s*$')
output = self.execute('ls /sys/devices/system/cpu')
self._number_of_cores = 0
for entry in output.split():
@ -175,14 +175,13 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
if self.iks_switch_frequency is None and self.scheduler == 'iks': # pylint: disable=E0203
self.iks_switch_frequency = 800000 # pylint: disable=W0201
def initialize(self, context, *args, **kwargs):
def initialize(self, context):
self.execute('mkdir -p {}'.format(self.working_directory))
if self.is_rooted:
if not self.is_installed('busybox'):
self.busybox = self.deploy_busybox(context)
else:
self.busybox = 'busybox'
self.init(context, *args, **kwargs)
def get_properties(self, context):
for propfile in self.property_files:
@ -395,7 +394,7 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
num_active_cores += 1
return num_active_cores
def set_number_of_active_cores(self, core, number):
def set_number_of_active_cores(self, core, number): # NOQA
if core not in self.core_names:
raise ValueError('Unexpected core: {}; must be in {}'.format(core, list(set(self.core_names))))
core_ids = [i for i, c in enumerate(self.core_names) if c == core]
@ -611,7 +610,8 @@ class LinuxDevice(BaseLinuxDevice):
def get_pids_of(self, process_name):
"""Returns a list of PIDs of all processes with the specified name."""
# result should be a column of PIDs with the first row as "PID" header
result = self.execute('ps -C {} -o pid'.format(process_name), check_exit_code=False).strip().split()
result = self.execute('ps -C {} -o pid'.format(process_name), # NOQA
check_exit_code=False).strip().split()
if len(result) >= 2: # at least one row besides the header
return map(int, result[1:])
else:
@ -624,7 +624,7 @@ class LinuxDevice(BaseLinuxDevice):
result = []
for line in lines:
parts = re.split('\s+', line, maxsplit=8)
parts = re.split(r'\s+', line, maxsplit=8)
if parts:
result.append(PsEntry(*(parts[0:1] + map(int, parts[1:5]) + parts[5:])))

View File

@ -45,12 +45,12 @@ class Command(Extension):
parser_params['formatter_class'] = self.formatter_class
self.parser = subparsers.add_parser(self.name, **parser_params)
init_argument_parser(self.parser) # propagate top-level options
self.initialize()
self.initialize(None)
def initialize(self):
def initialize(self, context):
"""
Perform command-specific initialisation (e.g. adding command-specific options to the command's
parser).
parser). ``context`` is always ``None``.
"""
pass

View File

@ -191,6 +191,14 @@ class Device(Extension):
if len(self.core_names) != len(self.core_clusters):
raise ConfigError('core_names and core_clusters are of different lengths.')
def initialize(self, context):
"""
Initialization that is performed at the begining of the run (after the device has
been connecte).
"""
pass
def reset(self):
"""
Initiate rebooting of the device.
@ -222,35 +230,6 @@ class Device(Extension):
""" Close the established connection to the device. """
raise NotImplementedError()
def initialize(self, context, *args, **kwargs):
"""
Default implementation just calls through to init(). May be overriden by specialised
abstract sub-cleasses to implent platform-specific intialization without requiring
concrete implementations to explicitly invoke parent's init().
Added in version 2.1.3.
"""
self.init(context, *args, **kwargs)
def init(self, context, *args, **kwargs):
"""
Initialize the device. This method *must* be called after a device reboot before
any other commands can be issued, however it may also be called without rebooting.
It is up to device-specific implementations to identify what initialisation needs
to be preformed on a particular invocation. Bear in mind that no assumptions can be
made about the state of the device prior to the initiation of workload execution,
so full initialisation must be performed at least once, even if no reboot has occurred.
After that, the device-specific implementation may choose to skip initialization if
the device has not been rebooted; it is up to the implementation to keep track of
that, however.
All arguments are device-specific (see the documentation for the your device).
"""
pass
def ping(self):
"""
This must return successfully if the device is able to receive commands, or must

View File

@ -553,10 +553,10 @@ class Extension(object):
for param in self.parameters:
param.validate(self)
def initialize(self, *args, **kwargs):
def initialize(self, context):
pass
def finalize(self, *args, **kwargs):
def finalize(self, context):
pass
def check_artifacts(self, context, level):
@ -615,7 +615,7 @@ class Extension(object):
raise ValueError(message.format(module_spec))
module = loader.get_module(name, owner=self, **params)
module.initialize()
module.initialize(None)
for capability in module.capabilities:
if capability not in self.capabilities:
self.capabilities.append(capability)
@ -678,6 +678,6 @@ class Module(Extension):
if owner.name == self.name:
raise ValueError('Circular module import for {}'.format(self.name))
def initialize(self):
def initialize(self, context):
pass

View File

@ -385,10 +385,10 @@ class Instrument(Extension):
self.is_enabled = True
self.is_broken = False
def initialize(self, context): # pylint: disable=arguments-differ
def initialize(self, context):
pass
def finalize(self, context): # pylint: disable=arguments-differ
def finalize(self, context):
pass
def __str__(self):

View File

@ -140,7 +140,7 @@ class ResultProcessor(Extension):
"""
def initialize(self, context): # pylint: disable=arguments-differ
def initialize(self, context):
pass
def process_iteration_result(self, result, context):
@ -155,7 +155,7 @@ class ResultProcessor(Extension):
def export_run_result(self, result, context):
pass
def finalize(self, context): # pylint: disable=arguments-differ
def finalize(self, context):
pass

View File

@ -61,7 +61,7 @@ class Workload(Extension):
"""
pass
def initialize(self, context): # pylint: disable=arguments-differ
def initialize(self, context):
"""
This method should be used to perform once-per-run initialization of a workload instance, i.e.,
unlike ``setup()`` it will not be invoked on each iteration.
@ -96,7 +96,7 @@ class Workload(Extension):
""" Perform any final clean up for the Workload. """
pass
def finalize(self, context): # pylint: disable=arguments-differ
def finalize(self, context):
pass
def __str__(self):

View File

@ -41,7 +41,7 @@ class Nexus10Device(AndroidDevice):
Parameter('core_clusters', default=[0, 0], override=True),
]
def init(self, context, *args, **kwargs):
def initialize(self, context):
time.sleep(self.long_delay)
self.execute('svc power stayon true', check_exit_code=False)
time.sleep(self.long_delay)

View File

@ -44,7 +44,7 @@ class Note3Device(AndroidDevice):
super(Note3Device, self).__init__(**kwargs)
self._just_rebooted = False
def init(self, context):
def initialize(self, context):
self.execute('svc power stayon true', check_exit_code=False)
def reset(self):

View File

@ -154,7 +154,7 @@ class Cgroups(Module):
description='Location where cgroups are mounted on the device.'),
]
def initialize(self):
def initialize(self, context):
self.device = self.root_owner
signal.connect(self._on_device_init, signal.RUN_INIT, priority=1)

View File

@ -28,7 +28,7 @@ class CpufreqModule(Module):
"""
capabilities = ['cpufreq']
def initialize(self):
def initialize(self, context):
# pylint: disable=W0201
CpufreqModule._available_governors = {}
CpufreqModule._available_governor_tunables = {}

View File

@ -86,7 +86,7 @@ class Cpuidle(Module):
root_path = '/sys/devices/system/cpu/cpuidle'
def initialize(self):
def initialize(self, context):
self.device = self.root_owner
signal.connect(self._on_device_init, signal.RUN_INIT, priority=1)

View File

@ -123,7 +123,7 @@ class MyCoolModule(Module):
capabilities = ['fizzle']
def initialize(self):
def initialize(self, context):
self.fizzle_factor = 0 # pylint: disable=attribute-defined-outside-init
def fizzle(self):
@ -227,16 +227,16 @@ class ExtensionMetaTest(TestCase):
def __init__(self, *args, **kwargs):
super(MyExt, self).__init__(*args, **kwargs)
self.instance_init = 0
def initialize(self):
def initialize(self, context):
self.values['a'] += 1
class MyChildExt(MyExt):
name = 'mychildext'
def initialize(self):
def initialize(self, context):
self.instance_init += 1
ext = _instantiate(MyChildExt)
ext.initialize()
ext.initialize(None)
assert_equal(MyExt.values['a'], 1)
assert_equal(ext.instance_init, 1)
@ -249,14 +249,14 @@ class ExtensionMetaTest(TestCase):
super(MyExt, self).__init__(*args, **kwargs)
self.instance_init = 0
self.instance_validate = 0
def initialize(self):
def initialize(self, context):
self.values['a'] += 1
def validate(self):
self.instance_validate += 1
class MyChildExt(MyExt):
name = 'mychildext'
def initialize(self):
def initialize(self, context):
self.instance_init += 1
def validate(self):
self.instance_validate += 1
@ -264,9 +264,9 @@ class ExtensionMetaTest(TestCase):
ext1 = _instantiate(MyExt)
ext2 = _instantiate(MyExt)
ext3 = _instantiate(MyChildExt)
ext1.initialize()
ext2.initialize()
ext3.initialize()
ext1.initialize(None)
ext2.initialize(None)
ext3.initialize(None)
ext1.validate()
ext2.validate()
ext3.validate()