tests: mgmt: mcumgr: os_mgmt_info: Add tests
Adds tests for the os_mgmt info command. Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
5ffbda342f
commit
43b4350744
12 changed files with 2197 additions and 0 deletions
24
tests/subsys/mgmt/mcumgr/os_mgmt_info/CMakeLists.txt
Normal file
24
tests/subsys/mgmt/mcumgr/os_mgmt_info/CMakeLists.txt
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(os_mgmt_info)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources
|
||||||
|
src/*.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
||||||
|
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/mgmt/mcumgr/transport/include/mgmt/mcumgr/transport/)
|
||||||
|
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/mgmt/mcumgr/grp/os_mgmt/include/)
|
||||||
|
|
||||||
|
if(DEFINED CONFIG_BUILD_DATE_TIME_TEST)
|
||||||
|
set(TEST_DATE_TIME_DIR ${PROJECT_BINARY_DIR}/test)
|
||||||
|
file(MAKE_DIRECTORY ${TEST_DATE_TIME_DIR})
|
||||||
|
file(WRITE ${TEST_DATE_TIME_DIR}/test_date.c "/* Auto generated file, do not edit */\n#include <stdint.h>\nuint8_t *test_date_time = __TIMESTAMP__;")
|
||||||
|
target_sources(app PRIVATE ${TEST_DATE_TIME_DIR}/test_date.c)
|
||||||
|
endif()
|
15
tests/subsys/mgmt/mcumgr/os_mgmt_info/Kconfig
Normal file
15
tests/subsys/mgmt/mcumgr/os_mgmt_info/Kconfig
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
config CUSTOM_OS_NAME_VALUE
|
||||||
|
string "Custom OS name"
|
||||||
|
default "Fake OS Name"
|
||||||
|
|
||||||
|
config BUILD_DATE_TIME_TEST
|
||||||
|
bool "Build date time test"
|
||||||
|
select MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME
|
||||||
|
|
||||||
|
config LIMITED_TEST
|
||||||
|
bool "Limited buffer size test"
|
||||||
|
|
||||||
|
source "Kconfig.zephyr"
|
|
@ -0,0 +1 @@
|
||||||
|
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
|
|
@ -0,0 +1 @@
|
||||||
|
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
|
|
@ -0,0 +1 @@
|
||||||
|
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
|
15
tests/subsys/mgmt/mcumgr/os_mgmt_info/prj.conf
Normal file
15
tests/subsys/mgmt/mcumgr/os_mgmt_info/prj.conf
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
CONFIG_ZTEST=y
|
||||||
|
CONFIG_MCUMGR=y
|
||||||
|
CONFIG_MCUMGR_SMP_DUMMY=y
|
||||||
|
CONFIG_MCUMGR_SMP_DUMMY_RX_BUF_SIZE=256
|
||||||
|
CONFIG_MCUMGR_CMD_OS_MGMT=y
|
||||||
|
CONFIG_MCUMGR_GRP_OS_INFO=y
|
||||||
|
CONFIG_MCUMGR_GRP_OS_INFO_CUSTOM_HOOKS=y
|
||||||
|
CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS=y
|
||||||
|
CONFIG_ZTEST_NEW_API=y
|
||||||
|
CONFIG_ZTEST_STACK_SIZE=2048
|
268
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c
Normal file
268
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c
Normal file
|
@ -0,0 +1,268 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(CONFIG_BUILD_DATE_TIME_TEST)
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
#include <zephyr/net/buf.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/transport/smp_dummy.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h>
|
||||||
|
#include <os_mgmt_processor.h>
|
||||||
|
#include <zcbor_common.h>
|
||||||
|
#include <zcbor_decode.h>
|
||||||
|
#include <zcbor_encode.h>
|
||||||
|
#include <mgmt/mcumgr/util/zcbor_bulk.h>
|
||||||
|
#include <version.h>
|
||||||
|
#include <smp_internal.h>
|
||||||
|
#include "smp_test_util.h"
|
||||||
|
|
||||||
|
#define SMP_RESPONSE_WAIT_TIME 3
|
||||||
|
#define ZCBOR_BUFFER_SIZE 256
|
||||||
|
#define OUTPUT_BUFFER_SIZE 256
|
||||||
|
#define ZCBOR_HISTORY_ARRAY_SIZE 4
|
||||||
|
|
||||||
|
static struct net_buf *nb;
|
||||||
|
|
||||||
|
/* Responses to commands */
|
||||||
|
extern uint8_t *test_date_time;
|
||||||
|
const uint8_t response_all_board_revision_left[] = "Zephyr unknown " STRINGIFY(BUILD_VERSION) " "
|
||||||
|
KERNEL_VERSION_STRING " ";
|
||||||
|
const uint8_t response_all_board_revision_right[] = " " CONFIG_ARCH " " PROCESSOR_NAME " "
|
||||||
|
CONFIG_BOARD "@" CONFIG_BOARD_REVISION
|
||||||
|
" Zephyr";
|
||||||
|
const uint8_t response_all_left[] = "Zephyr unknown " STRINGIFY(BUILD_VERSION) " "
|
||||||
|
KERNEL_VERSION_STRING " ";
|
||||||
|
const uint8_t response_all_right[] = " " CONFIG_ARCH " " PROCESSOR_NAME " " CONFIG_BOARD " Zephyr";
|
||||||
|
|
||||||
|
const uint8_t query_build_date[] = "b";
|
||||||
|
const uint8_t query_all[] = "a";
|
||||||
|
|
||||||
|
#define DATE_CHECK_LEFT_CHARS 11
|
||||||
|
#define DATE_CHECK_RIGHT_CHARS 5
|
||||||
|
#define TIME_CHECK_HH_START_CHAR 11
|
||||||
|
|
||||||
|
#define TIME_HH_OFFSET 0
|
||||||
|
#define TIME_MM_OFFSET 3
|
||||||
|
#define TIME_SS_OFFSET 6
|
||||||
|
|
||||||
|
#define SECONDS_PER_HOUR 3600
|
||||||
|
#define SECONDS_PER_MINUTE 60
|
||||||
|
|
||||||
|
#define TIME_DIFFERENCE_ALLOWANCE 60
|
||||||
|
|
||||||
|
static int32_t time_string_to_seconds(const uint8_t *time_string)
|
||||||
|
{
|
||||||
|
uint8_t time_hh;
|
||||||
|
uint8_t time_mm;
|
||||||
|
uint8_t time_ss;
|
||||||
|
|
||||||
|
/* Convert times to separate fields and then to timestamps which can be compared */
|
||||||
|
time_hh = ((time_string[TIME_HH_OFFSET] - '0') * 10) +
|
||||||
|
(time_string[TIME_HH_OFFSET + 1] - '0');
|
||||||
|
time_mm = ((time_string[TIME_MM_OFFSET] - '0') * 10) +
|
||||||
|
(time_string[TIME_MM_OFFSET + 1] - '0');
|
||||||
|
time_ss = ((time_string[TIME_SS_OFFSET] - '0') * 10) +
|
||||||
|
(time_string[TIME_SS_OFFSET + 1] - '0');
|
||||||
|
|
||||||
|
return (time_hh * SECONDS_PER_HOUR) + (time_mm * SECONDS_PER_MINUTE) + time_ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST(os_mgmt_info_build_date, test_info_build_date_1_build_date)
|
||||||
|
{
|
||||||
|
uint8_t buffer[ZCBOR_BUFFER_SIZE];
|
||||||
|
uint8_t buffer_out[OUTPUT_BUFFER_SIZE];
|
||||||
|
bool ok;
|
||||||
|
uint16_t buffer_size;
|
||||||
|
zcbor_state_t zse[ZCBOR_HISTORY_ARRAY_SIZE] = { 0 };
|
||||||
|
zcbor_state_t zsd[ZCBOR_HISTORY_ARRAY_SIZE] = { 0 };
|
||||||
|
bool received;
|
||||||
|
struct zcbor_string output = { 0 };
|
||||||
|
size_t decoded = 0;
|
||||||
|
int32_t expected_time_seconds;
|
||||||
|
int32_t received_time_seconds;
|
||||||
|
|
||||||
|
struct zcbor_map_decode_key_val output_decode[] = {
|
||||||
|
ZCBOR_MAP_DECODE_KEY_VAL(output, zcbor_tstr_decode, &output),
|
||||||
|
};
|
||||||
|
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
memset(buffer_out, 0, sizeof(buffer_out));
|
||||||
|
buffer_size = 0;
|
||||||
|
memset(zse, 0, sizeof(zse));
|
||||||
|
memset(zsd, 0, sizeof(zsd));
|
||||||
|
|
||||||
|
zcbor_new_encode_state(zse, 2, buffer, ARRAY_SIZE(buffer), 0);
|
||||||
|
|
||||||
|
ok = create_mcumgr_format_packet(zse, query_build_date, buffer, buffer_out, &buffer_size);
|
||||||
|
zassert_true(ok, "Expected packet creation to be successful\n");
|
||||||
|
|
||||||
|
/* Enable dummy SMP backend and ready for usage */
|
||||||
|
smp_dummy_enable();
|
||||||
|
smp_dummy_clear_state();
|
||||||
|
|
||||||
|
/* Send test echo command to dummy SMP backend */
|
||||||
|
(void)smp_dummy_tx_pkt(buffer_out, buffer_size);
|
||||||
|
smp_dummy_add_data();
|
||||||
|
|
||||||
|
/* For a short duration to see if response has been received */
|
||||||
|
received = smp_dummy_wait_for_data(SMP_RESPONSE_WAIT_TIME);
|
||||||
|
|
||||||
|
zassert_true(received, "Expected to receive data but timed out\n");
|
||||||
|
|
||||||
|
/* Retrieve response buffer and ensure validity */
|
||||||
|
nb = smp_dummy_get_outgoing();
|
||||||
|
smp_dummy_disable();
|
||||||
|
|
||||||
|
/* Process received data by removing header */
|
||||||
|
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
|
||||||
|
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
|
||||||
|
|
||||||
|
ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
|
||||||
|
|
||||||
|
zassert_true(ok, "Expected decode to be successful\n");
|
||||||
|
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
|
||||||
|
|
||||||
|
zassert_equal(strlen(test_date_time), output.len,
|
||||||
|
"Expected to receive %d bytes but got %d\n",
|
||||||
|
strlen(test_date_time), output.len);
|
||||||
|
|
||||||
|
/* Check left and right sides of date which should match */
|
||||||
|
zassert_mem_equal(test_date_time, output.value, DATE_CHECK_LEFT_CHARS,
|
||||||
|
"Expected received data mismatch");
|
||||||
|
zassert_mem_equal(&test_date_time[(strlen(test_date_time) - DATE_CHECK_RIGHT_CHARS)],
|
||||||
|
&output.value[(strlen(test_date_time) - DATE_CHECK_RIGHT_CHARS)],
|
||||||
|
DATE_CHECK_RIGHT_CHARS, "Expected received data mismatch");
|
||||||
|
|
||||||
|
/* Extract time strings into timestamps */
|
||||||
|
expected_time_seconds = time_string_to_seconds(&test_date_time[TIME_CHECK_HH_START_CHAR]);
|
||||||
|
received_time_seconds = time_string_to_seconds(&output.value[TIME_CHECK_HH_START_CHAR]);
|
||||||
|
|
||||||
|
zassert_within(expected_time_seconds, received_time_seconds, TIME_DIFFERENCE_ALLOWANCE,
|
||||||
|
"Expected times to be within %d seconds but got %d",
|
||||||
|
TIME_DIFFERENCE_ALLOWANCE,
|
||||||
|
abs(expected_time_seconds - received_time_seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST(os_mgmt_info_build_date, test_info_build_date_2_all)
|
||||||
|
{
|
||||||
|
uint8_t buffer[ZCBOR_BUFFER_SIZE];
|
||||||
|
uint8_t buffer_out[OUTPUT_BUFFER_SIZE];
|
||||||
|
bool ok;
|
||||||
|
uint16_t buffer_size;
|
||||||
|
zcbor_state_t zse[ZCBOR_HISTORY_ARRAY_SIZE] = { 0 };
|
||||||
|
zcbor_state_t zsd[ZCBOR_HISTORY_ARRAY_SIZE] = { 0 };
|
||||||
|
bool received;
|
||||||
|
struct zcbor_string output = { 0 };
|
||||||
|
size_t decoded = 0;
|
||||||
|
int32_t expected_time_seconds;
|
||||||
|
int32_t received_time_seconds;
|
||||||
|
|
||||||
|
struct zcbor_map_decode_key_val output_decode[] = {
|
||||||
|
ZCBOR_MAP_DECODE_KEY_VAL(output, zcbor_tstr_decode, &output),
|
||||||
|
};
|
||||||
|
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
memset(buffer_out, 0, sizeof(buffer_out));
|
||||||
|
buffer_size = 0;
|
||||||
|
memset(zse, 0, sizeof(zse));
|
||||||
|
memset(zsd, 0, sizeof(zsd));
|
||||||
|
|
||||||
|
zcbor_new_encode_state(zse, 2, buffer, ARRAY_SIZE(buffer), 0);
|
||||||
|
|
||||||
|
ok = create_mcumgr_format_packet(zse, query_all, buffer, buffer_out, &buffer_size);
|
||||||
|
zassert_true(ok, "Expected packet creation to be successful\n");
|
||||||
|
|
||||||
|
/* Enable dummy SMP backend and ready for usage */
|
||||||
|
smp_dummy_enable();
|
||||||
|
smp_dummy_clear_state();
|
||||||
|
|
||||||
|
/* Send test echo command to dummy SMP backend */
|
||||||
|
(void)smp_dummy_tx_pkt(buffer_out, buffer_size);
|
||||||
|
smp_dummy_add_data();
|
||||||
|
|
||||||
|
/* For a short duration to see if response has been received */
|
||||||
|
received = smp_dummy_wait_for_data(SMP_RESPONSE_WAIT_TIME);
|
||||||
|
|
||||||
|
zassert_true(received, "Expected to receive data but timed out\n");
|
||||||
|
|
||||||
|
/* Retrieve response buffer and ensure validity */
|
||||||
|
nb = smp_dummy_get_outgoing();
|
||||||
|
smp_dummy_disable();
|
||||||
|
|
||||||
|
/* Process received data by removing header */
|
||||||
|
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
|
||||||
|
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
|
||||||
|
|
||||||
|
ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
|
||||||
|
|
||||||
|
zassert_true(ok, "Expected decode to be successful\n");
|
||||||
|
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
|
||||||
|
|
||||||
|
if (sizeof(CONFIG_BOARD_REVISION) > 1) {
|
||||||
|
/* Check with board revision */
|
||||||
|
zassert_equal((strlen(test_date_time) + strlen(response_all_board_revision_left) +
|
||||||
|
strlen(response_all_board_revision_right)), output.len,
|
||||||
|
"Expected to receive %d bytes but got %d\n",
|
||||||
|
(strlen(test_date_time) + strlen(response_all_board_revision_left) +
|
||||||
|
strlen(response_all_board_revision_right)), output.len);
|
||||||
|
|
||||||
|
zassert_mem_equal(response_all_board_revision_left, output.value,
|
||||||
|
strlen(response_all_board_revision_left),
|
||||||
|
"Expected received data mismatch");
|
||||||
|
zassert_mem_equal(response_all_board_revision_right,
|
||||||
|
&output.value[strlen(response_all_board_revision_left) +
|
||||||
|
strlen(test_date_time)],
|
||||||
|
strlen(response_all_board_revision_right),
|
||||||
|
"Expected received data mismatch");
|
||||||
|
} else {
|
||||||
|
/* Check without board revision */
|
||||||
|
zassert_equal((strlen(test_date_time) + strlen(response_all_left) +
|
||||||
|
strlen(response_all_right)), output.len,
|
||||||
|
"Expected to receive %d bytes but got %d\n",
|
||||||
|
(strlen(test_date_time) + strlen(response_all_left) +
|
||||||
|
strlen(response_all_right)), output.len);
|
||||||
|
|
||||||
|
zassert_mem_equal(response_all_left, output.value, strlen(response_all_left),
|
||||||
|
"Expected received data mismatch");
|
||||||
|
zassert_mem_equal(response_all_right, &output.value[strlen(response_all_left) +
|
||||||
|
strlen(test_date_time)], strlen(response_all_right),
|
||||||
|
"Expected received data mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extract time strings into timestamps */
|
||||||
|
expected_time_seconds = time_string_to_seconds(&test_date_time[TIME_CHECK_HH_START_CHAR]);
|
||||||
|
received_time_seconds = time_string_to_seconds(&output.value[(strlen(response_all_left) +
|
||||||
|
TIME_CHECK_HH_START_CHAR)]);
|
||||||
|
|
||||||
|
zassert_within(expected_time_seconds, received_time_seconds, TIME_DIFFERENCE_ALLOWANCE,
|
||||||
|
"Expected times to be within %d seconds but got %d",
|
||||||
|
TIME_DIFFERENCE_ALLOWANCE,
|
||||||
|
abs(expected_time_seconds - received_time_seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *setup_tests(void)
|
||||||
|
{
|
||||||
|
/* Register os_mgmt mcumgr group */
|
||||||
|
os_mgmt_register_group();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cleanup_test(void *p)
|
||||||
|
{
|
||||||
|
if (nb != NULL) {
|
||||||
|
net_buf_unref(nb);
|
||||||
|
nb = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Build date/time test set */
|
||||||
|
ZTEST_SUITE(os_mgmt_info_build_date, NULL, setup_tests, NULL, cleanup_test, NULL);
|
||||||
|
|
||||||
|
#endif
|
187
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c
Normal file
187
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c
Normal file
|
@ -0,0 +1,187 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(CONFIG_LIMITED_TEST)
|
||||||
|
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
#include <zephyr/net/buf.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/transport/smp_dummy.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h>
|
||||||
|
#include <os_mgmt_processor.h>
|
||||||
|
#include <zcbor_common.h>
|
||||||
|
#include <zcbor_decode.h>
|
||||||
|
#include <zcbor_encode.h>
|
||||||
|
#include <mgmt/mcumgr/util/zcbor_bulk.h>
|
||||||
|
#include <version.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <smp_internal.h>
|
||||||
|
#include "smp_test_util.h"
|
||||||
|
|
||||||
|
#define SMP_RESPONSE_WAIT_TIME 3
|
||||||
|
#define ZCBOR_BUFFER_SIZE 64
|
||||||
|
#define OUTPUT_BUFFER_SIZE 64
|
||||||
|
#define ZCBOR_HISTORY_ARRAY_SIZE 4
|
||||||
|
|
||||||
|
static struct net_buf *nb;
|
||||||
|
|
||||||
|
/* Responses to commands */
|
||||||
|
const uint8_t response_kernel_name[] = "Zephyr";
|
||||||
|
|
||||||
|
const uint8_t query_kernel_name[] = "s";
|
||||||
|
const uint8_t query_all[] = "a";
|
||||||
|
|
||||||
|
ZTEST(os_mgmt_info_limited, test_info_1_kernel_name)
|
||||||
|
{
|
||||||
|
uint8_t buffer[ZCBOR_BUFFER_SIZE];
|
||||||
|
uint8_t buffer_out[OUTPUT_BUFFER_SIZE];
|
||||||
|
bool ok;
|
||||||
|
uint16_t buffer_size;
|
||||||
|
zcbor_state_t zse[ZCBOR_HISTORY_ARRAY_SIZE] = { 0 };
|
||||||
|
zcbor_state_t zsd[ZCBOR_HISTORY_ARRAY_SIZE] = { 0 };
|
||||||
|
bool received;
|
||||||
|
struct zcbor_string output = { 0 };
|
||||||
|
size_t decoded = 0;
|
||||||
|
|
||||||
|
struct zcbor_map_decode_key_val output_decode[] = {
|
||||||
|
ZCBOR_MAP_DECODE_KEY_VAL(output, zcbor_tstr_decode, &output),
|
||||||
|
};
|
||||||
|
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
memset(buffer_out, 0, sizeof(buffer_out));
|
||||||
|
buffer_size = 0;
|
||||||
|
memset(zse, 0, sizeof(zse));
|
||||||
|
memset(zsd, 0, sizeof(zsd));
|
||||||
|
|
||||||
|
zcbor_new_encode_state(zse, 2, buffer, ARRAY_SIZE(buffer), 0);
|
||||||
|
|
||||||
|
ok = create_mcumgr_format_packet(zse, query_kernel_name, buffer, buffer_out, &buffer_size);
|
||||||
|
zassert_true(ok, "Expected packet creation to be successful\n");
|
||||||
|
|
||||||
|
/* Enable dummy SMP backend and ready for usage */
|
||||||
|
smp_dummy_enable();
|
||||||
|
smp_dummy_clear_state();
|
||||||
|
|
||||||
|
/* Send query command to dummy SMP backend */
|
||||||
|
(void)smp_dummy_tx_pkt(buffer_out, buffer_size);
|
||||||
|
smp_dummy_add_data();
|
||||||
|
|
||||||
|
/* For a short duration to see if response has been received */
|
||||||
|
received = smp_dummy_wait_for_data(SMP_RESPONSE_WAIT_TIME);
|
||||||
|
|
||||||
|
zassert_true(received, "Expected to receive data but timed out\n");
|
||||||
|
|
||||||
|
/* Retrieve response buffer and ensure validity */
|
||||||
|
nb = smp_dummy_get_outgoing();
|
||||||
|
smp_dummy_disable();
|
||||||
|
|
||||||
|
/* Process received data by removing header */
|
||||||
|
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
|
||||||
|
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
|
||||||
|
|
||||||
|
ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
|
||||||
|
|
||||||
|
zassert_true(ok, "Expected decode to be successful\n");
|
||||||
|
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
|
||||||
|
|
||||||
|
zassert_equal((sizeof(response_kernel_name) - 1), output.len,
|
||||||
|
"Expected to receive %d bytes but got %d\n",
|
||||||
|
(sizeof(response_kernel_name) - 1), output.len);
|
||||||
|
|
||||||
|
zassert_mem_equal(response_kernel_name, output.value, output.len,
|
||||||
|
"Expected received data mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST(os_mgmt_info_limited, test_info_2_all)
|
||||||
|
{
|
||||||
|
uint8_t buffer[ZCBOR_BUFFER_SIZE];
|
||||||
|
uint8_t buffer_out[OUTPUT_BUFFER_SIZE];
|
||||||
|
bool ok;
|
||||||
|
uint16_t buffer_size;
|
||||||
|
zcbor_state_t zse[ZCBOR_HISTORY_ARRAY_SIZE] = { 0 };
|
||||||
|
zcbor_state_t zsd[ZCBOR_HISTORY_ARRAY_SIZE] = { 0 };
|
||||||
|
bool received;
|
||||||
|
struct zcbor_string output = { 0 };
|
||||||
|
size_t decoded = 0;
|
||||||
|
int32_t rc;
|
||||||
|
|
||||||
|
struct zcbor_map_decode_key_val output_decode[] = {
|
||||||
|
ZCBOR_MAP_DECODE_KEY_VAL(output, zcbor_tstr_decode, &output),
|
||||||
|
};
|
||||||
|
|
||||||
|
struct zcbor_map_decode_key_val error_decode[] = {
|
||||||
|
ZCBOR_MAP_DECODE_KEY_VAL(rc, zcbor_int32_decode, &rc),
|
||||||
|
};
|
||||||
|
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
memset(buffer_out, 0, sizeof(buffer_out));
|
||||||
|
buffer_size = 0;
|
||||||
|
memset(zse, 0, sizeof(zse));
|
||||||
|
memset(zsd, 0, sizeof(zsd));
|
||||||
|
|
||||||
|
zcbor_new_encode_state(zse, 2, buffer, ARRAY_SIZE(buffer), 0);
|
||||||
|
|
||||||
|
ok = create_mcumgr_format_packet(zse, query_all, buffer, buffer_out, &buffer_size);
|
||||||
|
zassert_true(ok, "Expected packet creation to be successful\n");
|
||||||
|
|
||||||
|
/* Enable dummy SMP backend and ready for usage */
|
||||||
|
smp_dummy_enable();
|
||||||
|
smp_dummy_clear_state();
|
||||||
|
|
||||||
|
/* Send query command to dummy SMP backend */
|
||||||
|
(void)smp_dummy_tx_pkt(buffer_out, buffer_size);
|
||||||
|
smp_dummy_add_data();
|
||||||
|
|
||||||
|
/* For a short duration to see if response has been received */
|
||||||
|
received = smp_dummy_wait_for_data(SMP_RESPONSE_WAIT_TIME);
|
||||||
|
|
||||||
|
zassert_true(received, "Expected to receive data but timed out\n");
|
||||||
|
|
||||||
|
/* Retrieve response buffer and ensure validity */
|
||||||
|
nb = smp_dummy_get_outgoing();
|
||||||
|
smp_dummy_disable();
|
||||||
|
|
||||||
|
/* Process received data by removing header */
|
||||||
|
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
|
||||||
|
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
|
||||||
|
|
||||||
|
/* Ensure only an error is received */
|
||||||
|
ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
|
||||||
|
|
||||||
|
zassert_true(ok, "Expected decode to be successful\n");
|
||||||
|
zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n");
|
||||||
|
|
||||||
|
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
|
||||||
|
ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0;
|
||||||
|
|
||||||
|
zassert_true(ok, "Expected decode to be successful\n");
|
||||||
|
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
|
||||||
|
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %d\n", output.len);
|
||||||
|
zassert_equal(rc, MGMT_ERR_EMSGSIZE, "Expected to receive EMSGSIZE error but got %d\n",
|
||||||
|
rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *setup_tests(void)
|
||||||
|
{
|
||||||
|
/* Register os_mgmt mcumgr group */
|
||||||
|
os_mgmt_register_group();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cleanup_test(void *p)
|
||||||
|
{
|
||||||
|
if (nb != NULL) {
|
||||||
|
net_buf_unref(nb);
|
||||||
|
nb = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Limited size buffer test set */
|
||||||
|
ZTEST_SUITE(os_mgmt_info_limited, NULL, setup_tests, NULL, cleanup_test, NULL);
|
||||||
|
|
||||||
|
#endif
|
1562
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c
Normal file
1562
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c
Normal file
File diff suppressed because it is too large
Load diff
43
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c
Normal file
43
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "smp_test_util.h"
|
||||||
|
#include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h>
|
||||||
|
#include <zephyr/net/buf.h>
|
||||||
|
#include <zephyr/sys/byteorder.h>
|
||||||
|
#include <zcbor_encode.h>
|
||||||
|
|
||||||
|
/* SMP header function for generating os_mgmt info command header with sequence number set to 1 */
|
||||||
|
void smp_make_hdr(struct smp_hdr *rsp_hdr, size_t len)
|
||||||
|
{
|
||||||
|
*rsp_hdr = (struct smp_hdr) {
|
||||||
|
.nh_len = sys_cpu_to_be16(len),
|
||||||
|
.nh_flags = 0,
|
||||||
|
.nh_op = 0,
|
||||||
|
.nh_group = sys_cpu_to_be16(MGMT_GROUP_ID_OS),
|
||||||
|
.nh_seq = 1,
|
||||||
|
.nh_id = OS_MGMT_ID_INFO,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Function for creating an os_mgmt info command */
|
||||||
|
bool create_mcumgr_format_packet(zcbor_state_t *zse, const uint8_t *format, uint8_t *buffer,
|
||||||
|
uint8_t *output_buffer, uint16_t *buffer_size)
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
ok = zcbor_map_start_encode(zse, 2) &&
|
||||||
|
zcbor_tstr_put_lit(zse, "format") &&
|
||||||
|
zcbor_tstr_put_term(zse, format) &&
|
||||||
|
zcbor_map_end_encode(zse, 2);
|
||||||
|
|
||||||
|
*buffer_size = (zse->payload_mut - buffer);
|
||||||
|
smp_make_hdr((struct smp_hdr *)output_buffer, *buffer_size);
|
||||||
|
memcpy(&output_buffer[sizeof(struct smp_hdr)], buffer, *buffer_size);
|
||||||
|
*buffer_size += sizeof(struct smp_hdr);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
23
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.h
Normal file
23
tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef H_SMP_TEST_UTIL_
|
||||||
|
#define H_SMP_TEST_UTIL_
|
||||||
|
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||||
|
#include <zcbor_common.h>
|
||||||
|
#include <smp_internal.h>
|
||||||
|
|
||||||
|
/* SMP header function for generating os_mgmt info command header with sequence number set to 1 */
|
||||||
|
void smp_make_hdr(struct smp_hdr *rsp_hdr, size_t len);
|
||||||
|
|
||||||
|
/* Function for creating an os_mgmt info command */
|
||||||
|
bool create_mcumgr_format_packet(zcbor_state_t *zse, const uint8_t *format, uint8_t *buffer,
|
||||||
|
uint8_t *output_buffer, uint16_t *buffer_size);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
57
tests/subsys/mgmt/mcumgr/os_mgmt_info/testcase.yaml
Normal file
57
tests/subsys/mgmt/mcumgr/os_mgmt_info/testcase.yaml
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
tests:
|
||||||
|
os.mgmt.info:
|
||||||
|
# FIXME: Exclude architectures that lack a reboot handler function
|
||||||
|
# FIXME: Exclude systems whereby the processor type is not known and emits a warning
|
||||||
|
arch_exclude: arm64 nios2 sparc arc xtensa mips posix
|
||||||
|
tags: os_mgmt_info
|
||||||
|
os.mgmt.info_no_hooks:
|
||||||
|
# FIXME: Exclude architectures that lack a reboot handler function
|
||||||
|
# FIXME: Exclude systems whereby the processor type is not known and emits a warning
|
||||||
|
arch_exclude: arm64 nios2 sparc arc xtensa mips posix
|
||||||
|
tags: os_mgmt_info
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_MCUMGR_GRP_OS_INFO_CUSTOM_HOOKS=n
|
||||||
|
- CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS=n
|
||||||
|
os.mgmt.info_bt:
|
||||||
|
depends_on: ble
|
||||||
|
# FIXME: Exclude architectures that lack a reboot handler function
|
||||||
|
# FIXME: Exclude systems whereby the processor type is not known and emits a warning
|
||||||
|
arch_exclude: arm64 nios2 sparc arc xtensa mips posix
|
||||||
|
tags: os_mgmt_info
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_BT=y
|
||||||
|
- CONFIG_BT_DEVICE_NAME="a_bt_name"
|
||||||
|
os.mgmt.info_net:
|
||||||
|
depends_on: netif
|
||||||
|
# FIXME: Exclude architectures that lack a reboot handler function
|
||||||
|
# FIXME: Exclude systems whereby the processor type is not known and emits a warning
|
||||||
|
arch_exclude: arm64 nios2 sparc arc xtensa mips posix
|
||||||
|
platform_exclude: qemu_cortex_a9 qemu_x86 qemu_riscv64_smp qemu_riscv64 qemu_riscv32e
|
||||||
|
qemu_riscv32 qemu_riscv32_smp qemu_cortex_m3 mps2_an385
|
||||||
|
tags: os_mgmt_info
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_NETWORKING=y
|
||||||
|
- CONFIG_NET_HOSTNAME_ENABLE=y
|
||||||
|
- CONFIG_NET_HOSTNAME="test_net_name"
|
||||||
|
- CONFIG_TEST_RANDOM_GENERATOR=y
|
||||||
|
os.mgmt.info_build_date:
|
||||||
|
# FIXME: Exclude architectures that lack a reboot handler function
|
||||||
|
# FIXME: Exclude systems whereby the processor type is not known and emits a warning
|
||||||
|
arch_exclude: arm64 nios2 sparc arc xtensa mips posix
|
||||||
|
tags: os_mgmt_info
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_BUILD_DATE_TIME_TEST=y
|
||||||
|
os.mgmt.info_limited_size:
|
||||||
|
# FIXME: Exclude architectures that lack a reboot handler function
|
||||||
|
# FIXME: Exclude systems whereby the processor type is not known and emits a warning
|
||||||
|
arch_exclude: arm64 nios2 sparc arc xtensa mips posix
|
||||||
|
tags: os_mgmt_info
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_LIMITED_TEST=y
|
||||||
|
- CONFIG_MCUMGR_SMP_DUMMY_RX_BUF_SIZE=64
|
||||||
|
- CONFIG_MCUMGR_GRP_OS_INFO_MAX_RESPONSE_SIZE=32
|
Loading…
Add table
Add a link
Reference in a new issue