-
Notifications
You must be signed in to change notification settings - Fork 1.4k
tests: subsys: Add test that verifies west debug command #26119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright (c) 2025 Nordic Semiconductor ASA | ||
| * | ||
| * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
| */ | ||
|
|
||
| #include <zephyr/kernel.h> | ||
|
|
||
| volatile int counter = 1; | ||
|
|
||
| int main(void) | ||
| { | ||
| while (true) { | ||
| k_busy_wait(500000); | ||
| counter++; | ||
| if (counter > 1000) { | ||
| counter = 0; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is related to zephyrproject-rtos/zephyr#100386 or not but FYI a user reported issues with doing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this PR is a result of I wasn't aware that it is possible to switch
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| - 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flpr/xip?