mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-31 02:01:16 +00:00
list_or: chaniging how list_or_* functions work and adding a generic list_or
list_or_* functions (e.g. list_or_string) will now always return a list, however will accept lists or indivitual values. Also added a list_or() generator function, similar to what already exists for list_of().
This commit is contained in:
parent
a9ab67990a
commit
f59da723fb
@ -492,19 +492,11 @@ class EnergyModelInstrument(Instrument):
|
||||
self.big_energy_metrics = []
|
||||
self.little_energy_metrics = []
|
||||
if self.power_metric:
|
||||
if isinstance(self.power_metric, basestring):
|
||||
self.big_power_metrics = [self.power_metric.format(core=self.big_core)]
|
||||
self.little_power_metrics = [self.power_metric.format(core=self.little_core)]
|
||||
else:
|
||||
self.big_power_metrics = [pm.format(core=self.big_core) for pm in self.power_metric]
|
||||
self.little_power_metrics = [pm.format(core=self.little_core) for pm in self.power_metric]
|
||||
self.big_power_metrics = [pm.format(core=self.big_core) for pm in self.power_metric]
|
||||
self.little_power_metrics = [pm.format(core=self.little_core) for pm in self.power_metric]
|
||||
else: # must be energy_metric
|
||||
if isinstance(self.energy_metric, basestring):
|
||||
self.big_energy_metrics = [self.energy_metric.format(core=self.big_core)]
|
||||
self.little_energy_metrics = [self.energy_metric.format(core=self.little_core)]
|
||||
else:
|
||||
self.big_energy_metrics = [em.format(core=self.big_core) for em in self.energy_metric]
|
||||
self.little_energy_metrics = [em.format(core=self.little_core) for em in self.energy_metric]
|
||||
self.big_energy_metrics = [em.format(core=self.big_core) for em in self.energy_metric]
|
||||
self.little_energy_metrics = [em.format(core=self.little_core) for em in self.energy_metric]
|
||||
|
||||
def configure_clusters(self):
|
||||
self.measured_cores = None
|
||||
|
@ -23,7 +23,7 @@ import itertools
|
||||
from wlauto import Instrument, Executable, Parameter
|
||||
from wlauto.exceptions import ConfigError
|
||||
from wlauto.utils.misc import ensure_file_directory_exists as _f
|
||||
from wlauto.utils.types import list_or_string, list_of_strs
|
||||
from wlauto.utils.types import arguments, list_of_strs
|
||||
|
||||
PERF_COMMAND_TEMPLATE = '{} stat {} {} sleep 1000 > {} 2>&1 '
|
||||
|
||||
@ -71,7 +71,7 @@ class PerfInstrument(Instrument):
|
||||
Parameter('events', kind=list_of_strs, default=['migrations', 'cs'],
|
||||
constraint=(lambda x: x, 'must not be empty.'),
|
||||
description="""Specifies the events to be counted."""),
|
||||
Parameter('optionstring', kind=list_or_string, default='-a',
|
||||
Parameter('optionstring', kind=arguments, default='-a',
|
||||
description="""Specifies options to be used for the perf command. This
|
||||
may be a list of option strings, in which case, multiple instances of perf
|
||||
will be kicked off -- one for each option string. This may be used to e.g.
|
||||
|
@ -21,6 +21,7 @@ from nose.tools import raises, assert_equal # pylint: disable=E0611
|
||||
|
||||
from wlauto.utils.android import check_output
|
||||
from wlauto.utils.misc import merge_dicts, TimeoutError
|
||||
from wlauto.utils.types import list_or_integer, list_or_bool
|
||||
|
||||
|
||||
class TestCheckOutput(TestCase):
|
||||
@ -61,3 +62,11 @@ class TestMerge(TestCase):
|
||||
other = {'a': 'test'}
|
||||
merge_dicts(base, other, match_types=True)
|
||||
|
||||
|
||||
class TestTypes(TestCase):
|
||||
|
||||
def test_list_or_conversion(self):
|
||||
assert_equal(list_or_integer([1, '2', 3]), [1, 2, 3])
|
||||
assert_equal(list_or_integer('0xF'), [15,])
|
||||
assert_equal(list_or_bool('False'), [False,])
|
||||
|
||||
|
@ -83,36 +83,6 @@ def numeric(value):
|
||||
return fvalue
|
||||
|
||||
|
||||
def list_or_string(value):
|
||||
"""
|
||||
If the value is a string, at will be kept as a string, otherwise it will be interpreted
|
||||
as a list. If that is not possible, it will be interpreted as a string.
|
||||
|
||||
"""
|
||||
if isinstance(value, basestring):
|
||||
return value
|
||||
else:
|
||||
try:
|
||||
return list(value)
|
||||
except ValueError:
|
||||
return str(value)
|
||||
|
||||
|
||||
def list_or_caseless_string(value):
|
||||
"""
|
||||
If the value is a string, at will be kept as a string, otherwise it will be interpreted
|
||||
as a list. If that is not possible, it will be interpreted as a string.
|
||||
|
||||
"""
|
||||
if isinstance(value, basestring):
|
||||
return caseless_string(value)
|
||||
else:
|
||||
try:
|
||||
return map(caseless_string, value)
|
||||
except ValueError:
|
||||
return caseless_string(value)
|
||||
|
||||
|
||||
def list_of_strs(value):
|
||||
"""
|
||||
Value must be iterable. All elements will be converted to strings.
|
||||
@ -190,6 +160,60 @@ def list_of(type_):
|
||||
})
|
||||
|
||||
|
||||
def list_or_string(value):
|
||||
"""
|
||||
Converts the value into a list of strings. If the value is not iterable,
|
||||
a one-element list with stringified value will be returned.
|
||||
|
||||
"""
|
||||
if isinstance(value, basestring):
|
||||
return [value]
|
||||
else:
|
||||
try:
|
||||
return list(value)
|
||||
except ValueError:
|
||||
return [str(value)]
|
||||
|
||||
|
||||
def list_or_caseless_string(value):
|
||||
"""
|
||||
Converts the value into a list of ``caseless_string``'s. If the value is not iterable
|
||||
a one-element list with stringified value will be returned.
|
||||
|
||||
"""
|
||||
if isinstance(value, basestring):
|
||||
return [caseless_string(value)]
|
||||
else:
|
||||
try:
|
||||
return map(caseless_string, value)
|
||||
except ValueError:
|
||||
return [caseless_string(value)]
|
||||
|
||||
|
||||
def list_or(type_):
|
||||
"""
|
||||
Generator for "list or" types. These take either a single value or a list values
|
||||
and return a list of the specfied ``type_`` performing the conversion on the value
|
||||
(if a single value is specified) or each of the elemented of the specified list.
|
||||
|
||||
"""
|
||||
list_type = list_of(type_)
|
||||
|
||||
class list_or_type(list_type):
|
||||
def __init__(self, value):
|
||||
# pylint: disable=non-parent-init-called,super-init-not-called
|
||||
if isiterable(value):
|
||||
list_type.__init__(self, value)
|
||||
else:
|
||||
list_type.__init__(self, [value])
|
||||
return list_or_type
|
||||
|
||||
|
||||
list_or_integer = list_or(integer)
|
||||
list_or_number = list_or(numeric)
|
||||
list_or_bool = list_or(boolean)
|
||||
|
||||
|
||||
regex_type = type(re.compile(''))
|
||||
|
||||
|
||||
|
@ -197,13 +197,11 @@ class Spec2000(Workload):
|
||||
if self.force_extract_assets:
|
||||
self.force_push_assets = True
|
||||
if self.benchmarks is None: # pylint: disable=access-member-before-definition
|
||||
self.benchmarks = 'all'
|
||||
if isinstance(self.benchmarks, basestring):
|
||||
if self.benchmarks == 'all':
|
||||
self.benchmarks = self.loaded_benchmarks.keys()
|
||||
else:
|
||||
self.benchmarks = [self.benchmarks]
|
||||
self.benchmarks = ['all']
|
||||
for benchname in self.benchmarks:
|
||||
if benchname == 'all':
|
||||
self.benchmarks = self.loaded_benchmarks.keys()
|
||||
break
|
||||
if benchname not in self.loaded_benchmarks:
|
||||
raise ConfigError('Unknown SPEC benchmark: {}'.format(benchname))
|
||||
if self.mode == 'speed':
|
||||
|
Loading…
x
Reference in New Issue
Block a user