From 0acc73423a72d05347fc736ffa7f0fd9a6f7ad13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20G=C5=82=C4=85b?= Date: Tue, 9 Dec 2025 15:01:19 +0100 Subject: [PATCH 1/2] manifest: update sdk-zephyr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Include boards: nordic: nrf54h20dk: Add workaround for RISC-V debugging https://github.com/nrfconnect/sdk-zephyr/pull/3621 Upstream PR #: 100744 Signed-off-by: Sebastian Głąb --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index fcfc5dcfd4e..d89d25388bb 100644 --- a/west.yml +++ b/west.yml @@ -64,7 +64,7 @@ manifest: # https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/modules.html - name: zephyr repo-path: sdk-zephyr - revision: 6a9f0debe2cb0d47328b26f109b09649b74ab269 + revision: pull/3621/head import: # In addition to the zephyr repository itself, NCS also # imports the contents of zephyr/west.yml at the above From 9ca44164b3266b881f860070c89777c1b6db2b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20G=C5=82=C4=85b?= Date: Fri, 5 Dec 2025 11:18:39 +0100 Subject: [PATCH 2/2] tests: subsys: Add test that verifies west debug command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add test that checks if platform can be debugged with - west attach - west debug. Add test variant with debug optimizations and thread info enabled. Signed-off-by: Sebastian Głąb --- CODEOWNERS | 3 +- scripts/ci/tags.yaml | 6 + tests/subsys/west_debug/CMakeLists.txt | 12 ++ tests/subsys/west_debug/prj.conf | 8 ++ .../west_debug/pytest/test_west_debug.py | 122 ++++++++++++++++++ tests/subsys/west_debug/src/main.c | 20 +++ tests/subsys/west_debug/testcase.yaml | 42 ++++++ 7 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 tests/subsys/west_debug/CMakeLists.txt create mode 100644 tests/subsys/west_debug/prj.conf create mode 100644 tests/subsys/west_debug/pytest/test_west_debug.py create mode 100644 tests/subsys/west_debug/src/main.c create mode 100644 tests/subsys/west_debug/testcase.yaml diff --git a/CODEOWNERS b/CODEOWNERS index 60ff3dbb6a3..8cffdcdf9a2 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -935,6 +935,7 @@ /tests/subsys/emds/ @balaklaka @nrfconnect/ncs-paladin /tests/subsys/event_manager_proxy/ @nrfconnect/ncs-si-muffin /tests/subsys/fw_info/ @nrfconnect/ncs-eris +/tests/subsys/ipc/ @nrfconnect/ncs-low-level-test /tests/subsys/kmu/ @nrfconnect/ncs-eris /tests/subsys/mpsl/ @nrfconnect/ncs-dragoon /tests/subsys/net/lib/aws_*/ @nrfconnect/ncs-cia @@ -958,7 +959,7 @@ /tests/subsys/rtt/ @nrfconnect/ncs-low-level-test /tests/subsys/swo/ @nrfconnect/ncs-low-level-test /tests/subsys/usb/negotiated_speed/ @nrfconnect/ncs-low-level-test -/tests/subsys/ipc/ @nrfconnect/ncs-low-level-test +/tests/subsys/west_debug/ @nrfconnect/ncs-low-level-test /tests/tfm/ @nrfconnect/ncs-aegir @magnev /tests/unity/ @nordic-krch /tests/zephyr/boards/nrf/ @nrfconnect/ncs-low-level-test diff --git a/scripts/ci/tags.yaml b/scripts/ci/tags.yaml index f90224db710..18e94001b87 100644 --- a/scripts/ci/tags.yaml +++ b/scripts/ci/tags.yaml @@ -1864,3 +1864,9 @@ ci_tests_subsys_swo: ci_tests_drivers_can: files: - zephyr/drivers/can/ + +ci_tests_subsys_west_debug: + files: + - nrf/tests/subsys/west_debug/ + - zephyr/boards/nordic/ + - nrf/boards/nordic/54* diff --git a/tests/subsys/west_debug/CMakeLists.txt b/tests/subsys/west_debug/CMakeLists.txt new file mode 100644 index 00000000000..7d2b4304bbe --- /dev/null +++ b/tests/subsys/west_debug/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(west_debug) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/subsys/west_debug/prj.conf b/tests/subsys/west_debug/prj.conf new file mode 100644 index 00000000000..e7fa2756fa1 --- /dev/null +++ b/tests/subsys/west_debug/prj.conf @@ -0,0 +1,8 @@ +CONFIG_BOOT_BANNER=n +CONFIG_NCS_BOOT_BANNER=n + +CONFIG_PRINTK=n +CONFIG_LOG=n +CONFIG_CONSOLE=n +CONFIG_UART_CONSOLE=n +CONFIG_SERIAL=n diff --git a/tests/subsys/west_debug/pytest/test_west_debug.py b/tests/subsys/west_debug/pytest/test_west_debug.py new file mode 100644 index 00000000000..3399a5d7daf --- /dev/null +++ b/tests/subsys/west_debug/pytest/test_west_debug.py @@ -0,0 +1,122 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +import logging +import re +import subprocess +import time + +import psutil +from twister_harness import DeviceAdapter + +logger = logging.getLogger(__name__) + + +# Kill parent process and all child processes (if started) +def _kill(proc): + try: + for child in psutil.Process(proc.pid).children(recursive=True): + child.kill() + proc.kill() + logger.debug("Process was killed.") + except Exception as e: + logger.exception(f"Could not kill process - {e}") + + +def test_west_debug(dut: DeviceAdapter): + """ + Compile and flash test application on MCU. + Start debug session by calling `west debug` command. + Set brakepoint and check that breakpoint was hit. + """ + BUILD_DIR = str(dut.device_config.build_dir) + SEGGER_ID = dut.device_config.id + COLLECT_TIMEOUT = 15.0 + EXPECTED = r"15\s+counter\+\+;" + + logger.debug(f"{dut.device_config=}") + + # Wait a bit for the core to boot + time.sleep(4) + + gdb_port = int(SEGGER_ID) % 1000 + 2331 + + # Check if west debug works + cmd = f"west debug -d {BUILD_DIR} -- --dev-id {SEGGER_ID} --gdb-port {gdb_port}" + logger.info(f"Executing:\n{cmd}") + proc = subprocess.Popen( + cmd.split(), + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + encoding='UTF-8', + text=True, + ) + + time.sleep(2) + logger.info("Try to communicate with the process.") + + try: + # set breakpoint in main.c line 18 which is `counter++;` + # continue + # [breakpoint shall hit] + # quit + outs, errs = proc.communicate( + input="b main.c:15\nc\ndisconnect\nq\n", + timeout=COLLECT_TIMEOUT, + ) + except subprocess.TimeoutExpired: + _kill(proc) + finally: + outs, errs = proc.communicate() + logger.info(f"{outs=}\n{errs=}") + + expected_str = re.search(EXPECTED, outs) + assert expected_str is not None, f"Failed to match {EXPECTED} in {outs}" + + +def test_west_attach(dut: DeviceAdapter): + """ + Compile and flash test application on MCU. + Cal `west atach` command. + Check response to where. + """ + BUILD_DIR = str(dut.device_config.build_dir) + SEGGER_ID = dut.device_config.id + COLLECT_TIMEOUT = 15.0 + EXPECTED = r"in k_busy_wait \(usec_to_wait=500000\)" + + # Wait a bit for the core to boot + time.sleep(4) + + gdb_port = int(SEGGER_ID) % 1000 + 2331 + cmd = f"west attach -d {BUILD_DIR} -- --dev-id {SEGGER_ID} --gdb-port {gdb_port}" + + logger.info(f"Executing:\n{cmd}") + proc = subprocess.Popen( + cmd.split(), + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + encoding='UTF-8', + text=True, + ) + + time.sleep(2) + logger.info("Try to communicate with the process.") + + try: + # where + # quit + outs, errs = proc.communicate(input="where\ndisconnect\nq\n", timeout=COLLECT_TIMEOUT) + except subprocess.TimeoutExpired: + _kill(proc) + finally: + outs, errs = proc.communicate() + logger.info(f"{outs=}\n{errs=}") + + expected_str = re.search(EXPECTED, outs) + assert expected_str is not None, f"Failed to match {EXPECTED} in {outs}" diff --git a/tests/subsys/west_debug/src/main.c b/tests/subsys/west_debug/src/main.c new file mode 100644 index 00000000000..f5258fdc232 --- /dev/null +++ b/tests/subsys/west_debug/src/main.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include + +volatile int counter = 1; + +int main(void) +{ + while (true) { + k_busy_wait(500000); + counter++; + if (counter > 1000) { + counter = 0; + } + } +} diff --git a/tests/subsys/west_debug/testcase.yaml b/tests/subsys/west_debug/testcase.yaml new file mode 100644 index 00000000000..a057f8d2098 --- /dev/null +++ b/tests/subsys/west_debug/testcase.yaml @@ -0,0 +1,42 @@ +common: + tags: ci_tests_subsys_west_debug + harness: pytest + harness_config: + pytest_root: + - "pytest/test_west_debug.py" + timeout: 30 + platform_allow: + - nrf52dk/nrf52832 + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpuapp/ns + - nrf5340dk/nrf5340/cpunet + - nrf54h20dk/nrf54h20/cpuapp + - nrf54h20dk/nrf54h20/cpuflpr + - nrf54h20dk/nrf54h20/cpuflpr/xip + - nrf54h20dk/nrf54h20/cpuppr + - nrf54h20dk/nrf54h20/cpuppr/xip + - nrf54h20dk/nrf54h20/cpurad + - nrf54l15dk/nrf54l05/cpuapp + - nrf54l15dk/nrf54l10/cpuapp + - nrf54l15dk/nrf54l10/cpuapp/ns + - nrf54l15dk/nrf54l15/cpuapp + - nrf54l15dk/nrf54l15/cpuapp/ns + - nrf54l15dk/nrf54l15/cpuflpr + - nrf54l15dk/nrf54l15/cpuflpr/xip + - nrf54lm20dk/nrf54lm20a/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp/ns + - nrf54lm20dk/nrf54lm20a/cpuflpr + - nrf54ls05dk/nrf54ls05b/cpuapp + - nrf54lv10dk/nrf54lv10a/cpuapp + - nrf54lv10dk/nrf54lv10a/cpuapp/ns + - nrf54lv10dk/nrf54lv10a/cpuflpr + integration_platforms: + - nrf54lm20dk/nrf54lm20a/cpuapp + +tests: + subsys.west_debug.normal: {} + subsys.west_debug.thread_info: + extra_args: + - CONFIG_DEBUG_OPTIMIZATIONS=y + - CONFIG_DEBUG_THREAD_INFO=y