drivers/android/tests/binder_alloc_kunit.c
Source file repositories/reference/linux-study-clean/drivers/android/tests/binder_alloc_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/android/tests/binder_alloc_kunit.c- Extension
.c- Size
- 15875 bytes
- Lines
- 573
- Domain
- Driver Families
- Bucket
- drivers/android
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/anon_inodes.hlinux/err.hlinux/file.hlinux/fs.hlinux/mm.hlinux/mman.hlinux/seq_buf.hlinux/sizes.h../binder_alloc.h../binder_internal.h
Detected Declarations
struct binder_alloc_test_case_infostruct binder_alloc_testenum buf_end_align_typefunction stringify_free_seqfunction stringify_alignmentsfunction check_buffer_pages_allocatedfunction binder_alloc_test_alloc_buffunction binder_alloc_test_free_buffunction binder_alloc_test_free_pagefunction binder_alloc_test_alloc_freefunction is_dupfunction permute_freesfunction gen_buf_sizesfunction gen_buf_offsetsfunction binder_alloc_test_init_freelistfunction binder_alloc_test_mmapfunction binder_alloc_exhaustive_testfunction binder_alloc_test_vma_closefunction binder_alloc_test_mmap_handlerfunction binder_alloc_test_initfunction binder_alloc_test_exit
Annotated Snippet
static const struct file_operations binder_alloc_test_fops = {
.mmap = binder_alloc_test_mmap_handler,
};
static int binder_alloc_test_init(struct kunit *test)
{
struct binder_alloc_test *priv;
int ret;
priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
test->priv = priv;
ret = list_lru_init(&priv->binder_test_freelist);
if (ret) {
kunit_err(test, "Failed to initialize test freelist\n");
return ret;
}
/* __binder_alloc_init requires mm to be attached */
ret = kunit_attach_mm();
if (ret) {
kunit_err(test, "Failed to attach mm\n");
return ret;
}
__binder_alloc_init(&priv->alloc, &priv->binder_test_freelist);
priv->filp = anon_inode_getfile("binder_alloc_kunit",
&binder_alloc_test_fops, &priv->alloc,
O_RDWR | O_CLOEXEC);
if (IS_ERR_OR_NULL(priv->filp)) {
kunit_err(test, "Failed to open binder alloc test driver file\n");
return priv->filp ? PTR_ERR(priv->filp) : -ENOMEM;
}
priv->mmap_uaddr = kunit_vm_mmap(test, priv->filp, 0, BINDER_MMAP_SIZE,
PROT_READ, MAP_PRIVATE | MAP_NORESERVE,
0);
if (!priv->mmap_uaddr) {
kunit_err(test, "Could not map the test's transaction memory\n");
return -ENOMEM;
}
return 0;
}
static void binder_alloc_test_exit(struct kunit *test)
{
struct binder_alloc_test *priv = test->priv;
/* Close the backing file to make sure binder_alloc_vma_close runs */
if (!IS_ERR_OR_NULL(priv->filp))
fput(priv->filp);
if (priv->alloc.mm)
binder_alloc_deferred_release(&priv->alloc);
/* Make sure freelist is empty */
KUNIT_EXPECT_EQ(test, list_lru_count(&priv->binder_test_freelist), 0);
list_lru_destroy(&priv->binder_test_freelist);
}
static struct kunit_case binder_alloc_test_cases[] = {
KUNIT_CASE(binder_alloc_test_init_freelist),
KUNIT_CASE(binder_alloc_test_mmap),
KUNIT_CASE_SLOW(binder_alloc_exhaustive_test),
{}
};
static struct kunit_suite binder_alloc_test_suite = {
.name = "binder_alloc",
.test_cases = binder_alloc_test_cases,
.init = binder_alloc_test_init,
.exit = binder_alloc_test_exit,
};
kunit_test_suite(binder_alloc_test_suite);
MODULE_AUTHOR("Tiffany Yang <ynaffit@google.com>");
MODULE_DESCRIPTION("Binder Alloc KUnit tests");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `kunit/test.h`, `linux/anon_inodes.h`, `linux/err.h`, `linux/file.h`, `linux/fs.h`, `linux/mm.h`, `linux/mman.h`, `linux/seq_buf.h`.
- Detected declarations: `struct binder_alloc_test_case_info`, `struct binder_alloc_test`, `enum buf_end_align_type`, `function stringify_free_seq`, `function stringify_alignments`, `function check_buffer_pages_allocated`, `function binder_alloc_test_alloc_buf`, `function binder_alloc_test_free_buf`, `function binder_alloc_test_free_page`, `function binder_alloc_test_alloc_free`.
- Atlas domain: Driver Families / drivers/android.
- Implementation status: pattern 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.