summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2009-04-14 14:30:22 +1000
committerDave Airlie <airlied@redhat.com>2009-04-14 14:30:22 +1000
commit529848ce0cdb0192589a636e6136fc5c4c8cdf9b (patch)
tree489f1cc081e00bb2057aee4ad13cbafa44b7572a
parent2f0720455da3e62a60221f876f95b5952e74111d (diff)
radeon: add quick bo test
-rw-r--r--libdrm/radeon/radeon_bo_gem.c17
-rw-r--r--libdrm/radeon/radeon_bo_gem.h1
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/radeon_bo_test.c120
4 files changed, 144 insertions, 3 deletions
diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c
index 70f4b6b4..dd840631 100644
--- a/libdrm/radeon/radeon_bo_gem.c
+++ b/libdrm/radeon/radeon_bo_gem.c
@@ -235,3 +235,20 @@ uint32_t radeon_gem_name_bo(struct radeon_bo *bo)
struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo;
return bo_gem->name;
}
+
+int radeon_gem_set_domain(struct radeon_bo *bo, uint32_t read_domains, uint32_t write_domain)
+{
+ struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo;
+ struct drm_radeon_gem_set_domain args;
+ int r;
+
+ args.handle = bo->handle;
+ args.read_domains = read_domains;
+ args.write_domain = write_domain;
+
+ r = drmCommandWriteRead(bo->bom->fd,
+ DRM_RADEON_GEM_SET_DOMAIN,
+ &args,
+ sizeof(args));
+ return r;
+}
diff --git a/libdrm/radeon/radeon_bo_gem.h b/libdrm/radeon/radeon_bo_gem.h
index 980a6a4e..9d9ce02c 100644
--- a/libdrm/radeon/radeon_bo_gem.h
+++ b/libdrm/radeon/radeon_bo_gem.h
@@ -38,4 +38,5 @@ struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd);
void radeon_bo_manager_gem_dtor(struct radeon_bo_manager *bom);
uint32_t radeon_gem_name_bo(struct radeon_bo *bo);
+int radeon_gem_set_domain(struct radeon_bo *bo, uint32_t read_domains, uint32_t write_domain);
#endif
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 805bf770..66c2f5e7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,8 @@
AM_CFLAGS = \
-I $(top_srcdir)/shared-core \
- -I $(top_srcdir)/libdrm
+ -I $(top_srcdir)/libdrm \
+ -I $(top_srcdir)/libdrm/radeon
+
noinst_PROGRAMS = \
dristat \
@@ -13,7 +15,7 @@ libdrmtest_la_SOURCES = \
libdrmtest_la_LIBADD = \
$(top_builddir)/libdrm/libdrm.la
-LDADD = libdrmtest.la
+LDADD = libdrmtest.la $(top_builddir)/libdrm/radeon/libdrm_radeon.la
TESTS = auth \
openclose \
@@ -28,7 +30,8 @@ TESTS = auth \
gem_readwrite \
gem_mmap \
radeon_gem_mmap \
- radeon_gem_basic
+ radeon_gem_basic \
+ radeon_bo_test
EXTRA_PROGRAMS = $(TESTS)
CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES)
diff --git a/tests/radeon_bo_test.c b/tests/radeon_bo_test.c
new file mode 100644
index 00000000..bfbf6be1
--- /dev/null
+++ b/tests/radeon_bo_test.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright © 2008 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Dave Airlie
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include "drm.h"
+#include "radeon_drm.h"
+#include "radeon_bo_gem.h"
+
+#define OBJECT_SIZE 16384
+
+int main(int argc, char **argv)
+{
+ int fd;
+ struct drm_radeon_gem_create create;
+ struct drm_radeon_gem_mmap mmap;
+ struct drm_gem_close unref;
+ uint8_t expected[OBJECT_SIZE];
+ uint8_t buf[OBJECT_SIZE];
+ uint8_t *addr;
+ int ret;
+ int handle;
+ struct radeon_bo_manager *bom;
+ struct radeon_bo *bo;
+ int i;
+
+ fd = drm_open_any();
+
+ bom = radeon_bo_manager_gem_ctor(fd);
+ if (!bom) {
+ fprintf(stderr,"failed to setup bom\n");
+ exit(-2);
+ }
+
+ bo = radeon_bo_open(bom, 0, OBJECT_SIZE, 0, 0, 0);
+ if (!bo) {
+ fprintf(stderr,"failed to open bo\n");
+ exit(-2);
+ }
+
+ ret = radeon_bo_map(bo, 1);
+ if (ret) {
+ fprintf(stderr,"failed to map bo\n");
+ exit(-2);
+ }
+
+ addr = bo->ptr;
+
+#if 0
+ printf("Testing contents of newly created object.\n");
+ memset(expected, 0, sizeof(expected));
+ assert(memcmp(addr, expected, sizeof(expected)) == 0);
+#endif
+
+ /* fill the buffer with something, then migrate in out */
+ memset(expected, 0xaa, sizeof(expected));
+ memset(addr, 0xaa, OBJECT_SIZE);
+
+ if (memcmp(addr, expected, sizeof(expected)))
+ fprintf(stderr,"0xaa failed to match up\n");
+
+ for (i = 0; i < 15000; i++) {
+ ret = radeon_gem_set_domain(bo, 0, RADEON_GEM_DOMAIN_VRAM);
+ if (ret) {
+ fprintf(stderr,"set domain failed\n");
+ break;
+ }
+
+ if (memcmp(addr, expected, sizeof(expected))) {
+ fprintf(stderr,"0xaa failed to match up -post VRAM move\n");
+ break;
+ }
+
+ ret = radeon_gem_set_domain(bo, 0, RADEON_GEM_DOMAIN_GTT);
+ if (ret) {
+ fprintf(stderr,"set domain failed\n");
+ break;
+ }
+ if (memcmp(addr, expected, sizeof(expected))) {
+ fprintf(stderr,"0xaa failed to match up -post GTT move\n");
+ break;
+ }
+ }
+ radeon_bo_unref(bo);
+
+ radeon_bo_manager_gem_dtor(bom);
+ close(fd);
+
+ return 0;
+}