Skip to content

test: math: port window CMocka test to ztest - #11371

Merged
lgirdwood merged 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ut/ztest/math/window
Oct 29, 2026
Merged

lgirdwood merged 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ut/ztest/math/window

Conversation

@tmleman

@tmleman tmleman commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Port the legacy CMocka unit test test/cmocka/src/math/window/window.c to a Zephyr ztest suite under test/ztest/unit/math/window/.

sof.unit.math.window mirrors window.c: it links src/math/window.c and its trig/log/decibels dependencies, matching the legacy CMakeLists.txt, and converts the 4 window checks (rectangular, Blackman, Hamming, Povey) into one ZTEST case each, all against the same 1.0 LSB RMS error limit, computed by the same float math. The reference windows (ref_window_*.h) are #included in place from the CMocka tree via the include path, shared verbatim between both frameworks, as test/ztest/unit/math/{a_law,mu_law,fft} already do. The CMocka test keeps running unchanged.

Each ZTEST case now calls its window function directly, so the strcmp() dispatch on a window name string of the original test_window() is dropped, along with the #ifdef DEBUG_FILES dump, which was an unused diagnostic. The scratch window is a static array sized by the longest reference vector rather than a malloc() per call, with BUILD_ASSERTs tying it to the reference lengths, so the suite needs no allocator at all.

Two build differences against CMocka, neither of which changes the error math: Zephyr compiles with -Wdouble-promotion, so the RMS uses sqrtf() and casts its float arguments to double explicitly at the printk() varargs call sites, and CONFIG_CBPRINTF_FP_SUPPORT=y is needed because printk() otherwise emits the %f conversions of the log and of the failure message literally.

Verified with:
west twister -T sof/test/ztest/unit/math/window/ --platform native_sim
-> sof.unit.math.window: 4/4 cases PASSED
-> whole unit tree: 15/15 configurations, 122/122 cases PASSED, with
and without --enable-asan --enable-lsan

The reported RMS errors are identical to the ones the CMocka test computes from the same references, in LSB:

window CMocka ztest limit
rectangular 0.00 0.00 1.00
blackman 0.67 0.67 1.00
hamming 0.00 0.00 1.00
povey 0.29 0.29 1.00

Like the CMocka test, the suite covers only the 16-bit windows that have reference vectors. win_rectangular_32b(), win_blackman_32b(), win_hann_16b(), win_hann_32b() and win_hamming_32b() stay uncovered.

Assisted-by: Copilot:claude-opus-5

Copilot AI balanced review requested due to automatic review settings October 28, 2026 15:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The window-function test migration has no active review issues.

No open issues 🎉

What changed in this PR

Ports the legacy CMocka window-function tests to Zephyr ztest while keeping the existing CMocka suite unchanged.

Changes:

  • Adds four tests for 16-bit rectangular, Blackman, Hamming, and Povey windows, sharing the existing reference vectors and RMS error threshold.
  • Uses a statically allocated scratch buffer with compile-time size checks.
  • Adds native_sim test configuration, math dependencies, and floating-point diagnostic support.
File Description
test/​ztest/​unit/​math/​window/​testcase.yaml Registers the window test suite for native_sim.
test/​ztest/​unit/​math/​window/​test_window_ztest.c Implements four window checks with shared RMS validation.
test/​ztest/​unit/​math/​window/​prj.conf Enables ztest and floating-point message formatting.
test/​ztest/​unit/​math/​window/​CMakeLists.txt Links window math sources and includes shared reference vectors.

Review effort: Balanced

@intel-sofci

intel-sofci commented Oct 28, 2026 •

Copy link
Copy Markdown

PR 11371: test results

Run date: 2026-10-29 17:36 UTC

Tested commit: ef83ef416323c3e0f19c0df12e993b540a1d6fe1

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood

Copy link
Copy Markdown
Member

@tmleman can you check CI thanks !

@tmleman
tmleman force-pushed the topic/upstream/pr/ut/ztest/math/window branch from 026f5fc to ef83ef4 Compare October 29, 2026 08:30
Port the legacy CMocka unit test test/cmocka/src/math/window/window.c to a
Zephyr ztest suite under test/ztest/unit/math/window/.

sof.unit.math.window mirrors window.c: it links src/math/window.c and its
trig/log/decibels dependencies, matching the legacy CMakeLists.txt, and
converts the 4 window checks (rectangular, Blackman, Hamming, Povey) into
one ZTEST case each, all against the same 1.0 LSB RMS error limit, computed
by the same float math. The reference windows (ref_window_*.h) are
#included in place from the CMocka tree via the include path, shared
verbatim between both frameworks, as test/ztest/unit/math/{a_law,mu_law,fft}
already do. The CMocka test keeps running unchanged.

Each ZTEST case now calls its window function directly, so the strcmp()
dispatch on a window name string of the original test_window() is dropped,
along with the #ifdef DEBUG_FILES dump, which was an unused diagnostic.
The scratch window is a static array sized by the longest reference vector
rather than a malloc() per call, with BUILD_ASSERTs tying it to the
reference lengths, so the suite needs no allocator at all.

Two build differences against CMocka, neither of which changes the error
math: Zephyr compiles with -Wdouble-promotion, so the RMS uses sqrtf() and
casts its float arguments to double explicitly at the printk() varargs call
sites, and CONFIG_CBPRINTF_FP_SUPPORT=y is needed because printk()
otherwise emits the %f conversions of the log and of the failure message
literally.

Verified with:
  west twister -T sof/test/ztest/unit/math/window/ --platform native_sim
  -> sof.unit.math.window: 4/4 cases PASSED
  -> whole unit tree: 15/15 configurations, 122/122 cases PASSED, with
     and without --enable-asan --enable-lsan

The reported RMS errors are identical to the ones the CMocka test computes
from the same references, in LSB:

  window        CMocka   ztest   limit
  rectangular     0.00    0.00    1.00
  blackman        0.67    0.67    1.00
  hamming         0.00    0.00    1.00
  povey           0.29    0.29    1.00

Like the CMocka test, the suite covers only the 16-bit windows that have
reference vectors. win_rectangular_32b(), win_blackman_32b(),
win_hann_16b(), win_hann_32b() and win_hamming_32b() stay uncovered.

Assisted-by: Copilot:claude-opus-5
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
@tmleman

tmleman commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@tmleman can you check CI thanks !

Not related to my PR.

@lgirdwood
lgirdwood merged commit e6c0f55 into thesofproject:main Oct 29, 2026
45 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.

5 participants