Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions scripts/ci/tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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*
12 changes: 12 additions & 0 deletions tests/subsys/west_debug/CMakeLists.txt
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)
8 changes: 8 additions & 0 deletions tests/subsys/west_debug/prj.conf
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
122 changes: 122 additions & 0 deletions tests/subsys/west_debug/pytest/test_west_debug.py
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}"
20 changes: 20 additions & 0 deletions tests/subsys/west_debug/src/main.c
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;
}
}
}
42 changes: 42 additions & 0 deletions tests/subsys/west_debug/testcase.yaml
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flpr/xip?

- 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 west flash with the JLink runner on flpr, I assume because in segger's eyes the flpr has no NVM and for that it would need to be programmed through the app core then debugged through the flpr core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is a result of west debug and west attach not working on some platforms.
Here is fix for one of such failures.

I wasn't aware that it is possible to switch west flash from nrfutil device to JLink.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

west flash -r jlink, I didn't try with the M33 but with the RISCV on nrf54l15dk it flat out fails (though debugging without loading works fine on RISCV)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-r jlink is a good candidate for another test

Copy link
Contributor

Choose a reason for hiding this comment

The 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
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading