lib/raid/xor/tests/xor_kunit.c
Source file repositories/reference/linux-study-clean/lib/raid/xor/tests/xor_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/raid/xor/tests/xor_kunit.c- Extension
.c- Size
- 4738 bytes
- Lines
- 188
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/prandom.hlinux/string_choices.hlinux/vmalloc.hlinux/raid/xor.h
Detected Declarations
function rand32function xor_reffunction random_lengthfunction random_alignmentfunction xor_generate_random_datafunction xor_testfunction xor_suite_initfunction xor_suite_exit
Annotated Snippet
if (max_alignment == 0) {
buffers = test_buffers;
} else if (rand32() % 2 == 0) {
/* Use random alignments mod 64 */
int j;
for (j = 0; j < nr_buffers; j++)
aligned_buffers[j] = test_buffers[j] +
random_alignment(max_alignment);
buffers = aligned_buffers;
align = random_alignment(max_alignment);
} else {
/* Go up to the guard page, to catch buffer overreads */
int j;
align = test_buflen - len;
for (j = 0; j < nr_buffers; j++)
aligned_buffers[j] = test_buffers[j] + align;
buffers = aligned_buffers;
}
/*
* Compute the XOR, and verify that it equals the XOR computed
* by a simple byte-at-a-time reference implementation.
*/
xor_ref(test_ref + align, buffers, nr_buffers, len);
xor_gen(test_dest + align, buffers, nr_buffers, len);
KUNIT_EXPECT_MEMEQ_MSG(test, test_ref + align,
test_dest + align, len,
"Wrong result with buffers=%u, len=%u, unaligned=%s, at_end=%s",
nr_buffers, len,
str_yes_no(max_alignment),
str_yes_no(align + len == test_buflen));
}
}
static struct kunit_case xor_test_cases[] = {
KUNIT_CASE(xor_test),
{},
};
static int xor_suite_init(struct kunit_suite *suite)
{
int i;
/*
* Allocate the test buffer using vmalloc() with a page-aligned length
* so that it is immediately followed by a guard page. This allows
* buffer overreads to be detected, even in assembly code.
*/
test_buflen = round_up(XOR_KUNIT_MAX_BYTES, PAGE_SIZE);
test_ref = vmalloc(test_buflen);
if (!test_ref)
return -ENOMEM;
test_dest = vmalloc(test_buflen);
if (!test_dest)
goto out_free_ref;
for (i = 0; i < XOR_KUNIT_MAX_BUFFERS; i++) {
test_buffers[i] = vmalloc(test_buflen);
if (!test_buffers[i])
goto out_free_buffers;
}
prandom_seed_state(&rng, XOR_KUNIT_SEED);
xor_generate_random_data();
return 0;
out_free_buffers:
while (--i >= 0)
vfree(test_buffers[i]);
vfree(test_dest);
out_free_ref:
vfree(test_ref);
return -ENOMEM;
}
static void xor_suite_exit(struct kunit_suite *suite)
{
int i;
vfree(test_ref);
vfree(test_dest);
for (i = 0; i < XOR_KUNIT_MAX_BUFFERS; i++)
vfree(test_buffers[i]);
}
static struct kunit_suite xor_test_suite = {
.name = "xor",
.test_cases = xor_test_cases,
.suite_init = xor_suite_init,
Annotation
- Immediate include surface: `kunit/test.h`, `linux/prandom.h`, `linux/string_choices.h`, `linux/vmalloc.h`, `linux/raid/xor.h`.
- Detected declarations: `function rand32`, `function xor_ref`, `function random_length`, `function random_alignment`, `function xor_generate_random_data`, `function xor_test`, `function xor_suite_init`, `function xor_suite_exit`.
- 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.