Skip to content

ut: ztest: Port of remaining tests from test/cmocka/src/math/arithmetic#10764

Merged
kv2019i merged 3 commits into
thesofproject:mainfrom
tmleman:topic/upstream/pr/unit_test/ztest/math/advanced_functions
May 13, 2026
Merged

ut: ztest: Port of remaining tests from test/cmocka/src/math/arithmetic#10764
kv2019i merged 3 commits into
thesofproject:mainfrom
tmleman:topic/upstream/pr/unit_test/ztest/math/advanced_functions

Conversation

@tmleman
Copy link
Copy Markdown
Contributor

@tmleman tmleman commented May 11, 2026

This PR contains the port of the last tests from category Advanced Math Functions. Porting is being done as part of #10110.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ztest cases for log10_int32(), ln_int32(), and sofm_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.

Comment thread test/ztest/unit/math/advanced/functions/test_base10_logarithm_ztest.c Outdated
Comment thread test/ztest/unit/math/advanced/functions/test_base_e_logarithm_ztest.c Outdated
Comment thread test/ztest/unit/math/advanced/functions/test_square_root_ztest.c
Comment thread test/ztest/unit/math/advanced/functions/test_square_root_ztest.c Outdated
Comment on lines +141 to +143
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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if we could just call sqrt(3) from libm instead of using a reference table?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but pls do resolve any copilot opens.

Comment thread test/ztest/unit/math/advanced/functions/test_square_root_ztest.c Outdated
Comment thread test/ztest/unit/math/advanced/functions/test_square_root_ztest.c Outdated
@tmleman tmleman force-pushed the topic/upstream/pr/unit_test/ztest/math/advanced_functions branch from 871e7cc to 997279b Compare May 13, 2026 09:34
tmleman added 3 commits May 13, 2026 12:57
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>
Comment on lines +141 to +143
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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

@tmleman can you check CI. Thanks !

@tmleman
Copy link
Copy Markdown
Contributor Author

tmleman commented May 13, 2026

@tmleman can you check CI. Thanks !

Strange failure in tests with dmic. Definitely not caused by adding unit tests. I will trigger rerun.

@kv2019i kv2019i merged commit 2896e23 into thesofproject:main May 13, 2026
43 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants