summaryrefslogtreecommitdiff
path: root/lib/tests/genalloc_kunit.c
AgeCommit message (Collapse)Author
4 dayslib/tests: add KUnit tests for genallocAmit Patole
lib/genalloc.c is the allocator that drivers use for on-chip SRAM, IRAM and other special memory (i.MX SDMA, CODA, Tegra BPMP, s390 CIO, USB local memory and others), but it has no unit tests. Add a KUnit suite that covers: - gen_pool_size(), gen_pool_avail() and gen_pool_has_addr(); - allocation and freeing, rounding to the allocation granule, zero and oversized requests, and an exact fit; - the first fit, best fit (including the tie-break between equal holes), first fit aligned, first fit order aligned and fixed offset algorithms, and gen_pool_set_algo(pool, NULL, NULL); - aligned allocation from a chunk that does not start on the alignment boundary; - pools with several chunks, gen_pool_virt_to_phys() and gen_pool_for_each_chunk(); - chunk owners; - the DMA helpers, including zeroing, alignment and a NULL pool; - devm_gen_pool_create() and gen_pool_get() with named and unnamed pools on a KUnit device. gen_pool_destroy() BUGs on outstanding allocations, so the cleanup clears the chunk bitmaps first, and allocation results that are freed later are checked with assertions; a failing test then fails cleanly instead of crashing the kernel. An AI coding assistant (Claude Opus 5.5) was used to draft the tests. They were run with "tools/testing/kunit/kunit.py run" on UML (12/12 pass), built with W=1 without warnings, and checked against deliberately broken versions of gen_pool_best_fit(), gen_pool_first_fit_align() and the accounting in gen_pool_free_owner(), each of which makes one test fail. Link: https://lore.kernel.org/20261106-kunit-genalloc-v1-2-ba1ea397dfd8@gmail.com Signed-off-by: Amit Patole <amit.patole@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Fredrik Noring <noring@nocrew.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Brendan Higgins <brendan.higgins@linux.dev> Cc: David Gow <david@davidgow.net> Cc: Rae Moar <raemoar63@gmail.com> Cc: Fredrik Noring <fredrik.noring@gmail.com>