lib/tests/cmdline_kunit.c
Source file repositories/reference/linux-study-clean/lib/tests/cmdline_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/tests/cmdline_kunit.c- Extension
.c- Size
- 7960 bytes
- Lines
- 276
- 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/kernel.hlinux/random.hlinux/sizes.hlinux/string.h
Detected Declarations
struct cmdline_test_memparse_entryfunction cmdline_do_one_testfunction cmdline_test_nointfunction cmdline_test_lead_intfunction cmdline_test_tail_intfunction cmdline_do_one_range_testfunction cmdline_test_rangefunction cmdline_test_next_arg_quoted_valuefunction cmdline_test_next_arg_bare_quote_regressionfunction cmdline_test_next_arg_mixed_tokensfunction cmdline_test_memparse
Annotated Snippet
struct cmdline_test_memparse_entry {
const char *input;
const char *unrecognized;
unsigned long long result;
};
static const struct cmdline_test_memparse_entry testdata[] = {
{ "0", "", 0ULL },
{ "1", "", 1ULL },
{ "a", "a", 0ULL },
{ "k", "k", 0ULL },
{ "E", "E", 0ULL },
{ "0xb", "", 11ULL },
{ "0xz", "x", 0ULL },
{ "1234", "", 1234ULL },
{ "04567", "", 2423ULL },
{ "0x9876", "", 39030LL },
{ "05678", "8", 375ULL },
{ "0xabcdefz", "z", 11259375ULL },
{ "0cdba", "c", 0ULL },
{ "4K", "", SZ_4K },
{ "0x10k@0xaaaabbbb", "@", SZ_16K },
{ "32M", "", SZ_32M },
{ "067m:foo", ":", 55 * SZ_1M },
{ "2G;bar=baz", ";", SZ_2G },
{ "07gz", "z", 7ULL * SZ_1G },
{ "3T+data", "+", 3 * SZ_1T },
{ "04t,ro", ",", SZ_4T },
{ "012p", "", 11258999068426240ULL },
{ "7P,sync", ",", 7881299347898368ULL },
{ "0x2e", "", 46ULL },
{ "2E and more", " ", 2305843009213693952ULL },
{ "18446744073709551615", "", ULLONG_MAX },
{ "0xffffffffffffffff0", "", ULLONG_MAX },
{ "1111111111111111111T", "", ULLONG_MAX },
{ "222222222222222222222G", "", ULLONG_MAX },
{ "3333333333333333333333M", "", ULLONG_MAX },
};
static void cmdline_test_memparse(struct kunit *test)
{
const struct cmdline_test_memparse_entry *e;
unsigned long long ret;
char *retptr;
for (e = testdata; e < testdata + ARRAY_SIZE(testdata); e++) {
ret = memparse(e->input, &retptr);
KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
" when parsing '%s'", e->input);
KUNIT_EXPECT_EQ_MSG(test, *retptr, *e->unrecognized,
" when parsing '%s'", e->input);
}
}
static struct kunit_case cmdline_test_cases[] = {
KUNIT_CASE(cmdline_test_noint),
KUNIT_CASE(cmdline_test_lead_int),
KUNIT_CASE(cmdline_test_tail_int),
KUNIT_CASE(cmdline_test_range),
KUNIT_CASE(cmdline_test_next_arg_quoted_value),
KUNIT_CASE(cmdline_test_next_arg_bare_quote_regression),
KUNIT_CASE(cmdline_test_next_arg_mixed_tokens),
KUNIT_CASE(cmdline_test_memparse),
{}
};
static struct kunit_suite cmdline_test_suite = {
.name = "cmdline",
.test_cases = cmdline_test_cases,
};
kunit_test_suite(cmdline_test_suite);
MODULE_DESCRIPTION("Test cases for API provided by cmdline.c");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `kunit/test.h`, `linux/kernel.h`, `linux/random.h`, `linux/sizes.h`, `linux/string.h`.
- Detected declarations: `struct cmdline_test_memparse_entry`, `function cmdline_do_one_test`, `function cmdline_test_noint`, `function cmdline_test_lead_int`, `function cmdline_test_tail_int`, `function cmdline_do_one_range_test`, `function cmdline_test_range`, `function cmdline_test_next_arg_quoted_value`, `function cmdline_test_next_arg_bare_quote_regression`, `function cmdline_test_next_arg_mixed_tokens`.
- 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.