test: ztest: Add scalar power function support and unit test#10364
Merged
lgirdwood merged 1 commit intothesofproject:mainfrom Nov 28, 2025
Merged
Conversation
There was a problem hiding this comment.
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.cusing 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.
| File | Description |
|---|---|
| test/ztest/unit/math/advanced/functions/test_scalar_power_ztest.c | New ztest implementation of scalar power unit tests with MATLAB reference validation |
| test/ztest/unit/math/advanced/functions/CMakeLists.txt | Build configuration for the new ztest suite with SOF-specific compiler flags |
| src/math/power.c | Added 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); |
There was a problem hiding this comment.
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.
test/ztest/unit/math/advanced/functions/test_scalar_power_ztest.c
Outdated
Show resolved
Hide resolved
2 tasks
lyakh
reviewed
Nov 14, 2025
0bac709 to
13bb7bc
Compare
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
approved these changes
Nov 17, 2025
softwarecki
approved these changes
Nov 27, 2025
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 Zephyr ztest framework support for scalar power function and convert existing CMock unit test to ztest.
Changes
math/power.c: Add conditional Zephyr logging for ztest compatibility