Skip to content

Commit

Permalink
tests: zbus: channel_id: test channel IDs
Browse files Browse the repository at this point in the history
Test the new channel identifiers.

Signed-off-by: Jordan Yates <jordan@embeint.com>
  • Loading branch information
JordanYates authored and kartben committed Dec 18, 2024
1 parent d2bb597 commit 17925dd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/subsys/zbus/channel_id/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
6 changes: 6 additions & 0 deletions tests/subsys/zbus/channel_id/prj.conf
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions tests/subsys/zbus/channel_id/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2024 Embeint Inc
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/zbus/zbus.h>
#include <zephyr/ztest.h>
#include <zephyr/ztest_assert.h>

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);
10 changes: 10 additions & 0 deletions tests/subsys/zbus/channel_id/testcase.yaml
Original file line number Diff line number Diff line change
@@ -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 (.*)"

0 comments on commit 17925dd

Please sign in to comment.