1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/fcntl.h>
10 #include <sys/ioctl.h>
11 #include <sys/syscall.h>
12 #include <linux/memfd.h>
13 #include <linux/udmabuf.h>
15 #define TEST_PREFIX "drivers/dma-buf/udmabuf"
18 static int memfd_create(const char *name
, unsigned int flags
)
20 return syscall(__NR_memfd_create
, name
, flags
);
23 int main(int argc
, char *argv
[])
25 struct udmabuf_create create
;
26 int devfd
, memfd
, buf
, ret
;
30 devfd
= open("/dev/udmabuf", O_RDWR
);
32 printf("%s: [skip,no-udmabuf]\n", TEST_PREFIX
);
36 memfd
= memfd_create("udmabuf-test", MFD_ALLOW_SEALING
);
38 printf("%s: [skip,no-memfd]\n", TEST_PREFIX
);
42 ret
= fcntl(memfd
, F_ADD_SEALS
, F_SEAL_SHRINK
);
44 printf("%s: [skip,fcntl-add-seals]\n", TEST_PREFIX
);
49 size
= getpagesize() * NUM_PAGES
;
50 ret
= ftruncate(memfd
, size
);
52 printf("%s: [FAIL,memfd-truncate]\n", TEST_PREFIX
);
56 memset(&create
, 0, sizeof(create
));
58 /* should fail (offset not page aligned) */
60 create
.offset
= getpagesize()/2;
61 create
.size
= getpagesize();
62 buf
= ioctl(devfd
, UDMABUF_CREATE
, &create
);
64 printf("%s: [FAIL,test-1]\n", TEST_PREFIX
);
68 /* should fail (size not multiple of page) */
71 create
.size
= getpagesize()/2;
72 buf
= ioctl(devfd
, UDMABUF_CREATE
, &create
);
74 printf("%s: [FAIL,test-2]\n", TEST_PREFIX
);
78 /* should fail (not memfd) */
79 create
.memfd
= 0; /* stdin */
82 buf
= ioctl(devfd
, UDMABUF_CREATE
, &create
);
84 printf("%s: [FAIL,test-3]\n", TEST_PREFIX
);
92 buf
= ioctl(devfd
, UDMABUF_CREATE
, &create
);
94 printf("%s: [FAIL,test-4]\n", TEST_PREFIX
);
98 fprintf(stderr
, "%s: ok\n", TEST_PREFIX
);