[igt-dev] [PATCH i-g-t v4 22/25] tests/prime_nv_api.c: Remove libdrm dependency
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Mon Sep 28 07:40:33 UTC 2020
On Tue, Sep 22, 2020 at 01:52:26PM +0200, Dominik Grzegorzek wrote:
> Use intel_bb / intel_buf to remove libdrm dependency.
>
> Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
> Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> ---
> tests/prime_nv_api.c | 203 +++++++++++++++++++++++--------------------
> 1 file changed, 111 insertions(+), 92 deletions(-)
>
> diff --git a/tests/prime_nv_api.c b/tests/prime_nv_api.c
> index 054a1ec6..a3adeddc 100644
> --- a/tests/prime_nv_api.c
> +++ b/tests/prime_nv_api.c
> @@ -15,18 +15,18 @@
> #include <fcntl.h>
> #include <sys/stat.h>
>
> -#include "intel_bufmgr.h"
> #include "nouveau.h"
>
> -#define BO_SIZE (256*1024)
> +#define WIDTH 256
> +#define HEIGHT 256
> +
> +#define BO_SIZE (WIDTH*HEIGHT*4)
>
> int intel_fd = -1, intel_fd2 = -1, nouveau_fd = -1, nouveau_fd2 = -1;
> -drm_intel_bufmgr *bufmgr;
> -drm_intel_bufmgr *bufmgr2;
> +struct buf_ops *bops;
> +struct buf_ops *bops2;
> struct nouveau_device *ndev, *ndev2;
> struct nouveau_client *nclient, *nclient2;
> -uint32_t devid;
> -struct intel_batchbuffer *intel_batch;
>
> static void find_and_open_devices(void)
> {
> @@ -69,13 +69,15 @@ static void find_and_open_devices(void)
>
> static void test_i915_nv_import_twice(void)
> {
> - drm_intel_bo *test_intel_bo;
> + struct intel_buf *test_intel_buf;
> int prime_fd;
> struct nouveau_bo *nvbo = NULL, *nvbo2 = NULL;
>
> - test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
> + test_intel_buf = intel_buf_create(bops, WIDTH, HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
0 instead 4096.
>
> - igt_assert(drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd) == 0);
> + prime_fd = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
prime_handle_to_fd_for_mmap(), likely doesn't differ for that case but
we don't want to change test coverage.
>
> igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
> igt_assert(nouveau_bo_prime_handle_ref(ndev2, prime_fd, &nvbo2) == 0);
> @@ -83,19 +85,21 @@ static void test_i915_nv_import_twice(void)
>
> nouveau_bo_ref(NULL, &nvbo2);
> nouveau_bo_ref(NULL, &nvbo);
> - drm_intel_bo_unreference(test_intel_bo);
> + intel_buf_destroy(test_intel_buf);
> }
>
> static void test_i915_nv_import_twice_check_flink_name(void)
> {
> - drm_intel_bo *test_intel_bo;
> + struct intel_buf *test_intel_buf;
> int prime_fd;
> struct nouveau_bo *nvbo = NULL, *nvbo2 = NULL;
> uint32_t flink_name1, flink_name2;
>
> - test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
> + test_intel_buf = intel_buf_create(bops, WIDTH, HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
>
> - igt_assert(drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd) == 0);
> + prime_fd = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
Same as above.
>
> igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
> igt_assert(nouveau_bo_prime_handle_ref(ndev2, prime_fd, &nvbo2) == 0);
> @@ -108,25 +112,27 @@ static void test_i915_nv_import_twice_check_flink_name(void)
>
> nouveau_bo_ref(NULL, &nvbo2);
> nouveau_bo_ref(NULL, &nvbo);
> - drm_intel_bo_unreference(test_intel_bo);
> + intel_buf_destroy(test_intel_buf);
> }
>
> static void test_i915_nv_reimport_twice_check_flink_name(void)
> {
> - drm_intel_bo *test_intel_bo;
> + struct intel_buf *test_intel_buf;
> int prime_fd;
> struct nouveau_bo *nvbo = NULL, *nvbo2 = NULL;
> uint32_t flink_name1, flink_name2;
>
> - test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
> + test_intel_buf = intel_buf_create(bops, WIDTH, HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
>
> - igt_assert(drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd) == 0);
> + prime_fd = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
>
> igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
>
> /* create a new dma-buf */
> close(prime_fd);
> - igt_assert(drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd) == 0);
> + prime_handle_to_fd(intel_fd, test_intel_buf->handle);
Same as above.
>
> igt_assert(nouveau_bo_prime_handle_ref(ndev2, prime_fd, &nvbo2) == 0);
> close(prime_fd);
> @@ -138,79 +144,91 @@ static void test_i915_nv_reimport_twice_check_flink_name(void)
>
> nouveau_bo_ref(NULL, &nvbo2);
> nouveau_bo_ref(NULL, &nvbo);
> - drm_intel_bo_unreference(test_intel_bo);
> + intel_buf_destroy(test_intel_buf);
> }
>
> static void test_nv_i915_import_twice_check_flink_name(void)
> {
> - drm_intel_bo *intel_bo = NULL, *intel_bo2 = NULL;
> + struct intel_buf *intel_buf1 = NULL, *intel_buf2 = NULL;
> int prime_fd;
> struct nouveau_bo *nvbo = NULL;
> - uint32_t flink_name1, flink_name2;
> + uint32_t flink_name1, flink_name2, handle;
>
> igt_assert(nouveau_bo_new(ndev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP,
> 0, BO_SIZE, NULL, &nvbo) == 0);
>
> igt_assert(nouveau_bo_set_prime(nvbo, &prime_fd) == 0);
>
> - intel_bo = drm_intel_bo_gem_create_from_prime(bufmgr, prime_fd, BO_SIZE);
> - igt_assert(intel_bo);
> -
> - intel_bo2 = drm_intel_bo_gem_create_from_prime(bufmgr2, prime_fd, BO_SIZE);
> - igt_assert(intel_bo2);
> + handle = prime_fd_to_handle(intel_fd, prime_fd);
> + intel_buf1 = intel_buf_create_using_handle(bops, handle, WIDTH, HEIGHT,
> + 32, 4096, I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
> + intel_buf_set_ownership(intel_buf1, true);
Assert if intel_buf_bo_size(buf) is not equal to BO_SIZE.
> +
> + handle = prime_fd_to_handle(intel_fd2, prime_fd);
> + intel_buf2 = intel_buf_create_using_handle(bops2, handle, WIDTH, HEIGHT,
> + 32, 4096, I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
> + intel_buf_set_ownership(intel_buf2, true);
> close(prime_fd);
>
> - igt_assert(drm_intel_bo_flink(intel_bo, &flink_name1) == 0);
> - igt_assert(drm_intel_bo_flink(intel_bo2, &flink_name2) == 0);
> + flink_name1 = gem_flink(intel_fd, intel_buf1->handle);
> + flink_name2 = gem_flink(intel_fd2, intel_buf2->handle);
>
> igt_assert_eq_u32(flink_name1, flink_name2);
>
> nouveau_bo_ref(NULL, &nvbo);
> - drm_intel_bo_unreference(intel_bo);
> - drm_intel_bo_unreference(intel_bo2);
> + intel_buf_destroy(intel_buf1);
> + intel_buf_destroy(intel_buf2);
> }
>
> static void test_nv_i915_reimport_twice_check_flink_name(void)
> {
> - drm_intel_bo *intel_bo = NULL, *intel_bo2 = NULL;
> + struct intel_buf *intel_buf1 = NULL, *intel_buf2 = NULL;
> int prime_fd;
> struct nouveau_bo *nvbo = NULL;
> - uint32_t flink_name1, flink_name2;
> + uint32_t flink_name1, flink_name2, handle;
>
> igt_assert(nouveau_bo_new(ndev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP,
> 0, BO_SIZE, NULL, &nvbo) == 0);
>
> igt_assert(nouveau_bo_set_prime(nvbo, &prime_fd) == 0);
>
> - intel_bo = drm_intel_bo_gem_create_from_prime(bufmgr, prime_fd, BO_SIZE);
> - igt_assert(intel_bo);
> - close(prime_fd);
> - igt_assert(nouveau_bo_set_prime(nvbo, &prime_fd) == 0);
> + handle = prime_fd_to_handle(intel_fd, prime_fd);
> + intel_buf1 = intel_buf_create_using_handle(bops, handle, WIDTH, HEIGHT,
> + 32, 4096, I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
> + intel_buf_set_ownership(intel_buf1, true);
Check intel_buf size like above.
>
> - intel_bo2 = drm_intel_bo_gem_create_from_prime(bufmgr2, prime_fd, BO_SIZE);
> - igt_assert(intel_bo2);
> + igt_assert(nouveau_bo_set_prime(nvbo, &prime_fd) == 0);
> + handle = prime_fd_to_handle(intel_fd2, prime_fd);
> + intel_buf2 = intel_buf_create_using_handle(bops2, handle, WIDTH, HEIGHT,
> + 32, 4096, I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
> + intel_buf_set_ownership(intel_buf2, true);
> close(prime_fd);
>
> - igt_assert(drm_intel_bo_flink(intel_bo, &flink_name1) == 0);
> - igt_assert(drm_intel_bo_flink(intel_bo2, &flink_name2) == 0);
> + flink_name1 = gem_flink(intel_fd, intel_buf1->handle);
> + flink_name2 = gem_flink(intel_fd2, intel_buf2->handle);
>
> igt_assert_eq_u32(flink_name1, flink_name2);
>
> nouveau_bo_ref(NULL, &nvbo);
> - drm_intel_bo_unreference(intel_bo);
> - drm_intel_bo_unreference(intel_bo2);
> + intel_buf_destroy(intel_buf1);
> + intel_buf_destroy(intel_buf2);
> }
>
> static void test_i915_nv_import_vs_close(void)
> {
> - drm_intel_bo *test_intel_bo;
> + struct intel_buf *test_intel_buf;
> int prime_fd;
> struct nouveau_bo *nvbo = NULL, *nvbo2 = NULL;
>
> - test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
> - igt_assert(test_intel_bo);
> + test_intel_buf = intel_buf_create(bops, WIDTH, HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
0 instead 4096.
>
> - igt_assert(drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd) == 0);
> + prime_fd = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
prime_handle_to_fd_for_mmap().
>
> igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
> close(prime_fd);
> @@ -218,21 +236,21 @@ static void test_i915_nv_import_vs_close(void)
>
> nouveau_bo_ref(NULL, &nvbo2);
> nouveau_bo_ref(NULL, &nvbo);
> - drm_intel_bo_unreference(test_intel_bo);
> + intel_buf_destroy(test_intel_buf);
> }
>
> /* import handle twice on one driver */
> static void test_i915_nv_double_import(void)
> {
> - drm_intel_bo *test_intel_bo;
> + struct intel_buf *test_intel_buf;
> int prime_fd;
> struct nouveau_bo *nvbo = NULL, *nvbo2 = NULL;
>
> - test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
> - igt_assert(test_intel_bo);
> -
> - igt_assert(drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd) == 0);
> + test_intel_buf = intel_buf_create(bops, WIDTH, HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
>
> + prime_fd = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
Same as above.
> igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
> igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo2) == 0);
> close(prime_fd);
> @@ -241,23 +259,24 @@ static void test_i915_nv_double_import(void)
>
> nouveau_bo_ref(NULL, &nvbo2);
> nouveau_bo_ref(NULL, &nvbo);
> - drm_intel_bo_unreference(test_intel_bo);
> + intel_buf_destroy(test_intel_buf);
> }
>
> /* export handle twice from one driver - import twice
> see if we get same object */
> static void test_i915_nv_double_export(void)
> {
> - drm_intel_bo *test_intel_bo;
> + struct intel_buf *test_intel_buf;
> int prime_fd, prime_fd2;
> struct nouveau_bo *nvbo = NULL, *nvbo2 = NULL;
>
> - test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
> - igt_assert(test_intel_bo);
> + test_intel_buf = intel_buf_create(bops, WIDTH, HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
>
> - drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
> + prime_fd = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
>
> - drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd2);
> + prime_fd2 = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
Same as above.
>
> igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
> close(prime_fd);
> @@ -268,27 +287,33 @@ static void test_i915_nv_double_export(void)
>
> nouveau_bo_ref(NULL, &nvbo2);
> nouveau_bo_ref(NULL, &nvbo);
> - drm_intel_bo_unreference(test_intel_bo);
> + intel_buf_destroy(test_intel_buf);
> }
>
> /* export handle from intel driver - reimport to intel driver
> see if you get same object */
> static void test_i915_self_import(void)
> {
> - drm_intel_bo *test_intel_bo, *test_intel_bo2;
> + struct intel_buf *test_intel_buf, *test_intel_buf2;
> + uint32_t handle;
> int prime_fd;
>
> - test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
> + test_intel_buf = intel_buf_create(bops, WIDTH, HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
>
> - drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
> + prime_fd = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
>
> - test_intel_bo2 = drm_intel_bo_gem_create_from_prime(bufmgr, prime_fd, BO_SIZE);
> - close(prime_fd);
> - igt_assert(test_intel_bo2);
> + handle = prime_fd_to_handle(intel_fd, prime_fd);
> + test_intel_buf2 = intel_buf_create_using_handle(bops, handle, WIDTH,
> + HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
Same as above.
>
> - igt_assert(test_intel_bo->handle == test_intel_bo2->handle);
> + igt_assert(test_intel_buf->handle == test_intel_buf2->handle);
>
> - drm_intel_bo_unreference(test_intel_bo);
> + intel_buf_destroy(test_intel_buf);
> + intel_buf_destroy(test_intel_buf2);
> }
>
> /* nouveau export reimport test */
> @@ -309,23 +334,31 @@ static void test_nv_self_import(void)
> nouveau_bo_ref(NULL, &nvbo2);
> }
>
> -/* export handle from intel driver - reimport to another intel driver bufmgr
> +/* export handle from intel driver - reimport to another intel driver
> see if you get same object */
> static void test_i915_self_import_to_different_fd(void)
> {
> - drm_intel_bo *test_intel_bo, *test_intel_bo2;
> + struct intel_buf *test_intel_buf, *test_intel_buf2;
> + uint32_t handle;
> int prime_fd;
>
> - test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
> + test_intel_buf = intel_buf_create(bops, WIDTH, HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
>
> - drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
> + prime_fd = prime_handle_to_fd(intel_fd, test_intel_buf->handle);
> +
> + handle = prime_fd_to_handle(intel_fd2, prime_fd);
> + test_intel_buf2 = intel_buf_create_using_handle(bops2, handle, WIDTH,
> + HEIGHT, 32, 4096,
> + I915_TILING_NONE,
> + I915_COMPRESSION_NONE);
> + intel_buf_set_ownership(test_intel_buf2, true);
Same as above.
>
> - test_intel_bo2 = drm_intel_bo_gem_create_from_prime(bufmgr2, prime_fd, BO_SIZE);
> close(prime_fd);
> - igt_assert(test_intel_bo2);
>
> - drm_intel_bo_unreference(test_intel_bo2);
> - drm_intel_bo_unreference(test_intel_bo);
> + intel_buf_destroy(test_intel_buf);
> + intel_buf_destroy(test_intel_buf2);
> }
>
> /* nouveau export reimport to other driver test */
> @@ -357,14 +390,8 @@ igt_main
> igt_require(intel_fd2 != -1);
>
> /* set up intel bufmgr */
> - bufmgr = drm_intel_bufmgr_gem_init(intel_fd, 4096);
> - igt_assert(bufmgr);
> - /* Do not enable reuse, we share (almost) all buffers. */
> - //drm_intel_bufmgr_gem_enable_reuse(bufmgr);
> -
> - bufmgr2 = drm_intel_bufmgr_gem_init(intel_fd2, 4096);
> - igt_assert(bufmgr2);
> - drm_intel_bufmgr_gem_enable_reuse(bufmgr2);
I've checked the code and it seems reusing has no influence for tests
behavior here.
> + bops = buf_ops_create(intel_fd);
> + bops2 = buf_ops_create(intel_fd2);
>
> /* set up nouveau bufmgr */
> igt_assert(nouveau_device_wrap(nouveau_fd, 0, &ndev) >= 0);
> @@ -374,11 +401,6 @@ igt_main
> igt_assert(nouveau_device_wrap(nouveau_fd2, 0, &ndev2) >= 0);
>
> igt_assert(nouveau_client_new(ndev2, &nclient2) >= 0);;
> -
> - /* set up an intel batch buffer */
> - devid = intel_get_drm_devid(intel_fd);
> - intel_batch = intel_batchbuffer_alloc(bufmgr, devid);
> - igt_assert(intel_batch);
> }
>
> #define xtest(name) \
> @@ -399,11 +421,8 @@ igt_main
> xtest(nv_self_import_to_different_fd);
>
> igt_fixture {
> - intel_batchbuffer_free(intel_batch);
> -
> nouveau_device_del(&ndev);
> - drm_intel_bufmgr_destroy(bufmgr);
> -
> + buf_ops_destroy(bops);
bops2 also should be destroyed, someone missed releasing bufmgr2.
> close(intel_fd);
> close(nouveau_fd);
> }
> --
> 2.20.1
>
More information about the igt-dev
mailing list