Re: [PATCH v2] lib/tests: add KUnit tests for the priority sorted list (plist)
From: Andy Shevchenko
Date: Mon Nov 09 2026 - 07:35:55 EST
On Fri, Nov 06, 2026 at 10:18:34AM +0800, Yuehong Wu wrote:
> lib/plist.c has no KUnit coverage; its only test is the in-module
> plist_test() under CONFIG_DEBUG_PLIST, which BUG_ON()s on the first
> violation and does not report results in KTAP format. The code has seen
> three regression-class changes since mid-2024:
>
> commit c8dab79f9eef ("lib/plist.c: avoid worst case scenario in
> plist_add")
> commit 95d4b3450ebe ("lib/plist.c: add shortcut for plist_requeue()")
> commit 43c91b152243 ("lib/plist: fix plist_requeue() corrupting order
> in the last bucket")
>
> The last one has no regression test: plist_kunit_requeue_last_bucket()
> covers exactly that wrap-around, and the other cases pin down the ordering
> invariants the previous two changes rely on. KUnit coverage makes such
> ordering regressions visible in CI, where CONFIG_DEBUG_PLIST is not
> normally enabled.
>
> Add lib/tests/plist_kunit.c, a KUnit suite that exercises plist_add(),
> plist_del() and plist_requeue() and validates the invariants documented
> in include/linux/plist.h after every operation:
>
> - node_list stays sorted by ascending numeric priority (descending
> priority order) with FIFO order inside a priority bucket;
>
> - exactly the first node of each bucket is linked on prio_list, and
> the headless prio_list ring visits the bucket heads in node_list
> order before wrapping back to the first bucket (a single bucket
> degenerates to a self loop on the first node).
>
> The fixed cases cover bucket head handover on delete (first, middle and
> last bucket), the plist_requeue() shortcut with and without a following
> bucket, requeueing the head of the first and of the last bucket where the
> ring wraps around, the INT_MIN/INT_MAX extremes, and plist_first_entry()/
> plist_last_entry(). A deterministic pseudo-random add/del/requeue churn
> test mirrors the in-module test but draws priorities from a small range
> so that multi-node buckets actually occur, and every requeue in the loop
> moves a node (a requeue without a same-priority successor is a no-op).
>
> The suite is wired up as CONFIG_PLIST_KUNIT_TEST next to the other
> library KUnit tests and is enabled by default with KUNIT_ALL_TESTS.
> lib/plist.c is built into the kernel and exports none of plist_add(),
> plist_del() or plist_requeue(), so the test cannot be built as a module:
> make it built-in only (bool, depends on KUNIT=y), like the other KUnit
> tests that use non-exported symbols.
>
> The tests were built into an x86_64 kernel and run under QEMU/KVM with
> kunit.enable=1 kunit.filter_glob=plist*: 17 of 17 tests pass.
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Closes: https://lore.kernel.org/oe-kbuild-all/202611052109.GqbzRkv1-lkp@xxxxxxxxx/
New code may not be reported as a regression. There was never the module
present, nothing to report, nothing to fix.
--
With Best Regards,
Andy Shevchenko