west: runners: mdb-hw: add hostlink-awareness
Add hostlink-awareness to mdb-hw runner. The mdb-nsim and arc-nsim runners (as well as cmake scripting for nSIM boards) doesn't require any changes. Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com> Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
This commit is contained in:
parent
d4a5f183d0
commit
6599c3796d
|
@ -17,16 +17,29 @@ from runners.core import ZephyrBinaryRunner, RunnerCaps
|
|||
# from it. However as we do lookup for runners with
|
||||
# ZephyrBinaryRunner.__subclasses__() such sub-sub-classes won't be found.
|
||||
# So, we move all common functionality to helper functions instead.
|
||||
def simulation_run(mdb_runner):
|
||||
def is_simulation_run(mdb_runner):
|
||||
return mdb_runner.nsim_args != ''
|
||||
|
||||
def is_hostlink_used(mdb_runner):
|
||||
return mdb_runner.build_conf.getboolean('CONFIG_UART_HOSTLINK')
|
||||
|
||||
def is_flash_cmd_need_exit_immediately(mdb_runner):
|
||||
if is_simulation_run(mdb_runner):
|
||||
# for nsim, we can't run and quit immediately
|
||||
return False
|
||||
elif is_hostlink_used(mdb_runner):
|
||||
# if hostlink is used we can't run and quit immediately, as we still need MDB process
|
||||
# attached to process hostlink IO
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def mdb_do_run(mdb_runner, command):
|
||||
commander = "mdb"
|
||||
|
||||
mdb_runner.require(commander)
|
||||
|
||||
mdb_basic_options = ['-nooptions', '-nogoifmain',
|
||||
'-toggle=include_local_symbols=1']
|
||||
mdb_basic_options = ['-nooptions', '-nogoifmain', '-toggle=include_local_symbols=1']
|
||||
|
||||
# remove previous .sc.project folder which has temporary settings
|
||||
# for MDB. This is useful for troubleshooting situations with
|
||||
|
@ -36,7 +49,7 @@ def mdb_do_run(mdb_runner, command):
|
|||
shutil.rmtree(mdb_cfg_dir)
|
||||
|
||||
# nsim
|
||||
if simulation_run(mdb_runner):
|
||||
if is_simulation_run(mdb_runner):
|
||||
mdb_target = ['-nsim', '@' + mdb_runner.nsim_args]
|
||||
# hardware target
|
||||
else:
|
||||
|
@ -48,19 +61,17 @@ def mdb_do_run(mdb_runner, command):
|
|||
raise ValueError('unsupported jtag adapter {}'.format(mdb_runner.jtag))
|
||||
|
||||
if command == 'flash':
|
||||
if simulation_run(mdb_runner):
|
||||
# for nsim , can't run and quit immediately
|
||||
mdb_run = ['-run', '-cl']
|
||||
else:
|
||||
if is_flash_cmd_need_exit_immediately(mdb_runner):
|
||||
mdb_run = ['-run', '-cmd=-nowaitq run', '-cmd=quit', '-cl']
|
||||
else:
|
||||
mdb_run = ['-run', '-cl']
|
||||
elif command == 'debug':
|
||||
# use mdb gui to debug
|
||||
mdb_run = ['-OKN']
|
||||
|
||||
if mdb_runner.cores == 1:
|
||||
# single core's mdb command is different with multicores
|
||||
mdb_cmd = ([commander] + mdb_basic_options + mdb_target +
|
||||
mdb_run + [mdb_runner.elf_name])
|
||||
mdb_cmd = [commander] + mdb_basic_options + mdb_target + mdb_run + [mdb_runner.elf_name]
|
||||
elif 1 < mdb_runner.cores <= 4:
|
||||
mdb_multifiles = '-multifiles='
|
||||
for i in range(mdb_runner.cores):
|
||||
|
@ -74,7 +85,7 @@ def mdb_do_run(mdb_runner, command):
|
|||
|
||||
# to enable multi-core aware mode for use with the MetaWare debugger,
|
||||
# need to set the NSIM_MULTICORE environment variable to a non-zero value
|
||||
if simulation_run(mdb_runner):
|
||||
if is_simulation_run(mdb_runner):
|
||||
os.environ["NSIM_MULTICORE"] = '1'
|
||||
|
||||
mdb_cmd = [commander] + [mdb_multifiles] + mdb_run
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import argparse
|
||||
from os import path
|
||||
from os import path, fspath
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import call
|
||||
|
||||
|
@ -18,6 +18,15 @@ TEST_NSIM_ARGS='test_nsim.args'
|
|||
TEST_TARGET = 'test-target'
|
||||
TEST_BOARD_NSIM_ARGS = '@' + path.join(RC_BOARD_DIR, 'support', TEST_NSIM_ARGS)
|
||||
|
||||
DOTCONFIG_HOSTLINK = f'''
|
||||
CONFIG_ARC=y
|
||||
CONFIG_UART_HOSTLINK=y
|
||||
'''
|
||||
|
||||
DOTCONFIG_NO_HOSTLINK = f'''
|
||||
CONFIG_ARC=y
|
||||
'''
|
||||
|
||||
# mdb-nsim
|
||||
TEST_NSIM_FLASH_CASES = [
|
||||
{
|
||||
|
@ -50,7 +59,7 @@ TEST_NSIM_CORES_LAUNCH = [TEST_DRIVER_CMD, '-multifiles=core1,core0',
|
|||
'-run', '-cl']
|
||||
|
||||
# mdb-hw
|
||||
TEST_HW_FLASH_CASES = [
|
||||
TEST_HW_FLASH_CASES_NO_HOSTLINK = [
|
||||
{
|
||||
'i': ['--jtag=digilent', '--cores=1'],
|
||||
'o': [TEST_DRIVER_CMD, '-nooptions', '-nogoifmain',
|
||||
|
@ -65,6 +74,19 @@ TEST_HW_FLASH_CASES = [
|
|||
'-run', '-cmd=-nowaitq run', '-cmd=quit', '-cl', RC_KERNEL_ELF]
|
||||
}]
|
||||
|
||||
TEST_HW_FLASH_CASES_HOSTLINK = [
|
||||
{
|
||||
'i': ['--jtag=digilent', '--cores=1'],
|
||||
'o': [TEST_DRIVER_CMD, '-nooptions', '-nogoifmain',
|
||||
'-toggle=include_local_symbols=1',
|
||||
'-digilent', '-run', '-cl', RC_KERNEL_ELF]
|
||||
}, {
|
||||
'i': ['--jtag=digilent', '--cores=1', '--dig-device=test'],
|
||||
'o': [TEST_DRIVER_CMD, '-nooptions', '-nogoifmain',
|
||||
'-toggle=include_local_symbols=1',
|
||||
'-digilent', '-prop=dig_device=test', '-run', '-cl', RC_KERNEL_ELF]
|
||||
}]
|
||||
|
||||
TEST_HW_FLASH_CASES_ERR = [
|
||||
{
|
||||
'i': ['--jtag=test_debug', '--cores=1'],
|
||||
|
@ -106,8 +128,23 @@ TEST_HW_CORE2 = [TEST_DRIVER_CMD, '-pset=2', '-psetname=core1',
|
|||
'-prop=download=2', '-nooptions', '-nogoifmain',
|
||||
'-toggle=include_local_symbols=1',
|
||||
'-digilent', RC_KERNEL_ELF]
|
||||
TEST_HW_CORES_LAUNCH = [TEST_DRIVER_CMD, '-multifiles=core1,core0', '-run',
|
||||
TEST_HW_CORES_LAUNCH_NO_HOSTLINK = [TEST_DRIVER_CMD, '-multifiles=core1,core0', '-run',
|
||||
'-cmd=-nowaitq run', '-cmd=quit', '-cl']
|
||||
TEST_HW_CORES_LAUNCH_HOSTLINK = [TEST_DRIVER_CMD, '-multifiles=core1,core0', '-run', '-cl']
|
||||
|
||||
|
||||
def adjust_runner_config(runner_config, tmpdir, dotconfig):
|
||||
# Adjust a RunnerConfig object, 'runner_config', by
|
||||
# replacing its build directory with 'tmpdir' after writing
|
||||
# the contents of 'dotconfig' to tmpdir/zephyr/.config.
|
||||
|
||||
zephyr = tmpdir / 'zephyr'
|
||||
zephyr.mkdir()
|
||||
with open(zephyr / '.config', 'w') as f:
|
||||
f.write(dotconfig)
|
||||
|
||||
print("" + fspath(tmpdir))
|
||||
return runner_config._replace(build_dir=fspath(tmpdir))
|
||||
|
||||
#
|
||||
# Fixtures
|
||||
|
@ -139,7 +176,13 @@ def mdb_nsim(runner_config, tmpdir):
|
|||
return mdb(runner_config, tmpdir, MdbNsimBinaryRunner)
|
||||
|
||||
@pytest.fixture
|
||||
def mdb_hw(runner_config, tmpdir):
|
||||
def mdb_hw_no_hl(runner_config, tmpdir):
|
||||
runner_config = adjust_runner_config(runner_config, tmpdir, DOTCONFIG_NO_HOSTLINK)
|
||||
return mdb(runner_config, tmpdir, MdbHwBinaryRunner)
|
||||
|
||||
@pytest.fixture
|
||||
def mdb_hw_hl(runner_config, tmpdir):
|
||||
runner_config = adjust_runner_config(runner_config, tmpdir, DOTCONFIG_HOSTLINK)
|
||||
return mdb(runner_config, tmpdir, MdbHwBinaryRunner)
|
||||
|
||||
#
|
||||
|
@ -183,37 +226,53 @@ def test_multicores_nsim(require, pii, cc, test_case, mdb_nsim):
|
|||
|
||||
|
||||
# mdb-hw test cases
|
||||
@pytest.mark.parametrize('test_case', TEST_HW_FLASH_CASES)
|
||||
@pytest.mark.parametrize('test_case', TEST_HW_FLASH_CASES_NO_HOSTLINK)
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.call')
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
def test_flash_hw(require, cc, test_case, mdb_hw):
|
||||
mdb_hw(test_case['i']).run('flash')
|
||||
def test_flash_hw_no_hl(require, cc, test_case, mdb_hw_no_hl, tmpdir):
|
||||
mdb_hw_no_hl(test_case['i']).run('flash')
|
||||
assert require.called
|
||||
cc.assert_called_once_with(test_case['o'], cwd=RC_BUILD_DIR)
|
||||
cc.assert_called_once_with(test_case['o'], cwd=tmpdir)
|
||||
|
||||
@pytest.mark.parametrize('test_case', TEST_HW_FLASH_CASES_HOSTLINK)
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.call')
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
def test_flash_hw_hl(require, cc, test_case, mdb_hw_hl, tmpdir):
|
||||
mdb_hw_hl(test_case['i']).run('flash')
|
||||
assert require.called
|
||||
cc.assert_called_once_with(test_case['o'], cwd=tmpdir)
|
||||
|
||||
@pytest.mark.parametrize('test_case', TEST_HW_FLASH_CASES_ERR)
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.call')
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
def test_flash_hw_err(require, cc, test_case, mdb_hw):
|
||||
def test_flash_hw_err(require, cc, test_case, mdb_hw_no_hl):
|
||||
with pytest.raises(ValueError) as rinfo:
|
||||
mdb_hw(test_case['i']).run('flash')
|
||||
mdb_hw_no_hl(test_case['i']).run('flash')
|
||||
|
||||
assert str(rinfo.value) == test_case['e']
|
||||
|
||||
@pytest.mark.parametrize('test_case', TEST_HW_DEBUG_CASES)
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.call')
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
def test_debug_hw(require, pii, test_case, mdb_hw):
|
||||
mdb_hw(test_case['i']).run('debug')
|
||||
def test_debug_hw(require, pii, test_case, mdb_hw_no_hl, tmpdir):
|
||||
mdb_hw_no_hl(test_case['i']).run('debug')
|
||||
assert require.called
|
||||
pii.assert_called_once_with(test_case['o'], cwd=RC_BUILD_DIR)
|
||||
pii.assert_called_once_with(test_case['o'], cwd=tmpdir)
|
||||
|
||||
@pytest.mark.parametrize('test_case', TEST_HW_DEBUG_CASES)
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.call')
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
def test_debug_hw_hl(require, pii, test_case, mdb_hw_hl, tmpdir):
|
||||
mdb_hw_hl(test_case['i']).run('debug')
|
||||
assert require.called
|
||||
pii.assert_called_once_with(test_case['o'], cwd=tmpdir)
|
||||
|
||||
@pytest.mark.parametrize('test_case', TEST_HW_DEBUG_CASES_ERR)
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.call')
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
def test_debug_hw_err(require, pii, test_case, mdb_hw):
|
||||
def test_debug_hw_err(require, pii, test_case, mdb_hw_no_hl):
|
||||
with pytest.raises(ValueError) as rinfo:
|
||||
mdb_hw(test_case['i']).run('debug')
|
||||
mdb_hw_no_hl(test_case['i']).run('debug')
|
||||
|
||||
assert str(rinfo.value) == test_case['e']
|
||||
|
||||
|
@ -221,9 +280,20 @@ def test_debug_hw_err(require, pii, test_case, mdb_hw):
|
|||
@patch('runners.mdb.MdbHwBinaryRunner.check_call')
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.call')
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
def test_multicores_hw(require, pii, cc, test_case, mdb_hw):
|
||||
mdb_hw(test_case).run('flash')
|
||||
def test_multicores_hw_no_hl(require, pii, cc, test_case, mdb_hw_no_hl, tmpdir):
|
||||
mdb_hw_no_hl(test_case).run('flash')
|
||||
assert require.called
|
||||
cc_calls = [call(TEST_HW_CORE1, cwd=RC_BUILD_DIR), call(TEST_HW_CORE2, cwd=RC_BUILD_DIR)]
|
||||
cc_calls = [call(TEST_HW_CORE1, cwd=tmpdir), call(TEST_HW_CORE2, cwd=tmpdir)]
|
||||
cc.assert_has_calls(cc_calls)
|
||||
pii.assert_called_once_with(TEST_HW_CORES_LAUNCH, cwd=RC_BUILD_DIR)
|
||||
pii.assert_called_once_with(TEST_HW_CORES_LAUNCH_NO_HOSTLINK, cwd=tmpdir)
|
||||
|
||||
@pytest.mark.parametrize('test_case', TEST_HW_MULTICORE_CASES)
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.check_call')
|
||||
@patch('runners.mdb.MdbHwBinaryRunner.call')
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
def test_multicores_hw_hl(require, pii, cc, test_case, mdb_hw_hl, tmpdir):
|
||||
mdb_hw_hl(test_case).run('flash')
|
||||
assert require.called
|
||||
cc_calls = [call(TEST_HW_CORE1, cwd=tmpdir), call(TEST_HW_CORE2, cwd=tmpdir)]
|
||||
cc.assert_has_calls(cc_calls)
|
||||
pii.assert_called_once_with(TEST_HW_CORES_LAUNCH_HOSTLINK, cwd=tmpdir)
|
||||
|
|
Loading…
Reference in a new issue