def test_enum_creation(self): e = enum(['one', 'two', 'three']) assert_list_equal(e.values, [0, 1, 2]) e = enum(['one', 'two', 'three'], start=10) assert_list_equal(e.values, [10, 11, 12]) e = enum(['one', 'two', 'three'], start=-10, step=10) assert_list_equal(e.values, [-10, 0, 10])
def test_enum_creation(self): e = enum(['one', 'two', 'three']) assert_list_equal(e.values, [0, 1, 2]) e = enum(['one', 'two', 'three'], start=10) assert_list_equal(e.values, [10, 11, 12]) e = enum(['one', 'two', 'three'], start=-10, step=10) assert_list_equal(e.values, [-10, 0, 10])
def test_enum_name_conflicts(self): assert_raises(ValueError, enum, ['names', 'one', 'two']) e = enum(['NAMES', 'one', 'two']) assert_in('names', e.levels) assert_list_equal(e.names, ['names', 'one', 'two']) assert_equal(e.ONE, 'one') result = not (e.ONE != 'one') assert_true(result)
def test_enum_name_conflicts(self): assert_raises(ValueError, enum, ['names', 'one', 'two']) e = enum(['NAMES', 'one', 'two']) assert_in('names', e.levels) assert_list_equal(e.names, ['names', 'one', 'two']) assert_equal(e.ONE, 'one') result = not (e.ONE != 'one') assert_true(result)
def test_enum_behavior(self): e = enum(['one', 'two', 'three']) # case-insensitive level name and level value may all # be used for equality comparisons. assert_equal(e.one, 'one') assert_equal(e.one, 'ONE') assert_equal(e.one, 0) assert_not_equal(e.one, '0') # ditto for enum membership tests assert_in('one', e.levels) assert_in(2, e.levels) assert_not_in('five', e.levels) # The same level object returned, only when # passing in a valid level name/value. assert_is(e('one'), e('ONE')) assert_is(e('one'), e(0)) assert_raises(ValueError, e, 'five')
def test_enum_behavior(self): e = enum(['one', 'two', 'three']) # case-insensitive level name and level value may all # be used for equality comparisons. assert_equal(e.one, 'one') assert_equal(e.one, 'ONE') assert_equal(e.one, 0) assert_not_equal(e.one, '0') # ditto for enum membership tests assert_in('one', e.levels) assert_in(2, e.levels) assert_not_in('five', e.levels) # The same level object returned, only when # passing in a valid level name/value. assert_is(e('one'), e('ONE')) assert_is(e('one'), e(0)) assert_raises(ValueError, e, 'five')
import logging import os import re from devlib.utils.android import ApkInfo from wa.framework import pluginloader from wa.framework.plugin import Plugin from wa.framework.exception import ResourceError from wa.framework.configuration import settings from wa.utils import log from wa.utils.misc import get_object_name from wa.utils.types import enum, list_or_string, prioritylist SourcePriority = enum(['package', 'remote', 'lan', 'local', 'perferred'], start=0, step=10) class __NullOwner(object): """Represents an owner for a resource not owned by anyone.""" name = 'noone' dependencies_directory = settings.dependencies_directory def __getattr__(self, name): return None def __str__(self): return 'no-one' __repr__ = __str__
def _retrieve_device_idle_info(self): for cpu in range(self.target.number_of_cpus): self.supported_idle_states[cpu] = self.target.cpuidle.get_states( cpu) def _get_common_idle_values(self): '''Find common values for cpu idle states across all cores''' common_idle_states = [] for cpu in range(self.target.number_of_cpus): for state in self.supported_idle_states.get(cpu) or []: if state.name not in common_idle_states: common_idle_states.append(state) return common_idle_states ScreenOrientation = enum(['NATURAL', 'LEFT', 'INVERTED', 'RIGHT']) class AndroidRuntimeConfig(RuntimeConfig): name = 'rt-android' @staticmethod def set_brightness(obj, value): if value is not None: obj.config['brightness'] = value @staticmethod def set_airplane_mode(obj, value): if value is not None: obj.config['airplane_mode'] = value
def test_deserialize_enum(self): e = enum(['one', 'two', 'three']) s = e.one.to_pod() l = e.from_pod(s) assert_equal(l, e.one)
AFTER_TARGET_CONNECT = Signal('after-target-connect') BEFORE_TARGET_DISCONNECT = Signal('before-target-disconnect', invert_priority=True) SUCCESSFUL_TARGET_DISCONNECT = Signal('successful-target-disconnect') AFTER_TARGET_DISCONNECT = Signal('after-target-disconnect') BEFORE_RUN_OUTPUT_PROCESSED = Signal( 'before-run-output-processed', invert_priority=True) SUCCESSFUL_RUN_OUTPUT_PROCESSED = Signal( 'successful-run-output-processed') AFTER_RUN_OUTPUT_PROCESSED = Signal( 'after-run-output-processed') CallbackPriority = enum(['extremely_low', 'very_low', 'low', 'normal', 'high', 'very_high', 'extremely_high'], -30, 10) class _prioritylist_wrapper(prioritylist): """ This adds a NOP append() method so that when louie invokes it to add the handler to receivers, nothing will happen; the handler is actually added inside the connect() below according to priority, before louie's connect() gets invoked. """ def append(self, *args, **kwargs): pass def connect(handler, signal, sender=dispatcher.Any, priority=0):
from wa.utils import log from wa.utils.misc import (get_article, merge_config_values) from wa.utils.types import (identifier, integer, boolean, list_of_strings, list_of, toggle_set, obj_dict, enum) from wa.utils.serializer import is_pod, Podable # Mapping for kind conversion; see docs for convert_types below KIND_MAP = { int: integer, bool: boolean, dict: OrderedDict, } Status = enum(['UNKNOWN', 'NEW', 'PENDING', 'STARTED', 'CONNECTED', 'INITIALIZED', 'RUNNING', 'OK', 'PARTIAL', 'FAILED', 'ABORTED', 'SKIPPED']) logger = logging.getLogger('config') ########################## ### CONFIG POINT TYPES ### ########################## class RebootPolicy(object): """ Represents the reboot policy for the execution -- at what points the device should be rebooted. This, in turn, is controlled by the policy value that is passed in on construction and would typically be read from the user's settings.
def test_deserialize_enum(self): e = enum(['one', 'two', 'three']) s = e.one.to_pod() l = e.from_pod(s) assert_equal(l, e.one)
def _retrieve_device_idle_info(self): for cpu in range(self.target.number_of_cpus): self.supported_idle_states[cpu] = self.target.cpuidle.get_states(cpu) def _get_common_idle_values(self): '''Find common values for cpu idle states across all cores''' common_idle_states = [] for cpu in range(self.target.number_of_cpus): for state in self.supported_idle_states.get(cpu) or []: if state.name not in common_idle_states: common_idle_states.append(state) return common_idle_states ScreenOrientation = enum(['NATURAL', 'LEFT', 'INVERTED', 'RIGHT']) class AndroidRuntimeConfig(RuntimeConfig): name = 'rt-android' @staticmethod def set_brightness(obj, value): if value is not None: obj.config['brightness'] = value @staticmethod def set_airplane_mode(obj, value): if value is not None: obj.config['airplane_mode'] = value
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import logging from datetime import datetime from wa.utils.types import enum LogcatLogLevel = enum(['verbose', 'debug', 'info', 'warn', 'error', 'assert'], start=2) log_level_map = ''.join(n[0].upper() for n in LogcatLogLevel.names) logger = logging.getLogger('logcat') class LogcatEvent(object): __slots__ = ['timestamp', 'pid', 'tid', 'level', 'tag', 'message'] def __init__(self, timestamp, pid, tid, level, tag, message): self.timestamp = timestamp self.pid = pid self.tid = tid self.level = level
pod['metrics'] = [m.to_pod() for m in self.metrics] pod['artifacts'] = [a.to_pod() for a in self.artifacts] pod['events'] = [e.to_pod() for e in self.events] pod['classifiers'] = copy(self.classifiers) pod['metadata'] = deepcopy(self.metadata) return pod @staticmethod def _pod_upgrade_v1(pod): pod['_pod_version'] = pod.get('_pod_version', 1) pod['status'] = Status(pod['status']).to_pod() return pod ARTIFACT_TYPES = ['log', 'meta', 'data', 'export', 'raw'] ArtifactType = enum(ARTIFACT_TYPES) class Artifact(Podable): """ This is an artifact generated during execution/post-processing of a workload. Unlike metrics, this represents an actual artifact, such as a file, generated. This may be "output", such as trace, or it could be "meta data" such as logs. These are distinguished using the ``kind`` attribute, which also helps WA decide how it should be handled. Currently supported kinds are: :log: A log file. Not part of the "output" as such but contains information about the run/workload execution that be useful for diagnostics/meta analysis. :meta: A file containing metadata. This is not part of the "output", but
# limitations under the License. # import logging import os from datetime import datetime from devlib.utils.android import ApkInfo as _ApkInfo from wa.framework.configuration import settings from wa.utils.serializer import read_pod, write_pod, Podable from wa.utils.types import enum from wa.utils.misc import atomic_write_path LogcatLogLevel = enum(['verbose', 'debug', 'info', 'warn', 'error', 'assert'], start=2) log_level_map = ''.join(n[0].upper() for n in LogcatLogLevel.names) logcat_logger = logging.getLogger('logcat') apk_info_cache_logger = logging.getLogger('apk_info_cache') apk_info_cache = None class LogcatEvent(object): __slots__ = ['timestamp', 'pid', 'tid', 'level', 'tag', 'message'] def __init__(self, timestamp, pid, tid, level, tag, message): self.timestamp = timestamp
BEFORE_TARGET_CONNECT = Signal('before-target-connect', invert_priority=True) SUCCESSFUL_TARGET_CONNECT = Signal('successful-target-connect') AFTER_TARGET_CONNECT = Signal('after-target-connect') BEFORE_TARGET_DISCONNECT = Signal('before-target-disconnect', invert_priority=True) SUCCESSFUL_TARGET_DISCONNECT = Signal('successful-target-disconnect') AFTER_TARGET_DISCONNECT = Signal('after-target-disconnect') BEFORE_RUN_OUTPUT_PROCESSED = Signal('before-run-output-processed', invert_priority=True) SUCCESSFUL_RUN_OUTPUT_PROCESSED = Signal('successful-run-output-processed') AFTER_RUN_OUTPUT_PROCESSED = Signal('after-run-output-processed') CallbackPriority = enum([ 'extremely_low', 'very_low', 'low', 'normal', 'high', 'very_high', 'extremely_high' ], -30, 10) class _prioritylist_wrapper(prioritylist): """ This adds a NOP append() method so that when louie invokes it to add the handler to receivers, nothing will happen; the handler is actually added inside the connect() below according to priority, before louie's connect() gets invoked. """ def append(self, *args, **kwargs): pass def connect(handler, signal, sender=dispatcher.Any, priority=0):
import logging import os import re from devlib.utils.android import ApkInfo from wa.framework import pluginloader from wa.framework.plugin import Plugin from wa.framework.exception import ResourceError from wa.framework.configuration import settings from wa.utils import log from wa.utils.misc import get_object_name from wa.utils.types import enum, list_or_string, prioritylist, version_tuple SourcePriority = enum(['package', 'remote', 'lan', 'local', 'perferred'], start=0, step=10) class __NullOwner(object): """Represents an owner for a resource not owned by anyone.""" name = 'noone' dependencies_directory = settings.dependencies_directory def __getattr__(self, name): return None def __str__(self): return 'no-one'
from wa.utils import log from wa.utils.misc import (get_article, merge_config_values) from wa.utils.types import (identifier, integer, boolean, list_of_strings, list_of, toggle_set, obj_dict, enum) from wa.utils.serializer import is_pod # Mapping for kind conversion; see docs for convert_types below KIND_MAP = { int: integer, bool: boolean, dict: OrderedDict, } Status = enum(['UNKNOWN', 'NEW', 'PENDING', 'STARTED', 'CONNECTED', 'INITIALIZED', 'RUNNING', 'OK', 'PARTIAL', 'FAILED', 'ABORTED', 'SKIPPED']) ########################## ### CONFIG POINT TYPES ### ########################## class RebootPolicy(object): """ Represents the reboot policy for the execution -- at what points the device should be rebooted. This, in turn, is controlled by the policy value that is passed in on construction and would typically be read from the user's settings. Valid policy values are: