tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c- Extension
.c- Size
- 10071 bytes
- Lines
- 443
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dirent.herrno.hfcntl.hstdio.hstdlib.hstdint.hstring.hunistd.hsys/ioctl.hsys/mman.hsys/types.hlinux/dma-buf.hlinux/dma-heap.hdrm/drm.hkselftest.h
Detected Declarations
struct dma_heap_allocation_data_smallerstruct dma_heap_allocation_data_biggerfunction check_vgemfunction open_vgemfunction import_vgem_fdfunction close_handlefunction dmabuf_heap_openfunction dmabuf_heap_alloc_fdflagsfunction dmabuf_heap_allocfunction dmabuf_syncfunction test_alloc_and_importfunction test_alloc_zeroedfunction dmabuf_heap_alloc_olderfunction dmabuf_heap_alloc_newerfunction test_alloc_compatfunction test_alloc_errorsfunction numer_of_heapsfunction main
Annotated Snippet
struct dma_heap_allocation_data_smaller {
__u64 len;
__u32 fd;
__u32 fd_flags;
} data = {
.len = len,
.fd = 0,
.fd_flags = O_RDWR | O_CLOEXEC,
};
older_alloc_ioctl = _IOWR(DMA_HEAP_IOC_MAGIC, 0x0,
struct dma_heap_allocation_data_smaller);
if (!dmabuf_fd)
return -EINVAL;
ret = ioctl(fd, older_alloc_ioctl, &data);
if (ret < 0)
return ret;
*dmabuf_fd = (int)data.fd;
return ret;
}
/* Test the ioctl version compatibility w/ a larger structure then expected */
static int dmabuf_heap_alloc_newer(int fd, size_t len, unsigned int flags,
int *dmabuf_fd)
{
int ret;
unsigned int newer_alloc_ioctl;
struct dma_heap_allocation_data_bigger {
__u64 len;
__u32 fd;
__u32 fd_flags;
__u64 heap_flags;
__u64 garbage1;
__u64 garbage2;
__u64 garbage3;
} data = {
.len = len,
.fd = 0,
.fd_flags = O_RDWR | O_CLOEXEC,
.heap_flags = flags,
.garbage1 = 0xffffffff,
.garbage2 = 0x88888888,
.garbage3 = 0x11111111,
};
newer_alloc_ioctl = _IOWR(DMA_HEAP_IOC_MAGIC, 0x0,
struct dma_heap_allocation_data_bigger);
if (!dmabuf_fd)
return -EINVAL;
ret = ioctl(fd, newer_alloc_ioctl, &data);
if (ret < 0)
return ret;
*dmabuf_fd = (int)data.fd;
return ret;
}
static void test_alloc_compat(char *heap_name)
{
int ret, heap_fd = -1, dmabuf_fd = -1;
heap_fd = dmabuf_heap_open(heap_name);
ksft_print_msg("Testing (theoretical) older alloc compat:\n");
ret = dmabuf_heap_alloc_older(heap_fd, ONE_MEG, 0, &dmabuf_fd);
if (dmabuf_fd >= 0)
close(dmabuf_fd);
ksft_test_result(!ret, "dmabuf_heap_alloc_older\n");
ksft_print_msg("Testing (theoretical) newer alloc compat:\n");
ret = dmabuf_heap_alloc_newer(heap_fd, ONE_MEG, 0, &dmabuf_fd);
if (dmabuf_fd >= 0)
close(dmabuf_fd);
ksft_test_result(!ret, "dmabuf_heap_alloc_newer\n");
close(heap_fd);
}
static void test_alloc_errors(char *heap_name)
{
int heap_fd = -1, dmabuf_fd = -1;
int ret;
heap_fd = dmabuf_heap_open(heap_name);
ksft_print_msg("Testing expected error cases:\n");
ret = dmabuf_heap_alloc(0, ONE_MEG, 0x111111, &dmabuf_fd);
ksft_test_result(ret, "Error expected on invalid fd %d\n", ret);
Annotation
- Immediate include surface: `dirent.h`, `errno.h`, `fcntl.h`, `stdio.h`, `stdlib.h`, `stdint.h`, `string.h`, `unistd.h`.
- Detected declarations: `struct dma_heap_allocation_data_smaller`, `struct dma_heap_allocation_data_bigger`, `function check_vgem`, `function open_vgem`, `function import_vgem_fd`, `function close_handle`, `function dmabuf_heap_open`, `function dmabuf_heap_alloc_fdflags`, `function dmabuf_heap_alloc`, `function dmabuf_sync`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.