test: unit: Port new cases from cmocka to ztest.#10590
Open
tmleman wants to merge 4 commits intothesofproject:mainfrom
Open
test: unit: Port new cases from cmocka to ztest.#10590tmleman wants to merge 4 commits intothesofproject:mainfrom
tmleman wants to merge 4 commits intothesofproject:mainfrom
Conversation
Standardize all test suite names to follow 'sof.unit.*' pattern: - fast_get.basic_functionality → sof.unit.fast_get - sof.list → sof.unit.list - sof.objpool → sof.unit.objpool - math.basic.arithmetic → sof.unit.math.basic.arithmetic - math.advanced.functions → sof.unit.math.advanced.functions - sof.unit.math.trigonometry → sof.unit.math.basic.trigonometry - sof.unit.math.complex → sof.unit.math.basic.complex Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
2 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates SOF unit tests from CMocka to Zephyr Ztest and aligns test identifiers/tags with a standardized naming scheme.
Changes:
- Renamed several Ztest
testcase.yamlentries tosof.unit.*-prefixed identifiers. - Added Ztest-based math “advanced functions” test coverage (exponential + base2 log) and updated build sources.
- Expanded tags for advanced math tests to improve test selection/filtering.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/ztest/unit/objpool/testcase.yaml | Renames objpool test ID to the standardized sof.unit.* namespace. |
| test/ztest/unit/math/basic/trigonometry/testcase.yaml | Renames trigonometry test ID under sof.unit.math.basic.*. |
| test/ztest/unit/math/basic/complex/testcase.yaml | Renames complex test ID under sof.unit.math.basic.*. |
| test/ztest/unit/math/basic/arithmetic/testcase.yaml | Renames arithmetic test ID to sof.unit.math.basic.arithmetic. |
| test/ztest/unit/math/advanced/functions/testcase.yaml | Renames advanced functions test ID and expands tags for filtering. |
| test/ztest/unit/math/advanced/functions/test_exponential_ztest.c | Adds Ztest port of exponential-related unit tests. |
| test/ztest/unit/math/advanced/functions/test_base2_logarithm_ztest.c | Adds Ztest port of base2 logarithm unit test. |
| test/ztest/unit/math/advanced/functions/CMakeLists.txt | Extends sources for new tests and math implementations. |
| test/ztest/unit/list/testcase.yaml | Renames list test ID to sof.unit.list. |
| test/ztest/unit/fast-get/testcase.yaml | Renames fast-get test ID to sof.unit.fast_get. |
Comments suppressed due to low confidence (1)
test/ztest/unit/math/advanced/functions/test_exponential_ztest.c:55
saturate32()returnsint32_tbut returnsx(anint64_t) directly. While the preceding bounds checks ensure it’s in range, adding an explicit cast (e.g.,(int32_t)x) avoids implicit-narrowing warnings and makes the intent clearer.
return x;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
test/ztest/unit/math/advanced/functions/test_exponential_ztest.c
Outdated
Show resolved
Hide resolved
test/ztest/unit/math/advanced/functions/test_base2_logarithm_ztest.c
Outdated
Show resolved
Hide resolved
serhiy-katsyuba-intel
approved these changes
Mar 3, 2026
Member
|
@tmleman I guess you have fixed the copilot comments ? If so, can you resolve. Btw, its OK to click the sign-off from copilot if needed to save effort. |
6defa2e to
d8d37f3
Compare
Contributor
Author
@lgirdwood now I have |
This patch converts 1 existing math advanced function unit test from CMock/Unity to Zephyr's Ztest framework, maintaining the same test coverage and functionality: - test_math_arithmetic_base2log_fixed: Fixed-point base-2 logarithm Original test converted from sof/test/cmocka/src/math/arithmetic/base2_logarithm.c authored by: - Shriram Shastry <malladi.sastry@linux.intel.com> The converted test validates the same base2_logarithm() function from src/math/base2log.c as the original CMock test, ensuring no regression in test coverage during the migration to Ztest framework. Reference tables and tolerance values are preserved to maintain identical test accuracy and validation criteria. Test validates 100 uniformly distributed input values across the full uint32_t range using MATLAB-generated reference data with fixed-point arithmetic: - Input values: Q32.0 format (unsigned 32-bit integers) - Results: Q16.16 format - Reference: MATLAB log2() function results - Tolerance: max error 0.0000236785999981, THD -92.5128795787487235 This continues the SOF unit test migration from CMock to Zephyr Ztest framework as part of the math/advanced/functions test suite. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Remove explicit linking of math library (-lm) from advanced math function tests to fix native_sim build failures. The explicit target_link_libraries(app PRIVATE m) caused linker errors with __x86.get_pc_thunk.bx symbols in Zephyr's native_sim builds. This occurs because native_sim's build system already handles math library linkage, and explicitly adding it creates conflicting symbol references during the final native simulator linking stage. The math library functions (exp, pow, log2, etc.) used in tests are still available as Zephyr automatically links libm for native_sim targets. Error example: `__x86.get_pc_thunk.bx' referenced in section `.text' of zephyr.elf.loc_cpusw.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' Related: zephyrproject-rtos/zephyr#97999 Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Port exponential function tests from CMock/CMocka to Zephyr Ztest framework. Migrates tests from test/cmocka/src/math/arithmetic/exponential.c to test/ztest/unit/math/advanced/functions/test_exponential_ztest.c. Test coverage includes: - sofm_exp_approx(): ULP-based validation of Q28 -> Q19 approximation (256 samples, range -8 to 8) - sofm_exp_fixed(): Fixed-point exponential Q27 -> Q20 - Full range: -16 to 16 (100 samples, coarse grid) - Middle range: -11.5 to 7.6245 (100 samples, fine grid) - sofm_db2lin_fixed(): dB to linear conversion Q24 -> Q20 (100 samples, range -128 to 128 dB) Changes: - Add test_exponential_ztest.c with 3 test functions (291 lines) - Update CMakeLists.txt to build exp_fcn.c and exp_fcn_hifi.c - Add comment noting exp_fcn_hifi.c is Xtensa HiFi-specific - Update testcase.yaml tags: exponential, exp, db2lin - Use Zephyr LOG_INF for diagnostic output instead of printf All tests validate against reference implementations using absolute and relative error tolerances appropriate for fixed-point arithmetic. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR migrates SOF math unit tests from CMock to Zephyr Ztest framework and standardizes test naming conventions.