Skip to content

Commit

Permalink
tests: gdbstub: qemu: Cross-validate test behavior
Browse files Browse the repository at this point in the history
Add a testcase to run the same test application and GDB script
which we use for Zephyr GDB stub testing, but now with
the GDB stub enabled at QEMU itself.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
  • Loading branch information
golowanow committed Oct 9, 2023
1 parent 79768f6 commit 26d2b0b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
2 changes: 0 additions & 2 deletions tests/subsys/debug/gdbstub/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CONFIG_GDBSTUB=y
CONFIG_GDBSTUB_SERIAL_BACKEND=y
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_USERSPACE=y
CONFIG_KOBJECT_TEXT_AREA=4096
12 changes: 10 additions & 2 deletions tests/subsys/debug/gdbstub/pytest/test_gdbstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ def expected_gdb():
re.compile(r'GDB:PASSED'),
]

def test_gdbstub(dut: DeviceAdapter, gdb_process, expected_app, expected_gdb):
@pytest.fixture(scope="module")
def expected_gdb_detach():
return [
re.compile(r'Inferior.*will be killed'), # Zephyr gdbstub
re.compile(r'Inferior.*detached') # QEMU gdbstub
]


def test_gdbstub(dut: DeviceAdapter, gdb_process, expected_app, expected_gdb, expected_gdb_detach):
"""
Test gdbstub feature using a GDB script. We connect to the DUT, run the
GDB script then evaluate return code and expected patterns at the GDB
Expand All @@ -68,7 +76,7 @@ def test_gdbstub(dut: DeviceAdapter, gdb_process, expected_app, expected_gdb):
logger.debug(f"GDB output:\n{gdb_process.stdout}\n")
assert gdb_process.returncode == 0
assert all([ex_re.search(gdb_process.stdout, re.MULTILINE) for ex_re in expected_gdb]), 'No expected GDB output'
assert 'Inferior 1 [Remote target] will be killed' in gdb_process.stdout,'Expecting explicit quit from the GDB script and kill QEMU test app.'
assert any([ex_re.search(gdb_process.stdout, re.MULTILINE) for ex_re in expected_gdb_detach]), 'No expected GDB quit'
app_output = '\n'.join(dut.readlines(print_output = False))
logger.debug(f"App output:\n{app_output}\n")
assert all([ex_re.search(app_output, re.MULTILINE) for ex_re in expected_app]), 'No expected Application output'
Expand Down
35 changes: 32 additions & 3 deletions tests/subsys/debug/gdbstub/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#

tests:
debug.gdbstub.breakpoints:
# Connect to Zephyr gdbstub and run a simple GDB script
debug.gdbstub_zephyr.breakpoints:
platform_allow: qemu_x86
harness: pytest
harness_config:
Expand All @@ -17,12 +18,40 @@ tests:
- "--gdb_script"
- "test_breakpoints.gdbinit"
- "--gdb_target_remote"
- "tcp:127.0.0.1:5678"
- "tcp::5678"
tags:
- debug
- gdbstub
- pytest
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"
- CONFIG_GDBSTUB=y
- CONFIG_GDBSTUB_SERIAL_BACKEND=y
- CONFIG_QEMU_EXTRA_FLAGS="-serial tcp::5678,server"

# Connect to QEMU gdbstub and run the same simple GDB script
# Use non-default QEMU gdbstub port 1235
debug.gdbstub_qemu.breakpoints:
platform_allow: qemu_x86
harness: pytest
harness_config:
pytest_root:
- "pytest/test_gdbstub.py"
pytest_args:
- "--gdb_timeout"
- "20"
- "--gdb_script"
- "test_breakpoints.gdbinit"
- "--gdb_target_remote"
- "tcp::1235"
tags:
- debug
- gdbstub
- pytest
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="-S -gdb tcp::1235"
# Clear QEMU default 'tcp::1234'
- CONFIG_QEMU_GDBSERVER_LISTEN_DEV=""

0 comments on commit 26d2b0b

Please sign in to comment.