Skip to content

Commit 41d8a47

Browse files
committed
app: tests: Add unit tests changes for updatable MCUboot
Unit test changes. Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
1 parent 506ede0 commit 41d8a47

11 files changed

Lines changed: 186 additions & 0 deletions

File tree

app/tests/at_commands/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ target_sources(app PRIVATE
6161
../stubs/sm_at_host_stubs.c
6262
../stubs/control_pin_stubs.c
6363
../stubs/pm_stubs.c
64+
../stubs/tfm_stubs.c
6465
../stubs/at_cmd_custom_stubs.c
6566
../stubs/sm_workq.c
6667
../../src/sm_util.c
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef FW_INFO_H__
8+
#define FW_INFO_H__
9+
10+
#include <stdint.h>
11+
12+
struct fw_info {
13+
uint32_t version;
14+
};
15+
16+
#endif /* FW_INFO_H__ */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef PM_CONFIG_H__
8+
#define PM_CONFIG_H__
9+
10+
#define PM_S0_ADDRESS 0x10000
11+
#define PM_S1_ADDRESS 0x20000
12+
13+
#endif /* PM_CONFIG_H__ */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef TFM_IOCTL_API_H__
8+
#define TFM_IOCTL_API_H__
9+
10+
#include <stdbool.h>
11+
#include <stdint.h>
12+
#include <fw_info.h>
13+
14+
/** Check if S0 is the active MCUboot slot. */
15+
int tfm_platform_s0_active(uint32_t s0_address, uint32_t s1_address, bool *s0_active);
16+
17+
/** Read firmware info from a given address. */
18+
int tfm_platform_firmware_info(uint32_t fw_address, struct fw_info *info);
19+
20+
#endif /* TFM_IOCTL_API_H__ */

app/tests/at_commands/src/nrf_modem_at_wrapper.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern int handle_at_datactrl_wrapper_xdatactrl(char *buf, size_t len, char *at_
2828
extern int handle_at_clac_wrapper_xclac(char *buf, size_t len, char *at_cmd);
2929
extern int handle_ate0_wrapper_ate0(char *buf, size_t len, char *at_cmd);
3030
extern int handle_ate1_wrapper_ate1(char *buf, size_t len, char *at_cmd);
31+
extern int handle_at_xbootinfo_wrapper_xbootinfo(char *buf, size_t len, char *at_cmd);
3132

3233
int nrf_modem_at_cmd(void *buf, size_t buf_size, const char *fmt, ...)
3334
{
@@ -60,6 +61,8 @@ int nrf_modem_at_cmd(void *buf, size_t buf_size, const char *fmt, ...)
6061
ret = handle_ate0_wrapper_ate0((char *)buf, buf_size, at_cmd);
6162
} else if (strncasecmp(at_cmd, "ATE1", 4) == 0) {
6263
ret = handle_ate1_wrapper_ate1((char *)buf, buf_size, at_cmd);
64+
} else if (strncasecmp(at_cmd, "AT#XBOOTINFO", 12) == 0) {
65+
ret = handle_at_xbootinfo_wrapper_xbootinfo((char *)buf, buf_size, at_cmd);
6366
} else {
6467
/* Unknown command - return error */
6568
ret = -NRF_EINVAL;

app/tests/at_commands/src/test_at_commands.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,63 @@ void test_ate_echo_control(void)
294294
TEST_ASSERT_TRUE(strstr(response, "OK") != NULL);
295295
}
296296

297+
/*
298+
* Test: AT#XBOOTINFO=0 - query MCUboot version
299+
* Stub reports firmware version 0, so response should indicate version 0.
300+
*/
301+
void test_xbootinfo_version(void)
302+
{
303+
const char *response;
304+
305+
send_at_command("AT#XBOOTINFO=0\r\n");
306+
307+
response = get_captured_response();
308+
TEST_ASSERT_TRUE(strstr(response, "#XBOOTINFO: 0") != NULL);
309+
TEST_ASSERT_TRUE(strstr(response, "OK") != NULL);
310+
}
311+
312+
/*
313+
* Test: AT#XBOOTINFO=1 - query active MCUboot slot
314+
* Stub reports S0 active, so response should indicate slot 0.
315+
*/
316+
void test_xbootinfo_slot(void)
317+
{
318+
const char *response;
319+
320+
send_at_command("AT#XBOOTINFO=1\r\n");
321+
322+
response = get_captured_response();
323+
TEST_ASSERT_TRUE(strstr(response, "#XBOOTINFO: 0") != NULL);
324+
TEST_ASSERT_TRUE(strstr(response, "OK") != NULL);
325+
}
326+
327+
/*
328+
* Test: AT#XBOOTINFO=2 - invalid op, should return error
329+
*/
330+
void test_xbootinfo_invalid_op(void)
331+
{
332+
const char *response;
333+
334+
send_at_command("AT#XBOOTINFO=2\r\n");
335+
336+
response = get_captured_response();
337+
TEST_ASSERT_TRUE(strstr(response, "ERROR") != NULL);
338+
}
339+
340+
/*
341+
* Test: AT#XBOOTINFO=? - test command syntax
342+
*/
343+
void test_xbootinfo_test(void)
344+
{
345+
const char *response;
346+
347+
send_at_command("AT#XBOOTINFO=?\r\n");
348+
349+
response = get_captured_response();
350+
TEST_ASSERT_TRUE(strstr(response, "#XBOOTINFO: (0,1)") != NULL);
351+
TEST_ASSERT_TRUE(strstr(response, "OK") != NULL);
352+
}
353+
297354
extern int unity_main(void);
298355

299356
int main(void)

app/tests/at_socket/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ target_sources(app PRIVATE
6565
../stubs/sm_at_host_stubs.c
6666
../stubs/control_pin_stubs.c
6767
../stubs/pm_stubs.c
68+
../stubs/tfm_stubs.c
6869
../stubs/at_cmd_custom_stubs.c
6970
../stubs/sm_workq.c
7071
../../src/sm_util.c
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef FW_INFO_H__
8+
#define FW_INFO_H__
9+
10+
#include <stdint.h>
11+
12+
struct fw_info {
13+
uint32_t version;
14+
};
15+
16+
#endif /* FW_INFO_H__ */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef PM_CONFIG_H__
8+
#define PM_CONFIG_H__
9+
10+
#define PM_S0_ADDRESS 0x10000
11+
#define PM_S1_ADDRESS 0x20000
12+
13+
#endif /* PM_CONFIG_H__ */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef TFM_IOCTL_API_H__
8+
#define TFM_IOCTL_API_H__
9+
10+
#include <stdbool.h>
11+
#include <stdint.h>
12+
#include <fw_info.h>
13+
14+
/** Check if S0 is the active MCUboot slot. */
15+
int tfm_platform_s0_active(uint32_t s0_address, uint32_t s1_address, bool *s0_active);
16+
17+
/** Read firmware info from a given address. */
18+
int tfm_platform_firmware_info(uint32_t fw_address, struct fw_info *info);
19+
20+
#endif /* TFM_IOCTL_API_H__ */

0 commit comments

Comments
 (0)