mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2025-12-20 04:40:09 +01:00
radeon: add quick bo test
This commit is contained in:
parent
2f0720455d
commit
529848ce0c
4 changed files with 144 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
120
tests/radeon_bo_test.c
Normal file
120
tests/radeon_bo_test.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue