mirror-linux/lib/tests
Ryota Sakamoto 4101b3b571 lib/tests: add KUnit test for bitops
Add a KUnit test suite for the bitops API.

The existing 'lib/test_bitops.c' is preserved as-is because it contains
ad-hoc micro-benchmarks 'test_fns' and is intended to ensure no compiler
warnings from C=1 sparse checker or -Wextra compilations.

Introduce 'lib/tests/bitops_kunit.c' for functional regression testing. It
ports the test logic and data patterns from 'lib/test_bitops.c' to KUnit,
verifying correct behavior across various input patterns and
architecture-specific edge cases using isolated stack-allocated bitmaps.

The following test logic has been ported from test_bitops_startup() in
lib/test_bitops.c:
- set_bit() / clear_bit() / find_first_bit() validation ->
  test_set_bit_clear_bit()
- get_count_order() validation -> test_get_count_order()
- get_count_order_long() validation -> test_get_count_order_long()

Also improve the find_first_bit() test to check the full bitmap length
(BITOPS_LENGTH) instead of omitting the last bit, ensuring the bitmap is
completely empty after cleanup.

Verified on x86_64, i386, and arm64 architectures.

Sample KUnit output:

    KTAP version 1
    # Subtest: bitops
    # module: bitops_kunit
    1..3
        KTAP version 1
        # Subtest: test_set_bit_clear_bit
        ok 1 BITOPS_4
        ok 2 BITOPS_7
        ok 3 BITOPS_11
        ok 4 BITOPS_31
        ok 5 BITOPS_88
    # test_set_bit_clear_bit: pass:5 fail:0 skip:0 total:5
    ok 1 test_set_bit_clear_bit
        KTAP version 1
        # Subtest: test_get_count_order
        ok 1 0x00000003
        ok 2 0x00000004
        ok 3 0x00001fff
        ok 4 0x00002000
        ok 5 0x50000000
        ok 6 0x80000000
        ok 7 0x80003000
    # test_get_count_order: pass:7 fail:0 skip:0 total:7
    ok 2 test_get_count_order
        KTAP version 1
        # Subtest: test_get_count_order_long
        ok 1 0x0000000300000000
        ok 2 0x0000000400000000
        ok 3 0x00001fff00000000
        ok 4 0x0000200000000000
        ok 5 0x5000000000000000
        ok 6 0x8000000000000000
        ok 7 0x8000300000000000
    # test_get_count_order_long: pass:7 fail:0 skip:0 total:7
    ok 3 test_get_count_order_long

[Yury: trim Kconfig help message]

CC: Jesse Brandeburg <jesse.brandeburg@intel.com>
CC: Wei Yang <richard.weiyang@gmail.com>
Signed-off-by: Ryota Sakamoto <sakamo.ryota@gmail.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
2026-02-08 18:47:29 -05:00
..
module tests/module: nix-ify 2025-03-10 11:54:13 +01:00
Makefile lib/tests: add KUnit test for bitops 2026-02-08 18:47:29 -05:00
base64_kunit.c lib: add KUnit tests for base64 encoding/decoding 2025-11-20 14:03:44 -08:00
bitfield_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
bitops_kunit.c lib/tests: add KUnit test for bitops 2026-02-08 18:47:29 -05:00
blackhole_dev_kunit.c Networking changes for 6.15. 2025-03-26 21:48:21 -07:00
checksum_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
cmdline_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
cpumask_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
ffs_kunit.c KUnit: ffs: Validate all the __attribute_const__ annotations 2025-09-08 14:58:52 -07:00
fortify_kunit.c kunit/fortify: Add back "volatile" for sizeof() constants 2025-07-14 22:43:52 -07:00
hashtable_test.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
is_signed_type_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
kfifo_kunit.c lib/tests/kfifo_kunit.c: add tests for the kfifo structure 2025-02-10 18:25:39 -08:00
kunit_iov_iter.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
list-test.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
longest_symbol_kunit.c kunit: fix longest symbol length test 2025-07-10 14:02:07 -06:00
memcpy_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
overflow_kunit.c kunit/overflow: Add tests for STACK_FLEX_ARRAY_SIZE() helper 2025-05-08 09:42:05 -07:00
printf_kunit.c lib/vsprintf: Add specifier for printing struct timespec64 2025-11-19 10:24:13 +01:00
randstruct_kunit.c lib/tests: randstruct: Add deep function pointer layout test 2025-05-08 09:42:40 -07:00
scanf_kunit.c scanf: break kunit into test cases 2025-03-14 13:56:15 -07:00
seq_buf_kunit.c seq_buf: Introduce KUnit tests 2025-07-19 23:03:24 -07:00
siphash_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
slub_kunit.c kunit: slub: add module description 2025-04-11 17:32:39 -07:00
stackinit_kunit.c Kbuild: remove structleak gcc plugin 2025-04-30 21:57:09 +02:00
string_helpers_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
string_kunit.c string: provide strends() 2025-11-17 10:15:32 +01:00
test_bits.c test_bits: add tests for __GENMASK() and __GENMASK_ULL() 2025-07-31 11:28:03 -04:00
test_fprobe.c lib/test_fprobe: add testcase for mixed fprobe 2025-11-11 22:32:09 +09:00
test_hash.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
test_kprobes.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
test_linear_ranges.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
test_list_sort.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
test_ratelimit.c lib: Add stress test for ratelimit 2025-06-24 05:47:35 -07:00
test_sort.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00
usercopy_kunit.c kunit/usercopy: Disable u64 test on 32-bit SPARC 2025-04-28 10:32:43 -07:00
util_macros_kunit.c lib: Move KUnit tests into tests/ subdirectory 2025-02-10 18:25:39 -08:00