mm/damon/tests/sysfs-kunit.h
Source file repositories/reference/linux-study-clean/mm/damon/tests/sysfs-kunit.h
File Facts
- System
- Linux kernel
- Corpus path
mm/damon/tests/sysfs-kunit.h- Extension
.h- Size
- 2621 bytes
- Lines
- 113
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- 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.h
Detected Declarations
function nr_damon_targetsfunction __damon_sysfs_test_get_any_pidfunction damon_sysfs_test_add_targets
Annotated Snippet
if (pid) {
put_pid(pid);
return i;
}
}
return -1;
}
static void damon_sysfs_test_add_targets(struct kunit *test)
{
struct damon_sysfs_targets *sysfs_targets;
struct damon_sysfs_target *sysfs_target;
struct damon_ctx *ctx;
sysfs_targets = damon_sysfs_targets_alloc();
if (!sysfs_targets)
kunit_skip(test, "sysfs_targets alloc fail");
sysfs_targets->nr = 1;
sysfs_targets->targets_arr = kmalloc_objs(*sysfs_targets->targets_arr,
1);
if (!sysfs_targets->targets_arr) {
kfree(sysfs_targets);
kunit_skip(test, "targets_arr alloc fail");
}
sysfs_target = damon_sysfs_target_alloc();
if (!sysfs_target) {
kfree(sysfs_targets->targets_arr);
kfree(sysfs_targets);
kunit_skip(test, "sysfs_target alloc fail");
}
sysfs_target->pid = __damon_sysfs_test_get_any_pid(12, 100);
sysfs_target->regions = damon_sysfs_regions_alloc();
if (!sysfs_target->regions) {
kfree(sysfs_targets->targets_arr);
kfree(sysfs_targets);
kfree(sysfs_target);
kunit_skip(test, "sysfs_regions alloc fail");
}
sysfs_targets->targets_arr[0] = sysfs_target;
ctx = damon_new_ctx();
if (!ctx) {
kfree(sysfs_targets->targets_arr);
kfree(sysfs_targets);
kfree(sysfs_target->regions);
kfree(sysfs_target);
kunit_skip(test, "ctx alloc fail");
}
damon_sysfs_add_targets(ctx, sysfs_targets);
KUNIT_EXPECT_EQ(test, 1u, nr_damon_targets(ctx));
sysfs_target->pid = __damon_sysfs_test_get_any_pid(
sysfs_target->pid + 1, 200);
damon_sysfs_add_targets(ctx, sysfs_targets);
KUNIT_EXPECT_EQ(test, 2u, nr_damon_targets(ctx));
damon_destroy_ctx(ctx);
kfree(sysfs_targets->targets_arr);
kfree(sysfs_targets);
kfree(sysfs_target->regions);
kfree(sysfs_target);
}
static struct kunit_case damon_sysfs_test_cases[] = {
KUNIT_CASE(damon_sysfs_test_add_targets),
{},
};
static struct kunit_suite damon_sysfs_test_suite = {
.name = "damon-sysfs",
.test_cases = damon_sysfs_test_cases,
};
kunit_test_suite(damon_sysfs_test_suite);
#endif /* _DAMON_SYSFS_TEST_H */
#endif /* CONFIG_DAMON_SYSFS_KUNIT_TEST */
Annotation
- Immediate include surface: `kunit/test.h`.
- Detected declarations: `function nr_damon_targets`, `function __damon_sysfs_test_get_any_pid`, `function damon_sysfs_test_add_targets`.
- Atlas domain: Core OS / Memory Management.
- 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.