[Intel-gfx] [PATCH] tests/prime_self_import: export/import a second gem buffer

Daniel Vetter daniel at ffwll.ch
Wed Apr 17 19:06:28 CEST 2013


On Wed, Apr 17, 2013 at 07:10:00PM +0300, Imre Deak wrote:
> Signed-off-by: Imre Deak <imre.deak at intel.com>

I'm a bit confused what this does ... can you please elaborate?
-Daniel

> ---
>  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
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch



More information about the Intel-gfx mailing list