From e58891d0aef37391ccd09091871db35516427884 Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Thu, 15 Aug 2013 14:00:23 +0200 Subject: [PATCH] tests/prime: test dma-buf llseek support This exercises a proposed patch from Christopher James Halse Rogers. Signed-off-by: Daniel Vetter --- lib/drmtest.c | 10 ++++++++ lib/drmtest.h | 1 + tests/prime_self_import.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/lib/drmtest.c b/lib/drmtest.c index e05dda1..98f4ac6 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -609,6 +609,16 @@ uint32_t prime_fd_to_handle(int fd, int dma_buf_fd) return args.handle; } +off_t prime_get_size(int dma_buf_fd) +{ + off_t ret; + ret = lseek(dma_buf_fd, 0, SEEK_END); + igt_assert(ret >= 0 || errno == ESPIPE); + igt_require(ret >= 0); + + return ret; +} + /* signal interrupt helpers */ static pid_t signal_helper = -1; long long int sig_stat; diff --git a/lib/drmtest.h b/lib/drmtest.h index 424fd04..7a36a48 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -85,6 +85,7 @@ int gem_available_fences(int fd); /* prime */ int prime_handle_to_fd(int fd, uint32_t handle); uint32_t prime_fd_to_handle(int fd, int dma_buf_fd); +off_t prime_get_size(int dma_buf_fd); /* generally useful helpers */ void igt_fork_signal_helper(void); diff --git a/tests/prime_self_import.c b/tests/prime_self_import.c index 89bcffe..6b3611d 100644 --- a/tests/prime_self_import.c +++ b/tests/prime_self_import.c @@ -365,6 +365,62 @@ static void test_export_close_race(void) igt_assert(obj_count == 0); } +static void test_llseek_size(void) +{ + int fd, i; + uint32_t handle; + int dma_buf_fd; + + counter = 0; + + fd = drm_open_any(); + + + for (i = 0; i < 10; i++) { + int bufsz = 4096 << i; + + handle = gem_create(fd, bufsz); + dma_buf_fd = prime_handle_to_fd(fd, handle); + + gem_close(fd, handle); + + igt_assert(prime_get_size(dma_buf_fd) == bufsz); + + close(dma_buf_fd); + } + + close(fd); +} + +static void test_llseek_bad(void) +{ + int fd; + uint32_t handle; + int dma_buf_fd; + + counter = 0; + + fd = drm_open_any(); + + + handle = gem_create(fd, BO_SIZE); + dma_buf_fd = prime_handle_to_fd(fd, handle); + + gem_close(fd, handle); + + igt_require(lseek(dma_buf_fd, 0, SEEK_END) >= 0); + + igt_assert(lseek(dma_buf_fd, -1, SEEK_END) == -1 && errno == EINVAL); + igt_assert(lseek(dma_buf_fd, 1, SEEK_SET) == -1 && errno == EINVAL); + igt_assert(lseek(dma_buf_fd, BO_SIZE, SEEK_SET) == -1 && errno == EINVAL); + igt_assert(lseek(dma_buf_fd, BO_SIZE + 1, SEEK_SET) == -1 && errno == EINVAL); + igt_assert(lseek(dma_buf_fd, BO_SIZE - 1, SEEK_SET) == -1 && errno == EINVAL); + + close(dma_buf_fd); + + close(fd); +} + int main(int argc, char **argv) { struct { @@ -377,6 +433,8 @@ int main(int argc, char **argv) { "with_fd_dup", test_with_fd_dup }, { "export-vs-gem_close-race", test_export_close_race }, { "reimport-vs-gem_close-race", test_reimport_close_race }, + { "llseek-size", test_llseek_size }, + { "llseek-bad", test_llseek_bad }, }; int i; -- 2.7.4