From 17925dde0ed86555f693c1515b00469da9c6f5d4 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Mon, 8 Jul 2024 12:44:22 +1000 Subject: [PATCH] tests: zbus: channel_id: test channel IDs Test the new channel identifiers. Signed-off-by: Jordan Yates --- tests/subsys/zbus/channel_id/CMakeLists.txt | 8 +++ tests/subsys/zbus/channel_id/prj.conf | 6 +++ tests/subsys/zbus/channel_id/src/main.c | 54 +++++++++++++++++++++ tests/subsys/zbus/channel_id/testcase.yaml | 10 ++++ 4 files changed, 78 insertions(+) create mode 100644 tests/subsys/zbus/channel_id/CMakeLists.txt create mode 100644 tests/subsys/zbus/channel_id/prj.conf create mode 100644 tests/subsys/zbus/channel_id/src/main.c create mode 100644 tests/subsys/zbus/channel_id/testcase.yaml diff --git a/tests/subsys/zbus/channel_id/CMakeLists.txt b/tests/subsys/zbus/channel_id/CMakeLists.txt new file mode 100644 index 000000000000..dbbe0809212a --- /dev/null +++ b/tests/subsys/zbus/channel_id/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_channel_id) + +FILE(GLOB app_sources src/main.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/subsys/zbus/channel_id/prj.conf b/tests/subsys/zbus/channel_id/prj.conf new file mode 100644 index 000000000000..d8c421c96abf --- /dev/null +++ b/tests/subsys/zbus/channel_id/prj.conf @@ -0,0 +1,6 @@ +CONFIG_ZTEST=y +CONFIG_ASSERT=n +CONFIG_LOG=y +CONFIG_ZBUS=y +CONFIG_ZBUS_CHANNEL_ID=y +CONFIG_ZBUS_CHANNEL_NAME=y diff --git a/tests/subsys/zbus/channel_id/src/main.c b/tests/subsys/zbus/channel_id/src/main.c new file mode 100644 index 000000000000..5f30bd2ec6a7 --- /dev/null +++ b/tests/subsys/zbus/channel_id/src/main.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Embeint Inc + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +struct msg { + int x; +}; + +enum channel_ids { + CHAN_A = 100, + CHAN_B = 123, + CHAN_C = 0x12343243, + CHAN_D = 123, + CHAN_E = 1, + CHAN_F = 357489, +}; + +ZBUS_CHAN_DEFINE_WITH_ID(chan_a, CHAN_A, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, + ZBUS_MSG_INIT(0)); +ZBUS_CHAN_DEFINE_WITH_ID(chan_b, CHAN_B, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, + ZBUS_MSG_INIT(0)); +ZBUS_CHAN_DEFINE_WITH_ID(chan_c, CHAN_C, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, + ZBUS_MSG_INIT(0)); +ZBUS_CHAN_DEFINE_WITH_ID(chan_d, CHAN_D, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, + ZBUS_MSG_INIT(0)); +ZBUS_CHAN_DEFINE_WITH_ID(chan_e, CHAN_E, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, + ZBUS_MSG_INIT(0)); +ZBUS_CHAN_DEFINE_WITH_ID(chan_f, CHAN_F, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, + ZBUS_MSG_INIT(0)); +ZBUS_CHAN_DEFINE(chan_g, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, ZBUS_MSG_INIT(0)); + +ZTEST(channel_id, test_channel_retrieval) +{ + /* Invalid/unknown channel IDs */ + zassert_is_null(zbus_chan_from_id(0x1000000)); + zassert_is_null(zbus_chan_from_id(ZBUS_CHAN_ID_INVALID)); + + /* Standard retrieval */ + zassert_equal(&chan_a, zbus_chan_from_id(CHAN_A)); + zassert_equal(&chan_c, zbus_chan_from_id(CHAN_C)); + zassert_equal(&chan_e, zbus_chan_from_id(CHAN_E)); + zassert_equal(&chan_f, zbus_chan_from_id(CHAN_F)); + + /* Duplicate channel IDs */ + zassert_true((&chan_b == zbus_chan_from_id(CHAN_B)) || + (&chan_d == zbus_chan_from_id(CHAN_B))); +} + +ZTEST_SUITE(channel_id, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/zbus/channel_id/testcase.yaml b/tests/subsys/zbus/channel_id/testcase.yaml new file mode 100644 index 000000000000..a13624d77c1b --- /dev/null +++ b/tests/subsys/zbus/channel_id/testcase.yaml @@ -0,0 +1,10 @@ +tests: + message_bus.zbus.channel_id: + tags: zbus + integration_platforms: + - native_sim + harness: console + harness_config: + type: one_line + regex: + - "Channels (.*) and (.*) have matching IDs (.*)"