diff options
author | Dave Airlie <airlied@redhat.com> | 2012-05-22 13:57:08 +0100 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2012-05-22 13:57:08 +0100 |
commit | 95d3231793e00a0f54a351dc2a389c50f11b28df (patch) | |
tree | 5714c4cc4c33e81f9c8592197b24eb79103fed0f | |
parent | e3fce518307254eeb5303d62c50d395193a9a5ac (diff) |
add intel pread/pwrite testprime-tests
-rw-r--r-- | tests/prime_test.c | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/tests/prime_test.c b/tests/prime_test.c index e9bd40ba..cdc91d09 100644 --- a/tests/prime_test.c +++ b/tests/prime_test.c @@ -18,8 +18,11 @@ #include <stdlib.h> #include <unistd.h> #include <fcntl.h> +#include <string.h> #include <sys/stat.h> +#include <sys/ioctl.h> +#include "i915_drm.h" #include "intel_bufmgr.h" #include "nouveau.h" #include "intel_gpu_tools.h" @@ -337,6 +340,88 @@ static int test6(void) 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) +{ + 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; + + test_intel_bo = drm_intel_bufmgr_gem_get_bo_prime(bufmgr, prime_fd, BO_SIZE); + close(prime_fd); + if (!test_intel_bo) + return -1; + + ret = nouveau_bo_map(nvbo, NOUVEAU_BO_RDWR, nclient); + if (ret < 0) { + fprintf(stderr,"failed to map nouveau bo\n"); + goto out; + } + + 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; + } + 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: + nouveau_bo_ref(NULL, &nvbo); + drm_intel_bo_unreference(test_intel_bo); + return ret; +} + static void set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) { @@ -369,7 +454,7 @@ 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 test7(void) +static int test8(void) { int ret; drm_intel_bo *test_intel_bo, *src_bo; @@ -474,6 +559,10 @@ int main(int argc, char **argv) if (ret) fprintf(stderr,"prime_test: failed test 6\n"); + ret = test7(); + if (ret) + fprintf(stderr,"prime_test: failed test 7\n"); + intel_batchbuffer_free(intel_batch); nouveau_device_del(&ndev); |