Skip to content

Commit 9b49ab8

Browse files
committed
tests: subsys: Add test that verifies west debug command
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 <[email protected]>
1 parent edfa36f commit 9b49ab8

File tree

7 files changed

+211
-1
lines changed

7 files changed

+211
-1
lines changed

CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@
935935
/tests/subsys/emds/ @balaklaka @nrfconnect/ncs-paladin
936936
/tests/subsys/event_manager_proxy/ @nrfconnect/ncs-si-muffin
937937
/tests/subsys/fw_info/ @nrfconnect/ncs-eris
938+
/tests/subsys/ipc/ @nrfconnect/ncs-low-level-test
938939
/tests/subsys/kmu/ @nrfconnect/ncs-eris
939940
/tests/subsys/mpsl/ @nrfconnect/ncs-dragoon
940941
/tests/subsys/net/lib/aws_*/ @nrfconnect/ncs-cia
@@ -958,7 +959,7 @@
958959
/tests/subsys/rtt/ @nrfconnect/ncs-low-level-test
959960
/tests/subsys/swo/ @nrfconnect/ncs-low-level-test
960961
/tests/subsys/usb/negotiated_speed/ @nrfconnect/ncs-low-level-test
961-
/tests/subsys/ipc/ @nrfconnect/ncs-low-level-test
962+
/tests/subsys/west_debug/ @nrfconnect/ncs-low-level-test
962963
/tests/tfm/ @nrfconnect/ncs-aegir @magnev
963964
/tests/unity/ @nordic-krch
964965
/tests/zephyr/boards/nrf/ @nrfconnect/ncs-low-level-test

scripts/ci/tags.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,3 +1864,9 @@ ci_tests_subsys_swo:
18641864
ci_tests_drivers_can:
18651865
files:
18661866
- zephyr/drivers/can/
1867+
1868+
ci_tests_subsys_west_debug:
1869+
files:
1870+
- nrf/tests/subsys/west_debug/
1871+
- zephyr/boards/nordic/
1872+
- nrf/boards/nordic/54*
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(west_debug)
11+
12+
target_sources(app PRIVATE src/main.c)

tests/subsys/west_debug/prj.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CONFIG_BOOT_BANNER=n
2+
CONFIG_NCS_BOOT_BANNER=n
3+
4+
CONFIG_PRINTK=n
5+
CONFIG_LOG=n
6+
CONFIG_CONSOLE=n
7+
CONFIG_UART_CONSOLE=n
8+
CONFIG_SERIAL=n
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
import logging
8+
import re
9+
import subprocess
10+
import time
11+
12+
import psutil
13+
from twister_harness import DeviceAdapter
14+
15+
logger = logging.getLogger(__name__)
16+
17+
18+
# Kill parent process and all child processes (if started)
19+
def _kill(proc):
20+
try:
21+
for child in psutil.Process(proc.pid).children(recursive=True):
22+
child.kill()
23+
proc.kill()
24+
logger.debug("Process was killed.")
25+
except Exception as e:
26+
logger.exception(f"Could not kill process - {e}")
27+
28+
29+
def test_west_debug(dut: DeviceAdapter):
30+
"""
31+
Compile and flash test application on MCU.
32+
Start debug session by calling `west debug` command.
33+
Set brakepoint and check that breakpoint was hit.
34+
"""
35+
BUILD_DIR = str(dut.device_config.build_dir)
36+
SEGGER_ID = dut.device_config.id
37+
COLLECT_TIMEOUT = 15.0
38+
EXPECTED = r"15\s+counter\+\+;"
39+
40+
logger.debug(f"{dut.device_config=}")
41+
42+
# Wait a bit for the core to boot
43+
time.sleep(4)
44+
45+
gdb_port = int(SEGGER_ID) % 1000 + 2331
46+
cmd = f"west debug -d {BUILD_DIR} -- --dev-id {SEGGER_ID} --gdb-port {gdb_port}"
47+
48+
logger.info(f"Executing:\n{cmd}")
49+
proc = subprocess.Popen(
50+
cmd.split(),
51+
stdin=subprocess.PIPE,
52+
stdout=subprocess.PIPE,
53+
stderr=subprocess.STDOUT,
54+
encoding='UTF-8',
55+
text=True,
56+
)
57+
58+
time.sleep(2)
59+
logger.info("Try to communicate with the process.")
60+
61+
try:
62+
# set breakpoint in main.c line 18 which is `counter++;`
63+
# continue
64+
# [breakpoint shall hit]
65+
# quit
66+
outs, errs = proc.communicate(
67+
input="b main.c:15\nc\ndisconnect\nq\n",
68+
timeout=COLLECT_TIMEOUT,
69+
)
70+
except subprocess.TimeoutExpired:
71+
_kill(proc)
72+
finally:
73+
outs, errs = proc.communicate()
74+
logger.info(f"{outs=}\n{errs=}")
75+
76+
expected_str = re.search(EXPECTED, outs)
77+
assert expected_str is not None, f"Failed to match {EXPECTED} in {outs}"
78+
79+
80+
def test_west_attach(dut: DeviceAdapter):
81+
"""
82+
Compile and flash test application on MCU.
83+
Cal `west atach` command.
84+
Check response to where.
85+
"""
86+
BUILD_DIR = str(dut.device_config.build_dir)
87+
SEGGER_ID = dut.device_config.id
88+
COLLECT_TIMEOUT = 15.0
89+
EXPECTED = r"in k_busy_wait \(usec_to_wait=500000\)"
90+
91+
# Wait a bit for the core to boot
92+
time.sleep(4)
93+
94+
gdb_port = int(SEGGER_ID) % 1000 + 2331
95+
cmd = f"west attach -d {BUILD_DIR} -- --dev-id {SEGGER_ID} --gdb-port {gdb_port}"
96+
97+
logger.info(f"Executing:\n{cmd}")
98+
proc = subprocess.Popen(
99+
cmd.split(),
100+
stdin=subprocess.PIPE,
101+
stdout=subprocess.PIPE,
102+
stderr=subprocess.STDOUT,
103+
encoding='UTF-8',
104+
text=True,
105+
)
106+
107+
time.sleep(2)
108+
logger.info("Try to communicate with the process.")
109+
110+
try:
111+
# where
112+
# quit
113+
outs, errs = proc.communicate(input="where\ndisconnect\nq\n", timeout=COLLECT_TIMEOUT)
114+
except subprocess.TimeoutExpired:
115+
_kill(proc)
116+
finally:
117+
outs, errs = proc.communicate()
118+
logger.info(f"{outs=}\n{errs=}")
119+
120+
expected_str = re.search(EXPECTED, outs)
121+
assert expected_str is not None, f"Failed to match {EXPECTED} in {outs}"

