2018-07-04 15:39:44 +01:00
|
|
|
# Copyright 2018 ARM Limited
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2017-02-21 13:51:12 +00:00
|
|
|
import logging
|
|
|
|
|
2018-07-10 10:59:41 +01:00
|
|
|
from devlib import Gem5SimulationPlatform
|
|
|
|
from devlib.utils.misc import memoized
|
|
|
|
|
2017-02-21 13:51:12 +00:00
|
|
|
from wa.framework import signal
|
2018-02-28 10:24:56 +00:00
|
|
|
from wa.framework.exception import ExecutionError, TargetError, TargetNotRespondingError
|
2017-03-06 11:10:25 +00:00
|
|
|
from wa.framework.plugin import Parameter
|
2017-12-15 09:58:08 +00:00
|
|
|
from wa.framework.target.descriptor import (get_target_description,
|
2017-03-27 17:31:44 +01:00
|
|
|
instantiate_target,
|
|
|
|
instantiate_assistant)
|
2018-07-13 15:28:23 +01:00
|
|
|
from wa.framework.target.info import get_target_info, get_target_info_from_cache, cache_target_info
|
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
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""),
|
|
|
|
]
|
|
|
|
|
2017-10-05 15:17:58 +01:00
|
|
|
def __init__(self, name, parameters, outdir):
|
|
|
|
self.outdir = outdir
|
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
|
2018-02-28 10:20:24 +00:00
|
|
|
self.is_responsive = None
|
2018-06-22 16:29:00 +01:00
|
|
|
self.rpm = None
|
2017-02-21 13:51:12 +00:00
|
|
|
self.parameters = parameters
|
|
|
|
self.disconnect = parameters.get('disconnect')
|
|
|
|
|
2018-06-22 16:29:00 +01:00
|
|
|
def initialize(self):
|
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):
|
2018-09-20 10:58:40 +01:00
|
|
|
if not self.target:
|
|
|
|
return
|
2017-10-05 18:25:29 +01:00
|
|
|
if self.disconnect or isinstance(self.target.platform, Gem5SimulationPlatform):
|
|
|
|
self.logger.info('Disconnecting from the device')
|
2017-02-21 13:51:12 +00:00
|
|
|
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):
|
2018-07-13 15:28:23 +01:00
|
|
|
info = get_target_info_from_cache(self.target.system_id)
|
|
|
|
if info is None:
|
|
|
|
info = get_target_info(self.target)
|
|
|
|
cache_target_info(info)
|
|
|
|
return info
|
2017-03-15 17:16:59 +00:00
|
|
|
|
2018-06-11 17:14:51 +01:00
|
|
|
def reboot(self, context, hard=False):
|
|
|
|
with signal.wrap('REBOOT', self, context):
|
|
|
|
self.target.reboot(hard)
|
2018-05-29 09:40:39 +01:00
|
|
|
|
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
|
|
|
|
2018-06-11 17:14:51 +01:00
|
|
|
def verify_target_responsive(self, context):
|
|
|
|
can_reboot = context.reboot_policy.can_reboot
|
2018-02-28 10:20:24 +00:00
|
|
|
if not self.target.check_responsive(explode=False):
|
|
|
|
self.is_responsive = False
|
2018-05-22 17:45:59 +01:00
|
|
|
if not can_reboot:
|
|
|
|
raise TargetNotRespondingError('Target unresponsive and is not allowed to reboot.')
|
|
|
|
elif self.target.has('hard_reset'):
|
2018-02-28 10:20:24 +00:00
|
|
|
self.logger.info('Target unresponsive; performing hard reset')
|
2018-06-11 17:14:51 +01:00
|
|
|
self.reboot(context, hard=True)
|
2018-02-28 10:20:24 +00:00
|
|
|
self.is_responsive = True
|
2018-02-28 10:24:56 +00:00
|
|
|
raise ExecutionError('Target became unresponsive but was recovered.')
|
2018-02-28 10:20:24 +00:00
|
|
|
else:
|
2018-02-28 10:24:56 +00:00
|
|
|
raise TargetNotRespondingError('Target unresponsive and hard reset not supported; bailing.')
|
2018-02-28 10:20:24 +00:00
|
|
|
|
2017-03-15 17:16:59 +00:00
|
|
|
def _init_target(self):
|
2017-12-15 09:58:08 +00:00
|
|
|
tdesc = get_target_description(self.target_name)
|
2017-10-05 15:17:58 +01:00
|
|
|
|
2018-07-04 13:40:21 +01:00
|
|
|
extra_plat_params = {}
|
2017-10-05 15:17:58 +01:00
|
|
|
if tdesc.platform is Gem5SimulationPlatform:
|
|
|
|
extra_plat_params['host_output_dir'] = self.outdir
|
|
|
|
|
2017-03-06 17:29:15 +00:00
|
|
|
self.logger.debug('Creating {} target'.format(self.target_name))
|
2017-10-05 15:17:58 +01:00
|
|
|
self.target = instantiate_target(tdesc, self.parameters, connect=False,
|
|
|
|
extra_platform_params=extra_plat_params)
|
2017-03-27 17:31:44 +01:00
|
|
|
|
2018-02-28 10:20:24 +00:00
|
|
|
self.is_responsive = True
|
|
|
|
|
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)
|