lib/tests/string_kunit.c
Source file repositories/reference/linux-study-clean/lib/tests/string_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/tests/string_kunit.c- Extension
.c- Size
- 29924 bytes
- Lines
- 925
- 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/ktime.hlinux/math64.hlinux/minmax.hlinux/mm.hlinux/module.hlinux/prandom.hlinux/printk.hlinux/slab.hlinux/string.hlinux/time64.hlinux/units.hlinux/vmalloc.h
Detected Declarations
function string_test_memset16function string_test_memset32function string_test_memset64function string_test_strlenfunction string_test_strnlenfunction string_test_strchrfunction string_test_strrchrfunction string_test_strnchrfunction string_test_strspnfunction strcmp_fill_buffersfunction string_test_strcmpfunction string_test_strcmp_long_stringsfunction string_test_strncmpfunction string_test_strncmp_long_stringsfunction string_test_strcasecmpfunction string_test_strcasecmp_long_stringsfunction string_test_strncasecmpfunction string_test_strncasecmp_long_stringsfunction strscpy_checkfunction string_test_strscpyfunction string_test_strcatfunction string_test_strncatfunction string_test_strlcatfunction string_test_strtomemfunction string_test_memtostrfunction string_test_strendsfunction alloc_max_bench_bufferfunction fill_random_stringfunction string_bench_strlenfunction string_bench_strnlenfunction string_bench_strchrfunction string_bench_strrchr
Annotated Snippet
if (k < i) {
KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1,
"i:%d j:%d k:%d", i, j, k);
} else if (k < i + j) {
KUNIT_ASSERT_EQ_MSG(test, v, 0xb1b2,
"i:%d j:%d k:%d", i, j, k);
} else {
KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1,
"i:%d j:%d k:%d", i, j, k);
}
}
}
}
}
static void string_test_memset32(struct kunit *test)
{
unsigned i, j, k;
u32 v, *p;
p = kunit_kzalloc(test, 256 * 2 * 4, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p);
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
memset(p, 0xa1, 256 * 2 * sizeof(v));
memset32(p + i, 0xb1b2b3b4, j);
for (k = 0; k < 512; k++) {
v = p[k];
if (k < i) {
KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1a1a1,
"i:%d j:%d k:%d", i, j, k);
} else if (k < i + j) {
KUNIT_ASSERT_EQ_MSG(test, v, 0xb1b2b3b4,
"i:%d j:%d k:%d", i, j, k);
} else {
KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1a1a1,
"i:%d j:%d k:%d", i, j, k);
}
}
}
}
}
static void string_test_memset64(struct kunit *test)
{
unsigned i, j, k;
u64 v, *p;
p = kunit_kzalloc(test, 256 * 2 * 8, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p);
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
memset(p, 0xa1, 256 * 2 * sizeof(v));
memset64(p + i, 0xb1b2b3b4b5b6b7b8ULL, j);
for (k = 0; k < 512; k++) {
v = p[k];
if (k < i) {
KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1a1a1a1a1a1a1ULL,
"i:%d j:%d k:%d", i, j, k);
} else if (k < i + j) {
KUNIT_ASSERT_EQ_MSG(test, v, 0xb1b2b3b4b5b6b7b8ULL,
"i:%d j:%d k:%d", i, j, k);
} else {
KUNIT_ASSERT_EQ_MSG(test, v, 0xa1a1a1a1a1a1a1a1ULL,
"i:%d j:%d k:%d", i, j, k);
}
}
}
}
}
static void string_test_strlen(struct kunit *test)
{
size_t buf_size;
char *buf, *s;
buf_size = PAGE_ALIGN(STRING_TEST_MAX_LEN + STRING_TEST_MAX_OFFSET + 1);
buf = vmalloc(buf_size);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
memset(buf, 'A', buf_size);
for (size_t offset = 0; offset < STRING_TEST_MAX_OFFSET; offset++) {
for (size_t len = 0; len <= STRING_TEST_MAX_LEN; len++) {
s = buf + buf_size - 1 - offset - len;
s[len] = '\0';
KUNIT_EXPECT_EQ_MSG(test, strlen(s), len,
"offset:%zu len:%zu", offset, len);
Annotation
- Immediate include surface: `kunit/test.h`, `linux/ktime.h`, `linux/math64.h`, `linux/minmax.h`, `linux/mm.h`, `linux/module.h`, `linux/prandom.h`, `linux/printk.h`.
- Detected declarations: `function string_test_memset16`, `function string_test_memset32`, `function string_test_memset64`, `function string_test_strlen`, `function string_test_strnlen`, `function string_test_strchr`, `function string_test_strrchr`, `function string_test_strnchr`, `function string_test_strspn`, `function strcmp_fill_buffers`.
- 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.