tests: zbus: add channel name test suite
Add tests to verify the zbus_chan_from_name() functionality Signed-off-by: Trond F. Christiansen <trond.christiansen@nordicsemi.no>
This commit is contained in:
committed by
Anas Nashif
parent
46eca1e3a9
commit
e716bb7546
13
tests/subsys/zbus/channel_name/CMakeLists.txt
Normal file
13
tests/subsys/zbus/channel_name/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
#
|
||||
# Copyright (c) 2025 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(test_channel_name)
|
||||
|
||||
FILE(GLOB app_sources src/main.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
11
tests/subsys/zbus/channel_name/prj.conf
Normal file
11
tests/subsys/zbus/channel_name/prj.conf
Normal file
@@ -0,0 +1,11 @@
|
||||
#
|
||||
# Copyright (c) 2025 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_ASSERT=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_ZBUS=y
|
||||
CONFIG_ZBUS_CHANNEL_NAME=y
|
||||
38
tests/subsys/zbus/channel_name/src/main.c
Normal file
38
tests/subsys/zbus/channel_name/src/main.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/zbus/zbus.h>
|
||||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/ztest_assert.h>
|
||||
#include <zephyr/sys/util_macro.h>
|
||||
|
||||
struct msg {
|
||||
int x;
|
||||
};
|
||||
|
||||
#define CHANNEL_COUNT 10
|
||||
|
||||
#define DEFINE_TEST_CHANNELS(i, _) \
|
||||
ZBUS_CHAN_DEFINE(test_chan_##i, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, \
|
||||
ZBUS_MSG_INIT(0));
|
||||
|
||||
LISTIFY(CHANNEL_COUNT, DEFINE_TEST_CHANNELS, (;))
|
||||
|
||||
ZTEST(channel_name, test_channel_retrieval)
|
||||
{
|
||||
/* invalid cases */
|
||||
zexpect_is_null(zbus_chan_from_name("unknown"));
|
||||
zexpect_is_null(zbus_chan_from_name(NULL));
|
||||
zexpect_is_null(zbus_chan_from_name(""));
|
||||
|
||||
/* valid cases */
|
||||
zexpect_equal_ptr(&test_chan_0, zbus_chan_from_name("test_chan_0"));
|
||||
zexpect_equal_ptr(&test_chan_4, zbus_chan_from_name("test_chan_4"));
|
||||
zexpect_equal_ptr(&test_chan_5, zbus_chan_from_name("test_chan_5"));
|
||||
zexpect_equal_ptr(&test_chan_9, zbus_chan_from_name("test_chan_9"));
|
||||
}
|
||||
|
||||
ZTEST_SUITE(channel_name, NULL, NULL, NULL, NULL, NULL);
|
||||
5
tests/subsys/zbus/channel_name/testcase.yaml
Normal file
5
tests/subsys/zbus/channel_name/testcase.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
tests:
|
||||
message_bus.zbus.channel_name:
|
||||
tags: zbus
|
||||
integration_platforms:
|
||||
- native_sim
|
||||
Reference in New Issue
Block a user