From 70afbead463fd0b5c9af29ebd7a169d316364c29 Mon Sep 17 00:00:00 2001 From: Imre Deak Date: Wed, 17 Apr 2013 23:18:02 +0300 Subject: tests/prime_self_import: add subtest to export/import a second gem buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add a subtest for the fd=handle_to_fd(), fd2=dup(fd), close(fd) case (idea from Kristian Høgsberg). Signed-off-by: Imre Deak v2: - add a new subtest instead of modifying the original test (Daniel) - add a new subtest for testing dup (Kristian) Signed-off-by: Daniel Vetter --- tests/prime_self_import.c | 88 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-) (limited to 'tests/prime_self_import.c') diff --git a/tests/prime_self_import.c b/tests/prime_self_import.c index 111ed4da..abdc2201 100644 --- a/tests/prime_self_import.c +++ b/tests/prime_self_import.c @@ -48,11 +48,14 @@ #define BO_SIZE (16*1024) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +static char counter; + static void check_bo(int fd1, uint32_t handle1, int fd2, uint32_t handle2) { char *ptr1, *ptr2; - static char counter = 0; int i; ptr1 = gem_mmap(fd1, handle1, BO_SIZE, PROT_READ | PROT_WRITE); @@ -75,7 +78,68 @@ check_bo(int fd1, uint32_t handle1, int fd2, uint32_t handle2) munmap(ptr2, BO_SIZE); } -int main(int argc, char **argv) +static void test_with_fd_dup(void) +{ + int fd1, fd2; + uint32_t handle, handle_import; + int dma_buf_fd1, dma_buf_fd2; + + counter = 0; + + fd1 = drm_open_any(); + fd2 = drm_open_any(); + + handle = gem_create(fd1, BO_SIZE); + + dma_buf_fd1 = prime_handle_to_fd(fd1, handle); + gem_close(fd1, handle); + + dma_buf_fd2 = dup(dma_buf_fd1); + close(dma_buf_fd1); + handle_import = prime_fd_to_handle(fd2, dma_buf_fd2); + check_bo(fd2, handle_import, fd2, handle_import); + + close(dma_buf_fd2); + check_bo(fd2, handle_import, fd2, handle_import); + + close(fd1); + close(fd2); +} + +static void test_with_two_bos(void) +{ + int fd1, fd2; + uint32_t handle1, handle2, handle_import; + int dma_buf_fd; + + counter = 0; + + fd1 = drm_open_any(); + fd2 = drm_open_any(); + + handle1 = gem_create(fd1, BO_SIZE); + handle2 = gem_create(fd1, BO_SIZE); + + dma_buf_fd = prime_handle_to_fd(fd1, handle1); + handle_import = prime_fd_to_handle(fd2, dma_buf_fd); + + close(dma_buf_fd); + gem_close(fd1, handle1); + + dma_buf_fd = prime_handle_to_fd(fd1, handle2); + handle_import = prime_fd_to_handle(fd2, dma_buf_fd); + check_bo(fd1, handle2, fd2, handle_import); + + gem_close(fd1, handle2); + close(dma_buf_fd); + + check_bo(fd2, handle_import, fd2, handle_import); + + close(fd1); + close(fd2); +} + +static void test_with_one_bo(void) { int fd1, fd2; uint32_t handle, handle_import1, handle_import2, handle_selfimport; @@ -118,6 +182,26 @@ int main(int argc, char **argv) /* Completely rip out exporting fd. */ close(fd1); check_bo(fd2, handle_import1, fd2, handle_import1); +} + +int main(int argc, char **argv) +{ + struct { + const char *name; + void (*fn)(void); + } tests[] = { + { "with_one_bo", test_with_one_bo }, + { "with_two_bos", test_with_two_bos }, + { "with_fd_dup", test_with_fd_dup }, + }; + int i; + + drmtest_subtest_init(argc, argv); + + for (i = 0; i < ARRAY_SIZE(tests); i++) { + if (drmtest_run_subtest(tests[i].name)) + tests[i].fn(); + } return 0; } -- cgit v1.2.3