Skip to content

Conversation

@tmleman
Copy link
Contributor

@tmleman tmleman commented Jul 24, 2025

Convert legacy CMock-based fast-get unit tests to Zephyr Ztest framework.

This patch converts the existing fast-get unit tests from CMock/Unity to Zephyr's Ztest framework, maintaining the same test coverage and functionality:

  • test_simple_fast_get_put: Basic fast_get/fast_put functionality
  • test_fast_get_size_missmatch_test: Size mismatch error handling
  • test_over_32_fast_gets_and_puts: Multiple allocation handling (>32)
  • test_fast_get_refcounting: Reference counting validation

The converted tests validate the same fast-get library functionality as the original CMock tests, ensuring no regression in test coverage during the migration to Ztest framework.

Copilot AI review requested due to automatic review settings July 24, 2025 16:59
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 legacy CMock-based fast-get unit tests to Zephyr's Ztest framework, maintaining equivalent test coverage while modernizing the testing approach. The conversion includes four main test functions that validate fast-get library functionality including basic operations, error handling, multiple allocations, and reference counting.

  • Converts four CMock/Unity tests to Ztest framework with identical functionality
  • Implements mock memory allocation functions using standard malloc/free
  • Adds proper Ztest configuration and build setup for the fast-get module

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
test/ztest/unit/fast-get/testcase.yaml Test configuration defining platform requirements and test metadata
test/ztest/unit/fast-get/test_fast_get_ztest.c Main test implementation with converted test cases and mock functions
test/ztest/unit/fast-get/prj.conf Zephyr project configuration enabling Ztest framework
test/ztest/unit/fast-get/CMakeLists.txt CMake build configuration with SOF integration and function wrapping

{ 18 },
{ 19 },
{ 20 },
{ 21 },
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

The testdata array has a gap in the sequence - it jumps from 21 to 23, skipping 22. This could indicate a copy-paste error or intentional omission that should be documented.

Suggested change
{ 21 },
{ 21 },
{ 22 },

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tmleman If intentional skip, this would warrant a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The data comes from the original test: https://github.com/thesofproject/sof/blob/main/test/cmocka/src/lib/fast-get/fast-get-tests.c#L54-L57
I'll check the history of those tests to see if I can find any justification for this. There's nothing in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kv2019i git didn't tell me anything interesting. The test has looked like this from the beginning, and there doesn't seem to be any hidden meaning behind it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ack @tmleman . It looks like a bug, but maybe fix in a follow-up PR and move the test code as-is in this one.

* Tests that fast_get returns NULL when requested size doesn't match
* previously allocated size for the same data pointer.
*/
ZTEST(fast_get_suite, test_fast_get_size_missmatch_test)
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Function name contains a spelling error: 'missmatch' should be 'mismatch'.

Suggested change
ZTEST(fast_get_suite, test_fast_get_size_missmatch_test)
ZTEST(fast_get_suite, test_fast_get_size_mismatch_test)

