diff --git a/samples/subsys/debug/gdbstub/pytest/test_gdbstub.py b/samples/subsys/debug/gdbstub/pytest/test_gdbstub.py new file mode 100755 index 00000000000..41dca1cfcae --- /dev/null +++ b/samples/subsys/debug/gdbstub/pytest/test_gdbstub.py @@ -0,0 +1,34 @@ +# Copyright (c) 2023 Intel Corporation. +# +# SPDX-License-Identifier: Apache-2.0 + +import os +import subprocess +from twister_harness import DeviceAdapter +import sys +import logging +import shlex + +ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") +sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "pylib", "twister")) +from twisterlib.cmakecache import CMakeCache + +logger = logging.getLogger(__name__) + + +def test_gdbstub(dut: DeviceAdapter): + """ + Test gdbstub feature using a gdb script. We connect to the DUT and run some + basic gdb commands and evaluate return code to determine pass or failure. + """ + build_dir = dut.device_config.build_dir + cmake_cache = CMakeCache.from_file(build_dir / 'CMakeCache.txt') + gdb = cmake_cache.get('CMAKE_GDB', None) + assert gdb + source_dir = cmake_cache.get('APPLICATION_SOURCE_DIR', None) + assert source_dir + cmd = [gdb, '-x', f'{source_dir}/run.gdbinit', f'{build_dir}/zephyr/zephyr.elf'] + logger.info(f'Test command: {shlex.join(cmd)}') + result = subprocess.run(cmd, capture_output=True, text=True, timeout=20) + logger.debug('Output:\n%s' % result.stdout) + assert result.returncode == 0 diff --git a/samples/subsys/debug/gdbstub/run.gdbinit b/samples/subsys/debug/gdbstub/run.gdbinit index 49181157ae2..abce598f54a 100644 --- a/samples/subsys/debug/gdbstub/run.gdbinit +++ b/samples/subsys/debug/gdbstub/run.gdbinit @@ -1,6 +1,6 @@ set pagination off -symbol-file zephyr/zephyr.elf -target remote 127.0.0.1:1234 +#symbol-file build/zephyr/zephyr.elf +target remote :5678 b test b main.c:33 c diff --git a/samples/subsys/debug/gdbstub/sample.yaml b/samples/subsys/debug/gdbstub/sample.yaml index 5f75a801541..638c5ec16cc 100644 --- a/samples/subsys/debug/gdbstub/sample.yaml +++ b/samples/subsys/debug/gdbstub/sample.yaml @@ -8,8 +8,8 @@ sample: name: gdbstub sample tests: sample.debug.gdbstub: - build_only: true platform_allow: qemu_x86 + harness: pytest tags: - debug - gdbstub