Skip to content

testing/mm/grantest: Add a test of the granule allocator. - #4064

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
acassis:testing-mm-grantest
Nov 17, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
acassis:testing-mm-grantest

Conversation

@acassis

@acassis acassis commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Test gran_reserve() and gran_alloc_align() on a heap of 16 granules of 16 bytes:

  • A reservation uses only the granules that hold the range, also in the last granule of the heap, and gran_free() releases all of them.
  • An alignment of zero means no alignment, and does not return memory that is in use.
  • An alignment that is not a power of two returns NULL. An alignment that is a power of two is kept.

On nuttx master, the reservation cases fail without "mm/mm_gran: Reserve only the granules that hold the range." and the alignment cases fail without "mm/mm_gran: Check the alignment given to gran_alloc_align()."

The test needs CONFIG_GRAN and the flat build, in which applications can call the granule allocator.

Impact

Improvement

Testing

  grantest: reserve one granule:               FAIL (expected 1, got 2)
  grantest: reserve the last granule:          FAIL (expected 15, got -1)
  grantest: reserve, free, allocate the heap:  FAIL (expected 0, got -1)
  grantest: align 0, two granules:             FAIL (expected 2, got 0)
  grantest: align 0, one granule:              FAIL (expected 0, got -1)
  grantest: align 3 granules:                  FAIL (expected -1, got 1)
  grantest: align 4 granules:                  PASS (expected 4, got 4)
  grantest: 6 failed

Test gran_reserve() and gran_alloc_align() on a heap of 16 granules
of 16 bytes:

* A reservation uses only the granules that hold the range, also in
  the last granule of the heap, and gran_free() releases all of them.
* An alignment of zero means no alignment, and does not return memory
  that is in use.
* An alignment that is not a power of two returns NULL.  An alignment
  that is a power of two is kept.

On nuttx master, the reservation cases fail without "mm/mm_gran:
Reserve only the granules that hold the range." and the alignment
cases fail without "mm/mm_gran: Check the alignment given to
gran_alloc_align()."

The test needs CONFIG_GRAN and the flat build, in which applications
can call the granule allocator.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Code:claude-opus-5-5
@xiaoxiang781216
xiaoxiang781216 merged commit b080ea7 into apache:master Nov 17, 2026
37 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants