Skip to content

Tests: kernel: mem_heap: increase k_heap test coverage #92740

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JarmouniA
Copy link
Contributor

Add test for k_heap_aligned_alloc() API.
Enhance k_heap_free() and k_heap_calloc() APIs testing.

@JarmouniA JarmouniA added area: Kernel area: Tests Issues related to a particular existing or missing test labels Jul 5, 2025
JarmouniA added 3 commits July 5, 2025 23:18
add test coverage for k_heap_aligned_alloc() k_heap API

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
Enhance k_heap_calloc() API coverage by testing overflow and zero-size
edge cases

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
Enhance k_heap_free() API coverage by testing NULL free & double free
edge cases

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
Copy link

sonarqubecloud bot commented Jul 5, 2025

@JarmouniA JarmouniA marked this pull request as ready for review July 5, 2025 21:48
@JarmouniA JarmouniA added this to the v4.2.0 milestone Jul 7, 2025
@JarmouniA
Copy link
Contributor Author

@andyross @peter-mitsis could you take a quick look? thanks!

Copy link

@npitre npitre left a comment

Choose a reason for hiding this comment

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

Please don't assume k_heap_aligned_alloc() may accept non-power-of-two
alignment. There is a special understanding between z_alloc_helper()
and sys_heap_aligned_alloc() for the meaning of such a non-power-of-two
alignment value and that's not what you are testing here.

There was a time when z_alloc_helper() was expressed in terms of
k_heap_aligned_alloc() so the later had to accept special alignment values
from the former. This is no longer the case and k_heap_aligned_alloc()
should probably enforce proper alignment values now.

The double-free test is also highly dubious. Either you have assertions
enabled and there's a chance (no guarantee) this will be caught, or
assertions are disabled and you'll definitely and silently corrupt memory.

@JarmouniA JarmouniA removed this from the v4.2.0 milestone Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Kernel area: Tests Issues related to a particular existing or missing test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants