tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c- Extension
.c- Size
- 8187 bytes
- Lines
- 323
- 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
test_progs.hbpf/libbpf.hbpf/btf.hdmabuf_iter.skel.hfcntl.hstdbool.hstdio.hstdlib.hstring.hsys/ioctl.hsys/mman.hunistd.hlinux/dma-buf.hlinux/dma-heap.hlinux/udmabuf.h
Detected Declarations
struct DmabufInfoenum Fieldsfunction create_udmabuffunction create_sys_heap_dmabuffunction create_test_buffersfunction destroy_test_buffersfunction check_dmabuf_infofunction subtest_dmabuf_iter_check_no_infinite_readsfunction subtest_dmabuf_iter_check_default_iterfunction subtest_dmabuf_iter_check_lots_of_buffersfunction subtest_dmabuf_iter_check_open_codedfunction test_dmabuf_iter
Annotated Snippet
struct DmabufInfo {
unsigned long inode;
unsigned long size;
char name[DMA_BUF_NAME_LEN];
char exporter[32];
};
static bool check_dmabuf_info(const struct DmabufInfo *bufinfo,
unsigned long size,
const char *name, const char *exporter)
{
return size == bufinfo->size &&
!strcmp(name, bufinfo->name) &&
!strcmp(exporter, bufinfo->exporter);
}
static void subtest_dmabuf_iter_check_no_infinite_reads(struct dmabuf_iter *skel)
{
int iter_fd;
char buf[256];
iter_fd = bpf_iter_create(bpf_link__fd(skel->links.dmabuf_collector));
if (!ASSERT_OK_FD(iter_fd, "iter_create"))
return;
while (read(iter_fd, buf, sizeof(buf)) > 0)
; /* Read out all contents */
/* Next reads should return 0 */
ASSERT_EQ(read(iter_fd, buf, sizeof(buf)), 0, "read");
close(iter_fd);
}
static void subtest_dmabuf_iter_check_default_iter(struct dmabuf_iter *skel)
{
bool found_test_sysheap_dmabuf = false;
bool found_test_udmabuf = false;
struct DmabufInfo bufinfo;
size_t linesize = 0;
char *line = NULL;
FILE *iter_file;
int iter_fd, f = INODE;
iter_fd = bpf_iter_create(bpf_link__fd(skel->links.dmabuf_collector));
if (!ASSERT_OK_FD(iter_fd, "iter_create"))
return;
iter_file = fdopen(iter_fd, "r");
if (!ASSERT_OK_PTR(iter_file, "fdopen"))
goto close_iter_fd;
while (getline(&line, &linesize, iter_file) != -1) {
if (f % FIELD_COUNT == INODE) {
ASSERT_EQ(sscanf(line, "%ld", &bufinfo.inode), 1,
"read inode");
} else if (f % FIELD_COUNT == SIZE) {
ASSERT_EQ(sscanf(line, "%ld", &bufinfo.size), 1,
"read size");
} else if (f % FIELD_COUNT == NAME) {
ASSERT_EQ(sscanf(line, "%s", bufinfo.name), 1,
"read name");
} else if (f % FIELD_COUNT == EXPORTER) {
ASSERT_EQ(sscanf(line, "%31s", bufinfo.exporter), 1,
"read exporter");
if (check_dmabuf_info(&bufinfo,
sysheap_test_buffer_size,
sysheap_test_buffer_name,
"system"))
found_test_sysheap_dmabuf = true;
else if (check_dmabuf_info(&bufinfo,
udmabuf_test_buffer_size,
udmabuf_test_buffer_name,
"udmabuf"))
found_test_udmabuf = true;
}
++f;
}
ASSERT_EQ(f % FIELD_COUNT, INODE, "number of fields");
ASSERT_TRUE(found_test_sysheap_dmabuf, "found_test_sysheap_dmabuf");
ASSERT_TRUE(found_test_udmabuf, "found_test_udmabuf");
free(line);
fclose(iter_file);
close_iter_fd:
close(iter_fd);
}
Annotation
- Immediate include surface: `test_progs.h`, `bpf/libbpf.h`, `bpf/btf.h`, `dmabuf_iter.skel.h`, `fcntl.h`, `stdbool.h`, `stdio.h`, `stdlib.h`.
- Detected declarations: `struct DmabufInfo`, `enum Fields`, `function create_udmabuf`, `function create_sys_heap_dmabuf`, `function create_test_buffers`, `function destroy_test_buffers`, `function check_dmabuf_info`, `function subtest_dmabuf_iter_check_no_infinite_reads`, `function subtest_dmabuf_iter_check_default_iter`, `function subtest_dmabuf_iter_check_lots_of_buffers`.
- 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.