Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/ztest/unit/common/xtensa_iss/include/math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2026 Intel Corporation.
*/

#ifndef __SOF_UT_XTENSA_ISS_MATH_H__
#define __SOF_UT_XTENSA_ISS_MATH_H__

/*
* The ISS unit tests are built with the Zephyr minimal C library, whose
* math.h only declares sqrt() and sqrtf(). The tests calculate reference
* values with more libm functions, which are linked from the math library of
* the Cadence toolchain. Declare the ones in use here: without a prototype
* the compiler assumes an int return value and the results are garbage.
*/

#include_next <math.h>

double exp(double x);
double fabs(double x);
float fabsf(float x);
double pow(double x, double y);
double round(double x);

#endif /* __SOF_UT_XTENSA_ISS_MATH_H__ */
11 changes: 11 additions & 0 deletions test/ztest/unit/common/xtensa_iss/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2026 Intel Corporation.
*/

#ifndef __PLATFORM_LIB_MEMORY_H__
#define __PLATFORM_LIB_MEMORY_H__

/* Core-only ISS tests use linker-provided heap bounds, not an ACE memory map. */

#endif /* __PLATFORM_LIB_MEMORY_H__ */
11 changes: 11 additions & 0 deletions test/ztest/unit/common/xtensa_iss/include/platform/platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2026 Intel Corporation.
*/

#ifndef __PLATFORM_PLATFORM_H__
#define __PLATFORM_PLATFORM_H__

/* Core-only ISS tests have no SOF platform devices or host interface. */

#endif /* __PLATFORM_PLATFORM_H__ */
22 changes: 22 additions & 0 deletions test/ztest/unit/common/xtensa_iss/newlib_errno.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2026 Intel Corporation.

/*
* The math library of the Cadence toolchain is built against newlib and
* reports range and domain errors through newlib's __errno(). The ISS unit
* tests link that libm for reference calculations (exp(), pow(), ...), while
* Zephyr is built with its minimal C library, which has no __errno(). Route
* it to the Zephyr per-thread errno.
*/

#include <errno.h>

/**
* @brief Return the location of errno for the newlib math library.
* @return Pointer to the errno of the calling thread.
*/
int *__errno(void)
{
return &errno;
}
32 changes: 26 additions & 6 deletions test/ztest/unit/math/advanced/functions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,38 @@ include(${SOF_ROOT}/scripts/cmake/uuid-registry.cmake)
target_include_directories(app PRIVATE
${SOF_ROOT}/zephyr/include
${SOF_ROOT}/src/include
${SOF_ROOT}/src/kernel/platform/posix/include
${SOF_ROOT}/src/platform/posix/include
${SOF_ROOT}/test/ztest/unit/include
${PROJECT_BINARY_DIR}/include/generated # For uuid-registry.h
)

# Define SOF-specific configurations for unit testing
target_compile_definitions(app PRIVATE
-DCONFIG_ZEPHYR_POSIX=1
-DCONFIG_LIBRARY=1
-DUNIT_TEST=1
)

if(CONFIG_ARCH_POSIX)
target_include_directories(app PRIVATE
${SOF_ROOT}/src/kernel/platform/posix/include
${SOF_ROOT}/src/platform/posix/include
)
target_compile_definitions(app PRIVATE
CONFIG_ZEPHYR_POSIX=1
CONFIG_LIBRARY=1
)
elseif(CONFIG_BOARD_INTEL_ADSP_ISS)
# The reference values are calculated with libm functions. The
# native_sim runner links the host libm, the ISS targets need the
# toolchain's, with its errno hook and the prototypes that the
# minimal C library's math.h does not declare.
target_include_directories(app BEFORE PRIVATE
${SOF_ROOT}/test/ztest/unit/common/xtensa_iss/include
)
target_sources(app PRIVATE
${SOF_ROOT}/test/ztest/unit/common/xtensa_iss/newlib_errno.c
)
target_link_libraries(app PRIVATE m)
endif()

