Re: [PATCH] lib/tests: kunit for associative array

From: Ben Boeckel

Date: Sat Oct 17 2026 - 21:11:15 EST


On Wed, Oct 14, 2026 at 19:01:38 +0300, Jarkko Sakkinen wrote:
> This is a kunit test for lib/assoc_array.c, which maintains a shadow model
> across assoc_array operations, and checks its integrity after every
> operation.
>
> I wrote a draft version so that I could properly test 'assoc-array-fixes'
> tag at Linus' tree, and spent today rewriting a new more polished version
> with as good description as I could possibly could on how the seeded test
> keys were cherry-picked. Along the way I also tweaked the numbers to be
> a bit less messier set than in my original version.
>
> The transcripts that follow were executed with this command-line:
>
> ./tools/testing/kunit/kunit.py run --raw_output assoc_array
>
> With 'assoc-array-fixes' commits and its subsequent tag iterations all
> eight tests pass, and without them all of them fail.
>
> Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
> ---
> lib/Kconfig.debug | 15 +
> lib/tests/Makefile | 1 +
> lib/tests/assoc_array_kunit.c | 570 ++++++++++++++++++++++++++++++++++
> 3 files changed, 586 insertions(+)
> create mode 100644 lib/tests/assoc_array_kunit.c
>
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 6b24a2c89b84..3e8d3852f53c 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -2857,6 +2857,21 @@ config HASHTABLE_KUNIT_TEST
>
> If unsure, say N.
>
> +config ASSOC_ARRAY_KUNIT_TEST
> + tristate "KUnit test for assoc_array" if !KUNIT_ALL_TESTS
> + depends on KUNIT
> + default KUNIT_ALL_TESTS
> + select ASSOCIATIVE_ARRAY
> + help
> + This builds the assoc_array KUnit test suite.
> + It tests the basic functionality of the API defined in
> + include/linux/assoc_array.h.
> +
> + For more information on KUnit and unit tests in general please refer
> + to the KUnit documentation in Documentation/dev-tools/kunit/.
> +
> + If unsure, say N.
> +
> config LINEAR_RANGES_TEST
> tristate "KUnit test for linear_ranges"
> depends on KUNIT
> diff --git a/lib/tests/Makefile b/lib/tests/Makefile
> index 3cac3b63a752..107e16b4ebc1 100644
> --- a/lib/tests/Makefile
> +++ b/lib/tests/Makefile
> @@ -4,6 +4,7 @@
>
> # KUnit tests
> CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN)
> +obj-$(CONFIG_ASSOC_ARRAY_KUNIT_TEST) += assoc_array_kunit.o
> obj-$(CONFIG_BASE64_KUNIT) += base64_kunit.o
> obj-$(CONFIG_BITOPS_KUNIT) += bitops_kunit.o
> obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o

Why does this one end with `_TEST` and the others do not? I see
`LINEAR_RANGES_TEST` in the context above, but it also lacks `_KUINT`.
There is `HASHTABLE_KUNIT_TEST` nearby too, so perhaps consistency has
just never been popular around these parts.

Thanks,

--Ben