-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: net: lib: nrf_cloud: add fota_common tests
Add test suite for nrf_cloud_fota_common.c. IRIS-4790 Signed-off-by: Justin Morton <justin.morton@nordicsemi.no>
- Loading branch information
Showing
7 changed files
with
1,037 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# | ||
# Copyright (c) 2022 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(nrf_cloud_fota_common_test) | ||
set(NRF_SDK_DIR ${ZEPHYR_BASE}/../nrf) | ||
cmake_path(NORMAL_PATH NRF_SDK_DIR) | ||
|
||
if (CONFIG_NRF_CLOUD_FOTA_FULL_MODEM_UPDATE) | ||
FILE(GLOB app_sources src/fmfu.c) | ||
else() | ||
FILE(GLOB app_sources src/main.c) | ||
endif() | ||
target_sources(app PRIVATE ${app_sources}) | ||
|
||
target_include_directories(app | ||
PRIVATE | ||
src | ||
${NRF_SDK_DIR}/subsys/net/lib/nrf_cloud/include | ||
${NRF_SDK_DIR}/subsys/net/lib/nrf_cloud/src | ||
${ZEPHYR_BASE}/subsys/testsuite/include | ||
) | ||
|
||
if (CONFIG_FOTA_DOWNLOAD) | ||
set_source_files_properties( | ||
${NRF_SDK_DIR}/subsys/net/lib/fota_download/src/fota_download.c | ||
DIRECTORY ${NRF_SDK_DIR}/subsys/net/lib/fota_download/ | ||
PROPERTIES HEADER_FILE_ONLY ON | ||
) | ||
endif() | ||
|
||
if (CONFIG_MCUBOOT_IMG_MANAGER) | ||
set_source_files_properties( | ||
${ZEPHYR_BASE}/subsys/dfu/boot/mcuboot.c | ||
DIRECTORY ${ZEPHYR_BASE}/subsys/dfu/boot/ | ||
PROPERTIES HEADER_FILE_ONLY ON | ||
) | ||
endif() | ||
|
||
if (CONFIG_NRF_CLOUD_FOTA_FULL_MODEM_UPDATE) | ||
set_source_files_properties( | ||
${NRF_SDK_DIR}/subsys/dfu/dfu_target/src/dfu_target_full_modem.c | ||
DIRECTORY ${NRF_SDK_DIR}/subsys/dfu/dfu_target/ | ||
PROPERTIES HEADER_FILE_ONLY ON | ||
) | ||
|
||
set_source_files_properties( | ||
${NRF_SDK_DIR}/subsys/dfu/fmfu_fdev/src/fmfu_fdev.c | ||
DIRECTORY ${NRF_SDK_DIR}/subsys/dfu/fmfu_fdev/ | ||
PROPERTIES HEADER_FILE_ONLY ON | ||
) | ||
|
||
set_source_files_properties( | ||
${NRF_SDK_DIR}/lib/nrf_modem_lib/nrf_modem_lib.c | ||
DIRECTORY ${NRF_SDK_DIR}/lib/nrf_modem_lib/ | ||
PROPERTIES HEADER_FILE_ONLY ON | ||
) | ||
endif() |
14 changes: 14 additions & 0 deletions
14
tests/subsys/net/lib/nrf_cloud/fota_common/boards/qemu_cortex_m3.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Copyright (c) 2023 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
# Disable networking | ||
CONFIG_NETWORKING=n | ||
|
||
# For the unit test to run in qemu_cortex_m3, | ||
# we need the following KConfig values to be set. | ||
# See https://github.com/zephyrproject-rtos/zephyr/issues/15565 | ||
CONFIG_ENTROPY_GENERATOR=y | ||
CONFIG_TEST_RANDOM_GENERATOR=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (c) 2022 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
# ZTEST with new API | ||
CONFIG_ZTEST=y | ||
CONFIG_ZTEST_NEW_API=y | ||
|
||
CONFIG_NRF_CLOUD_MQTT=y | ||
|
||
CONFIG_NETWORKING=y | ||
CONFIG_NET_SOCKETS=y | ||
CONFIG_NET_SOCKETS_POSIX_NAMES=y | ||
CONFIG_NRF_MODEM_LIB=y | ||
CONFIG_NRF_CLOUD_CONNECTION_POLL_THREAD=n | ||
CONFIG_FLASH=y | ||
CONFIG_FLASH_PAGE_LAYOUT=y | ||
CONFIG_FLASH_MAP=y | ||
CONFIG_STREAM_FLASH=y | ||
CONFIG_NEWLIB_LIBC=y | ||
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (c) 2023 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <zephyr/fff.h> | ||
#include <zephyr/ztest.h> | ||
|
||
DEFINE_FFF_GLOBALS; | ||
|
||
FAKE_VALUE_FUNC(int, fota_download_s0_active_get, bool *const); | ||
FAKE_VALUE_FUNC(bool, boot_is_img_confirmed); | ||
FAKE_VALUE_FUNC(int, boot_write_img_confirmed); | ||
FAKE_VALUE_FUNC(int, dfu_target_full_modem_cfg, const struct dfu_target_full_modem_params *); | ||
FAKE_VALUE_FUNC(int, dfu_target_full_modem_fdev_get, struct dfu_target_fmfu_fdev * const); | ||
|
||
#if defined(CONFIG_NRF_CLOUD_FOTA_FULL_MODEM_UPDATE) | ||
FAKE_VALUE_FUNC(int, nrf_modem_lib_init); | ||
FAKE_VALUE_FUNC(int, nrf_modem_lib_shutdown); | ||
FAKE_VALUE_FUNC(int, nrf_modem_lib_bootloader_init); | ||
FAKE_VALUE_FUNC(int, fmfu_fdev_load, uint8_t *, size_t, const struct device *, size_t); | ||
#endif /* CONFIG_NRF_CLOUD_FOTA_FULL_MODEM_UPDATE */ | ||
|
||
int fake_fota_download_s0_active_get__fails(bool *const s0) | ||
{ | ||
ARG_UNUSED(s0); | ||
return -1; | ||
} | ||
|
||
int fake_fota_download_s0_active_get__s0_active(bool *const s0) | ||
{ | ||
*s0 = true; | ||
return 0; | ||
} | ||
int fake_fota_download_s0_active_get__s0_inactive(bool *const s0) | ||
{ | ||
*s0 = false; | ||
return 0; | ||
} | ||
|
||
bool fake_boot_is_img_confirmed__true(void) | ||
{ | ||
return true; | ||
} | ||
|
||
bool fake_boot_is_img_confirmed__false(void) | ||
{ | ||
return false; | ||
} | ||
|
||
int fake_boot_write_img_confirmed__succeeds(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
int fake_boot_write_img_confirmed__fails(void) | ||
{ | ||
return -EIO; | ||
} | ||
|
||
#if defined(CONFIG_NRF_CLOUD_FOTA_FULL_MODEM_UPDATE) | ||
int fake_dfu_target_full_modem_cfg__succeeds(const struct dfu_target_full_modem_params *p) | ||
{ | ||
ARG_UNUSED(p); | ||
return 0; | ||
} | ||
|
||
int fake_dfu_target_full_modem_cfg__fails(const struct dfu_target_full_modem_params *p) | ||
{ | ||
ARG_UNUSED(p); | ||
return -1; | ||
} | ||
|
||
int fake_dfu_target_full_modem_fdev_get__succeeds(struct dfu_target_fmfu_fdev * const p) | ||
{ | ||
ARG_UNUSED(p); | ||
return 0; | ||
} | ||
|
||
int fake_dfu_target_full_modem_fdev_get__fails(struct dfu_target_fmfu_fdev * const p) | ||
{ | ||
ARG_UNUSED(p); | ||
return -1; | ||
} | ||
|
||
int nrf_modem_lib_shutdown__succeeds(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
int nrf_modem_lib_shutdown__fails(void) | ||
{ | ||
return -1; | ||
} | ||
|
||
int nrf_modem_lib_bootloader_init__succeeds(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
int nrf_modem_lib_bootloader_init__fails(void) | ||
{ | ||
return -1; | ||
} | ||
|
||
int fmfu_fdev_load__succeeds(uint8_t *buf, size_t buf_len, | ||
const struct device *fdev, size_t offset) | ||
{ | ||
ARG_UNUSED(buf); | ||
ARG_UNUSED(buf_len); | ||
ARG_UNUSED(fdev); | ||
ARG_UNUSED(offset); | ||
return 0; | ||
} | ||
|
||
int fmfu_fdev_load__fails(uint8_t *buf, size_t buf_len, | ||
const struct device *fdev, size_t offset) | ||
{ | ||
ARG_UNUSED(buf); | ||
ARG_UNUSED(buf_len); | ||
ARG_UNUSED(fdev); | ||
ARG_UNUSED(offset); | ||
return -1; | ||
} | ||
#endif /* CONFIG_NRF_CLOUD_FOTA_FULL_MODEM_UPDATE */ |
Oops, something went wrong.