lib/tests/bitops_kunit.c
Source file repositories/reference/linux-study-clean/lib/tests/bitops_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/tests/bitops_kunit.c- Extension
.c- Size
- 5555 bytes
- Lines
- 206
- 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
linux/bitops.hlinux/module.hkunit/test.h
Detected Declarations
struct bitops_test_casestruct order_test_casestruct order_long_test_caseenum bitops_funfunction test_set_bit_clear_bitfunction test_change_bitfunction test_test_and_set_bit_test_and_clear_bitfunction test_test_and_change_bitfunction test_get_count_orderfunction test_get_count_order_long
Annotated Snippet
struct bitops_test_case {
const char *str;
const long nr;
};
static struct bitops_test_case bitops_cases[] = {
{
.str = "BITOPS_4",
.nr = BITOPS_4,
},
{
.str = "BITOPS_7",
.nr = BITOPS_7,
},
{
.str = "BITOPS_11",
.nr = BITOPS_11,
},
{
.str = "BITOPS_31",
.nr = BITOPS_31,
},
{
.str = "BITOPS_88",
.nr = BITOPS_88,
},
};
KUNIT_ARRAY_PARAM_DESC(bitops, bitops_cases, str);
static void test_set_bit_clear_bit(struct kunit *test)
{
const struct bitops_test_case *params = test->param_value;
DECLARE_BITMAP(bitmap, BITOPS_LENGTH);
int bit_set;
bitmap_zero(bitmap, BITOPS_LENGTH);
set_bit(params->nr, bitmap);
KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap));
clear_bit(params->nr, bitmap);
KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap));
bit_set = find_first_bit(bitmap, BITOPS_LENGTH);
KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH);
}
static void test_change_bit(struct kunit *test)
{
const struct bitops_test_case *params = test->param_value;
DECLARE_BITMAP(bitmap, BITOPS_LENGTH);
int bit_set;
bitmap_zero(bitmap, BITOPS_LENGTH);
change_bit(params->nr, bitmap);
KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap));
change_bit(params->nr, bitmap);
KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap));
bit_set = find_first_bit(bitmap, BITOPS_LENGTH);
KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH);
}
static void test_test_and_set_bit_test_and_clear_bit(struct kunit *test)
{
const struct bitops_test_case *params = test->param_value;
DECLARE_BITMAP(bitmap, BITOPS_LENGTH);
int bit_set;
bitmap_zero(bitmap, BITOPS_LENGTH);
KUNIT_EXPECT_FALSE(test, test_and_set_bit(params->nr, bitmap));
KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap));
KUNIT_EXPECT_TRUE(test, test_and_set_bit(params->nr, bitmap));
KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap));
KUNIT_EXPECT_TRUE(test, test_and_clear_bit(params->nr, bitmap));
KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap));
KUNIT_EXPECT_FALSE(test, test_and_clear_bit(params->nr, bitmap));
KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap));
bit_set = find_first_bit(bitmap, BITOPS_LENGTH);
KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH);
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/module.h`, `kunit/test.h`.
- Detected declarations: `struct bitops_test_case`, `struct order_test_case`, `struct order_long_test_case`, `enum bitops_fun`, `function test_set_bit_clear_bit`, `function test_change_bit`, `function test_test_and_set_bit_test_and_clear_bit`, `function test_test_and_change_bit`, `function test_get_count_order`, `function test_get_count_order_long`.
- 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.