Skip to content

Commit 1f92890

Browse files
gchwierkartben
authored andcommitted
tests: upgrade: Upgrade with mcumgr using BLE transport
Extend tests/boot/with_mcumgr with BLE configuration. Updated sample to use the source code from smp_svr. Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
1 parent c6b3b93 commit 1f92890

File tree

11 files changed

+167
-39
lines changed

11 files changed

+167
-39
lines changed

tests/boot/with_mcumgr/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ cmake_minimum_required(VERSION 3.20.0)
55
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
66
project(with_mcumgr)
77

8-
FILE(GLOB app_sources src/*.c)
9-
target_sources(app PRIVATE ${app_sources})
8+
# This project uses orginal C source code from smp_svr sample
9+
target_sources(app PRIVATE ${ZEPHYR_BASE}/samples/subsys/mgmt/mcumgr/smp_svr/src/main.c)
10+
target_sources_ifdef(CONFIG_MCUMGR_TRANSPORT_BT app PRIVATE ${ZEPHYR_BASE}/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c)

tests/boot/with_mcumgr/README.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ use following command:
1919
-p nrf52840dk/nrf52840 --device-testing --device-serial /dev/ttyACM0
2020
2121
.. note::
22-
Twister requires ``--west-flash`` flag enabled (without additional parameters
23-
like ``erase``) to use sysbuild.
22+
Twister requires ``--west-flash`` flag enabled to use sysbuild.
23+
24+
To test with ``mcumgr`` with Bluetooth, one must add ``usb_hci:hciX`` fixture
25+
where ``hciX`` is the Bluetooth HCI device (e.g. ``hci1``).
26+
Fixture can be added to Twister command: ``-X usb_hci:hci1``,
27+
or added to the hardware map
28+
29+
.. code-block:: yaml
30+
31+
- connected: true
32+
fixtures:
33+
- usb_hci:hci1
2434
2535
Test scripts can be found in ``pytest`` directory. To list available
2636
scenarios with described procedures, one can use a pytest command:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
CONFIG_BT=y
2+
CONFIG_BT_PERIPHERAL=y
3+
4+
# Allow for large Bluetooth data packets.
5+
CONFIG_BT_L2CAP_TX_MTU=498
6+
CONFIG_BT_BUF_ACL_RX_SIZE=502
7+
CONFIG_BT_BUF_ACL_TX_SIZE=502
8+
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
9+
10+
# Enable the Bluetooth mcumgr transport (unauthenticated).
11+
CONFIG_MCUMGR_TRANSPORT_BT=y
12+
CONFIG_MCUMGR_TRANSPORT_BT_CONN_PARAM_CONTROL=y
13+
14+
# Enable the Shell mcumgr transport.
15+
CONFIG_BASE64=y
16+
CONFIG_CRC=y
17+
CONFIG_SHELL=y
18+
CONFIG_SHELL_BACKEND_SERIAL=y
19+
CONFIG_MCUMGR_TRANSPORT_SHELL=y
20+
21+
# Enable the mcumgr Packet Reassembly feature over Bluetooth and its configuration dependencies.
22+
# MCUmgr buffer size is optimized to fit one SMP packet divided into five Bluetooth Write Commands,
23+
# transmitted with the maximum possible MTU value: 498 bytes.
24+
CONFIG_MCUMGR_TRANSPORT_BT_REASSEMBLY=y
25+
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=2475
26+
CONFIG_MCUMGR_GRP_OS_MCUMGR_PARAMS=y
27+
CONFIG_MCUMGR_TRANSPORT_WORKQUEUE_STACK_SIZE=4608
28+
29+
# Enable the LittleFS file system.
30+
CONFIG_FILE_SYSTEM=y
31+
CONFIG_FILE_SYSTEM_LITTLEFS=y
32+
33+
# Enable file system commands
34+
CONFIG_MCUMGR_GRP_FS=y
35+
36+
# Enable the storage erase command.
37+
CONFIG_MCUMGR_GRP_ZBASIC=y
38+
CONFIG_MCUMGR_GRP_ZBASIC_STORAGE_ERASE=y
39+
40+
# Disable Bluetooth ping support
41+
CONFIG_BT_CTLR_LE_PING=n
42+
43+
# Disable shell commands that are not needed
44+
CONFIG_CLOCK_CONTROL_NRF_SHELL=n
45+
CONFIG_DEVICE_SHELL=n
46+
CONFIG_DEVMEM_SHELL=n
47+
CONFIG_FLASH_SHELL=n

tests/boot/with_mcumgr/prj.conf

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,50 @@ CONFIG_MCUMGR=y
66
CONFIG_STREAM_FLASH=y
77
CONFIG_FLASH_MAP=y
88

9-
# Enable the shell MCUmgr transport.
10-
CONFIG_BASE64=y
11-
CONFIG_SHELL=y
12-
CONFIG_MCUBOOT_SHELL=y
13-
CONFIG_SHELL_BACKEND_SERIAL=y
14-
CONFIG_MCUMGR_TRANSPORT_SHELL=y
9+
# Some command handlers require a large stack.
10+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
11+
CONFIG_MAIN_STACK_SIZE=2048
12+
13+
# Ensure an MCUboot-compatible binary is generated.
14+
CONFIG_BOOTLOADER_MCUBOOT=y
15+
16+
# Enable flash operations.
17+
CONFIG_FLASH=y
18+
19+
# Required by the `taskstat` command.
20+
CONFIG_THREAD_MONITOR=y
21+
22+
# Support for taskstat command
23+
CONFIG_MCUMGR_GRP_OS_TASKSTAT=y
24+
25+
# Enable statistics and statistic names.
26+
CONFIG_STATS=y
27+
CONFIG_STATS_NAMES=y
1528

1629
# Enable most core commands.
1730
CONFIG_FLASH=y
1831
CONFIG_IMG_MANAGER=y
1932
CONFIG_MCUMGR_GRP_IMG=y
2033
CONFIG_MCUMGR_GRP_OS=y
34+
CONFIG_MCUMGR_GRP_STAT=y
35+
36+
# Enable logging
37+
CONFIG_LOG=y
38+
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y
39+
40+
# Disable debug logging
41+
CONFIG_LOG_MAX_LEVEL=3
42+
43+
# Enable the Shell mcumgr transport.
44+
CONFIG_BASE64=y
45+
CONFIG_CRC=y
46+
CONFIG_SHELL=y
47+
CONFIG_SHELL_BACKEND_SERIAL=y
48+
CONFIG_MCUMGR_TRANSPORT_SHELL=y
49+
CONFIG_MCUBOOT_SHELL=y
2150

22-
# mcumgr-cli application doesn't accepts log in the channel it uses
23-
CONFIG_SHELL_LOG_BACKEND=n
51+
# Disable shell commands that are not needed
52+
CONFIG_CLOCK_CONTROL_NRF_SHELL=n
53+
CONFIG_DEVICE_SHELL=n
54+
CONFIG_DEVMEM_SHELL=n
55+
CONFIG_FLASH_SHELL=n
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import os
6+
import sys
7+
8+
# Add the directory to PYTHONPATH
9+
zephyr_base = os.getenv("ZEPHYR_BASE")
10+
if zephyr_base:
11+
sys.path.insert(
12+
0, os.path.join(zephyr_base, "scripts", "pylib", "pytest-twister-harness", "src")
13+
)
14+
else:
15+
raise OSError("ZEPHYR_BASE environment variable is not set")
16+
17+
pytest_plugins = [
18+
"twister_harness.plugin",
19+
]

tests/boot/with_mcumgr/pytest/test_downgrade_prevention.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import logging
77
from pathlib import Path
88

9-
from test_upgrade import create_signed_image
9+
from test_upgrade import WELCOME_STRING, create_signed_image
1010
from twister_harness import DeviceAdapter, MCUmgr, Shell
1111
from twister_harness.helpers.utils import find_in_config, match_lines, match_no_lines
1212
from utils import check_with_mcumgr_command, check_with_shell_command
@@ -48,7 +48,7 @@ def test_downgrade_prevention(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
4848
mcumgr.reset_device()
4949

5050
dut.connect()
51-
output = dut.readlines_until('Launching primary slot application')
51+
output = dut.readlines_until(WELCOME_STRING)
5252
match_no_lines(output, ['Starting swap using move algorithm'])
5353
match_lines(output, ['erased due to downgrade prevention'])
5454
logger.info('Verify that the original APP is booted')

tests/boot/with_mcumgr/pytest/test_upgrade.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
logger = logging.getLogger(__name__)
1616

17+
# This string is used to verify that the device is running the application
18+
WELCOME_STRING = "smp_sample: build time:"
19+
1720

1821
def create_signed_image(build_dir: Path, app_build_dir: Path, version: str) -> Path:
1922
image_to_test = Path(build_dir) / 'test_{}.signed.bin'.format(
@@ -49,7 +52,7 @@ def clear_buffer(dut: DeviceAdapter) -> None:
4952
dut.disconnect()
5053

5154

52-
def test_upgrade_with_confirm(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
55+
def run_upgrade_with_confirm(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
5356
"""
5457
Verify that the application can be updated
5558
1) Device flashed with MCUboot and an application that contains SMP server
@@ -77,7 +80,7 @@ def test_upgrade_with_confirm(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
7780
mcumgr.reset_device()
7881

7982
dut.connect()
80-
output = dut.readlines_until('Launching primary slot application')
83+
output = dut.readlines_until(WELCOME_STRING)
8184
upgrade_string_to_verify = get_upgrade_string_to_verify(dut.device_config.build_dir)
8285
match_lines(output, [
8386
'Swap type: test',
@@ -93,14 +96,19 @@ def test_upgrade_with_confirm(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
9396
mcumgr.reset_device()
9497

9598
dut.connect()
96-
output = dut.readlines_until('Launching primary slot application')
99+
output = dut.readlines_until(WELCOME_STRING)
97100
match_no_lines(output, [
98101
upgrade_string_to_verify
99102
])
100103
logger.info('Verify new APP is still booted')
101104
check_with_shell_command(shell, new_version)
102105

103106

107+
def test_upgrade_with_confirm(mcumgr: MCUmgr, dut: DeviceAdapter, shell: Shell):
108+
"""Verify that the application can be updated over serial"""
109+
run_upgrade_with_confirm(dut, shell, mcumgr)
110+
111+
104112
def test_upgrade_with_revert(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
105113
"""
106114
Verify that MCUboot will roll back an image that is not confirmed
@@ -133,7 +141,7 @@ def test_upgrade_with_revert(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
133141
mcumgr.reset_device()
134142

135143
dut.connect()
136-
output = dut.readlines_until('Launching primary slot application')
144+
output = dut.readlines_until(WELCOME_STRING)
137145
upgrade_string_to_verify = get_upgrade_string_to_verify(dut.device_config.build_dir)
138146
match_lines(output, [
139147
'Swap type: test',
@@ -148,7 +156,7 @@ def test_upgrade_with_revert(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
148156
mcumgr.reset_device()
149157

150158
dut.connect()
151-
output = dut.readlines_until('Launching primary slot application')
159+
output = dut.readlines_until(WELCOME_STRING)
152160
match_lines(output, [
153161
'Swap type: revert',
154162
upgrade_string_to_verify
@@ -159,10 +167,8 @@ def test_upgrade_with_revert(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
159167

160168
@pytest.mark.parametrize(
161169
'key_file', [None, 'root-ec-p256.pem'],
162-
ids=[
163-
'no_key',
164-
'invalid_key'
165-
])
170+
ids=['no_key', 'invalid_key']
171+
)
166172
def test_upgrade_signature(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr, key_file):
167173
"""
168174
Verify that the application is not updated when app is not signed or signed with invalid key
@@ -210,7 +216,7 @@ def test_upgrade_signature(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr, key
210216
mcumgr.reset_device()
211217

212218
dut.connect()
213-
output = dut.readlines_until('Launching primary slot application')
219+
output = dut.readlines_until(WELCOME_STRING)
214220
upgrade_string_to_verify = get_upgrade_string_to_verify(dut.device_config.build_dir)
215221
match_no_lines(output, [upgrade_string_to_verify])
216222
match_lines(output, ['Image in the secondary slot is not valid'])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
from __future__ import annotations
5+
6+
import logging
7+
8+
from test_upgrade import run_upgrade_with_confirm
9+
from twister_harness import DeviceAdapter, MCUmgrBle, Shell
10+
11+
logger = logging.getLogger(__name__)
12+
13+
14+
def test_upgrade_with_confirm_ble(mcumgr_ble: MCUmgrBle, dut: DeviceAdapter, shell: Shell):
15+
"""Verify that the application can be updated over BLE"""
16+
run_upgrade_with_confirm(dut, shell, mcumgr_ble)

tests/boot/with_mcumgr/src/main.c

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/boot/with_mcumgr/sysbuild/mcuboot.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)