From patchwork Wed Apr 17 20:18:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Imre Deak X-Patchwork-Id: 2456321 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id D511E3FD8C for ; Wed, 17 Apr 2013 20:18:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C17B2E60D6 for ; Wed, 17 Apr 2013 13:18:55 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 7553BE5DB9 for ; Wed, 17 Apr 2013 13:18:44 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 17 Apr 2013 13:18:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.87,495,1363158000"; d="scan'208";a="323950630" Received: from unknown (HELO localhost) ([10.252.121.30]) by fmsmga002.fm.intel.com with ESMTP; 17 Apr 2013 13:18:42 -0700 From: Imre Deak To: intel-gfx@lists.freedesktop.org Date: Wed, 17 Apr 2013 23:18:02 +0300 Message-Id: <1366229882-6497-1-git-send-email-imre.deak@intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1366215000-2366-1-git-send-email-imre.deak@intel.com> References: <1366215000-2366-1-git-send-email-imre.deak@intel.com> MIME-Version: 1.0 Cc: Daniel Vetter Subject: [Intel-gfx] [PATCH v2] tests/prime_self_import: add subtest to export/import a second gem buffer X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org 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) --- tests/Makefile.am | 2 +- tests/prime_self_import.c | 88 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index e147e4e..d4e25a7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -32,6 +32,7 @@ TESTS_progs_M = \ gem_tiled_partial_pwrite_pread \ $(NOUVEAU_TESTS_M) \ kms_flip \ + prime_self_import \ $(NULL) TESTS_progs = \ @@ -101,7 +102,6 @@ TESTS_progs = \ gem_reg_read \ gem_tiling_max_stride \ $(NOUVEAU_TESTS) \ - prime_self_import \ prime_udl \ $(NULL) diff --git a/tests/prime_self_import.c b/tests/prime_self_import.c index 111ed4d..abdc220 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; }