summaryrefslogtreecommitdiff
path: root/tests/prime_nv_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/prime_nv_test.c')
-rw-r--r--tests/prime_nv_test.c375
1 files changed, 97 insertions, 278 deletions
diff --git a/tests/prime_nv_test.c b/tests/prime_nv_test.c
index 2269f84f..8211cd6f 100644
--- a/tests/prime_nv_test.c
+++ b/tests/prime_nv_test.c
@@ -22,11 +22,13 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
-#include "i915_drm.h"
+#include "ioctl_wrappers.h"
#include "intel_bufmgr.h"
#include "nouveau.h"
-#include "intel_gpu_tools.h"
+#include "intel_io.h"
#include "intel_batchbuffer.h"
+#include "intel_chipset.h"
+#include "drmtest.h"
int intel_fd = -1, nouveau_fd = -1;
drm_intel_bufmgr *bufmgr;
@@ -46,6 +48,8 @@ static int find_and_open_devices(void)
char vendor_id[8];
int venid;
for (i = 0; i < 9; i++) {
+ char *ret;
+
sprintf(path, "/sys/class/drm/card%d/device/vendor", i);
if (stat(path, &buf))
break;
@@ -54,7 +58,8 @@ static int find_and_open_devices(void)
if (!fl)
break;
- fgets(vendor_id, 8, fl);
+ ret = fgets(vendor_id, 8, fl);
+ igt_assert(ret);
fclose(fl);
venid = strtoul(vendor_id, NULL, 16);
@@ -80,25 +85,22 @@ static int find_and_open_devices(void)
* close prime_fd,
* unref buffers
*/
-static int test1(void)
+static void test_i915_nv_sharing(void)
{
- int ret;
drm_intel_bo *test_intel_bo;
int prime_fd;
struct nouveau_bo *nvbo;
test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
+ igt_assert(test_intel_bo);
drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
- ret = nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo);
+ igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
close(prime_fd);
- if (ret < 0)
- return ret;
nouveau_bo_ref(NULL, &nvbo);
drm_intel_bo_unreference(test_intel_bo);
- return 0;
}
/*
@@ -109,38 +111,30 @@ static int test1(void)
* close prime_fd,
* unref buffers
*/
-static int test2(void)
+static void test_nv_i915_sharing(void)
{
- int ret;
drm_intel_bo *test_intel_bo;
int prime_fd;
struct nouveau_bo *nvbo;
- ret = nouveau_bo_new(ndev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP,
- 0, BO_SIZE, NULL, &nvbo);
- if (ret < 0)
- return ret;
- ret = nouveau_bo_set_prime(nvbo, &prime_fd);
- if (ret < 0)
- return ret;
+ 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);
test_intel_bo = drm_intel_bo_gem_create_from_prime(bufmgr, prime_fd, BO_SIZE);
close(prime_fd);
- if (!test_intel_bo)
- return -1;
+ igt_assert(test_intel_bo);
nouveau_bo_ref(NULL, &nvbo);
drm_intel_bo_unreference(test_intel_bo);
- return 0;
}
/*
* allocate intel, give to nouveau, map on nouveau
* write 0xdeadbeef, non-gtt map on intel, read
*/
-static int test3(void)
+static void test_nv_write_i915_cpu_mmap_read(void)
{
- int ret;
drm_intel_bo *test_intel_bo;
int prime_fd;
struct nouveau_bo *nvbo = NULL;
@@ -150,46 +144,28 @@ static int test3(void)
drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
- ret = nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo);
- if (ret < 0) {
- fprintf(stderr,"failed to ref prime buffer %d\n", ret);
- close(prime_fd);
- goto free_intel;
- }
+ igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
close(prime_fd);
- goto free_intel;
-
- ret = nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient);
- if (ret < 0) {
- fprintf(stderr,"failed to map nouveau bo\n");
- goto out;
- }
+ igt_assert(nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient) == 0);
ptr = nvbo->map;
*ptr = 0xdeadbeef;
drm_intel_bo_map(test_intel_bo, 1);
-
ptr = test_intel_bo->virtual;
+ igt_assert(ptr);
- if (*ptr != 0xdeadbeef) {
- fprintf(stderr,"mapped value doesn't match\n");
- ret = -1;
- }
-out:
+ igt_assert(*ptr == 0xdeadbeef);
nouveau_bo_ref(NULL, &nvbo);
-free_intel:
drm_intel_bo_unreference(test_intel_bo);
- return ret;
}
/*
* allocate intel, give to nouveau, map on nouveau
* write 0xdeadbeef, gtt map on intel, read
*/
-static int test4(void)
+static void test_nv_write_i915_gtt_mmap_read(void)
{
- int ret;
drm_intel_bo *test_intel_bo;
int prime_fd;
struct nouveau_bo *nvbo = NULL;
@@ -199,227 +175,118 @@ static int test4(void)
drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
- ret = nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo);
+ igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
close(prime_fd);
- if (ret < 0) {
- fprintf(stderr,"failed to ref prime buffer\n");
- return ret;
- }
-
- ret = nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient);
- if (ret < 0) {
- fprintf(stderr,"failed to map nouveau bo\n");
- goto out;
- }
-
-
+ igt_assert(nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient) == 0);
ptr = nvbo->map;
*ptr = 0xdeadbeef;
drm_intel_gem_bo_map_gtt(test_intel_bo);
ptr = test_intel_bo->virtual;
+ igt_assert(ptr);
+
+ igt_assert(*ptr == 0xdeadbeef);
- if (*ptr != 0xdeadbeef) {
- fprintf(stderr,"mapped value doesn't match\n");
- ret = -1;
- }
-out:
nouveau_bo_ref(NULL, &nvbo);
drm_intel_bo_unreference(test_intel_bo);
- return ret;
}
/* test drm_intel_bo_map doesn't work properly,
this tries to map the backing shmem fd, which doesn't exist
for these objects */
-static int test5(void)
+static void test_i915_import_cpu_mmap(void)
{
- int ret;
drm_intel_bo *test_intel_bo;
int prime_fd;
struct nouveau_bo *nvbo;
uint32_t *ptr;
- ret = nouveau_bo_new(ndev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP,
- 0, BO_SIZE, NULL, &nvbo);
- if (ret < 0)
- return ret;
- ret = nouveau_bo_set_prime(nvbo, &prime_fd);
- if (ret < 0)
- return ret;
-
+ 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);
test_intel_bo = drm_intel_bo_gem_create_from_prime(bufmgr, prime_fd, BO_SIZE);
close(prime_fd);
- if (!test_intel_bo)
- return -1;
+ igt_assert(test_intel_bo);
- ret = nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient);
- if (ret < 0) {
- fprintf(stderr,"failed to map nouveau bo\n");
- goto out;
- }
+ igt_assert(nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient) == 0);
ptr = nvbo->map;
*ptr = 0xdeadbeef;
- ret = drm_intel_bo_map(test_intel_bo, 0);
- if (ret != 0) {
- /* failed to map the bo is expected */
- ret = 0;
- goto out;
- }
- if (!test_intel_bo->virtual) {
- ret = 0;
- goto out;
- }
+ igt_assert(drm_intel_bo_map(test_intel_bo, 0) == 0);
+ igt_assert(test_intel_bo->virtual);
ptr = test_intel_bo->virtual;
- if (*ptr != 0xdeadbeef) {
- fprintf(stderr,"mapped value doesn't match %08x\n", *ptr);
- ret = -1;
- }
- out:
+ igt_assert(*ptr == 0xdeadbeef);
nouveau_bo_ref(NULL, &nvbo);
drm_intel_bo_unreference(test_intel_bo);
- return ret;
}
/* test drm_intel_bo_map_gtt works properly,
this tries to map the backing shmem fd, which doesn't exist
for these objects */
-static int test6(void)
+static void test_i915_import_gtt_mmap(void)
{
- int ret;
drm_intel_bo *test_intel_bo;
int prime_fd;
struct nouveau_bo *nvbo;
uint32_t *ptr;
- ret = nouveau_bo_new(ndev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP,
- 0, BO_SIZE, NULL, &nvbo);
- if (ret < 0)
- return ret;
- ret = nouveau_bo_set_prime(nvbo, &prime_fd);
- if (ret < 0)
- return ret;
+ 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);
test_intel_bo = drm_intel_bo_gem_create_from_prime(bufmgr, prime_fd, BO_SIZE);
close(prime_fd);
- if (!test_intel_bo)
- return -1;
+ igt_assert(test_intel_bo);
- ret = nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient);
- if (ret < 0) {
- fprintf(stderr,"failed to map nouveau bo\n");
- goto out;
- }
+ igt_assert(nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient) == 0);
ptr = nvbo->map;
*ptr = 0xdeadbeef;
*(ptr + 1) = 0xa55a55;
- ret = drm_intel_gem_bo_map_gtt(test_intel_bo);
- if (ret != 0) {
- fprintf(stderr,"failed to map bo\n");
- goto out;
- }
- if (!test_intel_bo->virtual) {
- ret = -1;
- fprintf(stderr,"failed to map bo\n");
- goto out;
- }
+ igt_assert(drm_intel_gem_bo_map_gtt(test_intel_bo) == 0);
+ igt_assert(test_intel_bo->virtual);
ptr = test_intel_bo->virtual;
- if (*ptr != 0xdeadbeef) {
- fprintf(stderr,"mapped value doesn't match %08x %08x\n", *ptr, *(ptr + 1));
- ret = -1;
- }
- out:
+ igt_assert(*ptr == 0xdeadbeef);
nouveau_bo_ref(NULL, &nvbo);
drm_intel_bo_unreference(test_intel_bo);
- return ret;
-}
-
-static int do_read(int fd, int handle, void *buf, int offset, int size)
-{
- struct drm_i915_gem_pread intel_pread;
-
- /* Ensure that we don't have any convenient data in buf in case
- * we fail.
- */
- memset(buf, 0xd0, size);
-
- memset(&intel_pread, 0, sizeof(intel_pread));
- intel_pread.handle = handle;
- intel_pread.data_ptr = (uintptr_t)buf;
- intel_pread.size = size;
- intel_pread.offset = offset;
-
- return ioctl(fd, DRM_IOCTL_I915_GEM_PREAD, &intel_pread);
-}
-
-static int do_write(int fd, int handle, void *buf, int offset, int size)
-{
- struct drm_i915_gem_pwrite intel_pwrite;
-
- memset(&intel_pwrite, 0, sizeof(intel_pwrite));
- intel_pwrite.handle = handle;
- intel_pwrite.data_ptr = (uintptr_t)buf;
- intel_pwrite.size = size;
- intel_pwrite.offset = offset;
-
- return ioctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &intel_pwrite);
}
/* test 7 - import from nouveau into intel, test pread/pwrite fail */
-static int test7(void)
+static void test_i915_import_pread_pwrite(void)
{
- int ret;
drm_intel_bo *test_intel_bo;
int prime_fd;
struct nouveau_bo *nvbo;
uint32_t *ptr;
uint32_t buf[64];
- ret = nouveau_bo_new(ndev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP,
- 0, BO_SIZE, NULL, &nvbo);
- if (ret < 0)
- return ret;
- ret = nouveau_bo_set_prime(nvbo, &prime_fd);
- if (ret < 0)
- return ret;
+ 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);
test_intel_bo = drm_intel_bo_gem_create_from_prime(bufmgr, prime_fd, BO_SIZE);
close(prime_fd);
- if (!test_intel_bo)
- return -1;
+ igt_assert(test_intel_bo);
- ret = nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient);
- if (ret < 0) {
- fprintf(stderr,"failed to map nouveau bo\n");
- goto out;
- }
+ igt_assert(nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient) == 0);
ptr = nvbo->map;
*ptr = 0xdeadbeef;
- ret = do_read(intel_fd, test_intel_bo->handle, buf, 0, 256);
- if (ret != -1) {
- fprintf(stderr,"pread succeedded %d\n", ret);
- goto out;
- }
+ gem_read(intel_fd, test_intel_bo->handle, 0, buf, 256);
+ igt_assert(buf[0] == 0xdeadbeef);
buf[0] = 0xabcdef55;
- ret = do_write(intel_fd, test_intel_bo->handle, buf, 0, 4);
- if (ret != -1) {
- fprintf(stderr,"pwrite succeedded\n");
- goto out;
- }
- ret = 0;
- out:
+ gem_write(intel_fd, test_intel_bo->handle, 0, buf, 4);
+
+ igt_assert(*ptr == 0xabcdef55);
+
nouveau_bo_ref(NULL, &nvbo);
drm_intel_bo_unreference(test_intel_bo);
- return ret;
}
static void
@@ -440,7 +307,7 @@ create_bo(drm_intel_bufmgr *ibufmgr, uint32_t val, int width, int height)
drm_intel_bo *bo;
bo = drm_intel_bo_alloc(ibufmgr, "bo", 4*width*height, 0);
- assert(bo);
+ igt_assert(bo);
/* gtt map doesn't have a write parameter, so just keep the mapping
* around (to avoid the set_domain with the gtt write domain set) and
@@ -454,9 +321,8 @@ create_bo(drm_intel_bufmgr *ibufmgr, uint32_t val, int width, int height)
/* use intel hw to fill the BO with a blit from another BO,
then readback from the nouveau bo, check value is correct */
-static int test8(void)
+static void test_i915_blt_fill_nv_read(void)
{
- int ret;
drm_intel_bo *test_intel_bo, *src_bo;
int prime_fd;
struct nouveau_bo *nvbo = NULL;
@@ -468,115 +334,68 @@ static int test8(void)
drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
- ret = nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo);
+ igt_assert(nouveau_bo_prime_handle_ref(ndev, prime_fd, &nvbo) == 0);
close(prime_fd);
- if (ret < 0) {
- fprintf(stderr,"failed to ref prime buffer\n");
- return ret;
- }
- intel_copy_bo(intel_batch, test_intel_bo, src_bo, 256, 1);
+ intel_copy_bo(intel_batch, test_intel_bo, src_bo, BO_SIZE);
- ret = nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient);
- if (ret < 0) {
- fprintf(stderr,"failed to map nouveau bo\n");
- goto out;
- }
+ igt_assert(nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient) == 0);
drm_intel_bo_map(test_intel_bo, 0);
ptr = nvbo->map;
- if (*ptr != 0xaa55aa55) {
- fprintf(stderr,"mapped value doesn't match\n");
- ret = -1;
- }
-out:
+ igt_assert(*ptr == 0xaa55aa55);
nouveau_bo_ref(NULL, &nvbo);
drm_intel_bo_unreference(test_intel_bo);
- return ret;
}
/* test 8 use nouveau to do blit */
/* test 9 nouveau copy engine?? */
-int main(int argc, char **argv)
+igt_main
{
- int ret;
+ igt_fixture {
+ igt_assert(find_and_open_devices() == 0);
- ret = find_and_open_devices();
- if (ret < 0)
- return ret;
+ igt_require(nouveau_fd != -1);
+ igt_require(intel_fd != -1);
- if (nouveau_fd == -1 || intel_fd == -1) {
- fprintf(stderr,"failed to find intel and nouveau GPU\n");
- return 77;
- }
+ /* 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);
- /* set up intel bufmgr */
- bufmgr = drm_intel_bufmgr_gem_init(intel_fd, 4096);
- if (!bufmgr)
- return -1;
- /* Do not enable reuse, we share (almost) all buffers. */
- //drm_intel_bufmgr_gem_enable_reuse(bufmgr);
-
- /* set up nouveau bufmgr */
- ret = nouveau_device_wrap(nouveau_fd, 0, &ndev);
- if (ret < 0) {
- fprintf(stderr,"failed to wrap nouveau device\n");
- return 77;
- }
+ /* set up nouveau bufmgr */
+ igt_assert(nouveau_device_wrap(nouveau_fd, 0, &ndev) == 0);
+ igt_assert(nouveau_client_new(ndev, &nclient) == 0);
- ret = nouveau_client_new(ndev, &nclient);
- if (ret < 0) {
- fprintf(stderr,"failed to setup nouveau client\n");
- return -1;
+ /* set up an intel batch buffer */
+ devid = intel_get_drm_devid(intel_fd);
+ intel_batch = intel_batchbuffer_alloc(bufmgr, devid);
}
- /* set up an intel batch buffer */
- devid = intel_get_drm_devid(intel_fd);
- intel_batch = intel_batchbuffer_alloc(bufmgr, devid);
-
- /* create an object on the i915 */
- ret = test1();
- if (ret)
- fprintf(stderr,"prime_test: failed test 1\n");
-
- ret = test2();
- if (ret)
- fprintf(stderr,"prime_test: failed test 2\n");
-
- ret = test3();
- if (ret)
- fprintf(stderr,"prime_test: failed test 3\n");
+#define xtest(name) \
+ igt_subtest(#name) \
+ test_##name();
- ret = test4();
- if (ret)
- fprintf(stderr,"prime_test: failed test 4\n");
+ xtest(i915_nv_sharing);
+ xtest(nv_i915_sharing);
+ xtest(nv_write_i915_cpu_mmap_read);
+ xtest(nv_write_i915_gtt_mmap_read);
+ xtest(i915_import_cpu_mmap);
+ xtest(i915_import_gtt_mmap);
+ xtest(i915_import_pread_pwrite);
+ xtest(i915_blt_fill_nv_read);
- ret = test5();
- if (ret)
- fprintf(stderr,"prime_test: failed test 5\n");
+ igt_fixture {
+ intel_batchbuffer_free(intel_batch);
- ret = test6();
- if (ret)
- fprintf(stderr,"prime_test: failed test 6\n");
+ nouveau_device_del(&ndev);
+ drm_intel_bufmgr_destroy(bufmgr);
- ret = test7();
- if (ret)
- fprintf(stderr,"prime_test: failed test 7\n");
-
- ret = test8();
- if (ret)
- fprintf(stderr,"prime_test: failed test 8\n");
-
- intel_batchbuffer_free(intel_batch);
-
- nouveau_device_del(&ndev);
- drm_intel_bufmgr_destroy(bufmgr);
-
- close(intel_fd);
- close(nouveau_fd);
-
- return ret;
+ close(intel_fd);
+ close(nouveau_fd);
+ }
}