From 4101b3b571701cdf1081b2f96124b1daaeaebbf1 Mon Sep 17 00:00:00 2001 From: Ryota Sakamoto Date: Sun, 11 Jan 2026 02:38:07 +0900 Subject: 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 CC: Wei Yang Signed-off-by: Ryota Sakamoto Signed-off-by: Yury Norov --- lib/Kconfig.debug | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/Kconfig.debug') diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index ba36939fda79..e4f8ba2f9f32 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2652,6 +2652,19 @@ config TEST_SYSCTL If unsure, say N. +config BITOPS_KUNIT + tristate "KUnit test for bitops" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + This option enables the KUnit test for the bitops library + which provides functions for bit operations. + + Note that this is a partial copy of the original test_bitops module. + For the full coverage, enable TEST_BITOPS. + + If unsure, say N. + config BITFIELD_KUNIT tristate "KUnit test bitfield functions at runtime" if !KUNIT_ALL_TESTS depends on KUNIT -- cgit v1.2.3