Skip to content

Commit 3f4aebf

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 d91bad7 commit 3f4aebf

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
@@ -934,6 +934,7 @@
934934
/tests/subsys/emds/ @balaklaka @nrfconnect/ncs-paladin
935935
/tests/subsys/event_manager_proxy/ @nrfconnect/ncs-si-muffin
936936
/tests/subsys/fw_info/ @nrfconnect/ncs-eris
937+
/tests/subsys/ipc/ @nrfconnect/ncs-low-level-test
937938
/tests/subsys/kmu/ @nrfconnect/ncs-eris
938939
/tests/subsys/mpsl/ @nrfconnect/ncs-dragoon
939940
/tests/subsys/net/lib/aws_*/ @nrfconnect/ncs-cia
@@ -957,7 +958,7 @@
957958
/tests/subsys/rtt/ @nrfconnect/ncs-low-level-test
958959
/tests/subsys/swo/ @nrfconnect/ncs-low-level-test
959960
/tests/subsys/usb/negotiated_speed/ @nrfconnect/ncs-low-level-test
960-
/tests/subsys/ipc/ @nrfconnect/ncs-low-level-test
961+
/tests/subsys/west_debug/ @nrfconnect/ncs-low-level-test
961962
/tests/tfm/ @nrfconnect/ncs-aegir @magnev
962963
/tests/unity/ @nordic-krch
963964
/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: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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+
except Exception as e:
25+
logger.exception(f"Could not kill process - {e}")
26+
27+
28+
def test_west_debug(dut: DeviceAdapter):
29+
"""
30+
Compile and flash test application on MCU.
31+
Start debug session by calling `west debug` command.
32+
Set brakepoint and check that breakpoint was hit.
33+
"""
34+
BUILD_DIR = str(dut.device_config.build_dir)
35+
SEGGER_ID = dut.device_config.id
36+
COLLECT_TIMEOUT = 15.0
37+
EXPECTED = r"15\s+counter\+\+;"
38+
39+
logger.debug(f"{dut.device_config=}")
40+
41+
# Wait a bit for the core to boot
42+
time.sleep(2)
43+
44+
# cmd = f"west debug -d {BUILD_DIR} --skip-rebuild"
45+
cmd = f"west debug -d {BUILD_DIR} -- --dev-id {SEGGER_ID}"
46+
try:
47+
logger.info(f"Executing:\n{cmd}")
48+
proc = subprocess.Popen(
49+
cmd.split(),
50+
stdin=subprocess.PIPE,
51+
stdout=subprocess.PIPE,
52+
stderr=subprocess.STDOUT,
53+
encoding='UTF-8',
54+
text=True,
55+
)
56+
except OSError as exc:
57+
logger.error(f"Unable to start debug session:\n{cmd=}\n{exc=}")
58+
59+
time.sleep(2)
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(2)
93+
94+
# cmd = f"west attach -d {BUILD_DIR} --skip-rebuild"
95+
cmd = f"west attach -d {BUILD_DIR} -- --dev-id {SEGGER_ID}"
96+
try:
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+
except OSError as exc:
107+
logger.error(f"Unable to start debug session:\n{cmd=}\n{exc=}")
108+
109+
time.sleep(2)
110+
111+
try:
112+
# where
113+
# quit
114+
outs, errs = proc.communicate(input="where\ndisconnect\nq\n", timeout=COLLECT_TIMEOUT)
115+
except subprocess.TimeoutExpired:
116+
_kill(proc)
117+
finally:
118+
outs, errs = proc.communicate()
119+
logger.info(f"{outs=}\n{errs=}")
120+
121+
expected_str = re.search(EXPECTED, outs)
122+
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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: 20
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/cpuppr
17+
- nrf54h20dk/nrf54h20/cpuppr/xip
18+
- nrf54h20dk/nrf54h20/cpurad
19+
- nrf54l15dk/nrf54l05/cpuapp
20+
- nrf54l15dk/nrf54l10/cpuapp
21+
- nrf54l15dk/nrf54l10/cpuapp/ns
22+
- nrf54l15dk/nrf54l15/cpuapp
23+
- nrf54l15dk/nrf54l15/cpuapp/ns
24+
- nrf54l15dk/nrf54l15/cpuflpr
25+
- nrf54l15dk/nrf54l15/cpuflpr/xip
26+
- nrf54lm20dk/nrf54lm20a/cpuapp
27+
- nrf54lm20dk/nrf54lm20a/cpuapp/ns
28+
- nrf54lm20dk/nrf54lm20a/cpuflpr
29+
- nrf54ls05dk/nrf54ls05b/cpuapp
30+
- nrf54lv10dk/nrf54lv10a/cpuapp
31+
- nrf54lv10dk/nrf54lv10a/cpuapp/ns
32+
- nrf54lv10dk/nrf54lv10a/cpuflpr
33+
integration_platforms:
34+
- nrf54lm20dk/nrf54lm20a/cpuapp
35+
36+
tests:
37+
subsys.west_debug.normal: {}
38+
subsys.west_debug.thread_info:
39+
extra_args:
40+
- CONFIG_DEBUG_OPTIMIZATIONS=y
41+
- CONFIG_DEBUG_THREAD_INFO=y

0 commit comments

Comments
 (0)