diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2013-08-15 14:00:23 +0200 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2013-08-15 14:01:10 +0200 |
commit | e58891d0aef37391ccd09091871db35516427884 (patch) | |
tree | aee9059ad0a506a63c27802b02ddcd067cfdd581 | |
parent | 79abed393f7c92255a1263c5ef3694befbea6812 (diff) |
tests/prime: test dma-buf llseek support
This exercises a proposed patch from Christopher James Halse Rogers.
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r-- | lib/drmtest.c | 10 | ||||
-rw-r--r-- | lib/drmtest.h | 1 | ||||
-rw-r--r-- | tests/prime_self_import.c | 58 |
3 files changed, 69 insertions, 0 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c index e05dda19..98f4ac6a 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 424fd04c..7a36a480 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 89bcffee..6b3611d6 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; |