Skip to content

ut: Port a_law_codec and mu_law_codec from cmock to ztest. - #11238

Merged
lgirdwood merged 2 commits into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ut/ztest/math/codec/port_from_cmock
Sep 25, 2026
Merged

lgirdwood merged 2 commits into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ut/ztest/math/codec/port_from_cmock

Conversation

@tmleman

@tmleman tmleman commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI lite review requested due to automatic review settings September 25, 2026 15:16

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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Ports A-law and μ-law codec unit tests from CMocka to Zephyr Ztest.

Changes:

  • Adds encode/decode Ztest coverage for both codecs.
  • Adds native_sim metadata and configurations.
  • Reuses shared codec reference vectors.
File Description
test/​ztest/​unit/​math/​mu_law/​testcase.yaml μ-law test registration
test/​ztest/​unit/​math/​mu_law/​test_mu_law_codec_ztest.c μ-law Ztest cases
test/​ztest/​unit/​math/​mu_law/​prj.conf μ-law Ztest configuration
test/​ztest/​unit/​math/​mu_law/​CMakeLists.txt μ-law build setup
test/​ztest/​unit/​math/​a_law/​testcase.yaml A-law test registration
test/​ztest/​unit/​math/​a_law/​test_a_law_codec_ztest.c A-law Ztest cases
test/​ztest/​unit/​math/​a_law/​prj.conf A-law Ztest configuration
test/​ztest/​unit/​math/​a_law/​CMakeLists.txt A-law build setup

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Convert the legacy CMocka a_law_codec unit test to a Zephyr ztest suite
under test/ztest/unit/math/a_law, running on native_sim via twister as
scenario sof.unit.math.a_law.

The two ported cases keep identical intent, test data and fixed-point
semantics: test_a_law_encode encodes every s16 chirp sample with
sofm_a_law_encode() and test_a_law_decode expands every reference code
word with sofm_a_law_decode(), both compared against the same
pre-computed reference vectors. The reference-data headers
(ref_chirp_mono_8k_s16.h, a_law_codec.h) are #included in place from the
CMocka tree rather than copied, so both frameworks share the exact same
data.

Coverage of src/math/a_law.c (lcov hit/total; CMocka unit_test_defconfig
gcc vs ztest native_sim clang):

src/math/a_law.c
    CMocka: lines 32/32  functions 2/2  branches 8/8
    ztest:  lines 28/29  functions 2/2  branches 9/10

Functions match 2/2 and ztest covers one extra branch (9/10 vs 8/8).
Every line gcc executes is also executed by ztest, the differing line
totals are pure gcc/clang bucketing. The only line clang marks unhit
(the saturation clamp sample = SOFM_ALAW_MAX) is unreachable with the
shared chirp data, so gcc emits no counter for it either, there is no
real coverage regression.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Port both mu-law codec cases to native_sim ztest. Encode every s16
chirp sample and decode every reference code word. Keep the original
fixed-point comparisons and share the legacy vectors in place.

Coverage of src/math/mu_law.c (gcc CMocka vs clang ztest):
  CMocka: lines 31/31  functions 2/2  branches 6/6
  ztest:  lines 26/26  functions 2/2  branches 6/6
Both have full source coverage; totals differ by instrumentation.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Assisted-by: GitHub Copilot CLI:gpt-6-sol
@lgirdwood
lgirdwood merged commit 8293527 into thesofproject:main Sep 25, 2026
46 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.

4 participants