1 // SPDX-License-Identifier: GPL-2.0
3 #define __EXPORTED_HEADERS__
13 #include <sys/ioctl.h>
14 #include <sys/syscall.h>
15 #include <linux/memfd.h>
16 #include <linux/udmabuf.h>
18 #define TEST_PREFIX "drivers/dma-buf/udmabuf"
21 static int memfd_create(const char *name, unsigned int flags)
23 return syscall(__NR_memfd_create, name, flags);
26 int main(int argc, char *argv[])
28 struct udmabuf_create create;
29 int devfd, memfd, buf, ret;
33 devfd = open("/dev/udmabuf", O_RDWR);
35 printf("%s: [skip,no-udmabuf]\n", TEST_PREFIX);
39 memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING);
41 printf("%s: [skip,no-memfd]\n", TEST_PREFIX);
45 ret = fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK);
47 printf("%s: [skip,fcntl-add-seals]\n", TEST_PREFIX);
52 size = getpagesize() * NUM_PAGES;
53 ret = ftruncate(memfd, size);
55 printf("%s: [FAIL,memfd-truncate]\n", TEST_PREFIX);
59 memset(&create, 0, sizeof(create));
61 /* should fail (offset not page aligned) */
63 create.offset = getpagesize()/2;
64 create.size = getpagesize();
65 buf = ioctl(devfd, UDMABUF_CREATE, &create);
67 printf("%s: [FAIL,test-1]\n", TEST_PREFIX);
71 /* should fail (size not multiple of page) */
74 create.size = getpagesize()/2;
75 buf = ioctl(devfd, UDMABUF_CREATE, &create);
77 printf("%s: [FAIL,test-2]\n", TEST_PREFIX);
81 /* should fail (not memfd) */
82 create.memfd = 0; /* stdin */
85 buf = ioctl(devfd, UDMABUF_CREATE, &create);
87 printf("%s: [FAIL,test-3]\n", TEST_PREFIX);
95 buf = ioctl(devfd, UDMABUF_CREATE, &create);
97 printf("%s: [FAIL,test-4]\n", TEST_PREFIX);
101 fprintf(stderr, "%s: ok\n", TEST_PREFIX);