Repository navigation
Conversation
tmleman
requested review from
dbaluta,
kv2019i,
lbetlej,
lgirdwood,
mmaka1 and
plbossart
as code owners
November 16, 2026 13:19
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The test comment incorrectly describes R = 1 as a pure differentiator, although the recurrence yields passthrough behavior with zero initial state.
1 open issue
What changed in this PR
Ports the DC-blocking filter’s fixed-point math tests from CMocka to Zephyr ztest, advancing SOF’s math-test migration without changing production code.
Changes:
- Adds six cases covering passthrough, DC removal, saturation, and reference comparisons for S32, S16, and S24 formats.
- Adds a minimal test target linking
dcblock_generic.candnumbers.c. - Configures native_sim execution and floating-point diagnostic output.
| File | Description |
|---|---|
| test/ztest/unit/math/dcblock/testcase.yaml | Registers the suite for native_sim. |
| test/ztest/unit/math/dcblock/test_dcblock_ztest.c | Implements six tests and reference helpers. |
| test/ztest/unit/math/dcblock/prj.conf | Enables ztest and floating-point formatting. |
| test/ztest/unit/math/dcblock/CMakeLists.txt | Defines the test target, sources, and dependencies. |
Review effort: Balanced
| return tail_count ? tail_abs_sum / tail_count : 0.0; | ||
| } | ||
|
|
||
| /* Passthrough: R = 1.0 gives y[n] = x[n] - x[n-1], a pure differentiator. */ |
Add a ztest suite for the DC-blocking filter's fixed-point math (dcblock_generic.c), covering the same six cases as the CMocka test: passthrough, DC removal convergence, saturation, and bit-exact checks for S32, S16 and S24 sample formats. This closes one of the two "misfiled" math tests identified in the Phase 3 plan (filed under test/cmocka/src/audio/dcblock/ despite testing pure math, not the component), with drc_math_test deferred to Phase 4. Only dcblock_generic.c and numbers.c are linked, matching the CMocka target's source list. M_PI is not exposed by <math.h> under this toolchain's strict -std=c17 build, so it is defined locally guarded by #ifndef, matching the value already used elsewhere without relying on glibc feature-test macros. Code coverage testing did not reveal any regression. CMock stats for dcblock_generic.c - lines: 100.0 % (78/78) - branches: 67.2 % (39/58) Ztest stats for dcblock_generic.c - lines: 74.0 % (74/100) - branches: 60.0 % (24/40) The ztest denominator is larger because CONFIG_FORMAT_FLOAT=y on native_sim compiles in dcblock_float_default(), an inert float code path that neither framework's test exercises (legacy CMocka scope is integer formats only); the cmocka build never compiles that function in at all. Restricted to the int-format code shared by both builds, coverage is equivalent. Mutation-tested by dropping the pole term from dcblock_generic()'s difference equation, confirming 5 of 6 cases fail, then reverting. Verified clean under --enable-asan --enable-lsan. Assisted-by: Copilot:claude-sonnet-5 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.

Add a ztest suite for the DC-blocking filter's fixed-point math (dcblock_generic.c), covering the same six cases as the CMocka test: passthrough, DC removal convergence, saturation, and bit-exact checks for S32, S16 and S24 sample formats. This closes one of the two "misfiled" math tests identified in the Phase 3 plan (filed under test/cmocka/src/audio/dcblock/ despite testing pure math, not the component), with drc_math_test deferred to Phase 4.
Only dcblock_generic.c and numbers.c are linked, matching the CMocka target's source list. M_PI is not exposed by <math.h> under this toolchain's strict -std=c17 build, so it is defined locally guarded by #ifndef, matching the value already used elsewhere without relying on glibc feature-test macros.
Code coverage testing did not reveal any regression.
CMock stats for dcblock_generic.c
Ztest stats for dcblock_generic.c
The ztest denominator is larger because CONFIG_FORMAT_FLOAT=y on native_sim compiles in dcblock_float_default(), an inert float code path that neither framework's test exercises (legacy CMocka scope is integer formats only); the cmocka build never compiles that function in at all. Restricted to the int-format code shared by both builds, coverage is equivalent.
Mutation-tested by dropping the pole term from dcblock_generic()'s difference equation, confirming 5 of 6 cases fail, then reverting. Verified clean under --enable-asan --enable-lsan.
Assisted-by: Copilot:claude-sonnet-5