Skip to content

test: ztest: Add scalar power function support and unit test - #10364

Merged
lgirdwood merged 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/unit_test/ztest/math/scalar_power
Nov 28, 2025
Merged

test: ztest: Add scalar power function support and unit test#10364
lgirdwood merged 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/unit_test/ztest/math/scalar_power

Conversation

@tmleman

@tmlemantmleman commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

Add Zephyr ztest framework support for scalar power function and convert existing CMock unit test to ztest.

Changes

  1. math/power.c: Add conditional Zephyr logging for ztest compatibility
  2. test_scalar_power_ztest.c: Convert CMock test to ztest framework

CopilotAI review requested due to automatic review settings November 13, 2025 13:26
@tmlemantmleman changed the title topic/upstream/pr/unit_test/ztest/math/scalar_powertest: ztest: Add scalar power function support and unit testNov 13, 2025

CopilotAI 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.

Pull Request Overview

This PR converts the scalar power function unit test from CMock to Zephyr's ztest framework and adds conditional Zephyr logging support to the implementation.

Key Changes:

  • Added Zephyr-compatible logging infrastructure to power.c using conditional compilation
  • Created new ztest-based unit test file (test_scalar_power_ztest.c) with 384 test cases (64 base values × 6 exponents)

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

FileDescription
test/ztest/unit/math/advanced/functions/test_scalar_power_ztest.cNew ztest implementation of scalar power unit tests with MATLAB reference validation
test/ztest/unit/math/advanced/functions/CMakeLists.txtBuild configuration for the new ztest suite with SOF-specific compiler flags
src/math/power.cAdded conditional compilation to support both traditional SOF trace logging and Zephyr logging

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to +51
float delta = fabsf((float)(power_table[i][j] - (double)p / (1 << 15)));

zassert_true(delta <= CMP_TOLERANCE);

CopilotAINov 13, 2025

Copy link

Choose a reason for hiding this comment

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

The magic number 1 << 15 represents the Q16.15 fixed-point scaling factor. Consider defining it as a named constant (e.g., Q16_15_SCALE) to improve code clarity and match the documented format in the function documentation.

Copilot uses AI. Check for mistakes.
Comment threadtest/ztest/unit/math/advanced/functions/test_scalar_power_ztest.c Outdated
Comment threadsrc/math/power.c Outdated
Comment threadsrc/math/power.c
@tmleman
tmlemanforce-pushed the topic/upstream/pr/unit_test/ztest/math/scalar_power branch from 0bac709 to 13bb7bcCompareNovember 14, 2025 14:42
@tmleman
tmleman requested a review from lyakhNovember 14, 2025 14:44
This patch converts 1 existing math advanced function unit test from
CMock/Unity to Zephyr's Ztest framework, maintaining the same test
coverage and functionality:
- test_math_arithmetic_power_fixed: Fixed-point scalar power function
Original test converted from
sof/test/cmocka/src/math/arithmetic/scalar_power.c authored by:
- Shriram Shastry <malladi.sastry@linux.intel.com>
The converted test validates the same power_int32() function from
src/math/power.c as the original CMock test, ensuring no regression in
test coverage during the migration to Ztest framework. Reference tables
and tolerance values are preserved to maintain identical test accuracy
and validation criteria.
Test validates 384 combinations (64 base values × 6 exponent values)
using MATLAB-generated reference data with fixed-point arithmetic:
- Base values: Q6.25 format (range -1.0 to 1.0)
- Exponent values: Q2.29 format
- Results: Q16.15 format
- Tolerance: max error 0.000034912111005, THD+N -96.457180359025074
This is part of the broader SOF unit test migration from CMock to Zephyr
Ztest framework, establishing the foundation for math/advanced/functions
tests in the new directory structure.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
@lgirdwood
lgirdwood merged commit e5bfb77 into thesofproject:mainNov 28, 2025
40 of 42 checks passed
lgirdwood pushed a commit that referenced this pull request Jul 2, 2026
This patch removes the scalar power test that has been successfully
converted from cmocka to ztest.
The ztest equivalent is in test/ztest/unit/math/advanced/functions/
test_scalar_power_ztest.c and was merged in PR #10364.
Ztest coverage for power.c:
- lines: 92.9% (13/14)
- funcs: 100% (1/1)
Code coverage testing did not reveal any regression.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Sign up for freeto 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

@tmleman@lyakh@lgirdwood@softwarecki