Skip to content

bitmap: convert self-test to KUnit

Tamir Duberstein linux-kselftest linux-m68k linux-mm linuxppc-dev lkml oe-kbuild-all 2 versions – New

Get series with b4
b4 am [email protected] change-id 20250207-bitmap-kunit-convert-92d3147b2eee

Versions newest first

  1. v2 Latest3 patches 0 repliesNew
  2. v13 patches 23 repliesSuperseded

Changes in v2 from the cover letter

- Rebase on v6.19-rc1, dropping the first patch.
- Extract benchmarks into new module and deduplicate test_bitmap_{read,write}_perf.
- Remove tc_err() and use KUnit assertions.
- Parameterize test_bitmap_cut and test_bitmap_parse{,list}.
- Drop KUnit boilerplate from BITMAP_KUNIT_TEST help text.
- Drop arch changes.
- Link to v1: https://lore.kernel.org/r/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3test_bitmap: extract benchmark moduleMAINTAINERS lib/Kconfig.debug lib/Makefile +2 more+99 -500 replies
2/3bitmap: convert self-test to KUnitMAINTAINERS lib/Kconfig.debug lib/Makefile +4 more+135 -2070 replies
3/3bitmap: break kunit into test caseslib/bitmap_kunit.c+191 -1970 replies

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchDavid GowMuhammad Usama Anjum
1/3
2/3R-b
3/3R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] bitmap: convert self-test to KUnit

This is the last remaining "Test Module" kselftest, the rest having been converted to KUnit.

Relative to v1 this keeps benchmarks out of KUnit in light of Yury's concerns:

Quoted 7 lines · Yury Norov

[...]

This is my evidence: sometimes people report performance or whatever issues on their systems, suspecting bitmaps guilty. I ask them to run the bitmap or find_bit test to narrow the problem. Sometimes I need to test a hardware I have no access to, and I have to (kindly!) ask

people

Quoted 4 lines

to build a small test and run it. I don't want to ask them to rebuild the whole kernel, or even to build something else.

https://lore.kernel.org/all/YuWk3titnOiQACzC@yury-laptop/

I tested this using:

$ tools/testing/kunit/kunit.py run --arch arm64 --make_options LLVM=1 bitmap

There was a previous attempt[2] to do this in July 2024. Please bear with me as I try to understand and address the objections from that time. I've spoken with Muhammad Usama Anjum, the author of that series, and received their approval to "take over" this work. Here we go...

Quoted 4 lines · John Hubbard

This changes the situation from "works for Linus' tab completion case", to "causes a tab completion problem"! :)

Quoted 8 lines

I think a tests/ subdir is how we eventually decided to do this [1], right?

So:

lib/tests/bitmap_kunit.c

[1] https://lore.kernel.org/[email protected]

This is true and unfortunate, but not trivial to fix because new kallsyms tests were placed in lib/tests in commit 84b4a51fce4c ("selftests: add new kallsyms selftests") *after* the KUnit filename best practices were adopted.

I propose that the KUnit maintainers blaze this trail using string_kunit.c which currently still lives in lib/ despite the KUnit docs giving it as an example at lib/tests/.

Quoted 8 lines · Shuah Khan

This change will take away the ability to run bitmap tests during boot on a non-kunit kernel.

Nack on this change. I wan to see all tests that are being removed from lib because they have been converted - also it doesn't make sense to convert some tests like this one that add the ability test during boot.

This point was also discussed in another thread[3] in which:

Quoted 8 lines · Shuah Khan

Please make sure you aren't taking away the ability to run these tests during boot.

It doesn't make sense to convert every single test especially when it is intended to be run during boot without dependencies - not as a kunit test but a regression test during boot.

Quoted 5 lines

bitmap is one example - pay attention to the config help test - bitmap one clearly states it runs regression testing during boot. Any test that says that isn't a candidate for conversion.

I am going to nack any such conversions.

The crux of the argument seems to be that the config help text is taken to describe the author's intent with the fragment "at boot". I think this may be a case of confirmation bias: I see at least the following KUnit tests with "at boot" in their help text:
- CPUMASK_KUNIT_TEST
- BITFIELD_KUNIT
- CHECKSUM_KUNIT
- UTIL_MACROS_KUNIT

It seems to me that the inference being made is that any test that runs "at boot" is intended to be run by both developers and users, but I find no evidence that bitmap in particular would ever provide additional value when run by users.

There's further discussion about KUnit not being "ideal for cases where people would want to check a subsystem on a running kernel", but I find no evidence that bitmap in particular is actually testing the running kernel; it is a unit test of the bitmap functions, which is also stated in the config help text.

David Gow made many of the same points in his final reply[4], which was never replied to.

Thanks for your attention.

---
Changes in v2:
- Rebase on v6.19-rc1, dropping the first patch.
- Extract benchmarks into new module and deduplicate test_bitmap_{read,write}_perf.
- Remove tc_err() and use KUnit assertions.
- Parameterize test_bitmap_cut and test_bitmap_parse{,list}.
- Drop KUnit boilerplate from BITMAP_KUNIT_TEST help text.
- Drop arch changes.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Tamir Duberstein (3):
test_bitmap: extract benchmark module
bitmap: convert self-test to KUnit
bitmap: break kunit into test cases

 MAINTAINERS                           |   3 +-
 lib/Kconfig.debug                     |  16 +-
 lib/Makefile                          |   5 +-
 lib/bitmap_benchmark.c                |  89 +++++
 lib/{test_bitmap.c => bitmap_kunit.c} | 630 ++++++++++++++--------------------
 tools/testing/selftests/lib/Makefile  |   2 +-
 tools/testing/selftests/lib/bitmap.sh |   3 -
 tools/testing/selftests/lib/config    |   1 -
 8 files changed, 360 insertions(+), 389 deletions(-)

---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20250207-bitmap-kunit-convert-92d3147b2eee

Best regards,

Signature · 1 line
Tamir Duberstein <[email protected]>