lib/tests/glob_kunit.c
Source file repositories/reference/linux-study-clean/lib/tests/glob_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/tests/glob_kunit.c- Extension
.c- Size
- 5044 bytes
- Lines
- 126
- 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/glob.hlinux/module.h
Detected Declarations
struct glob_test_casefunction glob_case_to_descfunction glob_test_match
Annotated Snippet
struct glob_test_case {
const char *pat;
const char *str;
bool expected;
};
static const struct glob_test_case glob_test_cases[] = {
/* Some basic tests */
{ .pat = "a", .str = "a", .expected = true },
{ .pat = "a", .str = "b", .expected = false },
{ .pat = "a", .str = "aa", .expected = false },
{ .pat = "a", .str = "", .expected = false },
{ .pat = "", .str = "", .expected = true },
{ .pat = "", .str = "a", .expected = false },
/* Simple character class tests */
{ .pat = "[a]", .str = "a", .expected = true },
{ .pat = "[a]", .str = "b", .expected = false },
{ .pat = "[!a]", .str = "a", .expected = false },
{ .pat = "[!a]", .str = "b", .expected = true },
{ .pat = "[ab]", .str = "a", .expected = true },
{ .pat = "[ab]", .str = "b", .expected = true },
{ .pat = "[ab]", .str = "c", .expected = false },
{ .pat = "[!ab]", .str = "c", .expected = true },
{ .pat = "[a-c]", .str = "b", .expected = true },
{ .pat = "[a-c]", .str = "d", .expected = false },
/* Corner cases in character class parsing */
{ .pat = "[a-c-e-g]", .str = "-", .expected = true },
{ .pat = "[a-c-e-g]", .str = "d", .expected = false },
{ .pat = "[a-c-e-g]", .str = "f", .expected = true },
{ .pat = "[]a-ceg-ik[]", .str = "a", .expected = true },
{ .pat = "[]a-ceg-ik[]", .str = "]", .expected = true },
{ .pat = "[]a-ceg-ik[]", .str = "[", .expected = true },
{ .pat = "[]a-ceg-ik[]", .str = "h", .expected = true },
{ .pat = "[]a-ceg-ik[]", .str = "f", .expected = false },
{ .pat = "[!]a-ceg-ik[]", .str = "h", .expected = false },
{ .pat = "[!]a-ceg-ik[]", .str = "]", .expected = false },
{ .pat = "[!]a-ceg-ik[]", .str = "f", .expected = true },
/* Simple wild cards */
{ .pat = "?", .str = "a", .expected = true },
{ .pat = "?", .str = "aa", .expected = false },
{ .pat = "??", .str = "a", .expected = false },
{ .pat = "?x?", .str = "axb", .expected = true },
{ .pat = "?x?", .str = "abx", .expected = false },
{ .pat = "?x?", .str = "xab", .expected = false },
/* Asterisk wild cards (backtracking) */
{ .pat = "*??", .str = "a", .expected = false },
{ .pat = "*??", .str = "ab", .expected = true },
{ .pat = "*??", .str = "abc", .expected = true },
{ .pat = "*??", .str = "abcd", .expected = true },
{ .pat = "??*", .str = "a", .expected = false },
{ .pat = "??*", .str = "ab", .expected = true },
{ .pat = "??*", .str = "abc", .expected = true },
{ .pat = "??*", .str = "abcd", .expected = true },
{ .pat = "?*?", .str = "a", .expected = false },
{ .pat = "?*?", .str = "ab", .expected = true },
{ .pat = "?*?", .str = "abc", .expected = true },
{ .pat = "?*?", .str = "abcd", .expected = true },
{ .pat = "*b", .str = "b", .expected = true },
{ .pat = "*b", .str = "ab", .expected = true },
{ .pat = "*b", .str = "ba", .expected = false },
{ .pat = "*b", .str = "bb", .expected = true },
{ .pat = "*b", .str = "abb", .expected = true },
{ .pat = "*b", .str = "bab", .expected = true },
{ .pat = "*bc", .str = "abbc", .expected = true },
{ .pat = "*bc", .str = "bc", .expected = true },
{ .pat = "*bc", .str = "bbc", .expected = true },
{ .pat = "*bc", .str = "bcbc", .expected = true },
/* Multiple asterisks (complex backtracking) */
{ .pat = "*ac*", .str = "abacadaeafag", .expected = true },
{ .pat = "*ac*ae*ag*", .str = "abacadaeafag", .expected = true },
{ .pat = "*a*b*[bc]*[ef]*g*", .str = "abacadaeafag", .expected = true },
{ .pat = "*a*b*[ef]*[cd]*g*", .str = "abacadaeafag", .expected = false },
{ .pat = "*abcd*", .str = "abcabcabcabcdefg", .expected = true },
{ .pat = "*ab*cd*", .str = "abcabcabcabcdefg", .expected = true },
{ .pat = "*abcd*abcdef*", .str = "abcabcdabcdeabcdefg", .expected = true },
{ .pat = "*abcd*", .str = "abcabcabcabcefg", .expected = false },
{ .pat = "*ab*cd*", .str = "abcabcabcabcefg", .expected = false },
};
static void glob_case_to_desc(const struct glob_test_case *t, char *desc)
{
snprintf(desc, KUNIT_PARAM_DESC_SIZE, "pat:\"%s\" str:\"%s\"", t->pat, t->str);
}
KUNIT_ARRAY_PARAM(glob, glob_test_cases, glob_case_to_desc);
static void glob_test_match(struct kunit *test)
{
const struct glob_test_case *params = test->param_value;
Annotation
- Immediate include surface: `kunit/test.h`, `linux/glob.h`, `linux/module.h`.
- Detected declarations: `struct glob_test_case`, `function glob_case_to_desc`, `function glob_test_match`.
- 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.