Copilot uses AI. Check for mistakes.
Comment on lines +144 to +147
copy[i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy); i++)
zassert_mem_equal(copy[i], testdata[i], sizeof(testdata[0]),
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Using sizeof(testdata[0]) for all array elements is incorrect. testdata[0] has 100 elements while testdata[1] through testdata[32] only have 1 element each. This should use sizeof(testdata[i]) to get the correct size for each test data array.

Suggested change
copy[i] = fast_get(testdata[i], sizeof(testdata[0]));
for (i = 0; i < ARRAY_SIZE(copy); i++)
zassert_mem_equal(copy[i], testdata[i], sizeof(testdata[0]),
copy[i] = fast_get(testdata[i], sizeof(testdata[i]));
for (i = 0; i < ARRAY_SIZE(copy); i++)
zassert_mem_equal(copy[i], testdata[i], sizeof(testdata[i]),

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

copilot forgot which language it's reviewing. False positive.

Comment on lines +144 to +147
copy[i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy); i++)
zassert_mem_equal(copy[i], testdata[i], sizeof(testdata[0]),
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Using sizeof(testdata[0]) for memory comparison is incorrect for elements beyond testdata[0]. This will read beyond the bounds of testdata[1] through testdata[32] which only contain 1 element each. Should use sizeof(testdata[i]).

Suggested change
copy[i] = fast_get(testdata[i], sizeof(testdata[0]));
for (i = 0; i < ARRAY_SIZE(copy); i++)
zassert_mem_equal(copy[i], testdata[i], sizeof(testdata[0]),
copy[i] = fast_get(testdata[i], sizeof(testdata[i]));
for (i = 0; i < ARRAY_SIZE(copy); i++)
zassert_mem_equal(copy[i], testdata[i], sizeof(testdata[i]),

Copilot uses AI. Check for mistakes.
Comment on lines +167 to +177
copy[0][i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[0]),
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Using sizeof(testdata[0]) for all elements is incorrect. Should use sizeof(testdata[i]) to get the correct size for each individual test data array.

Suggested change
copy[0][i] = fast_get(testdata[i], sizeof(testdata[0]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[0]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[0]),
copy[0][i] = fast_get(testdata[i], sizeof(testdata[i]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[i]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[i]),

Copilot uses AI. Check for mistakes.
Comment on lines +167 to +177
copy[0][i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[0]),
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Using sizeof(testdata[0]) for all elements is incorrect. Should use sizeof(testdata[i]) to get the correct size for each individual test data array.

Suggested change
copy[0][i] = fast_get(testdata[i], sizeof(testdata[0]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[0]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[0]),
copy[0][i] = fast_get(testdata[i], sizeof(testdata[i]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[i]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[i]),

Copilot uses AI. Check for mistakes.
Comment on lines +167 to +177
copy[0][i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");

for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[0]),
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Using sizeof(testdata[0]) for memory comparison will cause buffer overread for testdata[1] through testdata[32]. Should use sizeof(testdata[i]).

Suggested change
copy[0][i] = fast_get(testdata[i], sizeof(testdata[0]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[0]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[0]),
copy[0][i] = fast_get(testdata[i], sizeof(testdata[i]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
copy[1][i] = fast_get(testdata[i], sizeof(testdata[i]));
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_equal_ptr(copy[0][i], copy[1][i],
"Same data should return same pointer (refcounting)");
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[0][i], testdata[i], sizeof(testdata[i]),

Copilot uses AI. Check for mistakes.

/* Data should still be valid through second set of references */
for (i = 0; i < ARRAY_SIZE(copy[0]); i++)
zassert_mem_equal(copy[1][i], testdata[i], sizeof(testdata[0]),
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Using sizeof(testdata[0]) for memory comparison will cause buffer overread for testdata[1] through testdata[32]. Should use sizeof(testdata[i]).

Suggested change
zassert_mem_equal(copy[1][i], testdata[i], sizeof(testdata[0]),
zassert_mem_equal(copy[1][i], testdata[i], sizeof(testdata[i]),

Copilot uses AI. Check for mistakes.
Convert legacy CMock-based fast-get unit tests to Zephyr Ztest
framework.

This patch converts the existing fast-get unit tests from CMock/Unity
to Zephyr's Ztest framework, maintaining the same test coverage and
functionality:

- test_simple_fast_get_put: Basic fast_get/fast_put functionality
- test_fast_get_size_missmatch_test: Size mismatch error handling
- test_over_32_fast_gets_and_puts: Multiple allocation handling (>32)
- test_fast_get_refcounting: Reference counting validation

The converted tests validate the same fast-get library functionality
as the original CMock tests, ensuring no regression in test coverage
during the migration to Ztest framework.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Copy link
Collaborator

@lyakh lyakh left a comment

Choose a reason for hiding this comment

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

is it possible and do we plan to enable this in PR CI as a github worker?

Comment on lines +144 to +147
copy[i] = fast_get(testdata[i], sizeof(testdata[0]));

for (i = 0; i < ARRAY_SIZE(copy); i++)
zassert_mem_equal(copy[i], testdata[i], sizeof(testdata[0]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

copilot forgot which language it's reviewing. False positive.

@lyakh
Copy link
Collaborator

lyakh commented Jul 25, 2025

is it possible and do we plan to enable this in PR CI as a github worker?

false alarm - it's already running https://github.com/thesofproject/sof/actions/runs/16503100878/job/46666728466?pr=10136

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

@tmleman Can you check the one weird gap in test date copilot picked up? Rest looks great and good to go!

{ 18 },
{ 19 },
{ 20 },
{ 21 },
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tmleman If intentional skip, this would warrant a comment.

@kv2019i kv2019i merged commit bed24a7 into thesofproject:main Jul 30, 2025
39 of 45 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.

3 participants