-
Notifications
You must be signed in to change notification settings - Fork 349
test: ztest: Add math basic arithmetic unit tests converted from CMock #10138
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 math basic arithmetic unit tests converted from CMock #10138
Conversation
db3d0e6 to
a503091
Compare
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 legacy CMock-based math basic arithmetic unit tests to Zephyr's Ztest framework, maintaining the same test coverage while modernizing the test infrastructure.
- Migrates 6 math arithmetic test files from CMock/Unity to Ztest format
- Preserves original test functionality with 18 total test cases covering GCD, ceiling division, and array operations
- Establishes new directory structure for math unit tests under ztest framework
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| testcase.yaml | Defines test configuration for math.basic.arithmetic test suite |
| CMakeLists.txt | Build configuration linking SOF math sources and test files |
| prj.conf | Minimal Zephyr project configuration enabling Ztest |
| test_gcd_ztest.c | GCD function tests with 8 test cases including edge cases |
| test_ceil_divide_ztest.c | Ceiling division test with comprehensive parameter combinations |
| test_find_equal_int16_ztest.c | Array search tests for matching int16 values |
| test_find_min_int16_ztest.c | Minimum value finding tests for int16 arrays |
| test_find_max_abs_int32_ztest.c | Maximum absolute value tests for int32 arrays |
| test_norm_int32_ztest.c | Integer normalization tests with various input values |
| /** | ||
| * @brief Define and initialize the math arithmetic test suite | ||
| */ | ||
| ZTEST_SUITE(math_arithmetic_suite, NULL, NULL, NULL, NULL, NULL); |
Copilot
AI
Jul 31, 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 test suite is defined in test_gcd_ztest.c but used across multiple test files. This creates a dependency where other test files rely on this suite definition, making the code less maintainable. Consider moving the ZTEST_SUITE definition to a separate common file or define it in each test file that uses it.
lgirdwood
left a comment
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.
LGTM, but will need @singalsu to review the maths.
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(test_math_arithmetic) | ||
|
|
||
| set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../../..") |
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.
Longterm we should be able to get this from SOF_WORKSPACE environment variable.
|
@tmleman btw, do you plan to remove the cmocka test once this is merged ? |
@lgirdwood I was the first to ask this question: #10110 (comment) :) |
| int16_t vec[] = {5, 123, 5, 10, 123, 500, 123}; | ||
| int16_t template[] = {1, 4, 6}; | ||
|
|
||
| int r_num = find_equal_int16(r, vec, 123, 7, 4); |
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.
find_equal_int16() should have const arguments, then the above arrays could be const
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.
More functions could undergo such treatment, so it can be done in a later refactor (#10110 (comment)).
| ZTEST(math_arithmetic_suite, test_math_numbers_find_max_abs_int32_negative_max) | ||
| { | ||
| int32_t vec[] = {-100, 99, 98, 50}; | ||
| int r = find_max_abs_int32(vec, ARRAY_SIZE(vec)); |
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.
also should be const. Also to be perfectly strict r should be int32_t
|
@tmleman Do we have instructions how to run tests under ztest? I'm curious since I'm not familiar with it. |
a503091 to
8a83cdf
Compare
@singalsu I haven't prepared any documentation yet. Ultimately, it will rather be a brief description because Zephyr already has documentation for the entire framework: https://docs.zephyrproject.org/latest/develop/test/index.html Building and running can be done with a single command: If you have the environment to build FW, you're almost there, just install Clang. The GH workflow contains all the required steps: https://github.com/thesofproject/sof/blob/main/.github/workflows/zephyr-unit-tests.yml |
Convert legacy CMock-based math basic arithmetic unit tests to Zephyr Ztest framework. This patch converts 6 existing math arithmetic unit tests from CMock/Unity to Zephyr's Ztest framework, maintaining the same test coverage and functionality: - test_gcd_ztest.c: Greatest common divisor (8 test cases) - test_ceil_divide_ztest.c: Ceiling division (1 test case) - test_find_equal_int16_ztest.c: Find equal int16 values (2 test cases) - test_find_min_int16_ztest.c: Find minimum int16 (2 test cases) - test_find_max_abs_int32_ztest.c: Find max absolute int32 (2 test cases) - test_norm_int32_ztest.c: Normalize int32 (3 test cases) The converted tests validate the same mathematical functions from src/math/numbers.c as the original CMock tests, ensuring no regression in test coverage during the migration to Ztest framework. This is part of the broader SOF unit test migration from CMock to Zephyr Ztest framework, establishing the foundation for math/basic/arithmetic tests in the new directory structure. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Thanks, sounds good, I'll try the above! |
kv2019i
left a comment
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.
Given this is forklift of the cmock versions, I'm good with this version.
Convert legacy CMock-based math basic arithmetic unit tests to Zephyr Ztest framework.
This patch converts 6 existing math arithmetic unit tests from CMock/Unity to Zephyr's Ztest framework, maintaining the same test coverage and functionality:
The converted tests validate the same mathematical functions from src/math/numbers.c as the original CMock tests, ensuring no regression in test coverage during the migration to Ztest framework.
This is part of the broader SOF unit test migration from CMock to Zephyr Ztest framework, establishing the foundation for math/basic/arithmetic tests in the new directory structure.