ut: ztest: Port of remaining tests from test/cmocka/src/math/arithmetic#10764
Conversation
There was a problem hiding this comment.
Pull request overview
This PR continues the SOF unit test migration from CMocka to Zephyr’s ztest framework (issue #10110) by adding the remaining “Advanced Math Functions” tests (base-10 log, natural log, and square root) to the test/ztest/unit/math/advanced/functions suite.
Changes:
- Add new
ztestcases forlog10_int32(),ln_int32(), andsofm_sqrt_int16(). - Wire the new tests (and required SOF math sources) into the unit test CMake build.
- Update the test metadata tags to reflect the newly covered functions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/ztest/unit/math/advanced/functions/testcase.yaml | Updates test tags to include newly added advanced-math coverage. |
| test/ztest/unit/math/advanced/functions/CMakeLists.txt | Adds new test sources and links in required SOF math implementations. |
| test/ztest/unit/math/advanced/functions/test_square_root_ztest.c | New ztest for fixed-point square root against reference table. |
| test/ztest/unit/math/advanced/functions/test_base10_logarithm_ztest.c | New ztest for fixed-point base-10 log against reference table. |
| test/ztest/unit/math/advanced/functions/test_base_e_logarithm_ztest.c | New ztest for fixed-point natural log against reference table. |
| for (i = 0; i < ARRAY_SIZE(sqrt_ref_table); i++) { | ||
| y = (double)Q_CONVERT_QTOF(sofm_sqrt_int16(u[i]), 12); | ||
| diff = fabs(sqrt_ref_table[i] - y); |
There was a problem hiding this comment.
wondering if we could just call sqrt(3) from libm instead of using a reference table?
There was a problem hiding this comment.
Current approach validates against MATLAB-generated reference table which is the established SOF pattern. This PR is just porting old test to new framework. Improvents can be done as follow-up.
There was a problem hiding this comment.
ack, so our maths library is optimized for speed/size and accuracy need for audio sample size rather than accuracy needed for double, so results could vary depending on the input. Lets not use generic maths library.
lgirdwood
left a comment
There was a problem hiding this comment.
LGTM, but pls do resolve any copilot opens.
871e7cc to
997279b
Compare
Convert the square root math unit test from CMock/CMocka to Ztest. Port test_math_arithmetic_sqrt_fixed from sof/test/cmocka/src/math/arithmetic/square_root.c originally authored by Shriram Shastry <malladi.sastry@linux.intel.com>. Preserve the original reference data and tolerance, add the new Ztest source to the math advanced functions suite, and build src/math/sqrt_int16.c. Validated with west twister on native_sim using host/llvm. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Convert the base-10 logarithm math unit test from CMock/CMocka to Ztest. Port test_math_arithmetic_base10log_fixed from sof/test/cmocka/src/math/arithmetic/base_10_logarithm.c originally authored by Shriram Shastry <malladi.sastry@linux.intel.com>. Preserve the original reference data and tolerance, add the new Ztest source to the math advanced functions suite, and build src/math/log_10.c. Validated with west twister on native_sim using host/llvm. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Convert the natural (base-e) logarithm math unit test from CMock/CMocka to Ztest. Port test_math_arithmetic_base_e_log_fixed from sof/test/cmocka/src/math/arithmetic/base_e_logarithm.c originally authored by Shriram Shastry <malladi.sastry@linux.intel.com>. Preserve the original reference data and tolerance, add the new Ztest source to the math advanced functions suite, and build src/math/log_e.c. Validated with west twister on native_sim using host/llvm. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
| for (i = 0; i < ARRAY_SIZE(sqrt_ref_table); i++) { | ||
| y = (double)Q_CONVERT_QTOF(sofm_sqrt_int16(u[i]), 12); | ||
| diff = fabs(sqrt_ref_table[i] - y); |
There was a problem hiding this comment.
ack, so our maths library is optimized for speed/size and accuracy need for audio sample size rather than accuracy needed for double, so results could vary depending on the input. Lets not use generic maths library.
|
@tmleman can you check CI. Thanks ! |
Strange failure in tests with dmic. Definitely not caused by adding unit tests. I will trigger rerun. |
This PR contains the port of the last tests from category
Advanced Math Functions. Porting is being done as part of #10110.