-
Notifications
You must be signed in to change notification settings - Fork 349
test: ztest: Add scalar power function support and unit test #10364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: ztest: Add scalar power function support and unit test #10364
Conversation
There was a problem hiding this comment.
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.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.
| float delta = fabsf((float)(power_table[i][j] - (double)p / (1 << 15))); | ||
|
|
||
| zassert_true(delta <= CMP_TOLERANCE); |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
test/ztest/unit/math/advanced/functions/test_scalar_power_ztest.c
Outdated
Show resolved
Hide resolved
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>
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