tests/subsys/west_debug/src/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
9+
volatile int counter = 1;
10+
11+
int main(void)
12+
{
13+
while (true) {
14+
k_busy_wait(500000);
15+
counter++;
16+
if (counter > 1000) {
17+
counter = 0;
18+
}
19+
}
20+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
common:
2+
tags: ci_tests_subsys_west_debug
3+
harness: pytest
4+
harness_config:
5+
pytest_root:
6+
- "pytest/test_west_debug.py"
7+
timeout: 30
8+
platform_allow:
9+
- nrf52dk/nrf52832
10+
- nrf52840dk/nrf52840
11+
- nrf5340dk/nrf5340/cpuapp
12+
- nrf5340dk/nrf5340/cpuapp/ns
13+
- nrf5340dk/nrf5340/cpunet
14+
- nrf54h20dk/nrf54h20/cpuapp
15+
- nrf54h20dk/nrf54h20/cpuflpr
16+
- nrf54h20dk/nrf54h20/cpuflpr/xip
17+
- nrf54h20dk/nrf54h20/cpuppr
18+
- nrf54h20dk/nrf54h20/cpuppr/xip
19+
- nrf54h20dk/nrf54h20/cpurad
20+
- nrf54l15dk/nrf54l05/cpuapp
21+
- nrf54l15dk/nrf54l10/cpuapp
22+
- nrf54l15dk/nrf54l10/cpuapp/ns
23+
- nrf54l15dk/nrf54l15/cpuapp
24+
- nrf54l15dk/nrf54l15/cpuapp/ns
25+
- nrf54l15dk/nrf54l15/cpuflpr
26+
- nrf54l15dk/nrf54l15/cpuflpr/xip
27+
- nrf54lm20dk/nrf54lm20a/cpuapp
28+
- nrf54lm20dk/nrf54lm20a/cpuapp/ns
29+
- nrf54lm20dk/nrf54lm20a/cpuflpr
30+
- nrf54ls05dk/nrf54ls05b/cpuapp
31+
- nrf54lv10dk/nrf54lv10a/cpuapp
32+
- nrf54lv10dk/nrf54lv10a/cpuapp/ns
33+
- nrf54lv10dk/nrf54lv10a/cpuflpr
34+
integration_platforms:
35+
- nrf54lm20dk/nrf54lm20a/cpuapp
36+
37+
tests:
38+
subsys.west_debug.normal: {}
39+
subsys.west_debug.thread_info:
40+
extra_args:
41+
- CONFIG_DEBUG_OPTIMIZATIONS=y
42+
- CONFIG_DEBUG_THREAD_INFO=y

0 commit comments

Comments
 (0)