From: Imre Deak Subject: [PATCH] tests/prime_self_import: export/import a second gem buffer Date: Wed, 17 Apr 2013 19:10:00 +0300 Message-ID: <1366215000-2366-1-git-send-email-imre.deak@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id E9710E66D2 for ; Wed, 17 Apr 2013 09:10:03 -0700 (PDT) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org Signed-off-by: Imre Deak --- tests/prime_self_import.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/prime_self_import.c b/tests/prime_self_import.c index 111ed4d..a17e942 100644 --- a/tests/prime_self_import.c +++ b/tests/prime_self_import.c @@ -48,11 +48,13 @@ #define BO_SIZE (16*1024) +static char counter1; +static char counter2; + static void -check_bo(int fd1, uint32_t handle1, int fd2, uint32_t handle2) +check_bo(int fd1, uint32_t handle1, int fd2, uint32_t handle2, char *counter) { char *ptr1, *ptr2; - static char counter = 0; int i; ptr1 = gem_mmap(fd1, handle1, BO_SIZE, PROT_READ | PROT_WRITE); @@ -62,13 +64,13 @@ check_bo(int fd1, uint32_t handle1, int fd2, uint32_t handle2) /* check whether it's still our old object first. */ for (i = 0; i < BO_SIZE; i++) { - assert(ptr1[i] == counter); - assert(ptr2[i] == counter); + assert(ptr1[i] == *counter); + assert(ptr2[i] == *counter); } - counter++; + (*counter)++; - memset(ptr1, counter, BO_SIZE); + memset(ptr1, *counter, BO_SIZE); assert(memcmp(ptr1, ptr2, BO_SIZE) == 0); munmap(ptr1, BO_SIZE); @@ -79,17 +81,19 @@ int main(int argc, char **argv) { int fd1, fd2; uint32_t handle, handle_import1, handle_import2, handle_selfimport; + uint32_t handle2; int dma_buf_fd; fd1 = drm_open_any(); fd2 = drm_open_any(); handle = gem_create(fd1, BO_SIZE); + handle2 = gem_create(fd1, BO_SIZE); dma_buf_fd = prime_handle_to_fd(fd1, handle); handle_import1 = prime_fd_to_handle(fd2, dma_buf_fd); - check_bo(fd1, handle, fd2, handle_import1); + check_bo(fd1, handle, fd2, handle_import1, &counter1); /* reimport should give us the same handle so that userspace can check * whether it has that bo already somewhere. */ @@ -102,10 +106,17 @@ int main(int argc, char **argv) /* close dma_buf, check whether nothing disappears. */ close(dma_buf_fd); - check_bo(fd1, handle, fd2, handle_import1); + check_bo(fd1, handle, fd2, handle_import1, &counter1); gem_close(fd1, handle); - check_bo(fd2, handle_import1, fd2, handle_import1); + check_bo(fd2, handle_import1, fd2, handle_import1, &counter1); + + dma_buf_fd = prime_handle_to_fd(fd1, handle2); + handle = prime_fd_to_handle(fd2, dma_buf_fd); + check_bo(fd1, handle2, fd2, handle, &counter2); + gem_close(fd2, handle); + gem_close(fd1, handle2); + close(dma_buf_fd); /* re-import into old exporter */ dma_buf_fd = prime_handle_to_fd(fd2, handle_import1); @@ -113,11 +124,11 @@ int main(int argc, char **argv) gem_close(fd2, handle_import1); handle = prime_fd_to_handle(fd1, dma_buf_fd); handle_import1 = prime_fd_to_handle(fd2, dma_buf_fd); - check_bo(fd1, handle, fd2, handle_import1); + check_bo(fd1, handle, fd2, handle_import1, &counter1); /* Completely rip out exporting fd. */ close(fd1); - check_bo(fd2, handle_import1, fd2, handle_import1); + check_bo(fd2, handle_import1, fd2, handle_import1, &counter1); return 0; } -- 1.7.10.4