lib/tests/printf_kunit.c
Source file repositories/reference/linux-study-clean/lib/tests/printf_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/tests/printf_kunit.c- Extension
.c- Size
- 23959 bytes
- Lines
- 879
- 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/kernel.hlinux/module.hlinux/printk.hlinux/random.hlinux/rtc.hlinux/slab.hlinux/sprintf.hlinux/string.hlinux/bitmap.hlinux/dcache.hlinux/socket.hlinux/in.hlinux/in6.hlinux/gfp.hlinux/mm.hlinux/property.h
Detected Declarations
struct page_flags_teststruct fourcc_structfunction __printffunction __printffunction test_basicfunction test_numberfunction test_stringfunction plain_hash_to_bufferfunction hash_pointerfunction null_pointerfunction error_pointerfunction invalid_pointerfunction symbol_ptrfunction struct_resourcefunction struct_rangefunction addrfunction macfunction ip4function ip6function uuidfunction dentryfunction struct_va_formatfunction struct_clkfunction bitmapfunction netdev_featuresfunction page_flags_testfunction flagsfunction fwnode_pointerfunction fourcc_pointer_testfunction fourcc_pointerfunction errptrfunction printf_suite_initfunction printf_suite_exit
Annotated Snippet
struct page_flags_test {
int width;
int shift;
int mask;
const char *fmt;
const char *name;
};
static const struct page_flags_test pft[] = {
{SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK,
"%d", "section"},
{NODES_WIDTH, NODES_PGSHIFT, NODES_MASK,
"%d", "node"},
{ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK,
"%d", "zone"},
{LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK,
"%#x", "lastcpupid"},
{KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK,
"%#x", "kasantag"},
};
static void
page_flags_test(struct kunit *kunittest, int section, int node, int zone,
int last_cpupid, int kasan_tag, unsigned long flags, const char *name,
char *cmp_buf)
{
unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag};
unsigned long size;
bool append = false;
int i;
for (i = 0; i < ARRAY_SIZE(values); i++)
flags |= (values[i] & pft[i].mask) << pft[i].shift;
size = scnprintf(cmp_buf, BUF_SIZE, "%#lx(", flags);
if (flags & PAGEFLAGS_MASK) {
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
append = true;
}
for (i = 0; i < ARRAY_SIZE(pft); i++) {
if (!pft[i].width)
continue;
if (append)
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|");
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=",
pft[i].name);
size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
values[i] & pft[i].mask);
append = true;
}
snprintf(cmp_buf + size, BUF_SIZE - size, ")");
test(cmp_buf, "%pGp", &flags);
}
static void
flags(struct kunit *kunittest)
{
unsigned long flags;
char *cmp_buffer;
gfp_t gfp;
cmp_buffer = kunit_kmalloc(kunittest, BUF_SIZE, GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(kunittest, cmp_buffer);
flags = 0;
page_flags_test(kunittest, 0, 0, 0, 0, 0, flags, "", cmp_buffer);
flags = 1UL << NR_PAGEFLAGS;
page_flags_test(kunittest, 0, 0, 0, 0, 0, flags, "", cmp_buffer);
flags |= 1UL << PG_uptodate | 1UL << PG_dirty | 1UL << PG_lru
| 1UL << PG_active | 1UL << PG_swapbacked;
page_flags_test(kunittest, 1, 1, 1, 0x1fffff, 1, flags,
"uptodate|dirty|lru|active|swapbacked",
cmp_buffer);
flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
test("read|exec|mayread|maywrite|mayexec", "%pGv", &flags);
gfp = GFP_TRANSHUGE;
test("GFP_TRANSHUGE", "%pGg", &gfp);
gfp = GFP_ATOMIC|__GFP_DMA;
test("GFP_ATOMIC|GFP_DMA", "%pGg", &gfp);
Annotation
- Immediate include surface: `kunit/test.h`, `linux/kernel.h`, `linux/module.h`, `linux/printk.h`, `linux/random.h`, `linux/rtc.h`, `linux/slab.h`, `linux/sprintf.h`.
- Detected declarations: `struct page_flags_test`, `struct fourcc_struct`, `function __printf`, `function __printf`, `function test_basic`, `function test_number`, `function test_string`, `function plain_hash_to_buffer`, `function hash_pointer`, `function null_pointer`.
- 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.