mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-03-03 18:28:01 +01:00
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>
55 lines
2.6 KiB
Makefile
55 lines
2.6 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Makefile for tests of kernel library functions.
|
|
|
|
# KUnit tests
|
|
CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN)
|
|
obj-$(CONFIG_BASE64_KUNIT) += base64_kunit.o
|
|
obj-$(CONFIG_BITOPS_KUNIT) += bitops_kunit.o
|
|
obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
|
|
obj-$(CONFIG_BITS_TEST) += test_bits.o
|
|
obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) += blackhole_dev_kunit.o
|
|
obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
|
|
obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o
|
|
obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o
|
|
obj-$(CONFIG_FFS_KUNIT_TEST) += ffs_kunit.o
|
|
CFLAGS_fortify_kunit.o += $(call cc-disable-warning, unsequenced)
|
|
CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-overread)
|
|
CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-truncation)
|
|
CFLAGS_fortify_kunit.o += $(DISABLE_STRUCTLEAK_PLUGIN)
|
|
obj-$(CONFIG_FORTIFY_KUNIT_TEST) += fortify_kunit.o
|
|
CFLAGS_test_fprobe.o += $(CC_FLAGS_FTRACE)
|
|
obj-$(CONFIG_FPROBE_SANITY_TEST) += test_fprobe.o
|
|
obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o
|
|
obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
|
|
obj-$(CONFIG_TEST_IOV_ITER) += kunit_iov_iter.o
|
|
obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) += is_signed_type_kunit.o
|
|
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
|
|
obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
|
|
obj-$(CONFIG_KFIFO_KUNIT_TEST) += kfifo_kunit.o
|
|
obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o
|
|
obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
|
|
|
|
CFLAGS_longest_symbol_kunit.o += $(call cc-disable-warning, missing-prototypes)
|
|
obj-$(CONFIG_LONGEST_SYM_KUNIT_TEST) += longest_symbol_kunit.o
|
|
|
|
obj-$(CONFIG_MEMCPY_KUNIT_TEST) += memcpy_kunit.o
|
|
CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare)
|
|
obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o
|
|
obj-$(CONFIG_PRINTF_KUNIT_TEST) += printf_kunit.o
|
|
obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o
|
|
obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o
|
|
obj-$(CONFIG_SEQ_BUF_KUNIT_TEST) += seq_buf_kunit.o
|
|
obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o
|
|
obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o
|
|
obj-$(CONFIG_TEST_SORT) += test_sort.o
|
|
CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)
|
|
obj-$(CONFIG_STACKINIT_KUNIT_TEST) += stackinit_kunit.o
|
|
obj-$(CONFIG_STRING_KUNIT_TEST) += string_kunit.o
|
|
obj-$(CONFIG_STRING_HELPERS_KUNIT_TEST) += string_helpers_kunit.o
|
|
obj-$(CONFIG_USERCOPY_KUNIT_TEST) += usercopy_kunit.o
|
|
obj-$(CONFIG_UTIL_MACROS_KUNIT) += util_macros_kunit.o
|
|
obj-$(CONFIG_RATELIMIT_KUNIT_TEST) += test_ratelimit.o
|
|
|
|
obj-$(CONFIG_TEST_RUNTIME_MODULE) += module/
|