summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2012-12-21 09:41:05 +1000
committerDave Airlie <airlied@redhat.com>2012-12-21 09:41:05 +1000
commitb96d6623f0d2d2a1a4d46eb9c4293296501f1d97 (patch)
tree2059bd7bc4f0a87b8c14030c80b6f0a097697ece
parent0bd3111906bd7880a08d221a7e8ee3890267bf8c (diff)
prime: add some more intel/ati tests
-rw-r--r--tests/prime_test_intel_radeon.c155
1 files changed, 150 insertions, 5 deletions
diff --git a/tests/prime_test_intel_radeon.c b/tests/prime_test_intel_radeon.c
index 03843cfa..dba57d6e 100644
--- a/tests/prime_test_intel_radeon.c
+++ b/tests/prime_test_intel_radeon.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
@@ -30,6 +31,7 @@
#include "intel_gpu_tools.h"
#include "intel_batchbuffer.h"
+char intel_path[80];
int intel_fd = -1, radeon_fd = -1;
drm_intel_bufmgr *bufmgr;
struct radeon_bo_manager *rbom;
@@ -64,6 +66,8 @@ static int find_and_open_devices(void)
intel_fd = open(path, O_RDWR);
if (!intel_fd)
return -1;
+ strcpy(intel_path, path);
+
} else if (venid == 0x1002) {
radeon_fd = open(path, O_RDWR);
if (!radeon_fd)
@@ -81,7 +85,7 @@ static int find_and_open_devices(void)
* close prime_fd,
* unref buffers
*/
-static int test1(void)
+static int test_intel_to_radeon(bool close_order)
{
drm_intel_bo *test_intel_bo;
int prime_fd;
@@ -93,14 +97,137 @@ static int test1(void)
rbo = radeon_gem_bo_open_prime(rbom, prime_fd, BO_SIZE);
close(prime_fd);
- if (!rbo)
+ if (!rbo) {
+ drm_intel_bo_unreference(test_intel_bo);
return -1;
+ }
+
+ if (close_order) {
+ radeon_bo_unref(rbo);
+ drm_intel_bo_unreference(test_intel_bo);
+ } else {
+ drm_intel_bo_unreference(test_intel_bo);
+ radeon_bo_unref(rbo);
+ }
+ return 0;
+}
+
+/* allocate a bo on intel
+ export to prime fd
+ import prime fd
+ close prime fd
+ close radeon handle
+ export to prime fd again
+ close prime fd
+*/
+static int test_intel_to_radeon_complex(void)
+{
+ drm_intel_bo *test_intel_bo;
+ int prime_fd;
+ struct radeon_bo *rbo;
+
+ test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
+
+ drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
+
+ rbo = radeon_gem_bo_open_prime(rbom, prime_fd, BO_SIZE);
+ close(prime_fd);
+ if (!rbo) {
+ drm_intel_bo_unreference(test_intel_bo);
+ return -1;
+ }
+ radeon_bo_unref(rbo);
+
+ drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
+ rbo = radeon_gem_bo_open_prime(rbom, prime_fd, BO_SIZE);
+ close(prime_fd);
radeon_bo_unref(rbo);
drm_intel_bo_unreference(test_intel_bo);
+
return 0;
}
+/* export the bo from intel, then close the bo,
+ and try and import into radeon */
+static int test_intel_to_radeon_close_bo(void)
+{
+ drm_intel_bo *test_intel_bo;
+ int prime_fd;
+ struct radeon_bo *rbo;
+
+ test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
+
+ drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
+
+ drm_intel_bo_unreference(test_intel_bo);
+ rbo = radeon_gem_bo_open_prime(rbom, prime_fd, BO_SIZE);
+ close(prime_fd);
+ if (!rbo) {
+ drm_intel_bo_unreference(test_intel_bo);
+ return -1;
+ }
+
+ radeon_bo_unref(rbo);
+ return 0;
+}
+
+
+static int test_intel_to_intel(void)
+{
+ drm_intel_bo *test_intel_bo, *test_intel_bo2;
+ int prime_fd;
+ test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
+
+ drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
+
+ test_intel_bo2 = drm_intel_bo_gem_create_from_prime(bufmgr, prime_fd, BO_SIZE);
+ close(prime_fd);
+ if (!test_intel_bo2) {
+ fprintf(stderr,"test intel->intel: failed to import bo\n");
+ drm_intel_bo_unreference(test_intel_bo);
+ return -1;
+ }
+
+ if (test_intel_bo->handle != test_intel_bo2->handle)
+ fprintf(stderr,"handles different %d %d\n", test_intel_bo->handle, test_intel_bo2->handle);
+ drm_intel_bo_unreference(test_intel_bo);
+ drm_intel_bo_unreference(test_intel_bo2);
+ return 0;
+}
+
+static int test_intel_to_intel_complex(void)
+{
+ drm_intel_bo *test_intel_bo, *test_intel_bo2;
+ int prime_fd;
+ int intel_fd2 = open(intel_path, O_RDWR);
+ drm_intel_bufmgr *bufmgr2;
+ int ret = 0;
+ bufmgr2 = drm_intel_bufmgr_gem_init(intel_fd2, 4096);
+ drm_intel_bufmgr_gem_enable_reuse(bufmgr2);
+
+ test_intel_bo = drm_intel_bo_alloc(bufmgr, "test bo", BO_SIZE, 4096);
+
+ drm_intel_bo_gem_export_to_prime(test_intel_bo, &prime_fd);
+
+ test_intel_bo2 = drm_intel_bo_gem_create_from_prime(bufmgr2, prime_fd, BO_SIZE);
+ close(prime_fd);
+ if (!test_intel_bo2) {
+ fprintf(stderr,"test intel->intel: failed to import bo\n");
+ drm_intel_bo_unreference(test_intel_bo);
+ ret = -1;
+ goto out;
+ }
+
+ drm_intel_bo_unreference(test_intel_bo);
+ drm_intel_bo_unreference(test_intel_bo2);
+
+ out:
+ drm_intel_bufmgr_destroy(bufmgr2);
+ close(intel_fd2);
+ return ret;
+}
+
/*
* prime test 2 -
* allocate buffer on nouveau
@@ -131,6 +258,7 @@ static int test2(void)
close(prime_fd);
if (!test_intel_bo) {
fprintf(stderr,"test2: failed to import bo\n");
+ radeon_bo_unref(rbo);
return -1;
}
@@ -550,10 +678,28 @@ int main(int argc, char **argv)
intel_batch = intel_batchbuffer_alloc(bufmgr, devid);
/* create an object on the i915 */
- ret = test1();
+ ret = test_intel_to_radeon(false);
+ if (ret)
+ fprintf(stderr,"prime_test: failed test 1 - false\n");
+
+ ret = test_intel_to_radeon(true);
+ if (ret)
+ fprintf(stderr,"prime_test: failed test 1 - true\n");
+ ret = test_intel_to_radeon_complex();
if (ret)
- fprintf(stderr,"prime_test: failed test 1\n");
+ fprintf(stderr,"prime_test: failed test intel to radeon - reexport\n");
+ ret = test_intel_to_radeon_close_bo();
+ if (ret)
+ fprintf(stderr,"prime_test: failed test intel to radeon - close bo\n");
+
+ ret = test_intel_to_intel();
+ if (ret)
+ fprintf(stderr,"prime_test: failed test intel to self\n");
+
+ ret = test_intel_to_intel_complex();
+ if (ret)
+ fprintf(stderr,"prime_test: failed test intel complex to self\n");
ret = test2();
if (ret)
fprintf(stderr,"prime_test: failed test 2\n");
@@ -577,7 +723,6 @@ int main(int argc, char **argv)
ret = test7();
if (ret)
fprintf(stderr,"prime_test: failed test 7\n");
-
intel_batchbuffer_free(intel_batch);
radeon_bo_manager_gem_dtor(rbom);