From: Daniel Vetter Subject: Re: [PATCH v2] tests/prime_self_import: add subtest to export/import a second gem buffer Date: Wed, 17 Apr 2013 22:45:34 +0200 Message-ID: <20130417204516.GA6169@phenom.ffwll.local> References: <1366215000-2366-1-git-send-email-imre.deak@intel.com> <1366229882-6497-1-git-send-email-imre.deak@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail-ea0-f170.google.com (mail-ea0-f170.google.com [209.85.215.170]) by gabe.freedesktop.org (Postfix) with ESMTP id 841ADE6134 for ; Wed, 17 Apr 2013 13:42:38 -0700 (PDT) Received: by mail-ea0-f170.google.com with SMTP id a15so921051eae.15 for ; Wed, 17 Apr 2013 13:42:37 -0700 (PDT) Content-Disposition: inline In-Reply-To: <1366229882-6497-1-git-send-email-imre.deak@intel.com> 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: Imre Deak Cc: Daniel Vetter , intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org On Wed, Apr 17, 2013 at 11:18:02PM +0300, Imre Deak wrote: > Also add a subtest for the fd=3Dhandle_to_fd(), fd2=3Ddup(fd), close(fd) > case (idea from Kristian H=F8gsberg). > = > 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) Merged, thanks for the patch. -Daniel > --- > 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 =3D \ > gem_tiled_partial_pwrite_pread \ > $(NOUVEAU_TESTS_M) \ > kms_flip \ > + prime_self_import \ > $(NULL) > = > TESTS_progs =3D \ > @@ -101,7 +102,6 @@ TESTS_progs =3D \ > 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 =3D 0; > int i; > = > ptr1 =3D 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 =3D 0; > + > + fd1 =3D drm_open_any(); > + fd2 =3D drm_open_any(); > + > + handle =3D gem_create(fd1, BO_SIZE); > + > + dma_buf_fd1 =3D prime_handle_to_fd(fd1, handle); > + gem_close(fd1, handle); > + > + dma_buf_fd2 =3D dup(dma_buf_fd1); > + close(dma_buf_fd1); > + handle_import =3D 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 =3D 0; > + > + fd1 =3D drm_open_any(); > + fd2 =3D drm_open_any(); > + > + handle1 =3D gem_create(fd1, BO_SIZE); > + handle2 =3D gem_create(fd1, BO_SIZE); > + > + dma_buf_fd =3D prime_handle_to_fd(fd1, handle1); > + handle_import =3D prime_fd_to_handle(fd2, dma_buf_fd); > + > + close(dma_buf_fd); > + gem_close(fd1, handle1); > + > + dma_buf_fd =3D prime_handle_to_fd(fd1, handle2); > + handle_import =3D 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[] =3D { > + { "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 =3D 0; i < ARRAY_SIZE(tests); i++) { > + if (drmtest_run_subtest(tests[i].name)) > + tests[i].fn(); > + } > = > return 0; > } > -- = > 1.7.10.4 > = -- = Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch