Skip to content

Commit fb47ea2

Browse files
author
Jyri Sarha
committed
posix: add Zephyr logging and util stubs for testbench build
Add posix stub headers for <zephyr/logging/log.h> and <zephyr/sys/util.h> so that firmware source files using LOG_ERR, LOG_INF, LOG_WRN, LOG_DBG, KB, or MB can compile in the testbench / posix build without modification. Remove the #ifdef __ZEPHYR__ guard around the <zephyr/logging/log.h> include in sof/trace/trace.h and the <zephyr/sys/util.h> include in sof/common.h so the posix stubs are picked up automatically. The redundant LOG_MODULE_REGISTER / LOG_MODULE_DECLARE definitions in trace.h are removed since the posix stub now provides them. Remove the macros and fix couple of format string issues. Also the tools/logger CMakeList.txt requires some tuning to find the now unconditionally included zephyr/sys/util.h. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 70164ab commit fb47ea2

6 files changed

Lines changed: 57 additions & 19 deletions

File tree

posix/include/zephyr/logging/log.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause */
2+
/*
3+
* Copyright(c) 2026 Intel Corporation. All rights reserved.
4+
*
5+
* Stub for <zephyr/logging/log.h> used by testbench / posix builds.
6+
*/
7+
8+
#ifndef __POSIX_ZEPHYR_LOGGING_LOG_H__
9+
#define __POSIX_ZEPHYR_LOGGING_LOG_H__
10+
11+
#include <stdio.h>
12+
13+
#ifndef LOG_ERR
14+
#define LOG_ERR(fmt, ...) fprintf(stderr, "ERR: " fmt "\n", ##__VA_ARGS__)
15+
#endif
16+
#ifndef LOG_WRN
17+
#define LOG_WRN(fmt, ...) fprintf(stderr, "WRN: " fmt "\n", ##__VA_ARGS__)
18+
#endif
19+
#ifndef LOG_INF
20+
#define LOG_INF(fmt, ...) printf("INF: " fmt "\n", ##__VA_ARGS__)
21+
#endif
22+
#ifndef LOG_DBG
23+
#define LOG_DBG(fmt, ...) do { } while (0)
24+
#endif
25+
26+
#ifndef LOG_MODULE_REGISTER
27+
#define LOG_MODULE_REGISTER(ctx, level)
28+
#endif
29+
#ifndef LOG_MODULE_DECLARE
30+
#define LOG_MODULE_DECLARE(ctx, level)
31+
#endif
32+
33+
#endif /* __POSIX_ZEPHYR_LOGGING_LOG_H__ */

posix/include/zephyr/sys/util.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause */
2+
/*
3+
* Copyright(c) 2026 Intel Corporation. All rights reserved.
4+
*
5+
* Stub for <zephyr/sys/util.h> used by testbench / posix builds.
6+
*/
7+
8+
#ifndef __POSIX_ZEPHYR_SYS_UTIL_H__
9+
#define __POSIX_ZEPHYR_SYS_UTIL_H__
10+
11+
#include <stddef.h>
12+
13+
#ifndef KB
14+
#define KB(x) (((size_t)(x)) << 10)
15+
#endif
16+
17+
#ifndef MB
18+
#define MB(x) (KB(x) << 10)
19+
#endif
20+
21+
#endif /* __POSIX_ZEPHYR_SYS_UTIL_H__ */

src/include/sof/common.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
/* callers must check/use the return value */
1515
#define __must_check __attribute__((warn_unused_result))
1616

17-
#ifdef __ZEPHYR__
1817
#include <zephyr/sys/util.h>
19-
#endif
2018

2119
/* Align the number to the nearest alignment value */
2220
#ifndef IS_ALIGNED

src/include/sof/trace/trace.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
#ifdef __ZEPHYR__
2525
#include <zephyr/kernel.h>
26-
#include <zephyr/logging/log.h>
2726
#endif
27+
#include <zephyr/logging/log.h>
2828

2929
#if !CONFIG_LIBRARY
3030
#include <platform/trace/trace.h>
@@ -155,12 +155,4 @@ struct tr_ctx {
155155
.level = default_log_level, \
156156
}
157157

158-
/* Only define these two macros for XTOS to avoid the collision with
159-
* zephyr/include/zephyr/logging/log.h
160-
*/
161-
#ifndef __ZEPHYR__
162-
#define LOG_MODULE_REGISTER(ctx, level)
163-
#define LOG_MODULE_DECLARE(ctx, level)
164-
#endif
165-
166158
#endif /* __SOF_TRACE_TRACE_H__ */

tools/logger/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ target_compile_options(sof-logger PRIVATE
3838

3939
target_include_directories(sof-logger PRIVATE
4040
"${SOF_ROOT_SOURCE_DIRECTORY}/src/include"
41+
"${SOF_ROOT_SOURCE_DIRECTORY}/posix/include"
4142
"${SOF_ROOT_SOURCE_DIRECTORY}/tools/rimage/src/include"
4243
"${SOF_ROOT_SOURCE_DIRECTORY}"
4344
)

zephyr/lib/fast-get.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@
1919
#include <rtos/symbol.h>
2020
#include <ipc/topology.h>
2121

22-
#ifdef __ZEPHYR__
2322
#include <zephyr/logging/log.h>
24-
#else
25-
#define LOG_DBG(...) do {} while (0)
26-
#define LOG_INF(...) do {} while (0)
27-
#define LOG_WRN(...) do {} while (0)
28-
#define LOG_ERR(...) do {} while (0)
29-
#endif
3023

3124
struct sof_fast_get_entry {
3225
const void *dram_ptr;
@@ -154,7 +147,7 @@ const void *fast_get(struct mod_alloc_ctx *alloc, const void *dram_ptr, size_t s
154147

155148
if (entry->sram_ptr) {
156149
if (entry->size != size || entry->dram_ptr != dram_ptr) {
157-
LOG_ERR("size %u != %u or ptr %p != %p mismatch",
150+
LOG_ERR("size %zu != %zu or ptr %p != %p mismatch",
158151
entry->size, size, entry->dram_ptr, dram_ptr);
159152
ret = NULL;
160153
goto out;

0 commit comments

Comments
 (0)