2017-02-21 13:51:12 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from wa.framework import signal
|
2017-03-06 11:10:25 +00:00
|
|
|
from wa.framework.plugin import Parameter
|
2017-03-15 17:16:59 +00:00
|
|
|
from wa.framework.target.descriptor import (get_target_descriptions,
|
2017-03-27 17:31:44 +01:00
|
|
|
instantiate_target,
|
|
|
|
instantiate_assistant)
|
2017-03-06 11:10:25 +00:00
|
|
|
from wa.framework.target.info import TargetInfo
|
2017-03-06 17:29:15 +00:00
|
|
|
from wa.framework.target.runtime_parameter_manager import RuntimeParameterManager
|
2017-02-21 13:51:12 +00:00
|
|
|
|
2017-03-20 16:11:58 +00:00
|
|
|
from devlib.utils.misc import memoized
|
2017-06-13 17:20:49 +01:00
|
|
|
from devlib.exception import TargetError
|
2017-02-21 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TargetManager(object):
|
2017-03-06 17:29:15 +00:00
|
|
|
"""
|
|
|
|
Instantiate the required target and perform configuration and validation of the device.
|
2017-02-21 13:51:12 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
parameters = [
|
|
|
|
Parameter('disconnect', kind=bool, default=False,
|
|
|
|
description="""
|
|
|
|
Specifies whether the target should be disconnected from
|
|
|
|
at the end of the run.
|
|
|
|
"""),
|
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, name, parameters):
|
2017-03-20 16:11:58 +00:00
|
|
|
self.logger = logging.getLogger('tm')
|
2017-03-15 17:16:59 +00:00
|
|
|
self.target_name = name
|
2017-02-21 13:51:12 +00:00
|
|
|
self.target = None
|
|
|
|
self.assistant = None
|
|
|
|
self.platform_name = None
|
|
|
|
self.parameters = parameters
|
|
|
|
self.disconnect = parameters.get('disconnect')
|
|
|
|
|
2017-03-15 17:16:59 +00:00
|
|
|
self._init_target()
|
2017-03-06 17:29:15 +00:00
|
|
|
|
|
|
|
# If target supports hotplugging, online all cpus before perform discovery
|
2017-06-13 17:25:23 +01:00
|
|
|
# and restore original configuration after completed.
|
2017-03-06 17:29:15 +00:00
|
|
|
if self.target.has('hotplug'):
|
|
|
|
online_cpus = self.target.list_online_cpus()
|
2017-06-13 17:20:49 +01:00
|
|
|
try:
|
|
|
|
self.target.hotplug.online_all()
|
|
|
|
except TargetError:
|
|
|
|
msg = 'Failed to online all CPUS - some information may not be '\
|
|
|
|
'able to be retrieved.'
|
|
|
|
self.logger.debug(msg)
|
2017-03-06 17:29:15 +00:00
|
|
|
self.rpm = RuntimeParameterManager(self.target)
|
|
|
|
all_cpus = set(range(self.target.number_of_cpus))
|
|
|
|
self.target.hotplug.offline(*all_cpus.difference(online_cpus))
|
|
|
|
else:
|
|
|
|
self.rpm = RuntimeParameterManager(self.target)
|
2017-02-21 13:51:12 +00:00
|
|
|
|
|
|
|
def finalize(self):
|
2017-03-06 17:29:15 +00:00
|
|
|
self.logger.info('Disconnecting from the device')
|
2017-02-21 13:51:12 +00:00
|
|
|
if self.disconnect:
|
|
|
|
with signal.wrap('TARGET_DISCONNECT'):
|
|
|
|
self.target.disconnect()
|
|
|
|
|
2017-03-27 17:31:44 +01:00
|
|
|
def start(self):
|
|
|
|
self.assistant.start()
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self.assistant.stop()
|
|
|
|
|
|
|
|
def extract_results(self, context):
|
|
|
|
self.assistant.extract_results(context)
|
|
|
|
|
2017-03-20 16:11:58 +00:00
|
|
|
@memoized
|
2017-03-15 17:16:59 +00:00
|
|
|
def get_target_info(self):
|
|
|
|
return TargetInfo(self.target)
|
|
|
|
|
2017-03-06 17:29:15 +00:00
|
|
|
def merge_runtime_parameters(self, parameters):
|
|
|
|
return self.rpm.merge_runtime_parameters(parameters)
|
2017-03-15 17:16:59 +00:00
|
|
|
|
2017-03-06 17:29:15 +00:00
|
|
|
def validate_runtime_parameters(self, parameters):
|
|
|
|
self.rpm.validate_runtime_parameters(parameters)
|
2017-02-21 13:51:12 +00:00
|
|
|
|
2017-03-06 17:29:15 +00:00
|
|
|
def commit_runtime_parameters(self, parameters):
|
|
|
|
self.rpm.commit_runtime_parameters(parameters)
|
2017-02-21 13:51:12 +00:00
|
|
|
|
2017-03-15 17:16:59 +00:00
|
|
|
def _init_target(self):
|
|
|
|
target_map = {td.name: td for td in get_target_descriptions()}
|
|
|
|
if self.target_name not in target_map:
|
|
|
|
raise ValueError('Unknown Target: {}'.format(self.target_name))
|
|
|
|
tdesc = target_map[self.target_name]
|
2017-03-06 17:29:15 +00:00
|
|
|
self.logger.debug('Creating {} target'.format(self.target_name))
|
2017-03-15 17:16:59 +00:00
|
|
|
self.target = instantiate_target(tdesc, self.parameters, connect=False)
|
2017-03-27 17:31:44 +01:00
|
|
|
|
2017-03-15 17:16:59 +00:00
|
|
|
with signal.wrap('TARGET_CONNECT'):
|
|
|
|
self.target.connect()
|
2017-03-20 16:11:58 +00:00
|
|
|
self.logger.info('Setting up target')
|
2017-03-15 17:16:59 +00:00
|
|
|
self.target.setup()
|
2017-03-07 15:17:23 +00:00
|
|
|
|
2017-03-27 17:31:44 +01:00
|
|
|
self.assistant = instantiate_assistant(tdesc, self.parameters, self.target)
|