-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: zbus: channel_id: test channel IDs
Test the new channel identifiers. Signed-off-by: Jordan Yates <jordan@embeint.com>
- Loading branch information
1 parent
d2bb597
commit 17925dd
Showing
4 changed files
with
78 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,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}) |
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,6 @@ | ||
CONFIG_ZTEST=y | ||
CONFIG_ASSERT=n | ||
CONFIG_LOG=y | ||
CONFIG_ZBUS=y | ||
CONFIG_ZBUS_CHANNEL_ID=y | ||
CONFIG_ZBUS_CHANNEL_NAME=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,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); |
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,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 (.*)" |