1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-04-15 23:30:47 +01: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 formatter_class = argparse.RawDescriptionHelpFormatter
subcmd_classes = [CreateWorkloadSubcommand, CreatePackageSubcommand] subcmd_classes = [CreateWorkloadSubcommand, CreatePackageSubcommand]
def initialize(self): def initialize(self, context):
subparsers = self.parser.add_subparsers(dest='what') subparsers = self.parser.add_subparsers(dest='what')
self.subcommands = [] # pylint: disable=W0201 self.subcommands = [] # pylint: disable=W0201
for subcmd_cls in self.subcmd_classes: for subcmd_cls in self.subcmd_classes:

View File

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

View File

@ -30,7 +30,7 @@ class RunCommand(Command):
name = 'run' name = 'run'
description = 'Execute automated workloads on a remote device and process the resulting output.' 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', self.parser.add_argument('agenda', metavar='AGENDA',
help='Agenda for this workload automation run. This defines which workloads will ' + help='Agenda for this workload automation run. This defines which workloads will ' +
'be executed, how many times, with which tunables, etc. ' + '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.). Display documentation for the specified extension (workload, instrument, etc.).
""" """
def initialize(self): def initialize(self, context):
self.parser.add_argument('name', metavar='EXTENSION', self.parser.add_argument('name', metavar='EXTENSION',
help='''The name of the extension for which information will help='''The name of the extension for which information will
be shown.''') be shown.''')

View File

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

View File

@ -131,7 +131,7 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
""" """
if self._number_of_cores is None: 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') output = self.execute('ls /sys/devices/system/cpu')
self._number_of_cores = 0 self._number_of_cores = 0
for entry in output.split(): 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 if self.iks_switch_frequency is None and self.scheduler == 'iks': # pylint: disable=E0203
self.iks_switch_frequency = 800000 # pylint: disable=W0201 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)) self.execute('mkdir -p {}'.format(self.working_directory))
if self.is_rooted: if self.is_rooted:
if not self.is_installed('busybox'): if not self.is_installed('busybox'):
self.busybox = self.deploy_busybox(context) self.busybox = self.deploy_busybox(context)
else: else:
self.busybox = 'busybox' self.busybox = 'busybox'
self.init(context, *args, **kwargs)
def get_properties(self, context): def get_properties(self, context):
for propfile in self.property_files: for propfile in self.property_files:
@ -395,7 +394,7 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
num_active_cores += 1 num_active_cores += 1
return num_active_cores 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: if core not in self.core_names:
raise ValueError('Unexpected core: {}; must be in {}'.format(core, list(set(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] 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): def get_pids_of(self, process_name):
"""Returns a list of PIDs of all processes with the specified 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 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 if len(result) >= 2: # at least one row besides the header
return map(int, result[1:]) return map(int, result[1:])
else: else:
@ -624,7 +624,7 @@ class LinuxDevice(BaseLinuxDevice):
result = [] result = []
for line in lines: for line in lines:
parts = re.split('\s+', line, maxsplit=8) parts = re.split(r'\s+', line, maxsplit=8)
if parts: if parts:
result.append(PsEntry(*(parts[0:1] + map(int, parts[1:5]) + parts[5:]))) 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 parser_params['formatter_class'] = self.formatter_class
self.parser = subparsers.add_parser(self.name, **parser_params) self.parser = subparsers.add_parser(self.name, **parser_params)
init_argument_parser(self.parser) # propagate top-level options 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 Perform command-specific initialisation (e.g. adding command-specific options to the command's
parser). parser). ``context`` is always ``None``.
""" """
pass pass

View File

@ -191,6 +191,14 @@ class Device(Extension):
if len(self.core_names) != len(self.core_clusters): if len(self.core_names) != len(self.core_clusters):
raise ConfigError('core_names and core_clusters are of different lengths.') 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): def reset(self):
""" """
Initiate rebooting of the device. Initiate rebooting of the device.
@ -222,35 +230,6 @@ class Device(Extension):
""" Close the established connection to the device. """ """ Close the established connection to the device. """
raise NotImplementedError() 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): def ping(self):
""" """
This must return successfully if the device is able to receive commands, or must 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: for param in self.parameters:
param.validate(self) param.validate(self)
def initialize(self, *args, **kwargs): def initialize(self, context):
pass pass
def finalize(self, *args, **kwargs): def finalize(self, context):
pass pass
def check_artifacts(self, context, level): def check_artifacts(self, context, level):
@ -615,7 +615,7 @@ class Extension(object):
raise ValueError(message.format(module_spec)) raise ValueError(message.format(module_spec))
module = loader.get_module(name, owner=self, **params) module = loader.get_module(name, owner=self, **params)
module.initialize() module.initialize(None)
for capability in module.capabilities: for capability in module.capabilities:
if capability not in self.capabilities: if capability not in self.capabilities:
self.capabilities.append(capability) self.capabilities.append(capability)
@ -678,6 +678,6 @@ class Module(Extension):
if owner.name == self.name: if owner.name == self.name:
raise ValueError('Circular module import for {}'.format(self.name)) raise ValueError('Circular module import for {}'.format(self.name))
def initialize(self): def initialize(self, context):
pass pass

View File

@ -385,10 +385,10 @@ class Instrument(Extension):
self.is_enabled = True self.is_enabled = True
self.is_broken = False self.is_broken = False
def initialize(self, context): # pylint: disable=arguments-differ def initialize(self, context):
pass pass
def finalize(self, context): # pylint: disable=arguments-differ def finalize(self, context):
pass pass
def __str__(self): 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 pass
def process_iteration_result(self, result, context): def process_iteration_result(self, result, context):
@ -155,7 +155,7 @@ class ResultProcessor(Extension):
def export_run_result(self, result, context): def export_run_result(self, result, context):
pass pass
def finalize(self, context): # pylint: disable=arguments-differ def finalize(self, context):
pass pass

View File

@ -61,7 +61,7 @@ class Workload(Extension):
""" """
pass 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., 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. 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. """ """ Perform any final clean up for the Workload. """
pass pass
def finalize(self, context): # pylint: disable=arguments-differ def finalize(self, context):
pass pass
def __str__(self): def __str__(self):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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