tests/prime_self_import: export/import a second gem buffer
PATCH 1/1 tests/prime_self_import: export/import a second gem buffer
--- tests/prime_self_import.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
tests/prime_self_import.c +22 -11
@@ -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 ; }
Signature · 1 line
1.7.10.4
Quoted 1 line · Imre Deak
Signed-off-by Imre Deak <[email protected]>
I'm a bit confused what this does ... can you please elaborate? -Daniel
Quoted 104 lines
--- tests/prime_self_import.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)tests/prime_self_import.c +22
-11@@ -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 ; }Signature · 6 lines
1.7.10.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 4 lines · Daniel Vetter
Quoted 1 line · Imre Deak
Signed-off-by Imre Deak <[email protected]>I'm a bit confused what this does ... can you please elaborate?
It creates a second GEM buffer on fd1, exports it, imports it on fd2 and check if the imported buffer contents matches the original one.
--Imre
Quoted 107 lines
-Daniel
Quoted 104 lines
--- tests/prime_self_import.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)tests/prime_self_import.c +22
-11@@ -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 ; }Signature · 6 lines
1.7.10.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 1/1 tests/prime_self_import: add subtest to export/import a second gem buffer
In reply to Imre DeakAlso add a subtest for the fd=handle_to_fd(), fd2=dup(fd), close(fd) case (idea from Kristian Høgsberg).
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(-)
tests/Makefile.am +1 -1
@@ -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)
tests/prime_self_import.c +86 -2
110 lines not on this page · raw message
Signature · 6 lines
1.7.10.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Daniel Vetter
AppliedRe: [PATCH v2] tests/prime_self_import: add subtest to export/import a second gem buffer
Quoted 8 lines · Imre Deak
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 <[email protected]>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
Quoted 145 lines
--- tests/Makefile.am | 2 +- tests/prime_self_import.c | 88 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 3 deletions(-)tests/Makefile.am +1
-1@@ -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)tests/prime_self_import.c +86
-2@@ -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 ; }Signature · 1 line
1.7.10.4
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch