tools/testing/selftests/drivers/dma-buf/udmabuf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/dma-buf/udmabuf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/dma-buf/udmabuf.c- Extension
.c- Size
- 6996 bytes
- Lines
- 278
- 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
stdio.hstdlib.hunistd.hstring.herrno.hfcntl.hmalloc.hstdbool.hsys/ioctl.hsys/syscall.hsys/mman.hlinux/memfd.hlinux/udmabuf.hkselftest.h
Detected Declarations
function create_memfd_with_sealsfunction create_udmabuf_listfunction write_to_memfdfunction compare_chunksfunction main
Annotated Snippet
if (char1 != char2) {
ret = -1;
goto err;
}
}
i++;
}
err:
munmap(addr1, memfd_size);
munmap(addr2, NUM_ENTRIES * NUM_PAGES * getpagesize());
return ret;
}
int main(int argc, char *argv[])
{
struct udmabuf_create create;
int devfd, memfd, buf, ret;
off64_t size;
void *addr1, *addr2;
ksft_print_header();
ksft_set_plan(7);
devfd = open("/dev/udmabuf", O_RDWR);
if (devfd < 0) {
ksft_print_msg(
"%s: [skip,no-udmabuf: Unable to access DMA buffer device file]\n",
TEST_PREFIX);
exit(KSFT_SKIP);
}
memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING);
if (memfd < 0) {
ksft_print_msg("%s: [skip,no-memfd]\n", TEST_PREFIX);
exit(KSFT_SKIP);
}
ret = fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK);
if (ret < 0) {
ksft_print_msg("%s: [skip,fcntl-add-seals]\n", TEST_PREFIX);
exit(KSFT_SKIP);
}
size = getpagesize() * NUM_PAGES;
ret = ftruncate(memfd, size);
if (ret == -1) {
ksft_print_msg("%s: [FAIL,memfd-truncate]\n", TEST_PREFIX);
exit(KSFT_FAIL);
}
memset(&create, 0, sizeof(create));
/* should fail (offset not page aligned) */
create.memfd = memfd;
create.offset = getpagesize()/2;
create.size = getpagesize();
buf = ioctl(devfd, UDMABUF_CREATE, &create);
if (buf >= 0)
ksft_test_result_fail("%s: [FAIL,test-1]\n", TEST_PREFIX);
else
ksft_test_result_pass("%s: [PASS,test-1]\n", TEST_PREFIX);
/* should fail (size not multiple of page) */
create.memfd = memfd;
create.offset = 0;
create.size = getpagesize()/2;
buf = ioctl(devfd, UDMABUF_CREATE, &create);
if (buf >= 0)
ksft_test_result_fail("%s: [FAIL,test-2]\n", TEST_PREFIX);
else
ksft_test_result_pass("%s: [PASS,test-2]\n", TEST_PREFIX);
/* should fail (not memfd) */
create.memfd = 0; /* stdin */
create.offset = 0;
create.size = size;
buf = ioctl(devfd, UDMABUF_CREATE, &create);
if (buf >= 0)
ksft_test_result_fail("%s: [FAIL,test-3]\n", TEST_PREFIX);
else
ksft_test_result_pass("%s: [PASS,test-3]\n", TEST_PREFIX);
/* should work */
page_size = getpagesize();
addr1 = mmap_fd(memfd, size);
write_to_memfd(addr1, size, 'a');
create.memfd = memfd;
create.offset = 0;
create.size = size;
buf = ioctl(devfd, UDMABUF_CREATE, &create);
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `unistd.h`, `string.h`, `errno.h`, `fcntl.h`, `malloc.h`, `stdbool.h`.
- Detected declarations: `function create_memfd_with_seals`, `function create_udmabuf_list`, `function write_to_memfd`, `function compare_chunks`, `function main`.
- 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.