From 876219985141d8ef1f3ef012afd370712f6e8e1f Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Thu, 3 Dec 2026 11:50:24 +0000 Subject: [PATCH 01/10] posix: add a stub with the Zephyr semantics The non-Zephyr host builds (the host library and the testbench) compile the shared code against posix/include, which gives it the SOF atomic names from rtos/atomic.h. To switch that code to the Zephyr names, these builds need a that behaves like Zephyr's. Zephyr builds, native_sim included, keep using the Zephyr header. Add the stub with atomic_get(), atomic_set(), atomic_add() and atomic_sub(). Like Zephyr, atomic_set(), atomic_add() and atomic_sub() return the previous value. The GCC version of the host atomics returned the new value from add and sub, while the xt-xcc version (for the xt-run testbench) already returned the previous one. Make the GCC version return the previous value too, and replace the set and init functions with a swap that returns it. No host caller uses these return values. rtos/atomic.h now keeps only atomic_read() and atomic_init() on top of the stub, as on Zephyr. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/rtos/atomic.h | 22 +++--------- posix/include/zephyr/sys/atomic.h | 41 ++++++++++++++++++++++ src/kernel/arch/host/include/arch/atomic.h | 33 ++++++++--------- 3 files changed, 60 insertions(+), 36 deletions(-) create mode 100644 posix/include/zephyr/sys/atomic.h diff --git a/posix/include/rtos/atomic.h b/posix/include/rtos/atomic.h index 6d16b6b6c9e6..c01635031fec 100644 --- a/posix/include/rtos/atomic.h +++ b/posix/include/rtos/atomic.h @@ -8,32 +8,18 @@ #ifndef __SOF_ATOMIC_H__ #define __SOF_ATOMIC_H__ -#include +#include #include +/* SOF names for atomic_set() and atomic_get(), as in zephyr/include/rtos/atomic.h */ static inline void atomic_init(atomic_t *a, int32_t value) { - arch_atomic_init(a, value); + atomic_set(a, value); } static inline int32_t atomic_read(const atomic_t *a) { - return arch_atomic_read(a); -} - -static inline void atomic_set(atomic_t *a, int32_t value) -{ - arch_atomic_set(a, value); -} - -static inline int32_t atomic_add(atomic_t *a, int32_t value) -{ - return arch_atomic_add(a, value); -} - -static inline int32_t atomic_sub(atomic_t *a, int32_t value) -{ - return arch_atomic_sub(a, value); + return atomic_get(a); } #endif /* __SOF_ATOMIC_H__ */ diff --git a/posix/include/zephyr/sys/atomic.h b/posix/include/zephyr/sys/atomic.h new file mode 100644 index 000000000000..9ea325134778 --- /dev/null +++ b/posix/include/zephyr/sys/atomic.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Copyright(c) 2026 Intel Corporation. All rights reserved. + * + * Stub for used by the non-Zephyr host builds (the host + * library and the testbench), which compile the shared code against + * posix/include. Zephyr builds, native_sim included, use the Zephyr header. + * + * The functions have the Zephyr names and return values: atomic_set(), + * atomic_add() and atomic_sub() return the previous value. + */ + +#ifndef __POSIX_ZEPHYR_SYS_ATOMIC_H__ +#define __POSIX_ZEPHYR_SYS_ATOMIC_H__ + +#include +#include + +typedef int32_t atomic_val_t; + +static inline atomic_val_t atomic_get(const atomic_t *target) +{ + return arch_atomic_read(target); +} + +static inline atomic_val_t atomic_set(atomic_t *target, atomic_val_t value) +{ + return arch_atomic_swap(target, value); +} + +static inline atomic_val_t atomic_add(atomic_t *target, atomic_val_t value) +{ + return arch_atomic_add(target, value); +} + +static inline atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value) +{ + return arch_atomic_sub(target, value); +} + +#endif /* __POSIX_ZEPHYR_SYS_ATOMIC_H__ */ diff --git a/src/kernel/arch/host/include/arch/atomic.h b/src/kernel/arch/host/include/arch/atomic.h index 797ba5f5e1d4..180a0ba69140 100644 --- a/src/kernel/arch/host/include/arch/atomic.h +++ b/src/kernel/arch/host/include/arch/atomic.h @@ -6,7 +6,7 @@ * Ranjani Sridharan */ -#ifdef __SOF_ATOMIC_H__ +#if defined(__SOF_ATOMIC_H__) || defined(__POSIX_ZEPHYR_SYS_ATOMIC_H__) #ifndef __ARCH_ATOMIC_H__ #define __ARCH_ATOMIC_H__ @@ -24,24 +24,20 @@ static inline int32_t arch_atomic_read(const atomic_t *a) return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST); } -static inline void arch_atomic_set(atomic_t *a, int32_t value) +/* The swap, add and sub functions return the previous value, like Zephyr */ +static inline int32_t arch_atomic_swap(atomic_t *a, int32_t value) { - __atomic_store_n(&a->value, value, __ATOMIC_SEQ_CST); -} - -static inline void arch_atomic_init(atomic_t *a, int32_t value) -{ - __atomic_store_n(&a->value, value, __ATOMIC_SEQ_CST); + return __atomic_exchange_n(&a->value, value, __ATOMIC_SEQ_CST); } static inline int32_t arch_atomic_add(atomic_t *a, int32_t value) { - return __atomic_add_fetch(&a->value, value, __ATOMIC_SEQ_CST); + return __atomic_fetch_add(&a->value, value, __ATOMIC_SEQ_CST); } static inline int32_t arch_atomic_sub(atomic_t *a, int32_t value) { - return __atomic_sub_fetch(&a->value, value, __ATOMIC_SEQ_CST); + return __atomic_fetch_sub(&a->value, value, __ATOMIC_SEQ_CST); } #elif defined __XCC__ @@ -57,14 +53,15 @@ static inline int32_t arch_atomic_read(const atomic_t *a) return a->value; } -static inline void arch_atomic_set(atomic_t *a, int32_t value) +static inline int32_t arch_atomic_swap(atomic_t *a, int32_t value) { - a->value = value; -} + int32_t tmp; -static inline void arch_atomic_init(atomic_t *a, int32_t value) -{ - arch_atomic_set(a, value); + lock(); + tmp = a->value; + a->value = value; + unlock(); + return tmp; } static inline int32_t arch_atomic_add(atomic_t *a, int32_t value) @@ -99,6 +96,6 @@ static inline int32_t arch_atomic_sub(atomic_t *a, int32_t value) #else -#error "This file shouldn't be included from outside of sof/atomic.h" +#error "This file shouldn't be included from outside of rtos/atomic.h or zephyr/sys/atomic.h" -#endif /* __SOF_ATOMIC_H__ */ +#endif /* __SOF_ATOMIC_H__ || __POSIX_ZEPHYR_SYS_ATOMIC_H__ */ From 06ba39296a586db215705d99208963a83edeb3af Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Thu, 3 Dec 2026 11:50:24 +0000 Subject: [PATCH 02/10] posix: add a stub In the non-Zephyr host builds (the host library and the testbench), shared code calls the SOF cache wrappers because posix/include has no . Add a stub with sys_cache_data_flush_range(), sys_cache_data_invd_range(), sys_cache_data_flush_and_invd_range() and sys_cache_instr_invd_range(). The host has no cache to maintain, so they return -ENOTSUP, like Zephyr built without CONFIG_CACHE_MANAGEMENT. Zephyr builds, native_sim included, keep using the Zephyr header. The cached and uncached pointer conversions are not stubbed yet: the host currently reports every pointer as uncached, which does not map directly onto the Zephyr calls. They come with their first user. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/zephyr/cache.h | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 posix/include/zephyr/cache.h diff --git a/posix/include/zephyr/cache.h b/posix/include/zephyr/cache.h new file mode 100644 index 000000000000..c42f8fc291e6 --- /dev/null +++ b/posix/include/zephyr/cache.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Copyright(c) 2026 Intel Corporation. All rights reserved. + * + * Stub for used by the non-Zephyr host builds (the host + * library and the testbench), which compile the shared code against + * posix/include. Zephyr builds, native_sim included, use the Zephyr header. + * + * The host has no cache to maintain, so these return -ENOTSUP, like Zephyr + * built without CONFIG_CACHE_MANAGEMENT. + */ + +#ifndef __POSIX_ZEPHYR_CACHE_H__ +#define __POSIX_ZEPHYR_CACHE_H__ + +#include +#include + +static inline int sys_cache_data_flush_range(void *addr, size_t size) +{ + (void)addr; + (void)size; + return -ENOTSUP; +} + +static inline int sys_cache_data_invd_range(void *addr, size_t size) +{ + (void)addr; + (void)size; + return -ENOTSUP; +} + +static inline int sys_cache_data_flush_and_invd_range(void *addr, size_t size) +{ + (void)addr; + (void)size; + return -ENOTSUP; +} + +static inline int sys_cache_instr_invd_range(void *addr, size_t size) +{ + (void)addr; + (void)size; + return -ENOTSUP; +} + +#endif /* __POSIX_ZEPHYR_CACHE_H__ */ From 9063ab7a4cd88e6550f81252cc34277d320ce45f Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Thu, 3 Dec 2026 11:50:24 +0000 Subject: [PATCH 03/10] posix: add Zephyr assert and k_panic() stubs Shared code uses assert() and sof_panic() because the non-Zephyr host builds (the host library and the testbench) have neither nor k_panic() in posix/include. Code that already uses the Zephyr names has to be hidden from these builds, such as the coherent API checks. Add with __ASSERT() and __ASSERT_NO_MSG(). As in Zephyr, the __ASSERT() message is optional and its format does not have to be a string literal. The host checks its assertions in every build, as assert() does: a failed assertion prints the condition and any message, then panics with SOF_IPC_PANIC_ASSERT. Add k_panic() to rtos/panic.h, which already defines sof_panic(). It takes no panic code, so it reports SOF_IPC_PANIC_ASSERT, the code of a failed assert(): Zephyr also ends a failed assertion with k_panic(). Zephyr builds, native_sim included, keep using the Zephyr macros. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/rtos/panic.h | 6 ++++ posix/include/zephyr/sys/__assert.h | 54 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 posix/include/zephyr/sys/__assert.h diff --git a/posix/include/rtos/panic.h b/posix/include/rtos/panic.h index e4aca1661f56..2ba24eed48bc 100644 --- a/posix/include/rtos/panic.h +++ b/posix/include/rtos/panic.h @@ -38,6 +38,12 @@ void __panic(uint32_t p, const char *filename, uint32_t linenum) SOF_NORETURN; #define sof_panic(x) __panic((x), (RELATIVE_FILE), (__LINE__)) +/* + * Zephyr k_panic() takes no panic code. Report SOF_IPC_PANIC_ASSERT, the code + * of a failed assert(): Zephyr also ends a failed assertion with k_panic(). + */ +#define k_panic() sof_panic(SOF_IPC_PANIC_ASSERT) + /* runtime assertion */ #ifndef assert #define assert(cond) (void)((cond) || (sof_panic(SOF_IPC_PANIC_ASSERT), 0)) diff --git a/posix/include/zephyr/sys/__assert.h b/posix/include/zephyr/sys/__assert.h new file mode 100644 index 000000000000..227e0bcc52eb --- /dev/null +++ b/posix/include/zephyr/sys/__assert.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Copyright(c) 2026 Intel Corporation. All rights reserved. + * + * Stub for used by the non-Zephyr host builds (the host + * library and the testbench), which compile the shared code against + * posix/include. Zephyr builds, native_sim included, use the Zephyr header. + * + * The host checks its assertions in every build, as assert() does: a failed + * assertion prints the condition and any message, then panics with + * SOF_IPC_PANIC_ASSERT. + */ + +#ifndef __POSIX_ZEPHYR_SYS___ASSERT_H__ +#define __POSIX_ZEPHYR_SYS___ASSERT_H__ + +#include +#include +#include +#include + +/* + * Print a failed assertion. The variable arguments are the optional message + * format and its arguments, then NULL: NULL alone means there is no message. + */ +static inline void posix_assert_print(const char *test, const char *file, int line, ...) +{ + const char *fmt; + va_list ap; + + fprintf(stderr, "ASSERTION FAIL [%s] @ %s:%d\n", test, file, line); + va_start(ap, line); + fmt = va_arg(ap, const char *); + if (fmt) { + fprintf(stderr, "\t"); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + } + va_end(ap); +} + +/* as in Zephyr, the message format and its arguments are optional */ +#define __ASSERT(test, ...) \ + do { \ + if (!(test)) { \ + posix_assert_print(#test, RELATIVE_FILE, __LINE__, \ + ##__VA_ARGS__, NULL); \ + sof_panic(SOF_IPC_PANIC_ASSERT); \ + } \ + } while (0) + +#define __ASSERT_NO_MSG(test) __ASSERT(test) + +#endif /* __POSIX_ZEPHYR_SYS___ASSERT_H__ */ From 56fc1eeb3d6c567ab0ec2470a05b407ba2ec4230 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Thu, 3 Dec 2026 11:50:38 +0000 Subject: [PATCH 04/10] test: ztest: check the non-Zephyr host stubs of the Zephyr APIs SOF has two kinds of host build. The Zephyr ones, such as the native_sim ztests and the IPC fuzzer, use Zephyr itself and never see the stubs in posix/include. The non-Zephyr host library and testbench compile the shared code against posix/include, and nothing tested its stubs of the Zephyr APIs. Add a test that compiles one source file the way the non-Zephyr host builds compile the shared code: with the host include paths only, so that resolves to the stubs. The ztest code, built normally against Zephyr, calls it and compares the results with the Zephyr implementations. ztest and native_sim are only the harness here; the Zephyr builds do not depend on the stubs. The test checks that: - atomic_set(), atomic_add() and atomic_sub() return the previous value, and the values match Zephyr's; - the cache functions return -ENOTSUP, as on native_sim; - __ASSERT() and __ASSERT_NO_MSG() pass on a true condition and panic with SOF_IPC_PANIC_ASSERT on a false one, with a literal message, a format that is not a literal and no message, and evaluate the condition once; - k_panic() panics with SOF_IPC_PANIC_ASSERT. It catches panics by replacing the host __panic() with a longjmp() back to the test. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- test/ztest/unit/host_stubs/CMakeLists.txt | 35 ++++++ test/ztest/unit/host_stubs/host_stubs.c | 111 ++++++++++++++++++ test/ztest/unit/host_stubs/host_stubs.h | 45 +++++++ test/ztest/unit/host_stubs/prj.conf | 2 + .../unit/host_stubs/test_host_stubs_ztest.c | 99 ++++++++++++++++ test/ztest/unit/host_stubs/testcase.yaml | 14 +++ 6 files changed, 306 insertions(+) create mode 100644 test/ztest/unit/host_stubs/CMakeLists.txt create mode 100644 test/ztest/unit/host_stubs/host_stubs.c create mode 100644 test/ztest/unit/host_stubs/host_stubs.h create mode 100644 test/ztest/unit/host_stubs/prj.conf create mode 100644 test/ztest/unit/host_stubs/test_host_stubs_ztest.c create mode 100644 test/ztest/unit/host_stubs/testcase.yaml diff --git a/test/ztest/unit/host_stubs/CMakeLists.txt b/test/ztest/unit/host_stubs/CMakeLists.txt new file mode 100644 index 000000000000..e8f5d0d5c09b --- /dev/null +++ b/test/ztest/unit/host_stubs/CMakeLists.txt @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_host_stubs) + +set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../..") + +include(${SOF_ROOT}/scripts/cmake/misc.cmake) + +# SOF has two kinds of host build. The Zephyr ones (these ztests, the IPC +# fuzzer) use Zephyr itself. The non-Zephyr host library and testbench +# compile the shared code against posix/include, which has stubs of some +# Zephyr APIs. This test checks those stubs against Zephyr: ztest and +# native_sim are only the harness. +# +# host_stubs.c is compiled the way the non-Zephyr host builds compile the +# shared code: with the host include paths only, so that +# resolves to posix/include, not to Zephyr. +add_library(host_stubs STATIC host_stubs.c) +target_include_directories(host_stubs PRIVATE + ${SOF_ROOT}/posix/include + ${SOF_ROOT}/src/kernel/arch/host/include + ${SOF_ROOT}/src/include +) +target_compile_options(host_stubs PRIVATE -Wall -Werror) +if(NOT CONFIG_64BIT) + target_compile_options(host_stubs PRIVATE -m32) +endif() +sof_append_relative_path_definitions(host_stubs) + +target_include_directories(app PRIVATE ${SOF_ROOT}/src/include) +target_sources(app PRIVATE test_host_stubs_ztest.c) +target_link_libraries(app PRIVATE host_stubs) diff --git a/test/ztest/unit/host_stubs/host_stubs.c b/test/ztest/unit/host_stubs/host_stubs.c new file mode 100644 index 000000000000..b0acf57d03c7 --- /dev/null +++ b/test/ztest/unit/host_stubs/host_stubs.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. +// +// Uses the posix/include stubs of the Zephyr APIs, as the non-Zephyr host +// builds do. Built with the host include paths only, see CMakeLists.txt. + +#include +#include +#include +#include +#include + +#include +#include + +#include "host_stubs.h" + +static jmp_buf panic_env; +/* volatile: written between setjmp() and longjmp() */ +static volatile uint32_t panic_code; + +/* the host __panic() aborts, return to the caller of the stub instead */ +void __panic(uint32_t p, const char *filename, uint32_t linenum) +{ + (void)filename; + (void)linenum; + panic_code = p; + longjmp(panic_env, 1); +} + +void host_stub_atomic_seq(struct stub_atomic_seq *seq) +{ + atomic_t a; + + atomic_init(&a, STUB_ATOMIC_INIT); + seq->read_after_init = atomic_read(&a); + seq->set_ret = atomic_set(&a, STUB_ATOMIC_SET); + seq->add_ret = atomic_add(&a, STUB_ATOMIC_ADD); + seq->sub_ret = atomic_sub(&a, STUB_ATOMIC_SUB); + seq->get_final = atomic_get(&a); +} + +void host_stub_cache(int ret[STUB_CACHE_FUNCS]) +{ + static char buf[64]; + + ret[0] = sys_cache_data_flush_range(buf, sizeof(buf)); + ret[1] = sys_cache_data_invd_range(buf, sizeof(buf)); + ret[2] = sys_cache_data_flush_and_invd_range(buf, sizeof(buf)); + ret[3] = sys_cache_instr_invd_range(buf, sizeof(buf)); +} + +uint32_t host_stub_assert_no_msg(int cond) +{ + panic_code = 0; + if (!setjmp(panic_env)) { + __ASSERT_NO_MSG(cond); + } + return panic_code; +} + +uint32_t host_stub_assert_msg(int cond) +{ + panic_code = 0; + if (!setjmp(panic_env)) { + __ASSERT(cond, "condition is %d", cond); + } + return panic_code; +} + +uint32_t host_stub_assert_no_fmt(int cond) +{ + panic_code = 0; + if (!setjmp(panic_env)) { + __ASSERT(cond); + } + return panic_code; +} + +uint32_t host_stub_assert_var_fmt(int cond) +{ + const char *fmt = "condition is %d"; + + panic_code = 0; + if (!setjmp(panic_env)) { + __ASSERT(cond, fmt, cond); + } + return panic_code; +} + +uint32_t host_stub_k_panic(void) +{ + panic_code = 0; + if (!setjmp(panic_env)) { + k_panic(); + } + return panic_code; +} + +int host_stub_assert_eval_count(void) +{ + /* volatile: written between setjmp() and longjmp() */ + volatile int count = 0; + + panic_code = 0; + if (!setjmp(panic_env)) { + __ASSERT(++count > 0, "count %d", count); + } + return count; +} diff --git a/test/ztest/unit/host_stubs/host_stubs.h b/test/ztest/unit/host_stubs/host_stubs.h new file mode 100644 index 000000000000..160a1a5e50a9 --- /dev/null +++ b/test/ztest/unit/host_stubs/host_stubs.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Copyright(c) 2026 Intel Corporation. + * + * Interface between the ztest code and host_stubs.c, which is compiled with + * the host headers. Only plain C types cross it. + */ + +#ifndef __TEST_HOST_STUBS_H__ +#define __TEST_HOST_STUBS_H__ + +#include + +/* values returned by one sequence of atomic operations */ +struct stub_atomic_seq { + int32_t read_after_init; + int32_t set_ret; + int32_t add_ret; + int32_t sub_ret; + int32_t get_final; +}; + +#define STUB_ATOMIC_INIT 5 +#define STUB_ATOMIC_SET 10 +#define STUB_ATOMIC_ADD 3 +#define STUB_ATOMIC_SUB 4 + +/* number of sys_cache_*() functions in the stub */ +#define STUB_CACHE_FUNCS 4 + +void host_stub_atomic_seq(struct stub_atomic_seq *seq); +void host_stub_cache(int ret[STUB_CACHE_FUNCS]); + +/* return 0 if nothing panicked, else the panic code */ +uint32_t host_stub_assert_no_msg(int cond); +uint32_t host_stub_assert_msg(int cond); +/* __ASSERT() without a message, and with a format that is not a literal */ +uint32_t host_stub_assert_no_fmt(int cond); +uint32_t host_stub_assert_var_fmt(int cond); +uint32_t host_stub_k_panic(void); + +/* number of times __ASSERT() evaluates its condition */ +int host_stub_assert_eval_count(void); + +#endif /* __TEST_HOST_STUBS_H__ */ diff --git a/test/ztest/unit/host_stubs/prj.conf b/test/ztest/unit/host_stubs/prj.conf new file mode 100644 index 000000000000..d34c7781cd0a --- /dev/null +++ b/test/ztest/unit/host_stubs/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n diff --git a/test/ztest/unit/host_stubs/test_host_stubs_ztest.c b/test/ztest/unit/host_stubs/test_host_stubs_ztest.c new file mode 100644 index 000000000000..6c055f0ee3d1 --- /dev/null +++ b/test/ztest/unit/host_stubs/test_host_stubs_ztest.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. +// +// The non-Zephyr host builds (the host library and the testbench) compile +// the shared code against the posix/include stubs of the Zephyr APIs. Check +// that the stubs behave like the Zephyr implementations, which this test is +// linked with. + +#include +#include +#include +#include + +#include + +#include "host_stubs.h" + +/* the same sequence as host_stub_atomic_seq(), with the Zephyr atomics */ +static void zephyr_atomic_seq(struct stub_atomic_seq *seq) +{ + atomic_t a; + + atomic_set(&a, STUB_ATOMIC_INIT); + seq->read_after_init = atomic_get(&a); + seq->set_ret = atomic_set(&a, STUB_ATOMIC_SET); + seq->add_ret = atomic_add(&a, STUB_ATOMIC_ADD); + seq->sub_ret = atomic_sub(&a, STUB_ATOMIC_SUB); + seq->get_final = atomic_get(&a); +} + +ZTEST(host_stubs, test_atomic_like_zephyr) +{ + struct stub_atomic_seq host, zephyr; + + host_stub_atomic_seq(&host); + zephyr_atomic_seq(&zephyr); + + /* set, add and sub return the previous value */ + zassert_equal(host.read_after_init, STUB_ATOMIC_INIT); + zassert_equal(host.set_ret, STUB_ATOMIC_INIT); + zassert_equal(host.add_ret, STUB_ATOMIC_SET); + zassert_equal(host.sub_ret, STUB_ATOMIC_SET + STUB_ATOMIC_ADD); + zassert_equal(host.get_final, STUB_ATOMIC_SET + STUB_ATOMIC_ADD - STUB_ATOMIC_SUB); + + zassert_equal(host.read_after_init, zephyr.read_after_init); + zassert_equal(host.set_ret, zephyr.set_ret); + zassert_equal(host.add_ret, zephyr.add_ret); + zassert_equal(host.sub_ret, zephyr.sub_ret); + zassert_equal(host.get_final, zephyr.get_final); +} + +ZTEST(host_stubs, test_cache_like_zephyr) +{ + static char buf[64]; + int host[STUB_CACHE_FUNCS]; + int zephyr[STUB_CACHE_FUNCS] = { + sys_cache_data_flush_range(buf, sizeof(buf)), + sys_cache_data_invd_range(buf, sizeof(buf)), + sys_cache_data_flush_and_invd_range(buf, sizeof(buf)), + sys_cache_instr_invd_range(buf, sizeof(buf)), + }; + + host_stub_cache(host); + + for (int i = 0; i < STUB_CACHE_FUNCS; i++) { + /* native_sim has no cache management, like the host */ + zassert_equal(host[i], -ENOTSUP, "function %d", i); + zassert_equal(host[i], zephyr[i], "function %d", i); + } +} + +ZTEST(host_stubs, test_assert_pass) +{ + zassert_equal(host_stub_assert_no_msg(1), 0); + zassert_equal(host_stub_assert_msg(1), 0); + zassert_equal(host_stub_assert_no_fmt(1), 0); + zassert_equal(host_stub_assert_var_fmt(1), 0); +} + +ZTEST(host_stubs, test_assert_fail_panics) +{ + zassert_equal(host_stub_assert_no_msg(0), SOF_IPC_PANIC_ASSERT); + zassert_equal(host_stub_assert_msg(0), SOF_IPC_PANIC_ASSERT); + zassert_equal(host_stub_assert_no_fmt(0), SOF_IPC_PANIC_ASSERT); + zassert_equal(host_stub_assert_var_fmt(0), SOF_IPC_PANIC_ASSERT); +} + +ZTEST(host_stubs, test_assert_evaluates_once) +{ + zassert_equal(host_stub_assert_eval_count(), 1); +} + +ZTEST(host_stubs, test_k_panic) +{ + zassert_equal(host_stub_k_panic(), SOF_IPC_PANIC_ASSERT); +} + +ZTEST_SUITE(host_stubs, NULL, NULL, NULL, NULL, NULL); diff --git a/test/ztest/unit/host_stubs/testcase.yaml b/test/ztest/unit/host_stubs/testcase.yaml new file mode 100644 index 000000000000..9cff19adf32a --- /dev/null +++ b/test/ztest/unit/host_stubs/testcase.yaml @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. +# +# Checks that the posix/include stubs of Zephyr APIs, used by the non-Zephyr +# host builds, behave like Zephyr + +tests: + sof.unit.host_stubs: + tags: unit + platform_allow: native_sim + integration_platforms: + - native_sim + build_only: false From 59501d02ff67ce7f55577c006b093e3433f6731d Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Dec 2026 22:26:21 +0000 Subject: [PATCH 05/10] posix: provide the Zephyr assert macros from rtos/panic.h On Zephyr, rtos/panic.h includes , so code that includes it for assert() also gets __ASSERT() and __ASSERT_NO_MSG(). Include the stub from the host rtos/panic.h, so that shared code can switch to the Zephyr macros without new includes. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/rtos/panic.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/posix/include/rtos/panic.h b/posix/include/rtos/panic.h index 2ba24eed48bc..6310921d0ba3 100644 --- a/posix/include/rtos/panic.h +++ b/posix/include/rtos/panic.h @@ -49,4 +49,10 @@ void __panic(uint32_t p, const char *filename, uint32_t linenum) SOF_NORETURN; #define assert(cond) (void)((cond) || (sof_panic(SOF_IPC_PANIC_ASSERT), 0)) #endif +/* + * The Zephyr assert macros. On Zephyr, rtos/panic.h provides them through + * . + */ +#include + #endif /* __POSIX_RTOS_PANIC_H__ */ From d820546c811bfd8e4713d57da4a48ba4db9790b5 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Dec 2026 22:27:05 +0000 Subject: [PATCH 06/10] audio: use __ASSERT_NO_MSG() instead of assert() On Zephyr, assert() is defined as __ASSERT_NO_MSG(). The host builds now have the Zephyr assert macros too, so use __ASSERT_NO_MSG() directly in the audio code. No lines are added or removed, so __LINE__ in verbose asserts does not change. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/audio/asrc/asrc.c | 4 ++-- src/audio/buffers/audio_buffer.c | 2 +- src/audio/buffers/comp_buffer.c | 12 +++++------ src/audio/buffers/ring_buffer.c | 2 +- src/audio/component.c | 4 ++-- src/audio/copier/copier_dai.c | 2 +- src/audio/copier/copier_generic.c | 2 +- src/audio/crossover/crossover.c | 4 ++-- src/audio/dai-zephyr.c | 6 +++--- src/audio/data_blob.c | 20 +++++++++---------- src/audio/dsrc.c | 4 ++-- src/audio/eq_iir/eq_iir.c | 2 +- .../google/google_rtc_audio_processing.c | 4 ++-- src/audio/intel_uaol.c | 20 +++++++++---------- src/audio/kpb.c | 2 +- src/audio/mixin_mixout/mixin_mixout.c | 6 +++--- src/audio/mixin_mixout/mixin_mixout_arm.c | 16 +++++++-------- src/audio/mixin_mixout/mixin_mixout_generic.c | 16 +++++++-------- src/audio/mixin_mixout/mixin_mixout_hifi3.c | 18 ++++++++--------- src/audio/mixin_mixout/mixin_mixout_hifi5.c | 18 ++++++++--------- src/audio/module_adapter/module/generic.c | 4 ++-- .../module_adapter/module_adapter_ipc4.c | 6 +++--- src/audio/multiband_drc/multiband_drc.c | 2 +- src/audio/pipeline/pipeline-schedule.c | 4 ++-- src/audio/selector/selector.c | 4 ++-- src/audio/sink_source_utils.c | 4 ++-- src/audio/smart_amp/smart_amp.c | 6 +++--- src/audio/smart_amp/smart_amp_maxim_dsm.c | 2 +- src/audio/volume/volume_ipc4.c | 2 +- 29 files changed, 99 insertions(+), 99 deletions(-) diff --git a/src/audio/asrc/asrc.c b/src/audio/asrc/asrc.c index a62e968d3360..4241daa8b5d6 100644 --- a/src/audio/asrc/asrc.c +++ b/src/audio/asrc/asrc.c @@ -138,7 +138,7 @@ static void src_copy_s16(struct processing_module *mod, n_copy = (n < n_wrap_src) ? n : n_wrap_src; s_copy = n_copy * sizeof(int16_t); ret = memcpy_s(buf, s_copy, src, s_copy); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* Update and check both source and destination for wrap */ n -= n_copy; @@ -172,7 +172,7 @@ static void src_copy_s16(struct processing_module *mod, n_copy = (n < n_wrap_snk) ? n : n_wrap_snk; s_copy = n_copy * sizeof(int16_t); ret = memcpy_s(snk, s_copy, buf, s_copy); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* Update and check both source and destination for wrap */ n -= n_copy; diff --git a/src/audio/buffers/audio_buffer.c b/src/audio/buffers/audio_buffer.c index 1ecf8472dd65..5ff58e8f0648 100644 --- a/src/audio/buffers/audio_buffer.c +++ b/src/audio/buffers/audio_buffer.c @@ -226,7 +226,7 @@ void audio_buffer_init(struct sof_audio_buffer *buffer, uint32_t buffer_type, bo CORE_CHECK_STRUCT_INIT(buffer, is_shared); buffer->buffer_type = buffer_type; buffer->ops = audio_buffer_ops; - assert(audio_buffer_ops->free); + __ASSERT_NO_MSG(audio_buffer_ops->free); buffer->audio_stream_params = audio_stream_params; buffer->is_shared = is_shared; diff --git a/src/audio/buffers/comp_buffer.c b/src/audio/buffers/comp_buffer.c index 7c08d1f32f25..1c5f8bbf19f2 100644 --- a/src/audio/buffers/comp_buffer.c +++ b/src/audio/buffers/comp_buffer.c @@ -184,7 +184,7 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer) struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc; - assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); + __ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); if (alloc) sof_ctx_free(alloc, buffer->stream.addr); @@ -292,7 +292,7 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3 return NULL; } - assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); + __ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); if (alloc) stream_addr = sof_ctx_alloc(alloc, flags, size, align); @@ -340,7 +340,7 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe if (preferred_size % minimum_size) preferred_size += minimum_size - preferred_size % minimum_size; - assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); + __ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); for (size = preferred_size; size >= minimum_size; size -= minimum_size) { if (alloc) @@ -403,7 +403,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen if (size == audio_stream_get_size(&buffer->stream)) return 0; - assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); + __ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); if (alloc) new_ptr = sof_ctx_alloc(alloc, buffer->flags, size, alignment); @@ -458,7 +458,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz if (preferred_size == actual_size) return 0; - assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); + __ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc); for (new_size = preferred_size; new_size >= minimum_size; new_size -= minimum_size) { @@ -530,7 +530,7 @@ EXPORT_SYMBOL(buffer_set_params); bool buffer_params_match(struct comp_buffer *buffer, struct sof_ipc_stream_params *params, uint32_t flag) { - assert(params); + __ASSERT_NO_MSG(params); CORE_CHECK_STRUCT(&buffer->audio_buffer); if ((flag & BUFF_PARAMS_FRAME_FMT) && diff --git a/src/audio/buffers/ring_buffer.c b/src/audio/buffers/ring_buffer.c index fde594d32424..a01941a60197 100644 --- a/src/audio/buffers/ring_buffer.c +++ b/src/audio/buffers/ring_buffer.c @@ -136,7 +136,7 @@ uint8_t __sparse_cache *ring_buffer_get_pointer(struct ring_buffer *ring_buffer, static inline size_t ring_buffer_inc_offset(struct ring_buffer *ring_buffer, size_t offset, size_t inc) { - assert(inc <= ring_buffer->data_buffer_size); + __ASSERT_NO_MSG(inc <= ring_buffer->data_buffer_size); offset += inc; /* wrap around ? 2*size because of "double area" */ if (offset >= 2 * ring_buffer->data_buffer_size) diff --git a/src/audio/component.c b/src/audio/component.c index e2e670670126..4f34294e1d2a 100644 --- a/src/audio/component.c +++ b/src/audio/component.c @@ -40,7 +40,7 @@ static APP_SYSUSER_BSS struct comp_driver_list cd; #ifdef CONFIG_SOF_USERSPACE_LL struct comp_driver_list *comp_drivers_get(void) { - assert(!ll_sch_is_current()); + __ASSERT_NO_MSG(!ll_sch_is_current()); return &cd; } #endif @@ -586,7 +586,7 @@ int comp_copy(struct comp_dev *dev) { int ret = 0; - assert(dev->drv->ops.copy); + __ASSERT_NO_MSG(dev->drv->ops.copy); /* copy only if we are the owner of component OR this is DP component * diff --git a/src/audio/copier/copier_dai.c b/src/audio/copier/copier_dai.c index 508972b4773c..acd629ef50ad 100644 --- a/src/audio/copier/copier_dai.c +++ b/src/audio/copier/copier_dai.c @@ -541,7 +541,7 @@ void copier_dai_adjust_params(const struct copier_data *cd, int dma_buf_container_bits, dma_buf_valid_bits; /* Call this func only for DAI gateway with already setup DMA buffer */ - assert(cd->dd[0] && cd->dd[0]->dma_buffer); + __ASSERT_NO_MSG(cd->dd[0] && cd->dd[0]->dma_buffer); dma_buf = cd->dd[0]->dma_buffer; /* Unfortunately, configuring the gateway DMA buffer format is somewhat confusing. diff --git a/src/audio/copier/copier_generic.c b/src/audio/copier/copier_generic.c index 075066a57159..6e97c7640f4c 100644 --- a/src/audio/copier/copier_generic.c +++ b/src/audio/copier/copier_generic.c @@ -517,7 +517,7 @@ static bool is_remapping_chmap(uint32_t chmap, size_t out_channel_count) { size_t i; - assert(out_channel_count <= 8); + __ASSERT_NO_MSG(out_channel_count <= 8); for (i = 0; i < out_channel_count; i++) { if ((chmap & 0xf) != i) diff --git a/src/audio/crossover/crossover.c b/src/audio/crossover/crossover.c index 84cc3606dd12..44df0404ce6f 100644 --- a/src/audio/crossover/crossover.c +++ b/src/audio/crossover/crossover.c @@ -178,13 +178,13 @@ static int crossover_init_coef_lr4(struct processing_module *mod, /* coefficients of the first biquad */ ret = memcpy_s(lr4->coef, sizeof(struct sof_eq_iir_biquad), coef, sizeof(struct sof_eq_iir_biquad)); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* coefficients of the second biquad */ ret = memcpy_s(lr4->coef + SOF_EQ_IIR_NBIQUAD, sizeof(struct sof_eq_iir_biquad), coef, sizeof(struct sof_eq_iir_biquad)); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* LR4 filters are two 2nd order filters, so only need 4 delay slots * delay[0..1] -> state for first biquad diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index dc7c5542a81a..ea0569606a4b 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -550,7 +550,7 @@ dai_dma_multi_endpoint_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t fr if (dev->direction == SOF_IPC_STREAM_CAPTURE) audio_stream_invalidate(&dd->dma_buffer->stream, bytes); - assert(dd->channel_copy); + __ASSERT_NO_MSG(dd->channel_copy); /* copy all channels one by one */ for (i = 0; i < audio_stream_get_channels(&dd->dma_buffer->stream); i++) { @@ -1948,8 +1948,8 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun } } - assert(audio_stream_get_channels(&dd->dma_buffer->stream)); - assert(audio_stream_get_channels(&dd->local_buffer->stream)); + __ASSERT_NO_MSG(audio_stream_get_channels(&dd->dma_buffer->stream)); + __ASSERT_NO_MSG(audio_stream_get_channels(&dd->local_buffer->stream)); /* calculate minimum size to copy */ if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { diff --git a/src/audio/data_blob.c b/src/audio/data_blob.c index 530487f2f330..95b6f19ab410 100644 --- a/src/audio/data_blob.c +++ b/src/audio/data_blob.c @@ -40,7 +40,7 @@ struct comp_data_blob_handler { static void comp_free_data_blob(struct comp_data_blob_handler *blob_handler) { - assert(blob_handler); + __ASSERT_NO_MSG(blob_handler); if (!blob_handler->data) return; @@ -56,7 +56,7 @@ void comp_data_blob_set_validator(struct comp_data_blob_handler *blob_handler, int (*validator)(struct comp_dev *dev, void *new_data, uint32_t new_data_size)) { - assert(blob_handler); + __ASSERT_NO_MSG(blob_handler); blob_handler->validator = validator; } @@ -65,7 +65,7 @@ EXPORT_SYMBOL(comp_data_blob_set_validator); void *comp_get_data_blob(struct comp_data_blob_handler *blob_handler, size_t *size, uint32_t *crc) { - assert(blob_handler); + __ASSERT_NO_MSG(blob_handler); comp_dbg(blob_handler->dev, "comp_get_data_blob()"); @@ -110,7 +110,7 @@ EXPORT_SYMBOL(comp_get_data_blob); bool comp_is_new_data_blob_available(struct comp_data_blob_handler *blob_handler) { - assert(blob_handler); + __ASSERT_NO_MSG(blob_handler); comp_dbg(blob_handler->dev, "entry"); @@ -139,7 +139,7 @@ __cold int comp_init_data_blob(struct comp_data_blob_handler *blob_handler, assert_can_be_cold(); - assert(blob_handler); + __ASSERT_NO_MSG(blob_handler); comp_free_data_blob(blob_handler); @@ -158,7 +158,7 @@ __cold int comp_init_data_blob(struct comp_data_blob_handler *blob_handler, */ if (init_data) { ret = memcpy_s(blob_handler->data, size, init_data, size); - assert(!ret); + __ASSERT_NO_MSG(!ret); } else { bzero(blob_handler->data, size); } @@ -332,7 +332,7 @@ __cold int ipc4_comp_data_blob_set(struct comp_data_blob_handler *blob_handler, assert_can_be_cold(); - assert(blob_handler); + __ASSERT_NO_MSG(blob_handler); comp_dbg(blob_handler->dev, "data_offset = %d", @@ -474,7 +474,7 @@ __cold int comp_data_blob_set_cmd(struct comp_data_blob_handler *blob_handler, assert_can_be_cold(); - assert(blob_handler); + __ASSERT_NO_MSG(blob_handler); comp_dbg(blob_handler->dev, "msg_index = %d, num_elems = %d, remaining = %d ", cdata->msg_index, cdata->num_elems, @@ -619,7 +619,7 @@ __cold int comp_data_blob_get_cmd(struct comp_data_blob_handler *blob_handler, assert_can_be_cold(); - assert(blob_handler); + __ASSERT_NO_MSG(blob_handler); if (cdata->cmd != SOF_CTRL_CMD_BINARY) { comp_err(blob_handler->dev, "comp_data_blob_set_cmd(), illegal control command"); @@ -664,7 +664,7 @@ __cold int comp_data_blob_get_cmd(struct comp_data_blob_handler *blob_handler, ret = memcpy_s(cdata->data->data, size, (char *)blob_handler->data + blob_handler->data_pos, cdata->num_elems); - assert(!ret); + __ASSERT_NO_MSG(!ret); cdata->data->abi = SOF_ABI_VERSION; cdata->data->size = blob_handler->data_size; diff --git a/src/audio/dsrc.c b/src/audio/dsrc.c index de1fdcf4c7f6..f309c8fc0c8a 100644 --- a/src/audio/dsrc.c +++ b/src/audio/dsrc.c @@ -20,7 +20,7 @@ void dsrc_set_rate(struct dsrc *dsrc, uint32_t in_rate, uint32_t out_rate) if (out_rate > in_rate) max_phase = ((uint64_t)in_rate << 32) / (out_rate - in_rate); else - assert(out_rate == in_rate); + __ASSERT_NO_MSG(out_rate == in_rate); if (max_phase == dsrc->max_phase) return; @@ -30,7 +30,7 @@ void dsrc_set_rate(struct dsrc *dsrc, uint32_t in_rate, uint32_t out_rate) uint32_t new_32 = max_phase >> 32; /* Used below as divisors, non-zero as long as out_rate <= 2 * in_rate */ - assert(old_32 && new_32); + __ASSERT_NO_MSG(old_32 && new_32); /* Keep the same fractional delay, and phase_acc below the new max_phase */ dsrc->phase_acc = ((dsrc->phase_acc >> 32) * new_32 / old_32) << 32; diff --git a/src/audio/eq_iir/eq_iir.c b/src/audio/eq_iir/eq_iir.c index d59258e22514..e210fd51aaff 100644 --- a/src/audio/eq_iir/eq_iir.c +++ b/src/audio/eq_iir/eq_iir.c @@ -339,7 +339,7 @@ void eq_iir_pass(struct processing_module *mod, const struct cir_buf_source *sou } ret = memcpy_s(dst, dst_contiguous, src, copy); - assert(!ret); + __ASSERT_NO_MSG(!ret); bytes -= copy; src = source_cir_buf_wrap(src + copy, source->buf_start, source->buf_end); dst = cir_buf_wrap(dst + copy, sink->buf_start, sink->buf_end); diff --git a/src/audio/google/google_rtc_audio_processing.c b/src/audio/google/google_rtc_audio_processing.c index 28e36f3eb430..5d50a540c10b 100644 --- a/src/audio/google/google_rtc_audio_processing.c +++ b/src/audio/google/google_rtc_audio_processing.c @@ -159,7 +159,7 @@ static ALWAYS_INLINE void source_to_float(struct sof_source *src, float **dst_bu dst[i] = &dst_bufs[i][frame0]; err = source_get_data(src, bytes, (void *)&buf, (void *)&bufstart, &bufsz); - assert(err == 0); + __ASSERT_NO_MSG(err == 0); bufend = &bufstart[bufsz]; while (frames) { @@ -194,7 +194,7 @@ static ALWAYS_INLINE void float_to_sink(struct sof_sink *dst, float **src_bufs, src[i] = &src_bufs[i][0]; err = sink_get_buffer(dst, bytes, (void *)&buf, (void *)&bufstart, &bufsz); - assert(err == 0); + __ASSERT_NO_MSG(err == 0); bufend = &bufstart[bufsz]; while (frames) { diff --git a/src/audio/intel_uaol.c b/src/audio/intel_uaol.c index ebe77b487698..c88cbb8ec9dd 100644 --- a/src/audio/intel_uaol.c +++ b/src/audio/intel_uaol.c @@ -27,7 +27,7 @@ const struct device *const uaol_devs[] = { const struct device *get_uaol_zdevice(int uaol_link_id) { /* uaol_link_id is just an index for the device tree device */ - assert(uaol_link_id < ARRAY_SIZE(uaol_devs)); + __ASSERT_NO_MSG(uaol_link_id < ARRAY_SIZE(uaol_devs)); return uaol_devs[uaol_link_id]; } @@ -58,7 +58,7 @@ int dai_get_uaol_stream_id(struct dai *dai, int *uaol_link_id, int *uaol_stream_ */ void process_uaol_feedback(struct comp_dev *dev, struct dai_data *dd) { - assert(dd && dd->uaol.fb_chan_idx >= 0 && dd->uaol.fb_dma_buf); + __ASSERT_NO_MSG(dd && dd->uaol.fb_chan_idx >= 0 && dd->uaol.fb_dma_buf); struct dma_status stat = {0}; int ret = sof_dma_get_status(dd->uaol.fb_dma, dd->uaol.fb_chan_idx, &stat); @@ -71,11 +71,11 @@ void process_uaol_feedback(struct comp_dev *dev, struct dai_data *dd) if (stat.pending_length < 4) return; /* No feedback is normal as it might be sent rarely. */ - assert(is_uncached(dd->uaol.fb_dma_buf)); /* Use uncached pointer to read DMA buffer */ - assert(dd->uaol.fb_dma_buf_size >= 4); + __ASSERT_NO_MSG(is_uncached(dd->uaol.fb_dma_buf)); /* DMA buffer is read uncached */ + __ASSERT_NO_MSG(dd->uaol.fb_dma_buf_size >= 4); /* NOTE: Not all DMA drivers populate stat.write_position. Intel ACE HDA does. */ - assert((stat.write_position & 3) == 0); /* 4-byte alignment check. */ + __ASSERT_NO_MSG((stat.write_position & 3) == 0); /* 4-byte alignment check. */ /* Read the last received 4 bytes (ignore older ones if any). */ int last_4_bytes_pos = stat.write_position >= 4 ? (stat.write_position - 4) : (dd->uaol.fb_dma_buf_size - 4); @@ -145,7 +145,7 @@ int uaol_dma_buffer_copy_to(struct dai_data *dd, size_t dma_bytes) { int ret = 0; - assert(dd->uaol.feedback_drift != 0); + __ASSERT_NO_MSG(dd->uaol.feedback_drift != 0); if (dd->uaol.feedback_drift > 0) { size_t frames = dma_bytes / audio_stream_frame_bytes(&dd->dma_buffer->stream); @@ -155,7 +155,7 @@ int uaol_dma_buffer_copy_to(struct dai_data *dd, size_t dma_bytes) struct cir_buf_ptr in = { dd->local_buffer->stream.addr, dd->local_buffer->stream.end_addr, dd->local_buffer->stream.r_ptr }; - assert(dd->uaol.dsrc_buf); + __ASSERT_NO_MSG(dd->uaol.dsrc_buf); struct cir_buf_ptr out = { dd->uaol.dsrc_buf->stream.addr, dd->uaol.dsrc_buf->stream.end_addr, dd->uaol.dsrc_buf->stream.w_ptr }; @@ -179,7 +179,7 @@ int uaol_dma_buffer_copy_to(struct dai_data *dd, size_t dma_bytes) } else if (dd->uaol.feedback_drift < 0) { /* It is expected this func is called every 1 ms */ dd->uaol.ms_since_last_adjustment++; - assert(dd->uaol.feedback_drift < 0 && dd->uaol.feedback_drift >= -1000); + __ASSERT_NO_MSG(dd->uaol.feedback_drift < 0 && dd->uaol.feedback_drift >= -1000); if (dd->uaol.ms_since_last_adjustment >= -1000 / dd->uaol.feedback_drift) { dd->uaol.ms_since_last_adjustment = 0; adjust_uaol_rate(dd, false); @@ -213,7 +213,7 @@ int setup_uaol_feedback_dma(struct dai_data *dd, struct comp_dev *dev) return 0; /* UAOL feedback is an optional 2nd DMA link (1st is audio DMA link) */ - assert(GTW_DMA_DEVICE_MAX_COUNT >= 2); + __ASSERT_NO_MSG(GTW_DMA_DEVICE_MAX_COUNT >= 2); if (!dai->host_dma_config[1] || !dai->host_dma_config[1]->pre_allocated_by_host) { comp_info(dev, "No UAOL feedback DMA link supplied by host."); return 0; @@ -306,7 +306,7 @@ int setup_uaol_feedback_dma(struct dai_data *dd, struct comp_dev *dev) dma_cfg->head_block->next_block = dma_cfg->head_block; /* dai_common_params() must have created the DMA buffer already */ - assert(dd->dma_buffer); + __ASSERT_NO_MSG(dd->dma_buffer); /* dai_common_copy() keeps one free DMA frame for the DSRC-inserted one, so a copy * never exceeds the DMA buffer size in frames */ diff --git a/src/audio/kpb.c b/src/audio/kpb.c index f0f3ff743584..084f381c1d9f 100644 --- a/src/audio/kpb.c +++ b/src/audio/kpb.c @@ -1963,7 +1963,7 @@ static void adjust_drain_interval(struct comp_data *kpb, struct draining_data *d drained = dd->drained - dd->prev_adjustment_drained; elapsed = now - dd->prev_adjustment_time; - assert(elapsed); + __ASSERT_NO_MSG(elapsed); /* average drained bytes per second */ actual_pace = (size_t)k_ms_to_cyc_ceil64(1000) / elapsed * drained; diff --git a/src/audio/mixin_mixout/mixin_mixout.c b/src/audio/mixin_mixout/mixin_mixout.c index 60a5be20a782..04226caed7c4 100644 --- a/src/audio/mixin_mixout/mixin_mixout.c +++ b/src/audio/mixin_mixout/mixin_mixout.c @@ -221,7 +221,7 @@ static void silence(struct cir_buf_ptr *stream, uint32_t start_offset, uint8_t *ptr; int n; - assert(mixed_bytes >= start_offset); + __ASSERT_NO_MSG(mixed_bytes >= start_offset); skip_mixed_bytes = mixed_bytes - start_offset; if (size <= skip_mixed_bytes) @@ -385,7 +385,7 @@ static int mixin_process(struct processing_module *mod, * consumed and written there by mixin on previous mixin_process() run. * We do NOT want to overwrite that data. */ - assert(free_frames >= pending_frames->frames); + __ASSERT_NO_MSG(free_frames >= pending_frames->frames); sinks_free_frames = MIN(sinks_free_frames, free_frames - pending_frames->frames); } @@ -564,7 +564,7 @@ static int mixout_process(struct processing_module *mod, pending_frames->frames = 0; } - assert(md->mixed_frames >= frames_to_produce); + __ASSERT_NO_MSG(md->mixed_frames >= frames_to_produce); md->mixed_frames -= frames_to_produce; bytes_to_produce = frames_to_produce * sink_get_frame_bytes(sinks[0]); diff --git a/src/audio/mixin_mixout/mixin_mixout_arm.c b/src/audio/mixin_mixout/mixin_mixout_arm.c index aca7eba7dbfe..871f39eded15 100644 --- a/src/audio/mixin_mixout/mixin_mixout_arm.c +++ b/src/audio/mixin_mixout/mixin_mixout_arm.c @@ -23,7 +23,7 @@ static void mix_s16(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int16_t *dst = (int16_t *)sink->ptr + start_sample; int16_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -77,7 +77,7 @@ static void mix_s16_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t int16_t *dst = (int16_t *)sink->ptr + start_sample; int16_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -146,7 +146,7 @@ static void mix_s24(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -197,7 +197,7 @@ static void mix_s24_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -265,7 +265,7 @@ static void mix_s32(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -315,7 +315,7 @@ static void mix_s32_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -383,7 +383,7 @@ static void mix_float(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mi float *dst = (float *)sink->ptr + start_sample; const float *src = (const float *)source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -432,7 +432,7 @@ static void mix_float_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32 const float *src = (const float *)source->ptr; const float gain_f = (float)gain * (1.0f / (float)IPC4_MIXIN_UNITY_GAIN); - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; diff --git a/src/audio/mixin_mixout/mixin_mixout_generic.c b/src/audio/mixin_mixout/mixin_mixout_generic.c index 5d3852217dae..7bc490936d75 100644 --- a/src/audio/mixin_mixout/mixin_mixout_generic.c +++ b/src/audio/mixin_mixout/mixin_mixout_generic.c @@ -23,7 +23,7 @@ static void mix_s16(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int16_t *dst = (int16_t *)sink->ptr + start_sample; int16_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -74,7 +74,7 @@ static void mix_s16_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t int16_t *dst = (int16_t *)sink->ptr + start_sample; int16_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -141,7 +141,7 @@ static void mix_s24(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -191,7 +191,7 @@ static void mix_s24_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -261,7 +261,7 @@ static void mix_s32(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -310,7 +310,7 @@ static void mix_s32_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -375,7 +375,7 @@ static void mix_float(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mi float *dst = (float *)sink->ptr + start_sample; const float *src = (const float *)source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; @@ -424,7 +424,7 @@ static void mix_float_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32 const float *src = (const float *)source->ptr; const float gain_f = (float)gain * (1.0f / (float)IPC4_MIXIN_UNITY_GAIN); - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = mixed_samples - start_sample; samples_to_mix = MIN(samples_to_mix, sample_count); samples_to_copy = sample_count - samples_to_mix; diff --git a/src/audio/mixin_mixout/mixin_mixout_hifi3.c b/src/audio/mixin_mixout/mixin_mixout_hifi3.c index 40962339dbce..fd5cfd89db05 100644 --- a/src/audio/mixin_mixout/mixin_mixout_hifi3.c +++ b/src/audio/mixin_mixout/mixin_mixout_hifi3.c @@ -30,7 +30,7 @@ static void mix_s16(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe ae_int16 *dst = (ae_int16 *)sink->ptr + start_sample; ae_int16 *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN_32_signed(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -119,12 +119,12 @@ static void mix_s16_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t ae_f16x4 gain_vec; /* this func does not support unity gain as 1 cannot be represented as Q1.15 value */ - assert(gain < IPC4_MIXIN_UNITY_GAIN); + __ASSERT_NO_MSG(gain < IPC4_MIXIN_UNITY_GAIN); gain_vec = AE_L16_I((ae_int16 *)&gain, 0); gain_vec = AE_SLAI16S(gain_vec, 5); /* convert to Q1.15 */ - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN_32_signed(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -218,7 +218,7 @@ static void mix_s24(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN_32_signed(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -310,12 +310,12 @@ static void mix_s24_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t ae_int32 gain32 = (ae_int32)gain; /* this func does not support unity gain as 1 cannot be represented as Q1.23 value */ - assert(gain < IPC4_MIXIN_UNITY_GAIN); + __ASSERT_NO_MSG(gain < IPC4_MIXIN_UNITY_GAIN); gain_vec = AE_MOVF24X2_FROMINT32X2(AE_L32_I(&gain32, 0)); gain_vec = AE_SLAI24S(gain_vec, 13); /* convert to Q1.23 */ - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN_32_signed(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -404,7 +404,7 @@ static void mix_s32(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN_32_signed(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -487,12 +487,12 @@ static void mix_s32_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t ae_f16x4 gain_vec; /* this func does not support unity gain as 1 cannot be represented as Q1.15 value */ - assert(gain < IPC4_MIXIN_UNITY_GAIN); + __ASSERT_NO_MSG(gain < IPC4_MIXIN_UNITY_GAIN); gain_vec = AE_L16_I((ae_int16 *)&gain, 0); gain_vec = AE_SLAI16S(gain_vec, 5); /* convert to Q1.15 */ - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN_32_signed(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; diff --git a/src/audio/mixin_mixout/mixin_mixout_hifi5.c b/src/audio/mixin_mixout/mixin_mixout_hifi5.c index 7e42e0f8d376..e1e83e19d180 100644 --- a/src/audio/mixin_mixout/mixin_mixout_hifi5.c +++ b/src/audio/mixin_mixout/mixin_mixout_hifi5.c @@ -28,7 +28,7 @@ static void mix_s16(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe ae_int16 *dst = (ae_int16 *)sink->ptr + start_sample; ae_int16 *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN32(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -118,12 +118,12 @@ static void mix_s16_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t ae_f16x4 gain_vec; /* this func does not support unity gain as 1 cannot be represented as Q1.15 value */ - assert(gain < IPC4_MIXIN_UNITY_GAIN); + __ASSERT_NO_MSG(gain < IPC4_MIXIN_UNITY_GAIN); gain_vec = AE_L16_I((ae_int16 *)&gain, 0); gain_vec = AE_SLAI16S(gain_vec, 5); /* convert to Q1.15 */ - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN32(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -219,7 +219,7 @@ static void mix_s24(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN32(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -314,12 +314,12 @@ static void mix_s24_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t ae_int32 gain32 = (ae_int32)gain; /* this func does not support unity gain as 1 cannot be represented as Q1.23 value */ - assert(gain < IPC4_MIXIN_UNITY_GAIN); + __ASSERT_NO_MSG(gain < IPC4_MIXIN_UNITY_GAIN); gain_vec = AE_MOVF24X2_FROMINT32X2(AE_L32_I(&gain32, 0)); gain_vec = AE_SLAI24S(gain_vec, 13); /* convert to Q1.23 */ - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN32(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -410,7 +410,7 @@ static void mix_s32(struct cir_buf_ptr *sink, int32_t start_sample, int32_t mixe int32_t *dst = (int32_t *)sink->ptr + start_sample; int32_t *src = source->ptr; - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN32(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; @@ -493,12 +493,12 @@ static void mix_s32_gain(struct cir_buf_ptr *sink, int32_t start_sample, int32_t ae_f16x4 gain_vec; /* this func does not support unity gain as 1 cannot be represented as Q1.15 value */ - assert(gain < IPC4_MIXIN_UNITY_GAIN); + __ASSERT_NO_MSG(gain < IPC4_MIXIN_UNITY_GAIN); gain_vec = AE_L16_I((ae_int16 *)&gain, 0); gain_vec = AE_SLAI16S(gain_vec, 5); /* convert to Q1.15 */ - assert(mixed_samples >= start_sample); + __ASSERT_NO_MSG(mixed_samples >= start_sample); samples_to_mix = AE_MIN32(mixed_samples - start_sample, sample_count); samples_to_copy = sample_count - samples_to_mix; n = 0; diff --git a/src/audio/module_adapter/module/generic.c b/src/audio/module_adapter/module/generic.c index 219054dbd1de..5c4366943877 100644 --- a/src/audio/module_adapter/module/generic.c +++ b/src/audio/module_adapter/module/generic.c @@ -174,7 +174,7 @@ __cold int module_load_config(struct comp_dev *dev, const void *cfg, size_t size } ret = memcpy_s(dst->data, size, cfg, size); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* Config loaded, mark it as valid */ dst->size = size; @@ -1002,7 +1002,7 @@ int module_process_sink_src(struct processing_module *mod, /* set state to processing */ md->state = MODULE_PROCESSING; #endif - assert(ops->process); + __ASSERT_NO_MSG(ops->process); ret = ops->process(mod, sources, num_of_sources, sinks, num_of_sinks); if (ret && ret != -ENOSPC && ret != -ENODATA) { diff --git a/src/audio/module_adapter/module_adapter_ipc4.c b/src/audio/module_adapter/module_adapter_ipc4.c index 2eff3051a058..77dda88e1bab 100644 --- a/src/audio/module_adapter/module_adapter_ipc4.c +++ b/src/audio/module_adapter/module_adapter_ipc4.c @@ -39,7 +39,7 @@ __cold int module_ext_init_decode(const struct comp_driver *drv, assert_can_be_cold(); - assert(drv->type == SOF_COMP_MODULE_ADAPTER); + __ASSERT_NO_MSG(drv->type == SOF_COMP_MODULE_ADAPTER); /* Validate size before dereferencing ext_init pointer */ if (spec->size < sizeof(*ext_init)) { @@ -120,7 +120,7 @@ __cold int module_ext_init_decode(const struct comp_driver *drv, * obj never advances past spec->data + spec->size */ consumed = (unsigned char *)obj - spec->data; - assert(consumed <= spec->size); + __ASSERT_NO_MSG(consumed <= spec->size); spec->size -= consumed; spec->data = (const unsigned char *)obj; @@ -167,7 +167,7 @@ __cold int module_adapter_init_data(struct comp_dev *dev, assert_can_be_cold(); - assert(dev->drv->type == SOF_COMP_MODULE_ADAPTER); + __ASSERT_NO_MSG(dev->drv->type == SOF_COMP_MODULE_ADAPTER); cfg = (const struct ipc4_base_module_extended_cfg *)args->data; if (cfg == NULL) diff --git a/src/audio/multiband_drc/multiband_drc.c b/src/audio/multiband_drc/multiband_drc.c index f884e59bd263..826dae454a61 100644 --- a/src/audio/multiband_drc/multiband_drc.c +++ b/src/audio/multiband_drc/multiband_drc.c @@ -76,7 +76,7 @@ static int multiband_drc_eq_init_coef_ch(struct processing_module *mod, /* Coefficients of the first biquad and second biquad */ ret = memcpy_s(eq->coef, sizeof(struct sof_eq_iir_biquad) * SOF_EMP_DEEMP_BIQUADS, coef, sizeof(struct sof_eq_iir_biquad) * SOF_EMP_DEEMP_BIQUADS); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* EQ filters are two 2nd order filters, so only need 4 delay slots * delay[0..1] -> state for first biquad diff --git a/src/audio/pipeline/pipeline-schedule.c b/src/audio/pipeline/pipeline-schedule.c index 63b9fd979088..c444daee258b 100644 --- a/src/audio/pipeline/pipeline-schedule.c +++ b/src/audio/pipeline/pipeline-schedule.c @@ -427,8 +427,8 @@ void pipeline_schedule_triggered(struct pipeline_walk_context *ctx, * is expected in the pipelines list (it's unclear whether an empty list * should be tolerated). */ - assert(list_is_empty(&ctx->pipelines) || - list_item_is_last(ctx->pipelines.next, &ctx->pipelines)); + __ASSERT_NO_MSG(list_is_empty(&ctx->pipelines) || + list_item_is_last(ctx->pipelines.next, &ctx->pipelines)); #endif /* diff --git a/src/audio/selector/selector.c b/src/audio/selector/selector.c index 25824f345f1e..9ba8f22520b5 100644 --- a/src/audio/selector/selector.c +++ b/src/audio/selector/selector.c @@ -357,7 +357,7 @@ static int selector_ctrl_get_data(struct comp_dev *dev, ret = memcpy_s(cdata->data->data, size, &cd->config, sizeof(cd->config)); - assert(!ret); + __ASSERT_NO_MSG(!ret); cdata->data->abi = SOF_ABI_VERSION; cdata->data->size = sizeof(cd->config); @@ -735,7 +735,7 @@ static int selector_init(struct processing_module *mod) ret = memcpy_s(&cd->sel_ipc4_cfg.output_format, bs[1], &init_cfg_out_fmt->output_format, bs[1]); } - assert(!ret); + __ASSERT_NO_MSG(!ret); build_config(cd, cfg); diff --git a/src/audio/sink_source_utils.c b/src/audio/sink_source_utils.c index 9b01753f8670..4871e34a456a 100644 --- a/src/audio/sink_source_utils.c +++ b/src/audio/sink_source_utils.c @@ -70,7 +70,7 @@ int source_to_sink_copy(struct sof_source *source, to_copy = MIN(to_copy, size); ret = memcpy_s(dst_ptr, dst_to_buf_overlap, src_ptr, to_copy); - assert(!ret); + __ASSERT_NO_MSG(!ret); size -= to_copy; src_ptr += to_copy; @@ -110,7 +110,7 @@ int sink_fill_with_silence(struct sof_sink *sink, size_t size) uint32_t to_fill = MIN(dst_to_buf_overlap, size); ret = memset_s(dst_ptr, dst_to_buf_overlap, 0, to_fill); - assert(!ret); + __ASSERT_NO_MSG(!ret); size -= to_fill; dst_ptr += to_fill; diff --git a/src/audio/smart_amp/smart_amp.c b/src/audio/smart_amp/smart_amp.c index a069c14d64b4..421d2381379d 100644 --- a/src/audio/smart_amp/smart_amp.c +++ b/src/audio/smart_amp/smart_amp.c @@ -297,7 +297,7 @@ static int smart_amp_get_config(struct processing_module *mod, return -EINVAL; ret = memcpy_s(cdata->data->data, size, &sad->config, bs); - assert(!ret); + __ASSERT_NO_MSG(!ret); cdata->data->abi = SOF_ABI_VERSION; cdata->data->size = bs; @@ -314,7 +314,7 @@ static int smart_amp_ctrl_get_bin_data(struct processing_module *mod, struct comp_dev *dev = mod->dev; int ret = 0; - assert(sad); + __ASSERT_NO_MSG(sad); smod = sad->mod_data; switch (cdata->data->type) { @@ -366,7 +366,7 @@ static int smart_amp_ctrl_set_bin_data(struct processing_module *mod, struct comp_dev *dev = mod->dev; int ret = 0; - assert(sad); + __ASSERT_NO_MSG(sad); smod = sad->mod_data; if (dev->state < COMP_STATE_READY) { diff --git a/src/audio/smart_amp/smart_amp_maxim_dsm.c b/src/audio/smart_amp/smart_amp_maxim_dsm.c index 4b808dfaaf36..615077402cac 100644 --- a/src/audio/smart_amp/smart_amp_maxim_dsm.c +++ b/src/audio/smart_amp/smart_amp_maxim_dsm.c @@ -341,7 +341,7 @@ static int maxim_dsm_get_param(struct smart_amp_mod_struct_t *hspk, (char *)caldata->data + caldata->data_pos, bs); - assert(!ret); + __ASSERT_NO_MSG(!ret); cdata->data->abi = SOF_ABI_VERSION; cdata->data->size = caldata->data_size; diff --git a/src/audio/volume/volume_ipc4.c b/src/audio/volume/volume_ipc4.c index 7ca9b90c1ef6..bceeb8e26d9b 100644 --- a/src/audio/volume/volume_ipc4.c +++ b/src/audio/volume/volume_ipc4.c @@ -455,7 +455,7 @@ void volume_update_current_vol_ipc4(struct vol_data *cd) { int i; - assert(cd); + __ASSERT_NO_MSG(cd); for (i = 0; i < cd->channels; i++) cd->peak_regs.current_volume[i] = cd->volume[i]; From 42cbe46f8d183e78d5e3266268f56cadc0357c04 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Dec 2026 22:27:08 +0000 Subject: [PATCH 07/10] include: use __ASSERT_NO_MSG() instead of assert() On Zephyr, assert() is defined as __ASSERT_NO_MSG(). The host builds now have the Zephyr assert macros too, so use __ASSERT_NO_MSG() directly in the shared headers. No lines are added or removed, so __LINE__ in verbose asserts does not change. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/include/sof/audio/audio_stream.h | 18 +++++++++--------- src/include/sof/audio/audio_stream_hw.h | 8 ++++---- src/include/sof/audio/component.h | 2 +- src/include/sof/audio/component_ext.h | 4 ++-- src/include/sof/coherent.h | 2 +- src/include/sof/lib/mailbox.h | 12 ++++++------ src/include/sof/schedule/ll_schedule_domain.h | 8 ++++---- src/include/sof/schedule/schedule.h | 6 +++--- src/include/sof/schedule/zephyr_ll.h | 4 ++-- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/include/sof/audio/audio_stream.h b/src/include/sof/audio/audio_stream.h index 4f2d3a03c97c..bb27550d856b 100644 --- a/src/include/sof/audio/audio_stream.h +++ b/src/include/sof/audio/audio_stream.h @@ -404,7 +404,7 @@ static inline void *audio_stream_wrap(const struct audio_stream *buffer, void *p ptr = (char *)buffer->addr + ((char *)ptr - (char *)buffer->end_addr); - assert((uintptr_t)ptr <= (uintptr_t)buffer->end_addr); + __ASSERT_NO_MSG((uintptr_t)ptr <= (uintptr_t)buffer->end_addr); return ptr; } @@ -421,7 +421,7 @@ static inline void *audio_stream_rewind_wrap(const struct audio_stream *buffer, if (ptr < buffer->addr) ptr = (char *)buffer->end_addr - ((char *)buffer->addr - (char *)ptr); - assert((uintptr_t)ptr >= (uintptr_t)buffer->addr); + __ASSERT_NO_MSG((uintptr_t)ptr >= (uintptr_t)buffer->addr); return ptr; } @@ -774,7 +774,7 @@ static inline void audio_stream_writeback(struct audio_stream *buffer, uint32_t static inline int audio_stream_bytes_without_wrap(const struct audio_stream *source, const void *ptr) { - assert((uintptr_t)source->end_addr >= (uintptr_t)ptr); + __ASSERT_NO_MSG((uintptr_t)source->end_addr >= (uintptr_t)ptr); return (uintptr_t)source->end_addr - (uintptr_t)ptr; } @@ -789,7 +789,7 @@ audio_stream_bytes_without_wrap(const struct audio_stream *source, const void *p static inline int audio_stream_rewind_bytes_without_wrap(const struct audio_stream *source, const void *ptr) { - assert((uintptr_t)ptr >= (uintptr_t)source->addr); + __ASSERT_NO_MSG((uintptr_t)ptr >= (uintptr_t)source->addr); size_t to_begin = (uintptr_t)ptr - (uintptr_t)source->addr; return to_begin; } @@ -807,8 +807,8 @@ static inline uint32_t void *wptr = audio_stream_get_wptr(source); int to_begin = audio_stream_rewind_bytes_without_wrap(source, wptr); - assert((uintptr_t)wptr >= (uintptr_t)source->addr); - assert((uintptr_t)source->end_addr > (uintptr_t)wptr); + __ASSERT_NO_MSG((uintptr_t)wptr >= (uintptr_t)source->addr); + __ASSERT_NO_MSG((uintptr_t)source->end_addr > (uintptr_t)wptr); if (to_begin > bytes) return (uint32_t *)((intptr_t)wptr - bytes); @@ -828,7 +828,7 @@ audio_stream_samples_without_wrap_s16(const struct audio_stream *source, const v { int to_end = (int16_t *)source->end_addr - (int16_t *)ptr; - assert((uintptr_t)source->end_addr >= (uintptr_t)ptr); + __ASSERT_NO_MSG((uintptr_t)source->end_addr >= (uintptr_t)ptr); return to_end; } @@ -844,7 +844,7 @@ audio_stream_samples_without_wrap_s24(const struct audio_stream *source, const v { int to_end = (int32_t *)source->end_addr - (int32_t *)ptr; - assert((uintptr_t)source->end_addr >= (uintptr_t)ptr); + __ASSERT_NO_MSG((uintptr_t)source->end_addr >= (uintptr_t)ptr); return to_end; } @@ -860,7 +860,7 @@ audio_stream_samples_without_wrap_s32(const struct audio_stream *source, const v { int to_end = (int32_t *)source->end_addr - (int32_t *)ptr; - assert((uintptr_t)source->end_addr >= (uintptr_t)ptr); + __ASSERT_NO_MSG((uintptr_t)source->end_addr >= (uintptr_t)ptr); return to_end; } diff --git a/src/include/sof/audio/audio_stream_hw.h b/src/include/sof/audio/audio_stream_hw.h index 82ae90280be7..099ec332a171 100644 --- a/src/include/sof/audio/audio_stream_hw.h +++ b/src/include/sof/audio/audio_stream_hw.h @@ -38,10 +38,10 @@ static inline void audio_stream_sync_to_hw(struct audio_stream *stream, * such case. */ - assert(dma_status->write_position < audio_stream_get_size(stream)); - assert(dma_status->read_position < audio_stream_get_size(stream)); - assert(dma_status->pending_length <= audio_stream_get_size(stream)); - assert(dma_status->free <= audio_stream_get_size(stream)); + __ASSERT_NO_MSG(dma_status->write_position < audio_stream_get_size(stream)); + __ASSERT_NO_MSG(dma_status->read_position < audio_stream_get_size(stream)); + __ASSERT_NO_MSG(dma_status->pending_length <= audio_stream_get_size(stream)); + __ASSERT_NO_MSG(dma_status->free <= audio_stream_get_size(stream)); audio_stream_set_wptr(stream, (void *)(buf_start + dma_status->write_position)); audio_stream_set_rptr(stream, (void *)(buf_start + dma_status->read_position)); diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index e879888053b0..ff490d953bdf 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -1032,7 +1032,7 @@ static inline void component_set_nearest_period_frames(struct comp_dev *current, frames = SOF_DIV_ROUND_UP((uint64_t)rate * current->period, 1000000); - assert(frames <= UINT_MAX); + __ASSERT_NO_MSG(frames <= UINT_MAX); current->frames = (uint32_t)frames; } diff --git a/src/include/sof/audio/component_ext.h b/src/include/sof/audio/component_ext.h index 9a0ad328fec1..862793b1ff1f 100644 --- a/src/include/sof/audio/component_ext.h +++ b/src/include/sof/audio/component_ext.h @@ -65,7 +65,7 @@ static inline void comp_free(struct comp_dev *dev) { const struct comp_driver *drv = dev->drv; - assert(drv->ops.free); + __ASSERT_NO_MSG(drv->ops.free); /* * In DP case this will run in DP thread context, so the task can only @@ -226,7 +226,7 @@ static inline int comp_trigger_local(struct comp_dev *dev, int cmd) static inline int comp_trigger(struct comp_dev *dev, int cmd) { int ret; - assert(dev->drv->ops.trigger); + __ASSERT_NO_MSG(dev->drv->ops.trigger); if (dev->is_shared && !cpu_is_me(dev->ipc_config.core)) ret = comp_trigger_remote(dev, cmd); diff --git a/src/include/sof/coherent.h b/src/include/sof/coherent.h index d0b60a95f73a..bfc749631dd9 100644 --- a/src/include/sof/coherent.h +++ b/src/include/sof/coherent.h @@ -110,7 +110,7 @@ STATIC_ASSERT(sizeof(struct coherent) <= DCACHE_LINE_SIZE, DCACHE_LINE_SIZE_too #define CORE_CHECK_STRUCT_INIT(_c, is_shared) { (_c)->__core = cpu_get_id(); \ (_c)->__is_shared = is_shared; } #define CORE_CHECK_STRUCT(_c) { assert(!!(_c)->__is_shared == !!is_uncached(_c)); \ - assert(cpu_get_id() == (_c)->__core || (_c)->__is_shared); } + __ASSERT_NO_MSG(cpu_get_id() == (_c)->__core || (_c)->__is_shared); } #define CHECK_COHERENT_CORE(_c) assert((_c)->core == cpu_get_id()) diff --git a/src/include/sof/lib/mailbox.h b/src/include/sof/lib/mailbox.h index 5dbf0160332c..e663531c354c 100644 --- a/src/include/sof/lib/mailbox.h +++ b/src/include/sof/lib/mailbox.h @@ -48,7 +48,7 @@ void mailbox_dspbox_write(size_t offset, const void *src, size_t bytes) int dsp_write_err __unused = memcpy_s((void *)(MAILBOX_DSPBOX_BASE + offset), MAILBOX_DSPBOX_SIZE - offset, src, bytes); - assert(!dsp_write_err); + __ASSERT_NO_MSG(!dsp_write_err); dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_DSPBOX_BASE + offset), bytes); } @@ -63,7 +63,7 @@ void mailbox_dspbox_read(void *dest, size_t dest_size, offset), bytes); dsp_read_err = memcpy_s(dest, dest_size, (void *)(MAILBOX_DSPBOX_BASE + offset), bytes); - assert(!dsp_read_err); + __ASSERT_NO_MSG(!dsp_read_err); } #if CONFIG_LIBRARY @@ -79,7 +79,7 @@ void mailbox_hostbox_write(size_t offset, const void *src, size_t bytes) int host_write_err __unused = memcpy_s((void *)(MAILBOX_HOSTBOX_BASE + offset), MAILBOX_HOSTBOX_SIZE - offset, src, bytes); - assert(!host_write_err); + __ASSERT_NO_MSG(!host_write_err); dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_HOSTBOX_BASE + offset), bytes); } @@ -96,7 +96,7 @@ void mailbox_hostbox_read(void *dest, size_t dest_size, offset), bytes); host_read_err = memcpy_s(dest, dest_size, (void *)(MAILBOX_HOSTBOX_BASE + offset), bytes); - assert(!host_read_err); + __ASSERT_NO_MSG(!host_read_err); } #if CONFIG_IPC_MAJOR_4 @@ -104,7 +104,7 @@ static inline void mailbox_stream_write(size_t offset, const void *src, size_t bytes) { /* in IPC4, the stream mailbox must not be used */ - assert(false); + __ASSERT_NO_MSG(false); } #else static inline @@ -113,7 +113,7 @@ void mailbox_stream_write(size_t offset, const void *src, size_t bytes) int stream_write_err __unused = memcpy_s((void *)(MAILBOX_STREAM_BASE + offset), MAILBOX_STREAM_SIZE - offset, src, bytes); - assert(!stream_write_err); + __ASSERT_NO_MSG(!stream_write_err); dcache_writeback_region((__sparse_force void __sparse_cache *)(MAILBOX_STREAM_BASE + offset), bytes); } diff --git a/src/include/sof/schedule/ll_schedule_domain.h b/src/include/sof/schedule/ll_schedule_domain.h index b960c085920d..dcc069c3f455 100644 --- a/src/include/sof/schedule/ll_schedule_domain.h +++ b/src/include/sof/schedule/ll_schedule_domain.h @@ -411,7 +411,7 @@ static inline void domain_task_cancel(struct ll_schedule_domain *domain, static inline int domain_thread_init(struct ll_schedule_domain *domain, struct task *task) { - assert(domain->ops->domain_thread_init); + __ASSERT_NO_MSG(domain->ops->domain_thread_init); return domain->ops->domain_thread_init(domain, task); } @@ -446,7 +446,7 @@ static inline int domain_register(struct ll_schedule_domain *domain, { int ret; - assert(domain->ops->domain_register); + __ASSERT_NO_MSG(domain->ops->domain_register); ret = domain->ops->domain_register(domain, task, handler, arg); @@ -468,7 +468,7 @@ static inline void domain_unregister(struct ll_schedule_domain *domain, { int ret; - assert(domain->ops->domain_unregister); + __ASSERT_NO_MSG(domain->ops->domain_unregister); /* unregistering a task, decrement the count */ if (task) @@ -546,7 +546,7 @@ static inline bool domain_is_pending(struct ll_schedule_domain *domain, { bool ret; - assert(domain->ops->domain_is_pending); + __ASSERT_NO_MSG(domain->ops->domain_is_pending); ret = domain->ops->domain_is_pending(domain, task, comp); diff --git a/src/include/sof/schedule/schedule.h b/src/include/sof/schedule/schedule.h index cf58540a6032..d092ff402bda 100644 --- a/src/include/sof/schedule/schedule.h +++ b/src/include/sof/schedule/schedule.h @@ -308,7 +308,7 @@ static inline int schedule_task_running(struct task *task) { struct schedule_data *sch; - assert(task); + __ASSERT_NO_MSG(task); sch = task->sch; if (!sch->ops->schedule_task_running) @@ -407,7 +407,7 @@ static inline int reschedule_task(struct task *task, uint64_t start) { struct schedule_data *sch; - assert(task); + __ASSERT_NO_MSG(task); sch = task->sch; /* optional operation */ @@ -479,7 +479,7 @@ static inline struct k_thread *scheduler_init_context(struct task *task) { struct schedule_data *sch; - assert(task && task->sch); + __ASSERT_NO_MSG(task && task->sch); sch = task->sch; if (sch->ops->scheduler_init_context) diff --git a/src/include/sof/schedule/zephyr_ll.h b/src/include/sof/schedule/zephyr_ll.h index 1da2a2f64bc3..57c39cb06110 100644 --- a/src/include/sof/schedule/zephyr_ll.h +++ b/src/include/sof/schedule/zephyr_ll.h @@ -75,8 +75,8 @@ static inline void zephyr_ll_free(void *ptr) static inline void zephyr_ll_assert_core(const struct zephyr_ll *sch) { - assert(CONFIG_CORE_COUNT == 1 || IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || - sch->core == cpu_get_id()); + __ASSERT_NO_MSG(CONFIG_CORE_COUNT == 1 || IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || + sch->core == cpu_get_id()); } /* LL scheduler ops, see zephyr_ll.c */ From 28c77c8f0a04b69a662259f9192da401b9127c3a Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Dec 2026 22:27:26 +0000 Subject: [PATCH 08/10] ipc: use __ASSERT_NO_MSG() instead of assert() On Zephyr, assert() is defined as __ASSERT_NO_MSG(). The host builds now have the Zephyr assert macros too, so use __ASSERT_NO_MSG() directly in the IPC code. No lines are added or removed, so __LINE__ in verbose asserts does not change. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/ipc/ipc-helper.c | 2 +- src/ipc/ipc4/dai.c | 14 +++++++------- src/ipc/ipc4/helper.c | 2 +- src/kernel/ipc/ipc-common-kernel.c | 4 ++-- src/kernel/ipc/ipc3/dai.c | 2 +- src/kernel/ipc/ipc3/handler.c | 6 +++--- src/kernel/ipc/ipc4/handler-kernel.c | 4 ++-- src/kernel/ipc/ipc4/notification.c | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index c8e82587edf7..a85e114b6f38 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -211,7 +211,7 @@ __cold int comp_buffer_connect(struct comp_dev *comp, uint32_t comp_core, if (buffer->core != comp_core) { #if CONFIG_INCOHERENT /* buffer must be shared */ - assert(audio_buffer_is_shared(&buffer->audio_buffer)); + __ASSERT_NO_MSG(audio_buffer_is_shared(&buffer->audio_buffer)); #else buffer->audio_buffer.is_shared = true; #endif diff --git a/src/ipc/ipc4/dai.c b/src/ipc/ipc4/dai.c index 63fe9bc9b895..1eed75cab868 100644 --- a/src/ipc/ipc4/dai.c +++ b/src/ipc/ipc4/dai.c @@ -253,10 +253,10 @@ void dai_dma_release(struct dai_data *dd, struct comp_dev *dev) slot.node_id = dd->slot_info.node_id; ret = sys_mutex_lock(&llp_reading_slots_lock, K_FOREVER); - assert(!ret); + __ASSERT_NO_MSG(!ret); mailbox_sw_regs_write(dd->slot_info.reg_offset, &slot, sizeof(slot)); ret = sys_mutex_unlock(&llp_reading_slots_lock); - assert(!ret); + __ASSERT_NO_MSG(!ret); } /* The stop sequnece of host driver is first pause and then reset @@ -293,10 +293,10 @@ void dai_release_llp_slot(struct dai_data *dd) /* clear node id for released llp slot */ ret = sys_mutex_lock(&llp_reading_slots_lock, K_FOREVER); - assert(!ret); + __ASSERT_NO_MSG(!ret); mailbox_sw_regs_write(dd->slot_info.reg_offset, &slot, sizeof(slot)); ret = sys_mutex_unlock(&llp_reading_slots_lock); - assert(!ret); + __ASSERT_NO_MSG(!ret); dd->slot_info.reg_offset = 0; dd->slot_info.node_id = 0; @@ -321,7 +321,7 @@ static int dai_get_unused_llp_slot(struct comp_dev *dev, } ret = sys_mutex_lock(&llp_reading_slots_lock, K_FOREVER); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* find unused llp slot offset with node_id of zero */ for (i = 0; i < max_slot; i++, offset += sizeof(slot)) { @@ -335,7 +335,7 @@ static int dai_get_unused_llp_slot(struct comp_dev *dev, if (i >= max_slot) { comp_err(dev, "can't find free slot"); ret = sys_mutex_unlock(&llp_reading_slots_lock); - assert(!ret); + __ASSERT_NO_MSG(!ret); return -EINVAL; } @@ -344,7 +344,7 @@ static int dai_get_unused_llp_slot(struct comp_dev *dev, mailbox_sw_regs_write(offset, &slot, sizeof(slot)); ret = sys_mutex_unlock(&llp_reading_slots_lock); - assert(!ret); + __ASSERT_NO_MSG(!ret); return offset; } diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index 8dfb4f8430d7..2de63df7b453 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -585,7 +585,7 @@ __cold static struct comp_buffer *ipc4_create_buffer(struct comp_dev *src, bool * is privileged and so avoided here. */ ipc_buf.comp.core = cross_core ? PLATFORM_PRIMARY_CORE_ID : src->ipc_config.core; - assert(IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || ipc_buf.comp.core == cpu_get_id()); + __ASSERT_NO_MSG(IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || ipc_buf.comp.core == cpu_get_id()); return buffer_new(alloc, &ipc_buf, is_shared); } diff --git a/src/kernel/ipc/ipc-common-kernel.c b/src/kernel/ipc/ipc-common-kernel.c index 77c167d5984c..268cee7cefc7 100644 --- a/src/kernel/ipc/ipc-common-kernel.c +++ b/src/kernel/ipc/ipc-common-kernel.c @@ -194,7 +194,7 @@ __cold void ipc_msg_send_direct(struct ipc_msg *msg, void *data) if (data && msg->tx_size > 0 && msg->tx_size <= SOF_IPC_MSG_MAX_SIZE && msg->tx_data != data) { ret = memcpy_s(msg->tx_data, msg->tx_size, data, msg->tx_size); - assert(!ret); + __ASSERT_NO_MSG(!ret); } ipc_platform_send_msg_direct(msg); @@ -214,7 +214,7 @@ void z_impl_ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority) if (data && (msg->tx_size > 0 && msg->tx_size <= SOF_IPC_MSG_MAX_SIZE) && msg->tx_data != data) { ret = memcpy_s(msg->tx_data, msg->tx_size, data, msg->tx_size); - assert(!ret); + __ASSERT_NO_MSG(!ret); } /* diff --git a/src/kernel/ipc/ipc3/dai.c b/src/kernel/ipc/ipc3/dai.c index 5b0efff590da..ab52c821306a 100644 --- a/src/kernel/ipc/ipc3/dai.c +++ b/src/kernel/ipc/ipc3/dai.c @@ -45,7 +45,7 @@ int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void int channel; int handshake; - assert(config); + __ASSERT_NO_MSG(config); switch (config->type) { case SOF_DAI_INTEL_SSP: diff --git a/src/kernel/ipc/ipc3/handler.c b/src/kernel/ipc/ipc3/handler.c index c4b9cbc70c25..306199846fbe 100644 --- a/src/kernel/ipc/ipc3/handler.c +++ b/src/kernel/ipc/ipc3/handler.c @@ -83,18 +83,18 @@ LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL); int ___ret; \ if (rx_size > tx->size) { \ ___ret = memcpy_s(rx, rx_size, tx, tx->size); \ - assert(!___ret); \ + __ASSERT_NO_MSG(!___ret); \ bzero((char *)rx + tx->size, rx_size - tx->size);\ tr_dbg(&ipc_tr, "ipc: hdr 0x%x rx (%zu) > tx (%d)",\ rx->cmd, rx_size, tx->size); \ } else if (tx->size > rx_size) { \ ___ret = memcpy_s(rx, rx_size, tx, rx_size); \ - assert(!___ret); \ + __ASSERT_NO_MSG(!___ret); \ tr_warn(&ipc_tr, "ipc: hdr 0x%x tx (%d) > rx (%zu)",\ rx->cmd, tx->size, rx_size); \ } else { \ ___ret = memcpy_s(rx, rx_size, tx, rx_size); \ - assert(!___ret); \ + __ASSERT_NO_MSG(!___ret); \ } \ } while (0) diff --git a/src/kernel/ipc/ipc4/handler-kernel.c b/src/kernel/ipc/ipc4/handler-kernel.c index b8d02c3771ae..cae0ad0490c9 100644 --- a/src/kernel/ipc/ipc4/handler-kernel.c +++ b/src/kernel/ipc/ipc4/handler-kernel.c @@ -96,7 +96,7 @@ static inline void ipc4_send_reply(struct ipc4_message_reply *reply) /* copy the extension from the message reply */ reply->extension.dat = msg_reply.extension; ret = memcpy_s(ipc->comp_data, sizeof(*reply), reply, sizeof(*reply)); - assert(!ret); + __ASSERT_NO_MSG(!ret); } #else /* CONFIG_LIBRARY */ static inline struct ipc4_message_request *ipc4_get_message_request(void) @@ -339,7 +339,7 @@ __cold static int ipc4_module_process_d0ix(struct ipc4_message_request *ipc4) __cold static void ipc_sec_core_sync_boot(uint32_t core_id) { #ifdef CONFIG_SOF_USERSPACE_LL - assert(core_id != PLATFORM_PRIMARY_CORE_ID); + __ASSERT_NO_MSG(core_id != PLATFORM_PRIMARY_CORE_ID); ipc_user_wait_core_init(core_id); #endif diff --git a/src/kernel/ipc/ipc4/notification.c b/src/kernel/ipc/ipc4/notification.c index 196771ecc0c4..4ef4feaac428 100644 --- a/src/kernel/ipc/ipc4/notification.c +++ b/src/kernel/ipc/ipc4/notification.c @@ -73,7 +73,7 @@ bool z_impl_send_resource_notif(uint32_t resource_id, uint32_t event_type, * Using a data type that is not included in the event_data union. * Return true to prevent an infinite re-try loop in non-debug builds */ - assert(false); + __ASSERT_NO_MSG(false); return true; } } From 288057b8091acf57bf1c47ce611da7290fda30e3 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Dec 2026 22:27:26 +0000 Subject: [PATCH 09/10] lib, drivers, samples: use __ASSERT_NO_MSG() instead of assert() On Zephyr, assert() is defined as __ASSERT_NO_MSG(). The host builds now have the Zephyr assert macros too, so use __ASSERT_NO_MSG() directly in the library, DMA driver and sample code. No lines are added or removed, so __LINE__ in verbose asserts does not change. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/kernel/drivers/generic/dummy-dma.c | 2 +- src/lib/dma.c | 12 ++++++------ src/lib/notifier.c | 4 ++-- src/samples/audio/detect_test.c | 6 +++--- src/samples/audio/smart_amp_test_ipc3.c | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/kernel/drivers/generic/dummy-dma.c b/src/kernel/drivers/generic/dummy-dma.c index fd4efea90603..d377f1672aea 100644 --- a/src/kernel/drivers/generic/dummy-dma.c +++ b/src/kernel/drivers/generic/dummy-dma.c @@ -108,7 +108,7 @@ static ssize_t dummy_dma_copy_crt_elem(struct dma_chan_pdata *pdata, /* Perform the copy, being careful if we overflow the elem */ ret = memcpy_s((void *)wptr, remaining_size, (void *)rptr, copy_size); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* On capture, writeback the host buffer (it may lie in a cached area). * On playback, also writeback because host.c does an invalidate to diff --git a/src/lib/dma.c b/src/lib/dma.c index 8464f1c9e3d8..477acbf6c31a 100644 --- a/src/lib/dma.c +++ b/src/lib/dma.c @@ -110,8 +110,8 @@ int dma_buffer_copy_from(struct comp_buffer *source, * remapping conversion -- it's safe to use frame-based calculations in this * context. */ - assert(source_channels); - assert(sink_channels); + __ASSERT_NO_MSG(source_channels); + __ASSERT_NO_MSG(sink_channels); frames = source_bytes / audio_stream_frame_bytes(istream); sink_bytes = audio_stream_frame_bytes(&sink->stream) * frames; @@ -185,8 +185,8 @@ int dma_buffer_copy_to(struct comp_buffer *source, * remapping conversion -- it's safe to use frame-based calculations in this * context. */ - assert(source_channels); - assert(sink_channels); + __ASSERT_NO_MSG(source_channels); + __ASSERT_NO_MSG(sink_channels); frames = sink_bytes / audio_stream_frame_bytes(ostream); source_bytes = audio_stream_frame_bytes(&source->stream) * frames; @@ -260,8 +260,8 @@ int stream_copy_from_no_consume(struct comp_dev *dev, struct comp_buffer *source * remapping conversion -- it's safe to use frame-based calculations in this * context. */ - assert(source_channels); - assert(sink_channels); + __ASSERT_NO_MSG(source_channels); + __ASSERT_NO_MSG(sink_channels); frames = source_bytes / audio_stream_frame_bytes(istream); sink_bytes = audio_stream_frame_bytes(&sink->stream) * frames; diff --git a/src/lib/notifier.c b/src/lib/notifier.c index 42e9e50ef66b..18060376fd3a 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -44,7 +44,7 @@ int notifier_register(void *receiver, void *caller, enum notify_id type, k_spinlock_key_t key; int ret = 0; - assert((unsigned int)type < NOTIFIER_ID_COUNT); + __ASSERT_NO_MSG((unsigned int)type < NOTIFIER_ID_COUNT); key = k_spin_lock(¬ify->lock); @@ -77,7 +77,7 @@ void notifier_unregister(void *receiver, void *caller, enum notify_id type) struct callback_handle *handle; k_spinlock_key_t key; - assert((unsigned int)type < NOTIFIER_ID_COUNT); + __ASSERT_NO_MSG((unsigned int)type < NOTIFIER_ID_COUNT); key = k_spin_lock(¬ify->lock); diff --git a/src/samples/audio/detect_test.c b/src/samples/audio/detect_test.c index aab84ed3788f..1df028389084 100644 --- a/src/samples/audio/detect_test.c +++ b/src/samples/audio/detect_test.c @@ -301,7 +301,7 @@ __cold static int test_keyword_apply_config(struct comp_dev *dev, ret = memcpy_s(&cd->config, sizeof(cd->config), cfg, sizeof(struct sof_detect_test_config)); - assert(!ret); + __ASSERT_NO_MSG(!ret); #if CONFIG_IPC_MAJOR_4 sample_width = cd->base_cfg.audio_fmt.valid_bit_depth; @@ -401,7 +401,7 @@ __cold static int test_keyword_get_config(struct comp_dev *dev, char *data, /* Copy back to user space */ ret = memcpy_s(data, cfg_size, &cd->config, cfg_size); - assert(!ret); + __ASSERT_NO_MSG(!ret); return 0; } @@ -604,7 +604,7 @@ __cold static int test_keyword_get_config(struct comp_dev *dev, return -EINVAL; ret = memcpy_s(cdata->data->data, size, &cd->config, bs); - assert(!ret); + __ASSERT_NO_MSG(!ret); cdata->data->abi = SOF_ABI_VERSION; cdata->data->size = bs; diff --git a/src/samples/audio/smart_amp_test_ipc3.c b/src/samples/audio/smart_amp_test_ipc3.c index 49062474ed47..600747c81a41 100644 --- a/src/samples/audio/smart_amp_test_ipc3.c +++ b/src/samples/audio/smart_amp_test_ipc3.c @@ -143,7 +143,7 @@ static int smart_amp_get_config(struct comp_dev *dev, return -EINVAL; ret = memcpy_s(cdata->data->data, size, &sad->config, bs); - assert(!ret); + __ASSERT_NO_MSG(!ret); cdata->data->abi = SOF_ABI_VERSION; cdata->data->size = bs; @@ -157,7 +157,7 @@ static int smart_amp_ctrl_get_bin_data(struct comp_dev *dev, { struct smart_amp_data *sad = comp_get_drvdata(dev); - assert(sad); + __ASSERT_NO_MSG(sad); switch (cdata->data->type) { case SOF_SMART_AMP_CONFIG: @@ -191,7 +191,7 @@ static int smart_amp_ctrl_set_bin_data(struct comp_dev *dev, { struct smart_amp_data *sad = comp_get_drvdata(dev); - assert(sad); + __ASSERT_NO_MSG(sad); if (dev->state < COMP_STATE_READY) { comp_err(dev, "driver in init!"); From b1333f398955091a4300677ea76f0e67482e9612 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Dec 2026 22:28:05 +0000 Subject: [PATCH 10/10] coherent: use __ASSERT_NO_MSG() in the check macros The coherent API debug check macros still used assert(): the address alias and core checks, and the host versions of the sleep and atomic context checks. Use __ASSERT_NO_MSG() like the rest of the header. The Zephyr and host versions of the context checks stay separate, so that no lines move and __LINE__ in verbose asserts does not change. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/include/sof/coherent.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/include/sof/coherent.h b/src/include/sof/coherent.h index bfc749631dd9..afced9cde910 100644 --- a/src/include/sof/coherent.h +++ b/src/include/sof/coherent.h @@ -96,8 +96,8 @@ STATIC_ASSERT(sizeof(struct coherent) <= DCACHE_LINE_SIZE, DCACHE_LINE_SIZE_too /* debug address aliases */ #ifdef COHERENT_CHECK_ALIAS -#define ADDR_IS_INCOHERENT(_c) assert(!is_uncached(_c)) -#define ADDR_IS_COHERENT(_c) assert(is_uncached(_c)) +#define ADDR_IS_INCOHERENT(_c) __ASSERT_NO_MSG(!is_uncached(_c)) +#define ADDR_IS_COHERENT(_c) __ASSERT_NO_MSG(is_uncached(_c)) #else #define ADDR_IS_INCOHERENT(_c) #define ADDR_IS_COHERENT(_c) @@ -109,10 +109,10 @@ STATIC_ASSERT(sizeof(struct coherent) <= DCACHE_LINE_SIZE, DCACHE_LINE_SIZE_too #define CORE_CHECK_STRUCT_FIELD uint32_t __core; bool __is_shared #define CORE_CHECK_STRUCT_INIT(_c, is_shared) { (_c)->__core = cpu_get_id(); \ (_c)->__is_shared = is_shared; } -#define CORE_CHECK_STRUCT(_c) { assert(!!(_c)->__is_shared == !!is_uncached(_c)); \ +#define CORE_CHECK_STRUCT(_c) { __ASSERT_NO_MSG(!!(_c)->__is_shared == !!is_uncached(_c)); \ __ASSERT_NO_MSG(cpu_get_id() == (_c)->__core || (_c)->__is_shared); } -#define CHECK_COHERENT_CORE(_c) assert((_c)->core == cpu_get_id()) +#define CHECK_COHERENT_CORE(_c) __ASSERT_NO_MSG((_c)->core == cpu_get_id()) #else @@ -131,9 +131,9 @@ STATIC_ASSERT(sizeof(struct coherent) <= DCACHE_LINE_SIZE, DCACHE_LINE_SIZE_too #define CHECK_ATOMIC(_c) __ASSERT(!(_c)->sleep_allowed, \ "This context has been initialized for sleeping!") #else -#define CHECK_ISR() assert(!k_is_in_isr()) -#define CHECK_SLEEP(_c) assert((_c)->sleep_allowed) -#define CHECK_ATOMIC(_c) assert(!(_c)->sleep_allowed) +#define CHECK_ISR() __ASSERT_NO_MSG(!k_is_in_isr()) +#define CHECK_SLEEP(_c) __ASSERT_NO_MSG((_c)->sleep_allowed) +#define CHECK_ATOMIC(_c) __ASSERT_NO_MSG(!(_c)->sleep_allowed) #endif #if CONFIG_INCOHERENT