target_sources(app PRIVATE
test_scalar_power_ztest.c
test_base2_logarithm_ztest.c
Expand All @@ -41,8 +60,9 @@ target_sources(app PRIVATE
${SOF_ROOT}/src/math/log_e.c
${SOF_ROOT}/src/math/exp_fcn.c
${SOF_ROOT}/src/math/sqrt_int16.c
# Note: exp_fcn_hifi.c is conditionally compiled only for Xtensa HiFi platforms.
# TODO: Enable these tests on Xtensa platforms to also test HiFi-optimized code paths.
# exp_fcn_hifi.c provides the exponential functions on Xtensa HiFi
# targets (the .iss scenario) and compiles to nothing elsewhere, where
# exp_fcn.c provides them.
${SOF_ROOT}/src/math/exp_fcn_hifi.c
)

Expand Down
2 changes: 2 additions & 0 deletions test/ztest/unit/math/advanced/functions/prj.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
CONFIG_ZTEST=y
CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n
# The error messages of the tests print floating point values
CONFIG_CBPRINTF_FP_SUPPORT=y
14 changes: 13 additions & 1 deletion test/ztest/unit/math/advanced/functions/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
# generative artificial intelligence solutions.
#

common:
tags: [math, advanced, functions, power, logarithm, base2, base10, exponential, exp, db2lin, sqrt, log10]

tests:
sof.unit.math.advanced.functions:
tags: [math, advanced, functions, power, logarithm, base2, base10, exponential, exp, db2lin, sqrt, log10]
platform_allow: native_sim
integration_platforms:
- native_sim
build_only: false
# Cadence instruction-set simulator: executes the HiFi implementations of
# the exponential functions (src/math/exp_fcn_hifi.c)
sof.unit.math.advanced.functions.iss:
platform_allow:
- intel_adsp_iss/ace20_lnl_iss
- intel_adsp_iss/ace30_ptl_iss
- intel_adsp_iss/ace40_nvl_iss
toolchain_allow:
- xt-clang
build_only: false
13 changes: 10 additions & 3 deletions test/ztest/unit/math/dft3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ include(${SOF_ROOT}/scripts/cmake/uuid-registry.cmake)
target_include_directories(app PRIVATE
${SOF_ROOT}/zephyr/include
${SOF_ROOT}/src/include
${SOF_ROOT}/src/platform/posix/include
${PROJECT_BINARY_DIR}/include/generated
)

target_compile_definitions(app PRIVATE
-DCONFIG_ZEPHYR_POSIX=1
-DCONFIG_LIBRARY=1
-DUNIT_TEST=1
)

if(CONFIG_ARCH_POSIX)
target_include_directories(app PRIVATE
${SOF_ROOT}/src/platform/posix/include
)
target_compile_definitions(app PRIVATE
CONFIG_ZEPHYR_POSIX=1
CONFIG_LIBRARY=1
)
endif()

target_sources(app PRIVATE
test_dft3_ztest.c
${SOF_ROOT}/src/math/fft/fft_multi.c
Expand Down
1 change: 1 addition & 0 deletions test/ztest/unit/math/dft3/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

CONFIG_ZTEST=y
CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n
CONFIG_CBPRINTF_FP_SUPPORT=y
14 changes: 11 additions & 3 deletions test/ztest/unit/math/dft3/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ common:
- unit_test
- math
- fft
integration_platforms:
- native_sim
arch_exclude: xtensa

tests:
sof.unit.math.dft3:
integration_platforms:
- native_sim
platform_allow:
- native_sim
build_only: false
# Cadence instruction-set simulator (xt-run), core only
sof.unit.math.dft3.iss:
platform_allow:
- intel_adsp_iss/ace20_lnl_iss
- intel_adsp_iss/ace30_ptl_iss
- intel_adsp_iss/ace40_nvl_iss
toolchain_allow:
- xt-clang
build_only: false
20 changes: 16 additions & 4 deletions test/ztest/unit/math/fft_multi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,31 @@ target_include_directories(app PRIVATE
${SOF_ROOT}/zephyr/include
${SOF_ROOT}/src/include
${SOF_ROOT}/src/kernel/include
${SOF_ROOT}/src/kernel/platform/posix/include
${SOF_ROOT}/src/platform/posix/include
${SOF_ROOT}/test/ztest/unit/common
${SOF_ROOT}/test/ztest/unit/include
${PROJECT_BINARY_DIR}/include/generated
)

target_compile_definitions(app PRIVATE
-DCONFIG_ZEPHYR_POSIX=1
-DCONFIG_LIBRARY=1
-DCONFIG_NUMBERS_NORM=1
-DUNIT_TEST=1
)

if(CONFIG_ARCH_POSIX)
target_include_directories(app PRIVATE
${SOF_ROOT}/src/kernel/platform/posix/include
${SOF_ROOT}/src/platform/posix/include
)
target_compile_definitions(app PRIVATE
CONFIG_ZEPHYR_POSIX=1
CONFIG_LIBRARY=1
)
elseif(CONFIG_BOARD_INTEL_ADSP_ISS)
target_include_directories(app PRIVATE
${SOF_ROOT}/test/ztest/unit/common/xtensa_iss/include
)
endif()

target_compile_options(app PRIVATE
-Wno-error=deprecated-declarations
)
Expand All @@ -50,6 +61,7 @@ target_sources(app PRIVATE
${SOF_ROOT}/src/math/fft/fft_multi_hifi3.c
${SOF_ROOT}/src/math/fft/fft_common.c
${SOF_ROOT}/src/math/fft/fft_32.c
${SOF_ROOT}/src/math/fft/fft_32_hifi3.c
)

sof_append_relative_path_definitions(app)
6 changes: 6 additions & 0 deletions test/ztest/unit/math/fft_multi/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright(c) 2026 Intel Corporation.

# Keep native allocations visible to ASan/LSan.
CONFIG_SOF_NATIVE_SIM_HOST_HEAP=y
9 changes: 3 additions & 6 deletions test/ztest/unit/math/fft_multi/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
# Copyright(c) 2026 Intel Corporation. All rights reserved.

CONFIG_ZTEST=y
CONFIG_ZTEST_ASSERT_VERBOSE=1
CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n
# Route the SOF heap to the host malloc()/free() of the native simulator, so
# that ASan and LSan can see it. They cannot see blocks carved out of the
# static sys_heap arena that zephyr/lib/alloc.c uses by default.
CONFIG_SOF_NATIVE_SIM_HOST_HEAP=y
# The sys_heap arena is still reserved and initialised by heap_init(), and its
# 256 KiB are too large for SYS_HEAP_SMALL_ONLY (see app/boards/native_sim.conf)
CONFIG_CBPRINTF_FP_SUPPORT=y
# Both the native arena and the linker-bounded ISS heap need large-heap metadata.
CONFIG_SYS_HEAP_BIG_ONLY=y
14 changes: 11 additions & 3 deletions test/ztest/unit/math/fft_multi/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ common:
- unit_test
- math
- fft
integration_platforms:
- native_sim
arch_exclude: xtensa

tests:
sof.unit.math.fft_multi:
integration_platforms:
- native_sim
platform_allow:
- native_sim
build_only: false
# Cadence instruction-set simulator (xt-run), core only
sof.unit.math.fft_multi.iss:
platform_allow:
- intel_adsp_iss/ace20_lnl_iss
- intel_adsp_iss/ace30_ptl_iss
- intel_adsp_iss/ace40_nvl_iss
toolchain_allow:
- xt-clang
build_only: false
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ manifest:

- name: zephyr
repo-path: zephyr
revision: 25851fa15cdc2dc9c395807bce97fa81c46c10ee
revision: pull/128018/head
remote: zephyrproject

# Import some projects listed in zephyr/west.yml@revision
Expand Down
Loading