From 294007477d37721294fa37dafa363744ca2bac72 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Thu, 3 Dec 2026 15:57:36 +0100 Subject: [PATCH 1/4] west.yml: point zephyr to PR 128018 with the ADSP ISS boards Use the head of zephyrproject-rtos/zephyr PR 128018 as the Zephyr revision. The PR adds the Intel ADSP core instruction-set simulator boards intel_adsp_iss/ace20_lnl_iss, ace30_ptl_iss and ace40_nvl_iss, and the ztest changes needed to run unit tests on them with the Cadence xt-run simulator. The PR is based on the current Zephyr main, so this also moves SOF from 25851fa15cdc to a newer Zephyr. The revisions of the imported modules do not change. A pull request reference moves with the PR. It has to be replaced with a commit of Zephyr main once the PR is merged. Link: https://github.com/zephyrproject-rtos/zephyr/pull/128018 Assisted-by: Copilot:claude-fable-5.2 Signed-off-by: Tomasz Leman --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 204b94bb73b65dbb3963d18e48a1c0bc7bd850b1 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Thu, 3 Dec 2026 16:15:16 +0100 Subject: [PATCH 2/4] test: ztest: dft3: run on the Intel ADSP ISS boards Add a scenario that builds the DFT3 unit test with xt-clang for the Intel ADSP instruction-set simulator boards and runs it with xt-run, on the ACE20 (HiFi4), ACE30 (HiFi4) and ACE40 (HiFi5) core profiles. The native_sim scenario is unchanged. To build for a non-POSIX target, apply the POSIX platform include directory and the CONFIG_ZEPHYR_POSIX and CONFIG_LIBRARY definitions only to POSIX builds, and stop excluding the Xtensa architecture. Enable CONFIG_CBPRINTF_FP_SUPPORT, the test prints its error figures as floating point values. The ISS scenario has no integration_platforms entry: the boards only support xt-clang, and Twister in integration mode reports an integration platform that the selected toolchain cannot build as an error. Assisted-by: Copilot:gpt-6.1-sol Signed-off-by: Tomasz Leman --- test/ztest/unit/math/dft3/CMakeLists.txt | 13 ++++++++++--- test/ztest/unit/math/dft3/prj.conf | 1 + test/ztest/unit/math/dft3/testcase.yaml | 14 +++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) 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 From a1c654b3ceeba40893a1be6ae40e3c5989828dc1 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Thu, 3 Dec 2026 16:15:17 +0100 Subject: [PATCH 3/4] test: ztest: fft_multi: run on the Intel ADSP ISS boards Add a scenario that builds the multi-size FFT unit test with xt-clang for the Intel ADSP instruction-set simulator boards and runs all eleven FFT and IFFT cases with xt-run, with the same reference vectors and tolerances as on native_sim. To build for the simulator: - apply the POSIX platform include directories and definitions only to POSIX builds, and stop excluding the Xtensa architecture; - add core-only platform headers for the ISS boards. They are empty: the core simulator has no SOF platform devices and no ACE memory map, the SOF heap of zephyr/lib/alloc.c uses the linker-provided bounds; - link fft_32_hifi3.c, which provides the 32 bit FFT on HiFi targets and compiles to nothing elsewhere; - move CONFIG_SOF_NATIVE_SIM_HOST_HEAP to a native_sim board configuration, the option does not exist for other boards. Enable CONFIG_CBPRINTF_FP_SUPPORT for the floating point values in the test messages. The ISS scenario has no integration_platforms entry, for the same reason as in the dft3 test. Assisted-by: Copilot:gpt-6.1-sol Signed-off-by: Tomasz Leman --- .../xtensa_iss/include/platform/lib/memory.h | 11 ++++++++++ .../xtensa_iss/include/platform/platform.h | 11 ++++++++++ test/ztest/unit/math/fft_multi/CMakeLists.txt | 20 +++++++++++++++---- .../math/fft_multi/boards/native_sim.conf | 6 ++++++ test/ztest/unit/math/fft_multi/prj.conf | 9 +++------ test/ztest/unit/math/fft_multi/testcase.yaml | 14 ++++++++++--- 6 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 test/ztest/unit/common/xtensa_iss/include/platform/lib/memory.h create mode 100644 test/ztest/unit/common/xtensa_iss/include/platform/platform.h create mode 100644 test/ztest/unit/math/fft_multi/boards/native_sim.conf 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/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 From f47169807b5dd447d18b600774882fb1a9a1accf Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Thu, 3 Dec 2026 13:18:10 +0100 Subject: [PATCH 4/4] test: ztest: math advanced functions: run on the Intel ADSP ISS boards Add a scenario that builds the math advanced functions suite with xt-clang for the Intel ADSP ISS boards and runs it with xt-run. On these targets sofm_exp_approx(), sofm_exp_fixed() and sofm_db2lin_fixed() come from the HiFi implementation in src/math/exp_fcn_hifi.c, which no unit test executed so far: on native_sim the file compiles to nothing and the generic exp_fcn.c is tested instead. The tests calculate their reference values with libm functions. For the ISS targets: - link the math library of the Cadence toolchain. It is built against newlib and needs __errno(), which the Zephyr minimal C library does not have, so add a hook that returns the Zephyr errno; - declare exp(), fabs(), fabsf(), pow() and round(). The math.h of the minimal C library only declares sqrt() and sqrtf(), and without a prototype the calls return garbage; - scope the POSIX include directories and definitions to native_sim. Enable CONFIG_CBPRINTF_FP_SUPPORT, the failure messages of the tests print floating point values. Verification: - 8/8 cases pass on intel_adsp_iss/ace20_lnl_iss (HiFi4), ace30_ptl_iss (HiFi4) and ace40_nvl_iss (HiFi5), and on native_sim, also with ASan/LSan. - The ISS image links the three functions from exp_fcn_hifi.c; the object of exp_fcn.c has no code there. - Mutation test: adding 64 to the result of sofm_exp_fixed() in exp_fcn_hifi.c fails test_function_sofm_exp_fixed and test_function_sofm_db2lin_fixed on the ISS and does not affect native_sim. Reverted, no diff remains. The ISS scenario has no integration_platforms entry: the boards only support xt-clang, and Twister in integration mode reports an integration platform that the selected toolchain cannot build as an error. Closes #11591 Assisted-by: Copilot:claude-fable-5.2 Signed-off-by: Tomasz Leman --- .../unit/common/xtensa_iss/include/math.h | 25 +++++++++++++++ .../unit/common/xtensa_iss/newlib_errno.c | 22 +++++++++++++ .../math/advanced/functions/CMakeLists.txt | 32 +++++++++++++++---- .../unit/math/advanced/functions/prj.conf | 2 ++ .../math/advanced/functions/testcase.yaml | 14 +++++++- 5 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 test/ztest/unit/common/xtensa_iss/include/math.h create mode 100644 test/ztest/unit/common/xtensa_iss/newlib_errno.c 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/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