lib/tests/ffs_kunit.c
Source file repositories/reference/linux-study-clean/lib/tests/ffs_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/tests/ffs_kunit.c- Extension
.c- Size
- 16699 bytes
- Lines
- 567
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/bitops.h
Detected Declarations
struct ffs_test_casestruct ffs64_test_casestruct ffz_test_casefunction validate_ffs_resultfunction validate_ffs64_resultfunction validate_ffs_relationshipsfunction validate_ffs64_relationshipsfunction ffs_basic_correctness_testfunction ffs64_correctness_testfunction ffs_mathematical_relationships_testfunction ffs_edge_cases_testfunction ffs64_edge_cases_testfunction ffzfunction ffzfunction ffz_mathematical_relationships_testfunction ffzfunction ffs_attribute_const_test
Annotated Snippet
struct ffs_test_case {
unsigned long input;
int expected_ffs; /* ffs() result (1-based) */
int expected_fls; /* fls() result (1-based) */
const char *description;
};
struct ffs64_test_case {
u64 input;
int expected_fls64; /* fls64() result (1-based) */
unsigned int expected_ffs64_0based; /* __ffs64() result (0-based) */
const char *description;
};
/*
* Basic edge cases - core functionality validation
*/
static const struct ffs_test_case basic_test_cases[] = {
/* Zero case - special handling */
{0x00000000, 0, 0, "zero value"},
/* Single bit patterns - powers of 2 */
{0x00000001, 1, 1, "bit 0 set"},
{0x00000002, 2, 2, "bit 1 set"},
{0x00000004, 3, 3, "bit 2 set"},
{0x00000008, 4, 4, "bit 3 set"},
{0x00000010, 5, 5, "bit 4 set"},
{0x00000020, 6, 6, "bit 5 set"},
{0x00000040, 7, 7, "bit 6 set"},
{0x00000080, 8, 8, "bit 7 set"},
{0x00000100, 9, 9, "bit 8 set"},
{0x00008000, 16, 16, "bit 15 set"},
{0x00010000, 17, 17, "bit 16 set"},
{0x40000000, 31, 31, "bit 30 set"},
{0x80000000, 32, 32, "bit 31 set (sign bit)"},
/* Maximum values */
{0xFFFFFFFF, 1, 32, "all bits set"},
/* Multiple bit patterns */
{0x00000003, 1, 2, "bits 0-1 set"},
{0x00000007, 1, 3, "bits 0-2 set"},
{0x0000000F, 1, 4, "bits 0-3 set"},
{0x000000FF, 1, 8, "bits 0-7 set"},
{0x0000FFFF, 1, 16, "bits 0-15 set"},
{0x7FFFFFFF, 1, 31, "bits 0-30 set"},
/* Sparse patterns */
{0x00000101, 1, 9, "bits 0,8 set"},
{0x00001001, 1, 13, "bits 0,12 set"},
{0x80000001, 1, 32, "bits 0,31 set"},
{0x40000002, 2, 31, "bits 1,30 set"},
};
/*
* 64-bit test cases
*/
static const struct ffs64_test_case ffs64_test_cases[] = {
/* Zero case */
{0x0000000000000000ULL, 0, 0, "zero value"},
/* Single bit patterns */
{0x0000000000000001ULL, 1, 0, "bit 0 set"},
{0x0000000000000002ULL, 2, 1, "bit 1 set"},
{0x0000000000000004ULL, 3, 2, "bit 2 set"},
{0x0000000000000008ULL, 4, 3, "bit 3 set"},
{0x0000000000008000ULL, 16, 15, "bit 15 set"},
{0x0000000000010000ULL, 17, 16, "bit 16 set"},
{0x0000000080000000ULL, 32, 31, "bit 31 set"},
{0x0000000100000000ULL, 33, 32, "bit 32 set"},
{0x0000000200000000ULL, 34, 33, "bit 33 set"},
{0x4000000000000000ULL, 63, 62, "bit 62 set"},
{0x8000000000000000ULL, 64, 63, "bit 63 set (sign bit)"},
/* Maximum values */
{0xFFFFFFFFFFFFFFFFULL, 64, 0, "all bits set"},
/* Cross 32-bit boundary patterns */
{0x00000000FFFFFFFFULL, 32, 0, "lower 32 bits set"},
{0xFFFFFFFF00000000ULL, 64, 32, "upper 32 bits set"},
{0x8000000000000001ULL, 64, 0, "bits 0,63 set"},
{0x4000000000000002ULL, 63, 1, "bits 1,62 set"},
/* Mixed patterns */
{0x00000001FFFFFFFFULL, 33, 0, "bit 32 + lower 32 bits"},
{0xFFFFFFFF80000000ULL, 64, 31, "upper 32 bits + bit 31"},
};
/*
* Helper function to validate ffs results with detailed error messages
Annotation
- Immediate include surface: `kunit/test.h`, `linux/bitops.h`.
- Detected declarations: `struct ffs_test_case`, `struct ffs64_test_case`, `struct ffz_test_case`, `function validate_ffs_result`, `function validate_ffs64_result`, `function validate_ffs_relationships`, `function validate_ffs64_relationships`, `function ffs_basic_correctness_test`, `function ffs64_correctness_test`, `function ffs_mathematical_relationships_test`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.