Skip to content

Conversation

@tmleman
Copy link
Contributor

@tmleman tmleman commented Nov 13, 2025

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

Copilot AI review requested due to automatic review settings November 13, 2025 13:26
@tmleman tmleman changed the title topic/upstream/pr/unit_test/ztest/math/scalar_power test: ztest: Add scalar power function support and unit test Nov 13, 2025
Copy link

Copilot AI left a 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.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.

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);
Copy link

Copilot AI Nov 13, 2025

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.
@tmleman tmleman force-pushed the topic/upstream/pr/unit_test/ztest/math/scalar_power branch from 0bac709 to 13bb7bc Compare November 14, 2025 14:42
@tmleman tmleman requested a review from lyakh November 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:main Nov 28, 2025
40 of 42 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