Commit 236c1ac5 authored by Dmitrii Golovanov's avatar Dmitrii Golovanov Committed by Carles Cufi
Browse files

tests: gdbstub: Add GDB remote target parameter



Add `gdb_target_remote` test parameter for GDB `target remote`
command instead of its hardcoded value to allow different types
of gdbstub serial interfaces as well as different TCP ports in
gdbstub test suites possibly run in parallel on the same host.

Move all GDB log configuration parameters from GDB script to
the fixture code.

Signed-off-by: default avatarDmitrii Golovanov <dmitrii.golovanov@intel.com>
parent 5008c31f
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -2,10 +2,6 @@

cmake_minimum_required(VERSION 3.20.0)

if(BOARD MATCHES "qemu_x86")
  list(APPEND QEMU_EXTRA_FLAGS -serial tcp:127.0.0.1:5678,server)
endif()

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(debug_gdbstub)

+5 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
import pytest

def pytest_addoption(parser):
    parser.addoption('--gdb_target_remote')
    parser.addoption('--gdb_timeout')
    parser.addoption('--gdb_script')

@@ -17,4 +18,8 @@ def gdb_script(request):
@pytest.fixture()
def gdb_timeout(request):
    return int(request.config.getoption('--gdb_timeout', default=60))

@pytest.fixture()
def gdb_target_remote(request):
    return request.config.getoption('--gdb_target_remote', default=":5678")
#
+7 −2
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ from twisterlib.cmakecache import CMakeCache
logger = logging.getLogger(__name__)

@pytest.fixture()
def gdb_process(dut: DeviceAdapter, gdb_script, gdb_timeout):
def gdb_process(dut: DeviceAdapter, gdb_script, gdb_timeout, gdb_target_remote):
    build_dir = dut.device_config.build_dir
    cmake_cache = CMakeCache.from_file(os.path.join(build_dir, 'CMakeCache.txt'))
    gdb_exec = cmake_cache.get('CMAKE_GDB', None)
@@ -28,7 +28,12 @@ def gdb_process(dut: DeviceAdapter, gdb_script, gdb_timeout):
    build_image = cmake_cache.get('BYPRODUCT_KERNEL_ELF_NAME', None)
    assert build_image
    gdb_log_file = os.path.join(build_dir, 'gdb.log')
    cmd = [gdb_exec, '-batch', '-ex', f'set logging file {gdb_log_file}',
    cmd = [gdb_exec, '-batch',
           '-ex', f'set pagination off',
           '-ex', f'set trace-commands on',
           '-ex', f'set logging file {gdb_log_file}',
           '-ex', f'set logging enabled on',
           '-ex', f'target remote {gdb_target_remote}',
           '-x', f'{source_dir}/{gdb_script}', build_image]
    logger.info(f'Run GDB: {shlex.join(cmd)}')
    result = subprocess.run(cmd, capture_output=True, text=True, timeout=gdb_timeout)
+0 −6
Original line number Diff line number Diff line
set pagination off
set trace-commands on
set logging enabled on

target remote :5678

b test
b main.c:29
c
+11 −1
Original line number Diff line number Diff line
@@ -11,7 +11,17 @@ tests:
    harness_config:
      pytest_root:
        - "pytest/test_gdbstub.py"
      pytest_args: ["--gdb_timeout", "20", "--gdb_script", "test_breakpoints.gdbinit"]
      pytest_args:
        - "--gdb_timeout"
        - "20"
        - "--gdb_script"
        - "test_breakpoints.gdbinit"
        - "--gdb_target_remote"
        - "tcp:127.0.0.1:5678"
    tags:
      - debug
      - gdbstub
    extra_configs:
      # Make sure the gdbstub port chosen is unique for this test to avoid conflicts
      # when Twister runs tests in parallel on the same host.
      - CONFIG_QEMU_EXTRA_FLAGS="-serial tcp:127.0.0.1:5678,server"