diff --git a/test/ztest/unit/common/xtensa_iss/include/math.h b/test/ztest/unit/common/xtensa_iss/include/math.h new file mode 100644 index 000000000000..a0328a5e7cb0 --- /dev/null +++ b/test/ztest/unit/common/xtensa_iss/include/math.h @@ -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 + +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__ */ diff --git a/test/ztest/unit/common/xtensa_iss/include/platform/lib/memory.h b/test/ztest/unit/common/xtensa_iss/include/platform/lib/memory.h new file mode 100644 index 000000000000..9cc9bc07005b --- /dev/null +++ b/test/ztest/unit/common/xtensa_iss/include/platform/lib/memory.h @@ -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__ */ diff --git a/test/ztest/unit/common/xtensa_iss/include/platform/platform.h b/test/ztest/unit/common/xtensa_iss/include/platform/platform.h new file mode 100644 index 000000000000..dcc25eafb720 --- /dev/null +++ b/test/ztest/unit/common/xtensa_iss/include/platform/platform.h @@ -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__ */ diff --git a/test/ztest/unit/common/xtensa_iss/newlib_errno.c b/test/ztest/unit/common/xtensa_iss/newlib_errno.c new file mode 100644 index 000000000000..3bbdff91872e --- /dev/null +++ b/test/ztest/unit/common/xtensa_iss/newlib_errno.c @@ -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 + +/** + * @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; +} diff --git a/test/ztest/unit/math/advanced/functions/CMakeLists.txt b/test/ztest/unit/math/advanced/functions/CMakeLists.txt index 316da3d41b4e..72d5929992cb 100644 --- a/test/ztest/unit/math/advanced/functions/CMakeLists.txt +++ b/test/ztest/unit/math/advanced/functions/CMakeLists.txt @@ -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 @@ -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 ) diff --git a/test/ztest/unit/math/advanced/functions/prj.conf b/test/ztest/unit/math/advanced/functions/prj.conf index d34c7781cd0a..0dfc302057e6 100644 --- a/test/ztest/unit/math/advanced/functions/prj.conf +++ b/test/ztest/unit/math/advanced/functions/prj.conf @@ -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 diff --git a/test/ztest/unit/math/advanced/functions/testcase.yaml b/test/ztest/unit/math/advanced/functions/testcase.yaml index 897ecf05db18..b4d17c5b6480 100644 --- a/test/ztest/unit/math/advanced/functions/testcase.yaml +++ b/test/ztest/unit/math/advanced/functions/testcase.yaml @@ -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 diff --git a/test/ztest/unit/math/dft3/CMakeLists.txt b/test/ztest/unit/math/dft3/CMakeLists.txt index 056072211185..da59aaf7676f 100644 --- a/test/ztest/unit/math/dft3/CMakeLists.txt +++ b/test/ztest/unit/math/dft3/CMakeLists.txt @@ -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 diff --git a/test/ztest/unit/math/dft3/prj.conf b/test/ztest/unit/math/dft3/prj.conf index 848e53d24787..f34c0bbe45ba 100644 --- a/test/ztest/unit/math/dft3/prj.conf +++ b/test/ztest/unit/math/dft3/prj.conf @@ -4,3 +4,4 @@ CONFIG_ZTEST=y CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n +CONFIG_CBPRINTF_FP_SUPPORT=y diff --git a/test/ztest/unit/math/dft3/testcase.yaml b/test/ztest/unit/math/dft3/testcase.yaml index 6f34ca1f04ba..de784943bb3a 100644 --- a/test/ztest/unit/math/dft3/testcase.yaml +++ b/test/ztest/unit/math/dft3/testcase.yaml @@ -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 diff --git a/test/ztest/unit/math/fft_multi/CMakeLists.txt b/test/ztest/unit/math/fft_multi/CMakeLists.txt index 9afbbc08249b..7114e4a51e2c 100644 --- a/test/ztest/unit/math/fft_multi/CMakeLists.txt +++ b/test/ztest/unit/math/fft_multi/CMakeLists.txt @@ -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 ) @@ -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) diff --git a/test/ztest/unit/math/fft_multi/boards/native_sim.conf b/test/ztest/unit/math/fft_multi/boards/native_sim.conf new file mode 100644 index 000000000000..92d1840a179c --- /dev/null +++ b/test/ztest/unit/math/fft_multi/boards/native_sim.conf @@ -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 diff --git a/test/ztest/unit/math/fft_multi/prj.conf b/test/ztest/unit/math/fft_multi/prj.conf index 06beff4cad2c..7d50925970ee 100644 --- a/test/ztest/unit/math/fft_multi/prj.conf +++ b/test/ztest/unit/math/fft_multi/prj.conf @@ -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 diff --git a/test/ztest/unit/math/fft_multi/testcase.yaml b/test/ztest/unit/math/fft_multi/testcase.yaml index 15427c35de97..7151053b1551 100644 --- a/test/ztest/unit/math/fft_multi/testcase.yaml +++ b/test/ztest/unit/math/fft_multi/testcase.yaml @@ -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 diff --git a/west.yml b/west.yml index dc2952b891fb..8fbc02850391 100644 --- a/west.yml +++ b/west.yml @@ -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