Re: [PATCH v3] lib/tests: add KUnit tests for the priority sorted list (plist)
From: Andrew Morton
Date: Sat Nov 07 2026 - 02:07:30 EST
On Sat, 07 Nov 2026 12:45:00 +0800 Yuehong Wu <wuyuehong@xxxxxxxxxxxxxxxxxxxx> 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
> ordering-sensitive code paths have been changed three times 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 first two are performance optimizations; the third one fixes a real
> ordering bug. A deterministic case for that wrap-around now lives in the
> CONFIG_DEBUG_PLIST self-test, which only runs when that debug option is
> enabled by hand and stops at the first BUG_ON().
> plist_kunit_requeue_last_bucket() covers the same shape here, and the
> other cases pin down the ordering invariants the two optimizations rely
> on. KUnit coverage makes such regressions visible wherever KUnit is
> enabled, which CONFIG_DEBUG_PLIST is not.
>
> 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:
Thanks, let's get this into the pipeline for testing.
How does this play with CONFIG_TRIM_UNUSED_KSYMS=y, btw?
That darn thing removes symbols which no in-tree modules are using. So
the 20-odd selftests/ which build and load modules can break in
interesting ways.
Although they're shipped with the tree, such modules are out-of-tree
for kbuild purposes. If they work, it's by sheer luck - all the
exports they want happen to already be used by some in-tree module.
I assume that kunit-loaded modules suffer from the same issue.